akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    }
}

Measured memory_bytes: 65708
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int rev(int n)
{
    int ans = 0;
    while(n)
    {
        ans += n % 10;
        ans *= 10;
        n /= 10;
    }
    ans /= 10;
    return ans;
}
int main()
{
    ll a, b, cnt = 0;
    cin >> a >> b;
    for(ll i = a; i <= b; i ++)
    {
        if(i == rev(i))
        {
            cnt ++;
        }
    }
    cout << cnt;
}


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

using namespace std;
int num[1005];
int main()
{
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++)
        scanf("%d",&num[i]);
    sort(num,num+n);
    int all=0;
    for(int i=0;i<k;i++)
        all+=num[i];
    cout << all;
    return 0;
}


Measured memory_bytes: 3688
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a <= k and d - a <= k and b - e <= k and d - b <= k and e - c <= k and d - c <= k:
    print("Yay!")
else:
    print(":(")

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

using namespace std;

int main(){
	
	int a,b,sum,sub,mlt, inst;
	
	cin >> a >> b ;
	
	sum = a+b;
	sub = a-b;
	mlt = a*b;
	
	inst = sum;
	
	if (inst <= sub) inst = sub;
	if (inst <= mlt) inst = mlt;
	
	cout << inst << endl;
	
	
	
	
	
}


Measured memory_bytes: 256
import sys

X, Y = list(map(lambda x: int(x), list(input().split())))

if (X + Y) % 3 != 0:
    print(0)
    sys.exit(0)

a = int((X+Y)/3)
b = 0
while True:
    if a*2 + b == Y:
        break
    elif a == 0:
        print(0)
        sys.exit(0)

    b += 1
    a -= 1

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

r = cmb(a+b,a)%(10**9+7)

print(r)

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

int main()
{
    int T=0,H=0,N;
    string A,B;
    cin>>N;

    for(int i=1;i<=N;i++){
        cin>>A>>B;

        if(A>B){
            T+=3;
        }else if(A==B){
            T+=1;
            H+=1;
        }else{
            H+=3;
        }
    }

    cout<<T<<" "<<H<<endl;

    return 0;
}


Measured memory_bytes: 3168
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, K;
    cin >> N >> K;

    vector<pair<int, int>> v(N);
    REP(i, N) {
        int t, d;
        cin >> t >> d;
        v[i] = {d, t};
    }
    sort(v.begin(), v.end(), greater<P>());


    priority_queue<P, vector<P>, greater<P>> big;
    priority_queue<P> small;
    map<int, int> kind;

    int ans = 0;
    REP(i, N) {
        if (i < K) {
            big.push(v[i]);
            kind[v[i].second]++;
            ans += v[i].first;
        } else {
            small.push(v[i]);
        }
    }
    int size = kind.size();
    ans += size * size;

    map<int, int> kans;
    kans[size] = ans;
    while (!small.empty() && !big.empty()) {
        auto kvb = big.top();
        if (kind[kvb.second] == 1) {
            big.pop();
            continue;
        }
        auto kvs = small.top();
        if (kind[kvs.second] > 0) {
            small.pop();
            continue;
        }

        int tmp = kans[size] - kvb.first + kvs.first + (size + 1) * (size + 1) - size * size;
        ans = max(ans, tmp);

        size++;
        kans[size] = tmp;
        big.pop();
        small.pop();
        kind[kvs.second]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
bool isOK(string s){
    int n=s.size();
    if(n==1) return true;
    else{
        bool flag=true;
        For(i,0,n/2){
            flag=(s[i]==s[n-1-i]?flag:false);
        }
        return flag;
    }
}
void Main(){
    string s;cin>>s;
    int n=s.size();
    bool flag=true;
    flag&=isOK(s);
    string s2;
    For(i,0,n/2) s2+=s[i];
    flag&=isOK(s2);
    cout<<(flag?"Yes":"No")<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split(' '))
a_min = -(-a // 0.08)
a_max = (a + 1) // 0.08
b_min = -(-b // 0.1)
b_max = (b + 1) // 0.1
if(a_max < b_min or b_max < a_min):
    print(-1)
elif(a_min <= b_min):
    print(int(b_min))
elif(b_min <= a_min):
    print(int(a_min))


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

int main() {
  ll n, k;
  cin >> n >> k;
  
  ll ans = 1;
  while (pow(k, ans) <= n) {
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
main(){
    long long N;
    scanf("%lld",&N);
    long long max = (N+49)/50+49;
    //50
    int step = (50-N%50)%50;
    long long num[50];
    for(int i = 0;i < 50;i++){
        num[i] = max;
    }
    for(int i = 0;i < step;i++){
        for(int j = 0;j < 50;j++){
            num[j]++;
        }
        num[i] -= 51;
    }

    printf("50\n");
    for(int i = 0;i < 50;i++){
        printf("%lld ",num[i]);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<tuple>
#define MAX 1000007
#define MP make_pair
#define ii long long
#define dd double
#define MAX_SIZE 1e7
#define mod 1000000007
#define gc getchar_unlocked
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define REP(i, b, n) for (long long i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)  ..> ||
#define w(x) int x; cin>>x; while(x--)
#define inp(tmp) ii tmp; cin>>tmp
#define DBG 0
#define print if(DBG)
using namespace std;
typedef pair<ii, ii>	pii;
typedef pair<ll, ll>	pl;
typedef vector<ii>		vi;
typedef vector<ll>		vl;
typedef vector<string>	vs;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef pair<int,vi>	Node;

ii n,m;
vi par;
ii find_set(ii v) {
    if (v == par[v])
        return v;
    return par[v]=find_set(par[v]);
}

void con(ii a, ii b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
        par[b] = a;
}
int main() {
    cin>>n>>m;
    par.pb(-1);
    REP(i,1,n+1){
        par.pb(i);
    }

    rep(i,m){
        inp(x); inp(y);
        con(x,y);
    }
    ii comp=0;
    REP(i,1,n+1){
        if(par[i]==i){ print cout<<i<<" is main "; comp++; }
    }
    cout<<comp-1;
	cin>>n;
}
/*
3 1
1 2

*/


Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d,an=0;
  cin>>n>>d;
  for(int i=0,a;i<n;i++){
    cin>>a;
    an+=max(0,a-d);
  }
  if(an)cout<<an<<endl;
  else cout<<"kusoge"<<endl;
  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl;
#define ios cin.tie(0); ios_base::sync_with_stdio(0)
 
using namespace std;
using namespace __gnu_pbds;
 
// order_of_key
// find_by_order
// tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ja;
string s;
string wzor = "AKIHABARA";

int main() {				 
	ios;
	cin >> s;
	int n = ss(s);
	int wsk = 0;
	FOR(i, 0, n - 1) {
		if(wsk >= ss(wzor)) {
			cout << "NO";
			return 0;
		}
		if(s[i] == wzor[wsk])
			wsk += 1;
		else if(wzor[wsk] != 'A') {
			cout << "NO";
			return 0;
		}
		else {
			wsk += 1;
			i -= 1;
		}
	}
	
	if(wsk == ss(wzor) || wsk == ss(wzor) - 1)
		cout << "YES";
	else
		cout << "NO";
		
	
	
	return 0;
}
		


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    int A[N];
    REP(i, N) cin >> A[i];

    vector<pi> ret(N);
    REP(i, N) ret[i] = mp(A[i], i+1);

    sort(ret.begin(), ret.end());

    REP(i, N) cout << ret[i].second << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<int> vec(26,100);

  rep(i,n){
    vector<int> tmp(26,0);
    string s;
    cin>>s;
    for(char c : s) tmp[c-'a']++;
    rep(j,26) vec[j] = min(vec[j], tmp[j]);
  }

  rep(i,26) rep(j,vec[i]) cout << (char)('a'+i);
  cout<<endl;

  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,d,i,count=0;
  cin >>N;
  vector<int> vec(101);
  
  for(i=0;i<N;i++){
    cin >> d;
    vec.at(d)=1;
  }
  for(i=0;i<101;i++){
    if(vec.at(i)==1) count++;
  }
  cout<< count<<endl; 
}

Measured memory_bytes: 256
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
l = make_divisors(s)
l.sort(reverse=True)
for i in l:
    l2 = [j % i for j in a]
    l2.sort(reverse=True)
    m = sum(l2) - sum(l2[:sum(l2)//i])
    if i == 1:
        m = 0
    if m <= k:
        s = i
        break
print(s)

Measured memory_bytes: 9288
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc;
vector<ll> va,vb,vc;

int main(){
    cin>>a;
    
    C(a>=1200 ? "ARC":"ABC");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

int main() {
    ll a, b, c, d, ac, ad, bc, bd, ans;
    cin >> a >> b >> c >> d;
    ac = a * c;
    ad = a * d;
    bc = b * c;
    bd = b * d;
    ans = max(ac, max(ad, max(bc, bd)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		int[] l = sc.nextIntArray(n);
		Arrays.sort(l);
		int max = l[n-1];
		int sum = 0;
		for(int i =0; i < n-1; i++)
			sum += l[i];
		System.out.println(max < sum ? "Yes" : "No");
	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define endl "\n"
#define ioss ios::sync_with_stdio(false);cin.tie(NULL);
typedef  long long ll;
using namespace std;


int main()
{
    ioss
    int n,l;cin>>n>>l;
    vector <string> v;
    for(int i=0;i<n;i++)
    {
        string c;cin>>c;
        v.push_back(c);
    }
    string ans="";
    //for(string s:v)cout<<s<<endl;
    sort(v.begin(),v.end());
    for(string s:v) ans+=s;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 3e5 + 10;
const ll INF = 1e18;

ll W, E, n, a[N];
int main(){
	IOS;
	cin >> n;
	for (int i = 1; i <= n; i++) a[i] = 3;
	for (int i = 1; i <= n; i++){
		char c;
		cin >> c;
		if (c == 'W'){
			a[i] = 0;
		}else{
			if (i >= 2) E ++; 
			a[i] = 1;
		}
		
	}
	ll ans = INF;
	for (int i = 1; i <= n; i++){
		ans = min(ans, E + W);
		if (a[i + 1] == 1) E --;
		if (a[i] == 0) W ++;
	}
	cout << ans;
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int ans = 0;
    for (int i=1;i<n-1;++i) {
        if (!((p[i - 1] < p[i] && p[i + 1] < p[i]) || (p[i - 1] > p[i] && p[i + 1] > p[i]))) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = input()

r = s.count('R')
g = s.count('G')
b = n - r - g
ans = r * g * b
for i in range(n):
    d = 1
    j = i + d
    k = j + d
    while k < n:
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
        d += 1
        j += 1
        k += 2
print(ans)

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

multiset<int> comfort;
int n, a[200005];
long long ans;

int main(){
    scanf("%d", &n);
    for (int i=0; i<n; ++i){
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    comfort.insert(a[n-1]);
    for (int i = n-2; i>=0; --i){
        int max_c = *(--comfort.end());
        comfort.erase(--comfort.end());
        ans += max_c;
        comfort.insert(a[i]);
        comfort.insert(a[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 13844
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

const int MOD = 998244353;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void init_comb() {
  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 comb(int n, int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int modpow(int a, int n) {
  ll res = 1, p = a;
  while(n) {
    if (n&1)
      res = res*p%MOD;
    p = p*p%MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init_comb();
  int k, n;
  cin >> k >> n;
  for (int i = 2; i <= k*2; i++) {
    ll ans = 0;
    int cnt = 0;
    for (int j = 1; j <= k; j++) {
      if (i-j > 0 && i-j <= j)
        cnt++;
    }
    if (i%2) {
      rep(j, cnt+1) {
        ll tmp = comb(k-cnt*2+n-1, n-j);
        tmp = tmp*comb(cnt, j)%MOD;
        tmp = tmp*modpow(2, j)%MOD;
        ans = (ans+tmp)%MOD;
      }
    } else {
      rep(j, cnt) {
        ll tmp = comb(k-cnt*2+n, n-j);
        tmp = tmp*comb(cnt-1, j)%MOD;
        tmp = tmp*modpow(2, j)%MOD;
        ans = (ans+tmp)%MOD;
      }
      rep(j, cnt) {
        ll tmp = comb(k-cnt*2+n-1, n-j-1);
        tmp = tmp*comb(cnt-1, j)%MOD;
        tmp = tmp*modpow(2, j)%MOD;
        ans = (ans+tmp)%MOD;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 12288
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<ll> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1LL<<60;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

struct plp{
	ll sum;
	int c;
	int p;
	bool operator< (const plp &opp) const{
		return sum < opp.sum;
	}
	plp(){}
	plp(ll s, int a, int b):sum(s),c(a),p(b){}
};

main(){
	scanf("%d", &n);
	vi A(n+1);
	vector< set<plp> > vs(n+1);
	REP(i, n) scanf("%lld", &A[i+1]);
	vs[0].insert(plp(-INF, 0, 0));
	REP(i, n+1){
		ll sum = 0;
		for(int j=i+1;j<=n;j++){
			sum += A[j];
			auto it = vs[i].lower_bound(plp(sum, 0, 0));
			if(it == vs[i].begin()) continue;
			-- it;
			int c = it->c + 1;
			auto jt = vs[j].upper_bound(plp(sum, 0, 0));
			if(jt != vs[j].begin()){
				-- jt;
				if(jt->c >= c) continue;
				++ jt;
			}
			while(jt != vs[j].end() && jt->c <= c) jt = vs[j].erase(jt);
			vs[j].insert(plp(sum, c, i));
		}
	}
	auto it = vs[n].end();
	--it;
	int m = it->c;
	printf("%d\n", m);
	vi ans;
	RREP(i, m-1){
		ans.push_back(it->p);
		it = vs[it->p].lower_bound(plp(it->sum, 0, 0));
		-- it;
	}
	RREP(i, ans.size()) printf("%d%s", ans[i], i?" ":"");
	puts("");
	
	
	return 0;
}

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m=2,ans;
  cin >> n;
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];
  ans=a[0]-1;
  for(long i=1;i<n;i++) {
    if(a[i]==m) m++;
    else if(a[i]>m) ans+=(a[i]-1)/m;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4044
#include<stdio.h>

int main()
{
	int input;
	int stack[100];
	int sp=0;
	int outtrain[110];
	int i;

	for(i=0;i<11;i++){stack[i]=0;}
	for(i=0;i<11;i++){outtrain[i]=0;}
	i=0;
	while(scanf("%d",&input)!=EOF)
	{
		if(input==0)
		{	
			outtrain[i]=stack[sp];
			stack[sp]=0;
			i++;
			if(sp>0){sp--;}
		}
		else
		{
			if(stack[0]!=0){sp++;}
			stack[sp]=input;
		}
	}
	i=0;
	while(outtrain[i]!=0)
	{
		printf("%d\n",outtrain[i]);
		i++;
	}
	return 0;
}

Measured memory_bytes: 0
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut sp: Vec<(String, i32, usize)> = (0..n)
        .map(|i| {
            let s = input();
            let p = input::<i32>();
            (s, -p, i + 1)
        })
        .collect();
    sp.sort();

    for &(_, _, i) in &sp {
        println!("{}", i);
    }
}


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

long long N, A[200009], B[200009], dp[4009][4009], nr[4009][4009], mod = 1000000007, sum;

void init() {
	for (int i = 0; i < 4009; i++) {
		for (int j = 0; j < 4009; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % mod;
		}
	}
}

int C = 2000;

int main() {
	cin >> N; init();
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		sum += nr[A[i] * 2][B[i] * 2];
		dp[C - A[i]][C - B[i]]++;
	}
	sum += mod*mod; sum %= mod;
	long long s2 = 0;
	for (int i = 0; i <= 4000; i++) {
		for (int j = 0; j <= 4000; j++) {
			dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= mod;
			dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= mod;
		}
	}
	for (int i = 1; i <= N; i++) s2 += dp[C + A[i]][C + B[i]];
	s2 -= sum; s2 += mod; s2 %= mod;
	if (s2 % 2 == 1) s2 += mod;
	s2 /= 2;
	cout << s2 % mod << endl;
	return 0;
}

Measured memory_bytes: 254464
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
 
 
int main() {
	int r;
 
	cin >> r;

	cout << 3*r*r;
 
 
 
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
    double a,b,c,d,e,f,x,y;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
        if(a < 0){
            a = a * -1;
            b = b * -1;
            c = c * -1;
        }
        if(d < 0){
            d = d * -1;
            e = e * -1;
            f = f * -1;
        }
        if(!(a == 0 || d == 0)){
            b = b * d / a;
            c = c * d / a;
            a = d;
            e = e - b;
            f = f - c;
            y = f / e;
            e = e + b;
            f = f + c;
            x = (f - e * y) / d;
        }
        else if(a == 0){
            y = c / b;
            x = (f - e * y) / d;
        }
        else{
            y = f / e;
            x = (c - b * y) / a;
        }
        printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 652
type Range = (Int,Int)

parseInts :: String -> [Int]
parseInts line = map (\x -> read x :: Int) $ words line

rectRange :: Int -> Range
rectRange x = (0, x)

circleRange :: Int -> Int -> Range
circleRange x r = (x-r, x+r)

inRange :: Range -> Range -> Bool
inRange (cl, cu) (wl, wu)
    | wl <= cl && cu <= wu = True
    | otherwise            = False

circleInRect :: [Int] -> String
circleInRect [w, h, x, y, r] =
    if inW && inH
       then "Yes"
       else "No"
    where
        inW = inRange (circleRange x r) (rectRange w)
        inH = inRange (circleRange y r) (rectRange h)

main :: IO ()
main = do
    line <- getLine
    putStrLn $ circleInRect $ parseInts line

Measured memory_bytes: 3604
import java.util.Scanner;
 public class Main{
    public static void main(String args[]){
      Scanner in = new Scanner(System.in);
      int x = in.nextInt();
      int hour = x / 3600;
      int min = (x - (hour * 3600)) / 60;
      int sec = x - (hour * 3600 + min * 60);
      System.out.println(""+hour+":"+min+":"+sec+"");
    }
  }

Measured memory_bytes: 26160
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 998244353 
#define N 3005
#define M 1000003
#define LOG 20
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n,x,ans;
int dp[N][N*2],dp2[N],f[N],inv[N];

int mul(int x,int y) {
	
	return (ll)x*y%MOD;

}

int add(int x,int y) {

	x+=y;

	if(x>=MOD) x-=MOD;
	if(x<0) x+=MOD;

	return x;

}

int fe(int x,int y) {

	if(y==0) return 1;
	if(y&1) return mul(x,fe(x,y-1));

	int res=fe(x,y/2);

	return mul(res,res);

}

int fill(int has,int pos) {

	return mul(f[has+pos-1],mul(inv[has],inv[pos-1]));

}

int main() {

	scanf("%d %d",&n,&x);

	dp[0][0]=1;

	for(int i=1;i<=n;i++) {

		for(int tot=0;tot<=i*2;tot++) {

			if(tot>=1) dp[i][tot]=add(dp[i][tot],dp[i-1][tot-1]);
			if(tot>=2) dp[i][tot]=add(dp[i][tot],dp[i-1][tot-2]);

		}

	}

	f[0]=inv[0]=1;

	for(int i=1;i<=n;i++) {

		f[i]=mul(f[i-1],i);
		inv[i]=fe(f[i],MOD-2);

	}

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

		for(int j=0;j<=x-2;j++) {

			ans=add(ans,mul(dp[i][j],fill(n-i,i+1)));

		}

	}
	
	for(int i=0;i*2+2<=x;i++) {

		int ws=x-i*2-2;

		for(int len=0;len+i+1<=n;len++) {

			dp2[i+len+1]=add(dp2[i+len+1],dp[len][ws]);	
			dp2[min(n+1,i*2+len+2)]=add(dp2[min(n+1,i*2+len+2)],-dp[len][ws]);

		}

	}

	if(x%2) dp2[(x-1)/2]=add(dp2[(x-1)/2],1);

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

		if(i) dp2[i]=add(dp2[i],dp2[i-1]);

		ans=add(ans,mul(dp2[i],fill(n-i,i+1)));

	}

	printf("%d",ans);

}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    cout << "hon" << endl;
  else if (n == 3)
    cout << "bon" << endl;
  else
    cout << "pon" << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
typedef long long int lli;

lli gcd(lli a, lli b){
    if(a < b){
        lli temp = a;
        a = b;
        b = temp;
    }
    while (b != 0) {
        a %= b;
        if (a == 0) return b;
        b %= a;
    }
    return a;
}

lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}

int main()
{   
    lli A, B, C, D;
    lli answer;
    cin >> A >> B >> C >> D;
    lli lc;
    lc = lcm(C, D);
    answer = (B - A + 1);
    answer -= (B / C - ((A + (C - 1)) / C) + 1);
    answer -= (B / D - ((A + (D - 1)) / D) + 1);
    answer += (B / lc - ((A + (lc - 1)) / lc) + 1);
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 256
from heapq import heappush as push
from heapq import heappop as pop
def solve():
  n, k = map(int,input().split())
  group_num = 10
  
  book_map = [[] for i in range(group_num)]
  acc_map = [[0] for i in range(group_num)]

  for i in range(n):
    c,g = map(int,input().split())
    push(book_map[g - 1], -c)

  for i in range(group_num):
    bmi = book_map[i]
    append = acc_map[i].append
    acc = 0
    for j in range(len(bmi)):
      acc += (pop(bmi) - j * 2)
      append(acc)
  
  dp = [[0] * (k + 1) for i in range(group_num + 1)]
  for y in range(1,k + 1):
    for x in range(1,group_num + 1):
      mp = acc_map[x - 1]
      be = dp[x - 1]
      for z in range(min(y + 1, len(mp))):
        v1 = be[y - z]
        v2 = mp[z]
        if dp[x][y] > v1 + v2:
          dp[x][y] = v1 + v2
  
  print(-dp[group_num][k])
solve()



Measured memory_bytes: 6356
n = str(input())
n =list(n)
if n[len(n)-1] =='2' or n[len(n)-1] =='4' or n[len(n)-1] =='5' or n[len(n)-1] =='7' or n[len(n)-1] =='9':
    print("hon")
elif n[len(n)-1] =='0' or n[len(n)-1] =='1' or n[len(n)-1] =='6' or n[len(n)-1] =='8':
    print("pon")    
else:
    print("bon")

Measured memory_bytes: 9140
z[9999],a,b,c;f(x,y){fflush(!printf("? %d %d\n",x,y));scanf("%s",&b);b=b>78;}main(i){if(scanf("%d%d",&a,&b),a<=b){puts("Impossible");return;}for(i=a+=b;~--i;)!c||f(i,z[c-1])?(z[c++]=i):c--;for(c=*z,i=a;~--i;)z[i]=f(c,i);for(printf("! "),i=0;i<a;)printf("%d",z[i++]);}

Measured memory_bytes: 788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl


bool a[100005];
int sum[100005];
int l[100005],r[100005];


int main()
{
	int Q;
	cin >> Q;
	REP(i,Q){
		cin >> l[i] >> r[i];
	}

	REP(i,100001){
		a[i] = false;
	}

	a[1] = false;
	a[2] = true;


	for(int ii=3;ii <= 100000;ii+=2){
		int k=0;
		int j;
		for(j=3;j<=sqrt(ii);j+=2){
			if(ii%j==0){
				k=1;
				break;
			}
		}
		if(k==0) a[ii] = true;
	}

	sum[0]=0;
	sum[1]=0;
	sum[2]=0;
	FOR(i,3,100001){
		if(i%2==0)
			sum[i] = sum[i-1];
		else
			sum[i]= sum[i-1]+(a[i]&&a[(i+1)/2]);
	}

	REP(i,Q){
		cout << sum[r[i]]-sum[l[i]-1] << endl;
	}
}




Measured memory_bytes: 1920
import java.util.*;

public class Main {
  static final String weeks = "SUNSATFRITHUWEDTUEMON";
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int index = weeks.indexOf(str);
    if(index > 0){
      index = (index) / 3;
    }else {
      index = 7;
    }
    System.out.println(String.valueOf(index));
  }
}

Measured memory_bytes: 21588
int main(void)
{
	int S;			/* ??\?????? */
	int hou;		/* ??????   */
	int min;		/* ???     */
	int sec;		/* ?§?     */
	int tmp;		/* ????\???¨ */
	
	/* input */
	scanf("%d", &S);
	tmp = S;
	
	/* ??????????¨????	*/
	hou = S / 3600;
	tmp = S % 3600;
	
	/* ???????¨????		*/
	min = tmp / 60;
	tmp = tmp % 60;
	
	/* ?§?????¨????		*/
	sec = tmp;
	
	/* output */
	printf("%d:%d:%d\n", hou, min, sec);
	
	return 0;
}

Measured memory_bytes: 592
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, X = rl()
L = rl()

ans = 1
l = 0
for i in range(N):
	l += L[i]
	if l <= X:
		ans += 1
	else:
		break
print(ans)


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    if (s[1] == 'B')
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;

	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

#define ten(n) ((int)1e##n)
#define COUT cout <<
#define SPACE_COUT << " "  <<
#define COMMA_COUT << ", " <<
#define ENDL << endl;

double distance(tuple<ll, ll, ll> n1, tuple<ll, ll, ll> n2) {
    double x = get<0>(n1) - get<0>(n2);
    double y = get<1>(n1) - get<1>(n2);
    double r = get<2>(n1) + get<2>(n2);
    double dist = sqrt(x * x + y * y) - r;
    return dist > 0 ? dist : 0;
}

class AscendPair {
  public:
    bool operator() (pair<double, int> n1, pair<double, int> n2) {
        return n1.first > n2.first;
    }
};

int
main()
{
    cin.tie(0);
    cout << setprecision(12);
    ios::sync_with_stdio(false);
    
    int N;
    vector<tuple<ll, ll, ll> > nodes;
    ll x, y, r;
    cin >> x >> y;
    nodes.push_back(make_tuple(x, y, 0));
    cin >> x >> y;
    nodes.push_back(make_tuple(x, y, 0));
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> x >> y >> r;
        nodes.push_back(make_tuple(x, y, r));        
    }
    
    vector<double> dijkstra(nodes.size());
    vector<vector<double> >  paths(nodes.size());
    for (int i = 0; i < nodes.size(); ++i) {
        tuple<ll, ll, ll> node = nodes[i];
        vector<double>& path = paths[i];
        path.resize(nodes.size());
        for (int j = 0; j < nodes.size(); ++j) {
            double dist = distance(node, nodes[j]);
            path[j] = dist;
        }
        dijkstra[i] = DBL_MAX;
    }

    set<int> used;
    priority_queue<pair<double, int> , vector<pair<double, int> >, AscendPair > pq;
    pq.push(make_pair(0, 0));
    while(!pq.empty()) {
        pair<double, int> kv = pq.top(); pq.pop();
        double cost = kv.first;
        int index = kv.second;        
        used.insert(index);

        if (dijkstra[index] < cost) continue;
        dijkstra[index] = cost;
        if (index == 1) break;

        vector<double> path = paths[index];
        for (int i = 0; i < nodes.size(); ++i) { 
            if (used.find(i) != used.end()) continue;
            pq.push(make_pair(cost + path[i], i));
        }        
    }
    cout << dijkstra[1] << endl;

    return 0;
}


Measured memory_bytes: 73820
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;
int main(void)
{
    vector<int> weights;
    int N;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        sum += tmp;
        weights.push_back(tmp);
    }

    int min = pow(2, 30);
    int light = 0, hevy = sum;
    for (int i = 0; i < N; i++)
    {
        light += weights[i];
        hevy -= weights[i];
        int sub = abs(light - hevy);
        if (min > sub)
        {
            min = sub;
        }
    }
    cout << min;
}

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 FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> p(n);
	FDS(i,n){
		cin>>p[i];
	}
	int ans=0;
	FDS(i,n-2){
		if(p[i]<p[i+1]&&p[i+1]<p[i+2]){
			ans++;
		}
		if(p[i]>p[i+1]&&p[i+1]>p[i+2]){
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

static int isprime(int n);

int
main(void)
{
        int n;

        scanf("%d\n", &n);

        int cnt = 0;
        for (int i = 0; i < n; i++) {
                int x;
                scanf("%d\n", &x);

                cnt += isprime(x);
        }

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

        return 0;
}

static int
isprime(int x)
{
        if (x == 2)
                return 1;
        else if (x < 2 || !(x % 2))
                return 0;

        for (int i = 3; i <= sqrt(x); i += 2)
                if (!(x % i))
                        return 0;

        return 1;
}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
template<typename T, int N, T F(const T& a, const T& b)>
struct SegTree
{
public:
    SegTree()
    {
        dat = vector<T>(N * 2 - 1, 0);
    }

    void update(int i, T x)
    {
        i += N - 1;
        dat[i] = x;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = N)
    {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else
        {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return F(vl, vr);
        }
    }

    vector<T> dat;
};

/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<vector<int>> nodes(N);
    nodes.resize(N);
    int a, b;
    rep(i, 0, N - 1)
    {
        cin >> a >> b;
        --a; --b;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }

    array<vector<int>, 2> distss;
    rep(turn, 0, 2)
    {
        const int start = turn ? N - 1 : 0;
        queue<pair<int, int>> q;
        q.push(make_pair(start, 0));
        vector<int>& dists = distss[turn];
        dists.assign(N, -1);
        dists[start] = 0;
        while (!q.empty())
        {
            int curr, dist;
            tie(curr, dist) = q.front();
            q.pop();

            for (const int next : nodes[curr])
            {
                if (dists[next] != -1) continue;
                q.push(make_pair(next, dist + 1));
                dists[next] = dist + 1;
            }
        }
    }

    int fennec = 0;
    rep(node, 0, N)
    {
        if (distss[0][node] <= distss[1][node])
        {
            ++fennec;
        }
    }

    if (fennec > N - fennec)
    {
        cout << "Fennec" << endl;
    }
    else
    {
        cout << "Snuke" << endl;
    }
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vector<vector<pair<ll,ll>>> G(N);
    REP(i,0,N-1) {
        ll u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        G[u].eb(v, w%2);
        G[v].eb(u, w%2);
    }

    queue<ll> Q;
    vector<ll> F(N, -1);
    Q.push(0);
    F[0] = 0;
    while(!Q.empty()) {
        ll v = Q.front(); Q.pop();
        FORR(ne,G[v]) {
            ll nv = ne.first, val = ne.second;
            if(F[nv] == -1) {
                if(val == 1) F[nv] = 1 - F[v];
                else F[nv] = F[v];
                Q.push(nv);
            } 
        }
    }

    REP(i,0,N) PR(F[i]);

    return 0;
}

/*



*/

Measured memory_bytes: 11236
n = int(input())
a = list(map(int, input().split()))

l = [0]*9
for i in a:
    if 1<=i<=399:
        l[0] = 1
    elif 400<=i<=799:
        l[1] = 1
    elif 800<=i<=1199:
        l[2] = 1
    elif 1200<=i<=1599:
        l[3] = 1
    elif 1600<=i<=1999:
        l[4] = 1
    elif 2000<=i<=2399:
        l[5] = 1
    elif 2400<=i<=2799:
        l[6] = 1
    elif 2800<=i<=3199:
        l[7] = 1
    else:
        l[8] += 1
ls = l[:8]

if sum(ls) == 0:
    print(1, l[8])
else:
    print(sum(ls), sum(l))

Measured memory_bytes: 9072