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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int A,B,C;
    cin >> A >> B >> C;
    
    if(A%2!=0 || B%2!=0 || C%2!=0){
        cout << 0 << endl;
        return 0;
    }
    
    if(A==B && B==C){
        cout << -1 << endl;
        return 0;
    }
    
    int ans = 0,s=0;
    while(A%2==0 && B%2==0 &&C%2==0){
        ans++;
        s = A+B+C;
        A = (s-A)/2;
        B = (s-B)/2;
        C = (s-C)/2;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		S = S.replaceAll("eraser", "");
        S = S.replaceAll("erase", "");
        S = S.replaceAll("dreamer", "");
        S = S.replaceAll("dream", "");
        if(S.length() == 0) {
        	System.out.println("YES");
        }else{
        	System.out.println("NO");
        }
	}
}

Measured memory_bytes: 29248
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<stack>

using namespace std;

void split(string s, vector<string> &v){
    int pre_pos = 0;
    while(pre_pos < s.size()){
        int pos = s.find(" ", pre_pos);
        if(pos == string::npos){
            v.push_back(s.substr(pre_pos));
            break;
        }
        v.push_back(s.substr(pre_pos, pos-pre_pos));
        pre_pos = pos + 1;
    }
}

int calc(int x, int y, string ope){
    if(ope.compare("+") == 0)
        return x + y;
    else if(ope.compare("-") == 0)
        return x - y;
    else if(ope.compare("*") == 0)
        return x * y;
    else
        throw "operation err";
}

int rpn(vector<string> &v){
    set<string> ope;
    ope.insert("+");
    ope.insert("-");
    ope.insert("*");
    int ans;
    stack<int> st;
    for(int i = 0; i < v.size(); i++){
        if(ope.find(v[i]) != ope.end()){
            int y = st.top(); st.pop();
            int x = st.top(); st.pop();
            ans = calc(x, y, v[i]);
            st.push(ans);
        }else{
            st.push(stoi(v[i]));
        }
    }
    return ans;
}

int main(){
    string s;
    getline(cin, s);
    vector<string> iv;
    split(s, iv);
    cout << rpn(iv) << endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

/*** chmax, chmin ***/
// a < b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b; 
		return true;
	}
	return false;
}
// a > b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b; 
		return true;
	}
	return false;
}
/*** chmax, chmin ここまで ***/

void Main()
{
	int l, r;
  	cin >> l >> r;
  	if(l+2019<=r) {
    	cout << 0 << endl;
      	return;
    }
  	l %= 2019;
  	r %= 2019;
  	int ans = 10000;
  	rep3(i,l,r-1){
    	rep3(j,i+1,r){
        	chmin(ans,(i*j)%2019);
        }
    }
  	cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
l = ['###','#.#','.#.','...']
ans = []
for i in range(a//30+1):
    if i==a//30:
        if a%30==0:
            ans[-2] = l[1]*29+l[0]
            break
        k = max(a%30-1,0)
        ans.append(l[1]*k+l[0]*(30-k))
        ans.append(l[0]*30)
        break
    ans.append(l[1]*30)
    ans.append(l[0]*30)
ans.append(l[3]*30)
for i in range(b//30+1):
    if i==b//30:
        if b%30==0:
            ans[-2] = l[2]*29+l[3]
            break
        k = max(b%30-1,0)
        ans.append(l[2]*k+l[3]*(30-k))
        ans.append(l[3]*30)
        break
    ans.append(l[2]*30)
    ans.append(l[3]*30)
print(len(ans),90)
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 3064
#include <cstdio>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

const int N = 5000*100;

bool Pierwsza[N];
map <long long,int> A;
map < pair <long long,long long>, int> Odw;
map <long long,long long> Pierw;
pair <long long,long long> Wsk[N];
int czy_szescian;

void Inicjuj(){
	int i,j;
	Pierwsza[1] = 1;
	for(i=2; i<N; i++){
		if(Pierwsza[i] == 0){
			j = i+i;
			Pierw[(long long)i*(long long)i] = i;
			while(j<N) {
				Pierwsza[j] = 1;
				j += i;
			}
		}
	}
}

long long GetA(long long x){
	long long i,res;
	i = 1;
	res = x;
	while(i*i*i <= x){
		if(x%(i*i*i) == 0) res = min(res,x/(i*i*i));
		i++;
	}
	return res;
}

long long GetB(long long x){
	long long a,b,i,res,ile;
	res = i = 1;
	a = 1; b = x;
	while(i*i*i <= b){
		ile = 0;
		while(Pierwsza[i]==0 && b%i == 0){
			a *= i;
			b /= i;
			ile++;
		}
		if(ile == 1) res *= i*i;
		if(ile == 2) res *= i;
		i++;
	}
	if(Pierw[b] != 0) res *= Pierw[b];
	else res *= b*b;
	return res;
}

void Wczytaj(int n){
	int i;
	long long x,a,b;
	for(i=0; i<n; i++){
		scanf("%lld", &x);
		a = GetA(x); 
		b = GetB(a);
		if(a==1 && b==1) czy_szescian = 1;
		A[a]++;
		Wsk[i] = make_pair(a,b);
		//printf("%lld %lld\n", a,b);
	}
}

void Policz(int n){
	int i;
	long long res;
	res = 0;
	for(i=0; i<n; i++){
		if(Odw[Wsk[i]] == 0 && !(Wsk[i].first == 1 && Wsk[i].second == 1)){
			Odw[Wsk[i]] = 1;
			Odw[make_pair(Wsk[i].second,Wsk[i].first)] = 1;
			res += max(A[Wsk[i].first],A[Wsk[i].second]);
		}
	}
	printf("%lld\n", res+czy_szescian);
}

int main(){
	int n;
	scanf("%d", &n);
	Inicjuj();
	Wczytaj(n);
	Policz(n);
	return 0;
}

Measured memory_bytes: 35968
import math
from itertools import permutations
N = int(input())

points = [tuple(map(int, input().split())) for _ in range(N)]

def dist(p1, p2):
    return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)

math.factorial(N)

d = 0
for p in permutations(range(N)):
    for p0, p1 in zip(p[:-1], p[1:]):
        d += dist(points[p0], points[p1])
print(d / math.factorial(N))


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    string n; cin >> n;
    int64_t x = 0;
    for(const char& c : n) {
        x += (int64_t)(c - '0');
    }
    cout << (x % 9 == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3780
# -*- coding: utf-8 -*-
r, d, x2000 = map(int, raw_input().split())
# 文字列の入力
#s = raw_input()
# 出力

def xiplus1(r,d,x,i):
    if(i < 2010):
        x = r*x - d
        print x
        xiplus1(r,d,x,i+1)

xiplus1(r,d,x2000,2000)

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

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


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

int
main(int argc, char *argv[])
{
    unsigned long long int n,a,b;
    int ok = 1;
    scanf("%lld%lld%lld",&n,&a,&b);
     unsigned long long int min = (n-1)*a + b;
    unsigned long long int max =(n-1)*b + a;
    
    if(a>b){
        ok = 0;
        
    }
    else if((a!=b) && n<=1){
        ok = 0;
    }
    else{
        printf("%lld\n",max-min+1);
    }
    if(ok == 0){
        printf("%d",0);
    }
        return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define bk back()
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(x,a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
    // cin.exceptions(cin.failbit);
    // throws exception when do smth illegal
    // ex. try to read letter into int
    if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int32_t main() {

    setIO();

    string S; cin >> S;

    cout << S.substr(0,3) << "\n";

}


Measured memory_bytes: 3656
#include <stdio.h> 
int main()
{
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d",&k);
    printf("%d\n",a[k-1]);
    return 0;
}

Measured memory_bytes: 760
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let t = read::<String>().chars().collect::<Vec<char>>();
    let q = read::<usize>();
    let mut query = vec![(0, 0, 0, 0); q];
    for i in 0..q {
        query[i].0 = read::<usize>() - 1;
        query[i].1 = read::<usize>() - 1;
        query[i].2 = read::<usize>() - 1;
        query[i].3 = read::<usize>() - 1;
    }
    let mut ssum = vec![0; s.len() + 1];
    for i in 0..s.len() {
        let v = if s[i] == 'A' { 1 } else { 2 };
        ssum[i + 1] = ssum[i] + v;
    }
    let mut tsum = vec![0; t.len() + 1];
    for i in 0..t.len() {
        let v = if t[i] == 'A' { 1 } else { 2 };
        tsum[i + 1] = tsum[i] + v;
    }
    for i in 0..q {
        if (ssum[query[i].1 + 1] - ssum[query[i].0]) % 3
            == (tsum[query[i].3 + 1] - tsum[query[i].2]) % 3
        {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


Measured memory_bytes: 10748
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

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

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

int main()
{
    int a,b,ans;
	double c,d;
    while(scanf("%d %d",&a, &b) != EOF)
	{
		c=(double)(a+b);
		d=log10(c);
		ans=((int) d)+1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int T;
  map<char,int> data;
  data['R']=0;
  data['G']=1;
  data['B']=2;
  cin >> T;
  for(int i=0;i<T;i++){
    int RGB[3][15]={0},cnt=0;
    int CARD[10];
    char COLOR[10];
    for(int j=0;j<9;j++){
      cin >> CARD[j];
    }
    for(int j=0;j<9;j++){
      cin >> COLOR[j];
    }
    for(int j=0;j<9;j++) RGB[data[COLOR[j]]][CARD[j]]++;

    for(int k=0;k<3;k++){
      for(int j=0;j<=9;){
	if(RGB[k][j]>=3)RGB[k][j]-=3,cnt++;
	else if(RGB[k][j]>0&&RGB[k][j+1]>0&&RGB[k][j+2]>0){
	  RGB[k][j]--,RGB[k][j+1]--,RGB[k][j+2]--,cnt++;
	} else j++;
      }
    }
    if(cnt==3)printf("1\n");
    else printf("0\n");
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    vector<long long int> v(n, 0);
    unordered_map<int, int> um;
    um[0] = 1;
    long long int res = 0;
    long long int c = 0;
    for (int i = 0; i < n; i++) {
    	cin >> v[i];
    	c += v[i];
    	res += um[c % m];
    	um[c % m]++;
    }
    cout << res << endl;
}


Measured memory_bytes: 7404
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.next();
		int x = 700;

		if (string.charAt(0) == 'o') {
			x += 100;
		}
		if (string.charAt(1) == 'o') {
			x += 100;
		}
		if (string.charAt(2) == 'o') {
			x += 100;
		}

		System.out.println(x);
	}
}


Measured memory_bytes: 21716
def main():
    n, t = list(map(int, input().split()))
    shower = list(map(int, input().split()))
    seconds = 0
    for i in range(len(shower) - 1):
        if shower[i + 1] - shower[i] < t:
            seconds += shower[i + 1] - shower[i]
        else:
            seconds += t
    print(seconds + t)


if __name__ == '__main__':
    main()

Measured memory_bytes: 26708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
const int maxm = 2e6+7;
const ll mod = 1e9+7;
int n,m;
bool vis[maxn][3];
vector<int> g[maxn];
int d[maxn][3];
priority_queue<pair<int, int>> qu;
int main()
{
    memset(d, -1, sizeof(d));
    scanf("%d%d", &n, &m);
    for(int i=1;i<=m;i++){
        int a,b;scanf("%d%d",&a,&b);
        g[a].push_back(b);
    }
    int s,t;
    scanf("%d%d", &s, &t);
    qu.push(make_pair(0, s*3));
    int ans = -1;
    while(!qu.empty()){
        int dis = -qu.top().first, u = qu.top().second/3, ins = qu.top().second%3;qu.pop();
        if(u == t && ins == 0){
            ans = dis;
            break;
        }
        vis[u][ins] = 1;
        for(int v : g[u]){
            int nins = ins+1;
            int ndis = dis;
            if(nins==3){
                nins=0;
                ndis++;
            }
            if(!vis[v][nins]){
                vis[v][nins]=1;
                qu.push(make_pair(-ndis, v*3+nins));
            }
        }
    }
    printf("%d\n", ans);


    return 0;
}


Measured memory_bytes: 40192
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>
using ll = long long;
using namespace std;

using Tu = tuple<int, int, int>;
int arr[101];
int main(void)
{
    int N;
    cin >> N;
    set<Tu> s;
    for (int i = 1; i <= N; ++i)
    {
        int t = i;
        for (int j = 2; j <= 100; ++j)
        {
            while (t % j == 0)
            {
                arr[j]++;
                t /= j;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= 50; ++i)
        if (arr[i] >= 74)
            ans++;

    for (int i = 1; i <= 50; ++i)
    {
        for (int j = 1; j <= 50; ++j)
        {
            if (i == j)
                continue;

            if (arr[i] >= 2 && arr[j] >= 24)
                ans++;
            if (arr[i] >= 14 && arr[j] >= 4)
                ans++;
        }
    }

    for (int i = 1; i <= 50; ++i)
    {
        for (int j = 1; j <= 50; ++j)
        {
            if (i == j)
                continue;
            for (int k = j + 1; k <= 50; ++k)
            {
                if (i == k || j == k)
                    continue;

                if (arr[i] >= 2 && arr[j] >= 4 && arr[k] >= 4)
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s, t;
    cin >> s >> t;
    vector<int> as(s.size() + 1, 0), at(t.size() + 1, 0);
    
    rep(i, s.size()){
        if(s[i] == 'A'){
            as[i + 1] = as[i] + 1;
        }
        else{
            as[i + 1] = as[i] + 2;
        }
    }
    rep(i, t.size()){
        if(t[i] == 'A'){
            at[i + 1] = at[i] + 1;
        }
        else{
            at[i + 1] = at[i] + 2;
        }
    }
    
    int Q;
    cin >> Q;
    rep(q, Q){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int qs = as[b] - as[a - 1];
        int qt = at[d] - at[c - 1];
//        cout << qs << "," << qt << endl;
        if((qs - qt) % 3 == 0) output("YES");
        else output("NO");
    }
    
    return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n, k;
	char Ck;
	string s;
	cin >> n >> s >> k;
	Ck = s[k-1];
	for (int i = 0; i < n; i++) {
		if (s[i] != Ck) {
			s[i] = '*';
		}
	}
	cout << s << endl;
	cin >> n;
	return 0;
}

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


int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<int> ans(n);
	
	rep(rp,2){
		// solve R
		int cnt = 0;
		
		rep(i,n){
			if(s[i] == 'R') cnt++;
			else{
				ans[i] += cnt/2;
				ans[i-1] += (cnt+1)/2;
				cnt = 0;
			}
		}
		
		reverse(s.begin(), s.end());
		reverse(ans.begin(), ans.end());
		
		rep(i,n){
			if(s[i] == 'R') s[i] = 'L';
			else s[i] = 'R';
		}
	}
	
	rep(i,n){
		printf("%d%c", ans[i], i==n-1? '\n' : ' ');
	}

  
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	int a[55];
	string s[55];
	rep(i, n) {
		cin >> s[i] >> a[i];
	}
	string x;
	cin >> x;
	int ans = 0;
	bool bou = false;
	rep(i,n){
		if (bou) {
			ans += a[i];
		}
		if (s[i] == x) bou = true;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] num = sc.nextLine().split("", 0);



		switch(num[num.length - 1]) {
		case "2":
		case "4":
		case "5":
		case "7":
		case "9":
			System.out.println("hon");
			break;
		case "0":
		case "1":
		case "6":
		case "8":
			System.out.println("pon");
			break;
		case "3":
			System.out.println("bon");
			break;
		}

	}
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d) cout << "Yes" << endl;
    else if(abs(a - b) <=d && abs(b - c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main(){
	int l,m,n;
	while(cin>>l){
		int flag=0;
		if(l==0)break;
		for(int i=1;i<=12;i++){
			cin>>m>>n;
			l=l-(m-n);
			if(l<=0&&flag==0){
				cout<<i<<endl;
				flag=1;
			}
		}
		if(flag==0)cout<<"NA"<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 2956
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int a, b, c, k; cin >> a >> b >> c >> k;

	REP(k) {
		if (a >= b) b *= 2;
		else c *= 2;
		if (a < b && b < c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

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


using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

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

    if(N%2==1)
        printf("%d\n",N/2);
    else
        printf("%d\n",N/2-1);
    
    return 0;
}

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

int main(){
  int c,l,ms;
  string s,s2,s2fr,s2br;
  set<string> m;
  cin>>c;
  for(int i=0;i<c;i++){
    cin >>s;
    l=s.size();
    for(int j=1;j<l;j++){
      s2=s;
      m.insert(s2);
      s2.clear();

      s2.append(&s[j],&s[l]);s2.append(&s[0],&s[j]);
      m.insert(s2);
      s2.clear();

      s2fr.clear();
      s2br.clear();
      for(int k=j;k>0;k--){
	s2fr+=s[k-1];
      }
      for(int k=l;k>j;k--){
	s2br+=s[k-1];
      }
 
      s2+=s2fr;s2.append(&s[j],&s[l]);
      m.insert(s2);
      s2.clear();

      s2.append(&s[j],&s[l]);s2+=s2fr;
      m.insert(s2);
      s2.clear();

      s2.append(&s[0],&s[j]);s2+=s2br;
      m.insert(s2);
      s2.clear();

      s2+=s2br;s2.append(&s[0],&s[j]);
      m.insert(s2);
      s2.clear();

      s2=s2fr+s2br;
      m.insert(s2);
      s2.clear();

      s2=s2br+s2fr;
      m.insert(s2);
      s2.clear();
    }
    ms=m.size();
    cout<<ms<<endl;
    m.clear();
  }
  return 0;
}

Measured memory_bytes: 1292
N = int(input())
A = list(map(int, input().split()))
A.append(0)

ans = [None] * (N+1)
ans[0] = abs(0 - A[0])
for i in range(N):
  ans[i+1] =  abs(A[i] - A[i+1])
  
ansS = sum(ans)

for i in range(N):
  if i == 0:
    tmp = abs(A[1])
  else:
    tmp = abs(A[i+1] - A[i-1])
  print(ansS - ans[i] - ans[i+1] + tmp)

Measured memory_bytes: 14048
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int H, W;
int c[10][10];
void solve() {
    cin >> H >> W;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if (c[i][j] > c[i][k] + c[k][j]) {
                    c[i][j] = c[i][k] + c[k][j];
                }
            }
        }
    }
    int num = 0;
    int ans =  0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> num;
            if (num >= 0) {
                ans += c[num][1];
            }
        }
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);	
}
int main(){
	fastio;
	//fopen();
	int n;
	cin>>n;
	if(!(n%2)){cout<<(n-2)/2;}
	else{cout<<(n-1)/2;}

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.nextLine());
        String[] subs = scan.nextLine().split(" ");
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < subs.length; i++) {
            int val = Integer.valueOf(subs[i]);
            if (map.containsKey(val)) map.replace(val, map.get(val) + 1);
            else map.put(val, 1);
        }
        
        for (int i = 1; i <= n; i++) {
            if (map.containsKey(i)) System.out.println(map.get(i));
            else System.out.println(0);
        }
    }
}

Measured memory_bytes: 87388
from collections import deque
import copy
def check(y,x):
    if 0<=y<=h-1 and 0<=x<=w-1:
        return True
    return False

h,w,n=map(int,raw_input().split())
g=[[] for _ in xrange(h)]
for i in xrange(h):
    r=raw_input()
    for j in xrange(w):
        if r[j]=="S":
             sy,sx=i,j
        g[i].append(r[j])
d=[[0]*w for i in xrange(h)]
d1=copy.deepcopy(d)
visited=[[0]*w for i in xrange(h)]
visited1=copy.deepcopy(visited)
dx=(1,0,-1,0)
dy=(0,1,0,-1)
q=deque([(sy,sx)])
ans=0
for i in xrange(1,n+1):
    f=0
    while len(q)!=0:
        y,x=q.popleft()
        visited1[y][x]=2
        for j in xrange(4):
            nexty=y+dy[j]
            nextx=x+dx[j]
            if not check(nexty,nextx):continue
            if g[nexty][nextx]!="X" and visited1[nexty][nextx]==0:
                q.append((nexty,nextx))
                d1[nexty][nextx]=d1[y][x]+1
                visited1[nexty][nextx]=1
                if g[nexty][nextx]==str(i):
                    ans+=d1[nexty][nextx]
                    q=deque([(nexty,nextx)])
                    visited1=copy.deepcopy(visited)
                    d1=copy.deepcopy(d)
                    f=1
                    break
        if f==1:break
print(ans)

Measured memory_bytes: 63672
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int N = sc.nextInt();
		Set<Integer> p = new HashSet<>();
		for(int i = 0; i < N; i++)
			p.add(sc.nextInt());
		int ans = 0, min = Integer.MAX_VALUE/2;
		for(int i = -100; i <= 200; i++)
			if(!p.contains(i) && Math.abs(i-X) < min) {
				ans = i;
				min = Math.abs(i-X);
			}
		System.out.println(ans);
	}

}

Measured memory_bytes: 36100
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long h=sc.nextLong(),w=sc.nextLong();
		if(h==1 || w==1) {
			System.out.println(1);
		}
		else if(h%2==0) {
			System.out.println((long)((Math.ceil(h/2.0)*w)));
		}else {
			System.out.println((long)(Math.ceil(h/2.0)*Math.ceil(w/2.0)+(h/2)*(w/2)));
		}
	}
}


Measured memory_bytes: 23252
s = list(input())
K = int(input())

res = []
charGram = [[''.join(s[i:i + n]) for i in range(len(s) + 1 - n)] for n in range(1,K + 1)]

for i in range(len(charGram)):
    res += charGram[i]

res = sorted(set(res))
print(res[K - 1])


Measured memory_bytes: 5236
import java.util.*;
import java.io.BufferedInputStream;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner (new BufferedInputStream(System.in));
    int n = sc.nextInt();
    int[] num = new int[n];
    long[] count = new long[n + 1];
    for(int i = 0; i < n; ++i) {
      num[i] = sc.nextInt();
      count[num[i]]++;
    }
    long res = 0;
    for(int i = 0; i <= n; ++i) {
        if(count[i] > 1) res += count[i] * (count[i] - 1) / 2;
    }
    for(int i = 0; i < n; ++i) {
        if(count[num[i]] < 2) System.out.println(res);
        else System.out.println(res - count[num[i]] * (count[num[i]] - 1) / 2 + (count[num[i]] - 1)* (count[num[i]] - 2) / 2);
    }
  }
}

Measured memory_bytes: 119784
N = int(input())
S = list(input())

num_r = S.count('R')
num_g = S.count('G')
num_b = N - num_r - num_g
C = [[num_r, num_g, num_b] for _ in range(N)]
r_cnt, g_cnt, b_cnt = 0, 0, 0

for i in range(N):
    if S[i] == 'R':
        r_cnt += 1
    elif S[i] == 'G':
        g_cnt += 1
    else:
        b_cnt += 1

    C[i][0] -= r_cnt
    C[i][1] -= g_cnt
    C[i][2] -= b_cnt

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] != S[j]:
            if 'R' not in [S[i], S[j]]:
                ans += C[j][0]
                if j+(j-i) < N and S[j+(j-i)]=='R':
                    ans -= 1
            if 'G' not in [S[i], S[j]]:
                ans += C[j][1]
                if j+(j-i) < N and S[j+(j-i)]=='G':
                    ans -= 1
            if 'B' not in [S[i], S[j]]:
                ans += C[j][2]
                if j+(j-i) < N and S[j+(j-i)]=='B':
                    ans -= 1

        #print(S[i], S[j], ans)

print(ans)

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

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

void solve(){
  int64 a,b,c,d;
  cin >> a >> b >> c >> d;
  if(b > d || a < b){
    Yes(false);
    return;
  }
  int64 g = gcd(b,d);
  int64 mn = llinf;
  if(a < (c+1)){
    mn = a;
  }else{
    mn = a - (a - c - 1) / g * g;
  }
  Yes(mn-b>=0);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 t;
  cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1e8;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef unsigned long long ll;
struct edge
{
	int to;
	int cost;
	edge(){}
	edge(int _to,int _cost){
		to = _to;
		cost = _cost;
	}
};
struct node
{
	int to;
	int cost;
	int blood;
	node(){}
	node(int _to,int _cost,int _blood){
		to = _to;
		cost = _cost;
		blood = _blood;
	}
	bool operator<(const node &a)const{
		return cost > a.cost;
	}
};

vector < edge > graph[128];
int main(){
	int N,M,L,K,S,G;
	while(scanf("%d %d %d %d %d %d",&N ,&M ,&L ,&K, &S, &G),N){
		rep(i,128){
			graph[i].clear();
		}
		bool add_place[128]={false};
		rep(i,L){
			int tmp;
			scanf("%d" ,&tmp);
			add_place[tmp] = true;
		}
		rep(i,K){
			int a,b,c;
			scanf("%d %d %d" ,&a ,&b ,&c);
			graph[a].PB(edge(b,c));
			graph[b].PB(edge(a,c));
		}

		priority_queue < node > Q;
		Q.push(node(S,0,M));
		int memo[128][128];
		rep(i,128){
			rep(j,128){
				memo[i][j] = INF;
			}
		}


		int ans = -1;
		while( !Q.empty() ){
			node e = Q.top();Q.pop();
			if(memo[e.to][e.blood] != INF)continue;
			memo[e.to][e.blood] = e.cost;
			if(e.to == G){
				ans = e.cost;
				break;
			}

			if(add_place[e.to] && e.blood < M){
				Q.push(node(e.to,e.cost+1,e.blood+1));
			}

			rep(i,graph[e.to].size()){
				edge n = graph[e.to][i];
				if(e.blood - n.cost >= 0){
					Q.push(node(n.to,e.cost + n.cost,e.blood - n.cost));
				}

			}

		}

		if(ans != -1)printf("%d\n",ans);
		else puts("Help!");
	}
    return 0;
}

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

void solve_A(){
	//AAAAAAAAAA
	int a,b;
	cin >> a >> b;
	cout << max(0,a-2*b) << endl;
}

void solve_B(){
	//BBBBBBBBBB
	int n,i,d[100],sum=0,sum2=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> d[i];
		sum+=d[i];
		sum2+=(d[i]*d[i]);
	}
	cout << (sum*sum-sum2)/2 << endl;
}

void solve_C(){
	//CCCCCCCCCC
	int n,i,ans=1;
	char s[100005];
	cin >> n >> s;
	for(i=1;i<n;i++) if(s[i-1]!=s[i]) ans++;
	cout << ans << endl;
}

void solve_D(){
	//DDDDDDDDDD
	long long n,i,j,l,m,ans=0;
	vector<long long> g;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> l;
		g.push_back(l);
	}
	sort(g.begin(),g.end());
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			m=g[i]+g[j];
			ans += (n-(lower_bound(g.begin(),g.end(),m)-g.begin()));
		}
	}
	cout << n*(n-1)*(n-2)/6 - ans << endl;
}

int main() {
	// your code goes here
	//solve_A();
	//solve_B();
	//solve_C();
	solve_D();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
vector<ll> vec;
ll lower(ll first,ll last,ll a){
  ll mid;
  while(first < last){
    mid = (first+last)/2;
    if(vec[mid] < a){
      first = mid + 1;
    }else{
      last = mid;
    }
  }
  if(vec[first] < a){
    return first;
  }else{
    return first-1;
  }
}
int main(){
  ll n;
  cin >> n;
  ll a[n];
  ll size=0;
  ll first,last;
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    if(i == 0 || a[i] <= vec[0]){
      vec.insert(vec.begin(),a[i]);
      size++;
    }else{
      first=0;
      last=size-1;
      auto itr = lower_bound(all(vec),a[i]);
      itr--;
      //MSG(*itr);
      *itr = a[i];
    }

    rep(j,size){
      //cout << vec[j] << " ";
    }
    //cout << endl;
  }
  cout << size;
}


Measured memory_bytes: 2168
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    if (s[0] == '7' || s[2] == '7' || s[1] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 300000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

vector<edge> G[20000];
int level[20000];
int iter[20000];
int res[500000];
int n;

void add_edge(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

int x[501];
vector<int> xs;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
		x[i]--;
		xs.push_back(x[i]);
	}
	xs.push_back(-1);
	xs.push_back(n*n);
	int s=10*n,t=s+1;
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=0;i+1<xs.size();i++){
		if(xs[i+1]-xs[i]>1){
			add_edge(5*n+i,t,xs[i+1]-xs[i]-1);
		}
	}
	for(int i=0;i<n;i++){
		add_edge(s,i,n);
		if(i>0){
			add_edge(i,n+i,i);
			for(int j=0;j+1<xs.size();j++){
				if(xs[j+1]<=x[i])add_edge(n+i,5*n+j,xs[j+1]-xs[j]-1);
			}
		}
		add_edge(i,n*2+i,1);
		add_edge(n*2+i,n*4+i,1);
		if(i<n-1){
			add_edge(i,3*n+i,n-i-1);
			for(int j=0;j+1<xs.size();j++){
				if(xs[j]>=x[i])add_edge(3*n+i,5*n+j,xs[j+1]-xs[j]-1);
			}
		}
	}
	for(int i=0;i<n;i++){
		add_edge(4*n+i,t,1);
	}
	if(max_flow(s,t)==n*n){
		printf("Yes\n");
		for(int i=0;i<n;i++){
			res[x[i]]=i;
		}
		for(int i=0;i+1<xs.size();i++){
			int cnt=0;
			for(int j=0;j<G[5*n+i].size();j++){
				if(G[5*n+i][j].cap!=0){
					int va=G[5*n+i][j].cap;
					for(int l=0;l<va;l++){
						res[xs[i]+1+cnt+l]=G[5*n+i][j].to%n;
					}
					cnt+=va;
				}
			}
		}
		for(int i=0;i<n*n;i++){
			printf("%d%c",res[i]+1,i==n*n-1?'\n':' ');
		}
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 9984
import math

def RotationMatrix(theta):
    '''
    theta in degree
    '''
    c = math.cos(theta*math.pi/180)
    s = math.sin(theta*math.pi/180)
    mat = [[c,-s],[s,c]]
    return mat

def Rotate60(vec):
    mat = RotationMatrix(60)
    result_vec = []
    result_vec.append(mat[0][0]*vec[0] + mat[0][1]*vec[1])
    result_vec.append(mat[1][0]*vec[0] + mat[1][1]*vec[1])
    return result_vec

def get_points(a_vec,b_vec):
    s_vec = [(2*a+b)/3 for (a,b) in zip(a_vec, b_vec)]
    t_vec = [(a+2*b)/3 for (a,b) in zip(a_vec, b_vec)]
    u_vec = [(b-a)/3 for (a,b) in zip(a_vec,b_vec)]
    u_vec = Rotate60(u_vec)
    u_vec = [s+u for (s,u) in zip(s_vec,u_vec)]
    return s_vec, t_vec, u_vec

def get_koch(A, n,cnt, a_vec,b_vec):
    if cnt >= n:
        return
    else:
        cnt += 1
        s_vec, t_vec, u_vec = get_points(a_vec,b_vec)
        get_koch(A, n,cnt, a_vec, s_vec)
        A.append(s_vec)
        get_koch(A, n,cnt, s_vec, u_vec)
        A.append(u_vec)
        get_koch(A, n,cnt, u_vec, t_vec)
        A.append(t_vec)
        get_koch(A, n,cnt, t_vec, b_vec)
        
        
n = int(input())
cnt = 0
a_vec = [0,0]
b_vec = [100,0]
A = []
A.append(a_vec)
get_koch(A, n,cnt, a_vec,b_vec)
A.append(b_vec)
for a in A:
    print(*a)


Measured memory_bytes: 6416
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define YES cout << "YES" << endl
#define NO  cout << "NO"  << endl
#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 100001
using namespace std;
typedef long long ll;

int main(){
  string s; cin >> s;
  int minN = 100100100;
  rep(i, 0, s.length()-2){
    int tmp = abs(753 - stoi(s.substr(i, 3)));
    if(minN > tmp){
      minN = tmp;
    }
  }
  cout << minN << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> xx, yy;

char s[8001];
int dpx[2][16001], dpy[2][16001];

int main() {
	scanf("%s", s);
	int n = strlen(s);

	int x, y;
	scanf("%d %d", &x, &y);

	int cnt = 0;
	int bit = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'F') cnt++;
		else {
			if (bit == 0) xx.push_back(cnt);
			else yy.push_back(cnt);
			cnt = 0;
			bit ^= 1;
		}
	}
	if (bit == 0) xx.push_back(cnt);
	else yy.push_back(cnt);

	x -= xx[0];
	xx.erase(xx.begin());

	x += 8000; y += 8000;
	dpx[1][8000] = 1;
	dpy[1][8000] = 1;
	
	for (int i = 0; i < sz(xx); i++) {
		for (int j = 0; j <= 16000; j++) {
			if (j - xx[i] >= 0 && dpx[(i + 1) & 1][j - xx[i]])
				dpx[i & 1][j] = 1;
			if (j + xx[i] <= 16000 && dpx[(i + 1) & 1][j + xx[i]])
				dpx[i & 1][j] = 1;
		}
		memset(dpx[(i + 1) & 1], 0, sizeof(dpx[0]));
	}

	for (int i = 0; i < sz(yy); i++) {
		for (int j = 0; j <= 16000; j++) {
			if (j - yy[i] >= 0 && dpy[(i + 1) & 1][j - yy[i]])
				dpy[i & 1][j] = 1;
			if (j + yy[i] <= 16000 && dpy[(i + 1) & 1][j + yy[i]])
				dpy[i & 1][j] = 1;
		}
		memset(dpy[(i + 1) & 1], 0, sizeof(dpy[0]));
	}

	if (dpx[sz(xx) & 1 ^ 1][x] && dpy[sz(yy) & 1 ^ 1][y]) return !printf("Yes");
	else printf("No");
}

Measured memory_bytes: 640
/**
 * author: BueVonHun 🐼🎋
 * More Info: https://github.com/Bue-von-hon
**/

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>

typedef long long ll;
using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define X first
#define Y second

template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
template<class T> void read(T& x) {cin >> x;}

int tc;
int main(void) {
    fast_cin();

    int d,t,s;
    cin >> d >> t >> s;

    float a = d/s;
    if (d%s!=0) a+=0.1;

    if (a <=t) cout << "Yes";
    else cout << "No";

    return 0;
}


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

const int Maxn = 100005;
int n, ct, cnt, head[Maxn], dep[Maxn], p[Maxn], deg[Maxn], ans[Maxn], ans2[Maxn];
bool vis[Maxn];
struct edg
{
	int nxt, to;
}edge[2 * Maxn];
void add(int x, int y)
{
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
void dfs(int u, int fa)
{
	dep[u] = dep[fa] + 1;
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
			dfs(to, u);
	}
}
void dfs2(int u, int fa, int dep)
{
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
		{
			dfs2(to, u, dep - 1);
			if (ct)
			{
				p[++ct] = u;
				return ;
			}
		}
	}
	if (!dep) p[++ct] = u;
}
void print(int now[])
{
	for (int i = 1; i <= n; i++)
		printf("%d ", now[i]);
	exit(0);
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y);
		add(y, x);
	}
	dfs(1, 0);
	int root = 0, maxi = 0;
	for (int i = 1; i <= n; i++)
		if (dep[i] > maxi) maxi = dep[i], root = i;
	dfs(root, 0);
	for (int i = 1; i <= n; i++)
		if (dep[i] > maxi) maxi = dep[i], root = i; 
	dfs2(root, 0, maxi - 1);
	for (int i = 1; i <= ct; i++)
		vis[p[i]] = true;
	for (int u = 1; u <= n; u++)
	{
		if (vis[u]) continue;
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (!vis[to])
			{
				puts("-1");
				return 0;
			}
			deg[to]++;
		}
	}
	int now = 0;
	for (int i = 1; i <= ct; i++)
	{
		for (int j = now + 1; j <= now + deg[p[i]]; j++)
			ans[j] = j + 1;
		now += deg[p[i]] + 1;
		ans[now] = now - deg[p[i]];
	}
	reverse(p + 1, p + 1 + ct);
	now = 0;
	for (int i = 1; i <= ct; i++)
	{
		for (int j = now + 1; j <= now + deg[p[i]]; j++)
			ans2[j] = j + 1;
		now += deg[p[i]] + 1;
		ans2[now] = now - deg[p[i]];
	}
	for (int i = 1; i <= n; i++)
		if (ans[i] > ans2[i])
			print(ans2);
		else if (ans[i] < ans2[i])
			print(ans);
	print(ans); 
	return 0;
}

Measured memory_bytes: 9088