akhauriyash/Code-Regression huggingface dataset:
/**
 * Road to ROI
**/ 
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  string s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  map<char,int> m;
  for(int i=0;i<26;i++) m[s[i]]=i+1;
  int k;
  cin>>k;
  string d;
  cin>>d;
  int n=d.size();
  forn
  {
            if(m[d[i]]+k==26) cout<<"Z";
            else cout<<s[(m[d[i]]+k-1)%26];
  }
  return 0;
  
  
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    long long N=0;
    long long h=0;
    long long n =0;
    long long w = 0;
    long long count = 1;
    long long tmp = 1;
    long long tmp2 = 1;

    cin >> N;

    for(int h=1;h<=3500;h++){
        for(int n=1;n<=3500;n++){
            if((4*h*n - N*n - N*h) > 0){
                if((N*h*n % (4*h*n - N*n - N*h) == 0)){
                    w =  N*h*n / (4*h*n - N*n - N*h);
                    cout << h << ' ' << n << ' ' << w;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
# include <cstdio>
# include <iostream>
# define R register int

using namespace std;

const int maxn=100005;
int n,m,cnt;
int a[maxn],b[maxn];

int main()
{
    scanf("%d%d",&n,&m);
    for (R i=1;i<=m;++i)
    {
        scanf("%d",&a[i]);
        if(a[i]&1) cnt++;
    }
    if(m==1)
    {
    	if(a[1]==1) printf("1\n1\n1\n");
		else printf("%d\n2\n%d %d\n",a[1],a[1]-1,1);
		return 0;
	}
    if(cnt>2) puts("Impossible");
    else
    {
        int p=1;
		for (R i=1;i<=m;++i)
		{
			if((a[i]%2)&&p==1) swap(a[i],a[1]),p++;
			else if((a[i]%2)&&p==2) swap(a[i],a[m]);
		}
        for (R i=1;i<=m;++i)
        	printf("%d ",a[i]);
        printf("\n");
        printf("%d\n",m-(a[m]==1));
        printf("%d ",a[1]+1);
        for (R i=2;i<m;++i)
        	printf("%d ",a[i]);
        if(a[m]>1) printf("%d ",a[m]-1);
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int main(void){
	int x,a,b,c;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	int s=0;
	reg(i,0,a)reg(j,0,b)reg(k,0,c){
		if(i*500+j*100+k*50==x)s++;
	}
	printf("%d\n",s);
	return 0;
}






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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int N, M;
vec<pii> v;

signed main() {
  cin >> N >> M;
  v.resize(N);
  rep (i, N) {
    cin >> v[i].first >> v[i].second;
  }

  sort(all(v));

  int ans = 0;
  int nokori = M;
  rep (i, N) {
    if (nokori <= 0) break;
    int hon = min(nokori, v[i].second);
    ans += hon * v[i].first;
    nokori -= hon;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull B=5575777;
int K;
 
int n,m;
char a[5000];
char b[5000];
ull po[5000];

int main(){
  po[0]=1;
  for(int i=1;i<500;i++)po[i]=po[i-1]*B;
   
  scanf("%s %s",a,b);
  n=strlen(a);
  m=strlen(b);
 
  int ans=0;
  for(int K=1;K<=min(n,m);K++){

    set< ull > st;
    ull key,d;
     
    key=0,d=1;
    for(int i=0;i<n;i++){
      key+= po[ (int)a[i] ];
      if(i-K>=0){
        key-= po[ (int)a[i-K] ];
      }else d*=B;
      if(i>=K-1)st.insert(key);
    }
     
    key=0,d=1;
    for(int i=0;i<m;i++){
      key+= po[ (int)b[i] ];
      if(i-K>=0){
        key-= po[ (int)b[i-K] ];
      }else d*=B;
      
      if(i>=K-1)
        if( st.count(key)>0 )
          ans=K;
    }
     
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 3408
# Aizu Problem 0218: Dividing Students

import sys, math, os, fractions

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def grade(m, e, j):
    if m + e >= 180 or m + e + j >= 240 or max(e, j, m) == 100:
        return 'A'
    elif m + e + j >= 210:
        return 'B'
    elif m + e + j >= 150 and max(m, e) >= 80:
        return 'B'
    return 'C'


while True:
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        m, e, j = [int(__) for __ in input().split()]
        print(grade(m, e, j))

Measured memory_bytes: 10108
#include<iostream>
#include<vector>
#include<chrono>
#include<cmath>
#include<random>
using namespace std;
using ll = long long;

int d;
vector<vector<int>> s(365,vector<int>(26));
vector<int> c(26);

auto start=chrono::system_clock::now();
inline double get_time(){
    auto end=chrono::system_clock::now();
    auto dur=end-start;
    double msec=chrono::duration_cast<chrono::microseconds>(dur).count();
    return msec;
}

random_device seed_gen;
uint64_t get_rand_range(uint64_t min_val,uint64_t max_val){
    static mt19937_64 mt64(seed_gen());
    uniform_int_distribution<uint64_t> get_rand_uni_int(min_val,max_val);
    return get_rand_uni_int(mt64);
}

ll calc(vector<int> t){
    ll score=0;
    vector<int> last(26);
    for(int i=0;i<(int)t.size();i++){
        last[t[i]]=i;
        for(int j=0;j<26;j++) score-=c[j]*(i+1-last[j]);
        score+=s[i][t[i]];
    }
    return score;
}

void solve(){
    vector<int> v(d);
    double t0=2000,t1=600;
    int cnt=0;
    double T=t0;
    for(int i=0;i<d;i++) v[i]=get_rand_range(0,25);
    ll score=calc(v);
    vector<int> b=v;
    while(1){
        cnt++;
        if(cnt%100==0){
            double t=get_time()/19e5;
            if(t>=1) break;
            T=powl(t0,1.0-t)*powl(t1,t);
        }
        if(get_rand_range(0,1)){
            int i=get_rand_range(0,d-1);
            int q=get_rand_range(0,25);
            int old=v[i];
            v[i]=q;
            ll new_score=calc(v);
            if(score>new_score&&!get_rand_range(0,exp((new_score-score)/T))) v[i]=old;
            else score=new_score;
        }else{
            int i=get_rand_range(0,d-2);
            int j=get_rand_range(i+1,min(i+16,d)-1);
            swap(v[i],v[j]);
            ll new_score=calc(v);
            if(score>new_score&&!get_rand_range(0,exp((new_score-score)/T))) swap(v[i],v[j]);
            else score=new_score;
        }
    }
    for(int k : v) cout<<k+1<<endl;
}

int main(){
    cin>>d;
    for(int i=0;i<26;i++){
        cin>>c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin>>s[i][j];
        }
    }
    solve();
}

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

int main(){
  int hoge,a,b,c,nya,wan;
  cin >> hoge;
  for(int i=0;i<hoge;i++){
    nya = 0;
    cin >> a >> b >> c;
    wan = a;
	if(b*b+c*c==a*a) nya = 1;
	if(b>wan){ wan = b; if(a*a+c*c==b*b) nya = 1;}
    if(c>wan) if(a*a+b*b==c*c) nya = 1;

	if(nya == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
MOD = 1
m = 100
COMB_table = [[0]*(m+1) for _ in range(m+1)]

fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


def COMB(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def make_COMB_table(m):
    for i in range(m+1):
        for j in range(i+1):
            if j == 0 or j == i:
                COMB_table[i][j] = 1
            else:
                COMB_table[i][j] = COMB_table[i-1][j-1] + COMB_table[i-1][j]


def COMB_2(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return COMB_table[n][k]


make_COMB_table(m)


def main():
    from collections import Counter
    N, A, B = (int(i) for i in input().split())
    V = [int(i) for i in input().split()]
    V.sort(reverse=True)
    ans = sum(v for v in V[:A])/A
    c = Counter(V)
    c_ans = Counter(V[:A])
    cnt = 0
    if V[0] != V[A-1]:
        cnt = COMB_2(c[V[A-1]], c_ans[V[A-1]])
    else:
        for i in range(A, B+1):
            cnt += COMB_2(c[V[0]], i)
    print(ans)
    print(cnt)


if __name__ == '__main__':
    main()


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

int main(){
    int b;
    cin >> b;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < b;i++){
        string s;
        cin >> s;
        if(s=="AC"){
            ac++;
        }else if(s=="WA"){
            wa++;
        }else if(s=="TLE"){
            tle++;
        }else{
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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

int main(){
int N, M, K, i, j, k; cin >> N >> M >> K; int a, b, d; 
vector< vector<int> > nxt(N), blk(N); for(i=0; i<N; i++){ nxt[i]={}; blk[i]={}; }
for(i=0; i<M; i++){ cin >> a >> b; a--; b--; nxt[a].push_back(b); nxt[b].push_back(a); }
for(i=0; i<K; i++){ cin >> a >> b; a--; b--; blk[a].push_back(b); blk[b].push_back(a); }

int col[N]={}, n=0; bool ksht[N]={};
for(i=0; i<N; i++){
  if(col[i]){ continue; }
  vector<int> V={i}; ksht[i]=true; n++;
  for(j=0; j<V.size(); j++){ 
    int v=V[j], l=nxt[v].size(); col[v]=n; 
    for(k=0; k<l; k++){
      int nv=nxt[v][k];
      if(!ksht[nv]){ V.push_back(nv); ksht[nv]=true; } 
    }
  }
}
int siz[n+1]={}; for(i=0; i<N; i++){ siz[col[i]]++; }
for(i=0; i<N; i++){ 
for(d=j=0; j<blk[i].size(); j++){ if(col[i]==col[blk[i][j]]){ d++; } }
cout << siz[col[i]]-nxt[i].size()-d-1 << " ";
}
cout << "\n";
}

Measured memory_bytes: 12536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	int HH=abs(H-h);
	int WW=(W-w);
	int ans=HH*WW;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 305, mod = (int) 0;
string a[N];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int res = 0;
	for (int shift = 0; shift < n; shift++) {
		int can = 1;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (a[(i + shift) % n][j] != a[(j + shift) % n][i])
					can = 0;
		res += can * n;
	}
	cout << res << endl;
}








Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
static const int MAX = 100000;



int main(){
    int mina = MAX, minb = MAX, ans;
    int A, B, M;
    int a[MAX], b[MAX];

    cin >> A >> B >> M;

    for(int i = 0; i < A; i++){
        cin >> a[i];
        mina = min(mina, a[i]);
    }
    for(int i = 0; i < B; i++){
        cin >> b[i];
        minb = min(mina, b[i]);
    }
    ans = mina + minb;
    for(int i = 0; i < M; i++){
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, a[x-1] + b[y-1] - c);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt(); //T時間勉強する必要がある
        int X = sc.nextInt(); //X倍になる
        double A = (double)T / X; //世界Aで何時間進んだか



        System.out.println(String.format("%.4f",A));
	}

}

Measured memory_bytes: 23124
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		while(true){
			short n=scan.nextShort(),m=scan.nextShort();
			if(n==0) break;
			UnionFind uni = new UnionFind(n);
			List<edge> list = new ArrayList<edge>();
			for (int i = 0; i < m; i++)
				list.add(new edge(scan.nextShort(),scan.nextShort(),scan.nextShort()));
			Collections.sort(list);

			int res=0;
			for (int i = 0; i < m; i++) {
				edge e = list.get(i);
				if(!uni.isSame(e.from,e.to)){
					uni.unite(e.from, e.to);
					res+=e.cost;
				}
			}
			out.println(res);
		}
		out.flush();
	}
}

class edge implements Comparable<Object> {
	short from,to,cost;
	edge(short f,short t,short c){
		from=f;
		to=t;
		cost=c;
	}
	@Override
	public int compareTo(Object o) {
		return this.cost-((edge)o).cost;
	}
}

class UnionFind {

	int[] par,rank;

	UnionFind(int n){
		par = new int[n];
		rank = new int[n];
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}

	int root(int x){
		if(par[x]==x)
			return x;
		else
			return par[x] = root(par[x]);
	}

	void unite(int x,int y){
		x=root(x);
		y=root(y);
		if(x==y) return;

		if(rank[x]<rank[y])
			par[x]=y;
		else{
			par[y]=x;
			if(rank[x]==rank[y])
				rank[x]++;
		}
	}

	boolean isSame(int x,int y){
		return root(x)==root(y);
	}
}

Measured memory_bytes: 23236
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
int n;
LL a,b;
int main()
{
	LL t1=0,t2=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld%lld",&a,&b);
		if(t1==0) {
			t1=a,t2=b;
			continue;
		}
		LL x=max(t1/a,t2/b);
		if(x*a<t1||x*b<t2) x++;
		t1=x*a,t2=x*b;
	}
	printf("%lld",t1+t2);
}

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

int main() {
    string n;
    cin >> n;
    if(n[0] == n[1] && n[1] == n[2]){
        cout << "Yes" << endl;
    }else if(n[1] == n[2] && n[2] == n[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// ABC083B - Some Sums
fn main() {
    use std::io::{stdin, Read};
    let mut input = String::new();
    stdin().read_to_string(&mut input).expect("read_to_string");
    let input = input
        .split_whitespace()
        .collect::<Vec<&str>>()
        .into_iter()
        .map(|x| x.trim().parse::<u64>().unwrap())
        .collect::<Vec<u64>>();
    let mut answer = 0;
    for num in 0..input[0] + 1 {
        let digit_one = num % 10;
        let digit_ten = (num % 100 - digit_one) / 10;
        let digit_hundred = (num % 1000 - digit_ten * 10 - digit_one) / 100;
        let digit_thousand =
            (num % 10000 - digit_hundred * 100 - digit_ten * 10 - digit_one) / 1000;
        let digit_man =
        	(num - digit_thousand*1000 - digit_hundred*100 - digit_ten * 10 - digit_one) / 10000;
        // println!("{}{}{}", digit_hundred, digit_ten, digit_one);
        let sum = digit_one + digit_ten + digit_hundred + digit_thousand + digit_man;
        if sum >= input[1] && sum <= input[2] {
            answer = answer + num;
        }
    }
    println!("{}", answer);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include<limits.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll dp[n];
	fillv(dp,0);
	dp[1]=abs(a[1]-a[0]);
	for(ll i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int dfs(int p, int q, vector<vector<int>> &V, int &ans){
	int a = 0, b = 0;
	for(auto u : V[q]) if(u != p){
		int x = dfs(q,u,V,ans);
		if(a < x){
			b = a;
			a = x;
		} else if(b < x){
			b = x;
		}
	}
	ans = max(ans,a+b);
	return a+1;
}

int main(){
	int N; cin >> N;
	vector<vector<int>> V(N);
	repp(i,1,N){
		int a,b; cin >> a >> b;
		V[a-1].push_back(b-1);
		V[b-1].push_back(a-1);
	}
	int ans = 0;
	dfs(-1,0,V,ans);
	cout << (ans%3==1?"Second":"First") << endl;
	return 0;
}


Measured memory_bytes: 26112
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


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

  int N; std::cin >> N;
  std::vector<ll> A(N); rep(i,N) std::cin >> A[i];

  std::sort( all(A) , std::greater<>());

  std::vector<ll> ans;
  std::unordered_map<ll, ll> candidate;
  rep(i,N) {
    if ( candidate.count(A[i]) == 1 ) {
      candidate.erase(A[i]);
      ans.push_back(A[i]);
    }
    else {
      candidate[A[i]] = 1;
    }
    if ( ans.size() >= 2 ) {
      std::cout << ans[0]*ans[1] << std::endl;
      return 0;
    }
  }

  std::cout << 0 << std::endl;
  return 0;
}


Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, ans = 0;
    cin >> N;
    if (N % 2 == 1) {
        cout << 0 << endl;
    }
    else {
        for (int64_t i = 0; i < 25; i++) {
            ans += N / (10 * int64_t(pow(5, i)));
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 100002;
ll n;
vector<ll> a;
ll x,y,ans;

int main(){
	cin>>n;
	FOR(i,0,n){
		ll k;
		cin>>k;
		a.push_back(k);
	}
	if(n==2){
		cout<<max(a[0],a[1])<<" "<<min(a[0],a[1])<<endl;
		return 0;
	}
	sort(a.begin(),a.end());
	ans=a[0];
	ll d=INF;
	FOR(i,0,n){
		if(d>abs(a[n-1]-a[i]-a[i])){
			ans=a[i];
			d=abs(a[n-1]-a[i]-a[i]);
		}
	}
	cout<<a[n-1]<<" "<<ans<<endl;
	return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    for(int i = 1; i < N; i++){
        if (S[i] == 'E'){
            ans++;
        }
    }
    int ans_copy = ans;
    for (int i = 1; i < N; i++){
        if (S[i - 1] == 'W'){
            ans_copy++;
        }
        if (S[i] == 'E'){
            ans_copy--;
        }
        if (ans_copy < ans){
            ans = ans_copy;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define mi -1e11;
#define ll long long
vector<vector<ll>> v(102,vector<ll>(2));
vector<vector<ll>> dp(102,vector<ll>(100005));
int n,w;
ll solve(int i,ll aw)
{
    if(aw<0)
    return mi;
    if(i>=n)
    return 0;
    if(dp[i][aw])
    return dp[i][aw];
    ll ans=0;
    ans = max(ans,v[i][1]+solve(i+1,aw-v[i][0]));
    ans = max(ans,solve(i+1,aw));
    return dp[i][aw]=ans;
}
int main() {
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v[i][0]=a;
        v[i][1]=b;
    }
    cout<<solve(0,w);
}


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

using namespace std;

int main(){
  int N;
  cin >>N;
  vector<int> V(N);
  vector<int> C(N);
  vector<int> XY(N);
  int ans=0;
  for(int i=0;i<N;i++){
 cin >>V.at(i);
  } 
  for(int i=0;i<N;i++){
 cin >>C.at(i);
    XY.at(i)=V.at(i)-C.at(i);
  }
  sort(XY.begin(),XY.end());
  reverse(XY.begin(),XY.end());
   for(int i=0;i<N;i++){
     if(XY.at(i)<0){break;}
     ans+=XY.at(i);
}
  cout <<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
    int a[1000010], b[1000010];
    int t=0;
    for(int i=0; i<n; i++){
        string s; cin>>s;
        int d=0, mn=0;
        for(int j=0; j<s.size(); j++){
            if(s[j]=='('){
                d++;
            }else{
                d--;
            }
            mn=min(mn, d);
        }
        a[i]=-mn, b[i]=d-mn;
        t+=d;
    }
    if(t!=0){
        cout<<"No"<<endl;
        return 0;
    }
    vector<P> v1, v2;
    for(int i=0; i<n; i++){
        if(a[i]<=b[i]) v1.push_back({a[i], b[i]});
        else v2.push_back({b[i], a[i]});
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end(), greater<P>());
    int sum=0;
    for(auto p:v1){
        sum-=p.first;
        if(sum<0){
            cout<<"No"<<endl;
            return 0;
        }
        sum+=p.second;
    }
    for(auto p:v2){
        sum-=p.second;
        if(sum<0){
            cout<<"No"<<endl;
            return 0;
        }
        sum+=p.first;
    }
    cout<<"Yes"<<endl;
	return 0;
}


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d || (abs(c-b)<=d && abs(a-b)<=d)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int n; cin >> n;
    vector<int> w(n);
    rep(i, n) cin >> w[i];
    int ans = 1e9;
    for(int i = 1; i < n; i++) {
        int l = 0;
        int r = 0;
        for(int j = 0; j < i; j++) {
            l += w[j];
        }
        for(int j = i; j < n; j++) {
            r += w[j];
        }
        ans = min(abs(l - r), ans);
    }
    COUT(ans);
}

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO                      \
  std::ios::sync_with_stdio(false); \
  cin.tie(0)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

/*-----------------END TEMPLATE-----------------*/

int main() {
  FASTIO;
  int n;
  cin >> n;
  cout << n * n << endl;
}


Measured memory_bytes: 256
n,ma,mb,*L=map(int,open(0).read().split())
INF=float('inf')
dp=[[INF]*420 for _ in range(420)]
dp[0][0]=0
for a,b,c in zip(*[iter(L)]*3):
	for i in range(400,-1,-1):
		for j in range(400,-1,-1):
			t=dp[i][j]+c
			if dp[i+a][j+b]>t:
				dp[i+a][j+b]=t
ans=INF
_ma,_mb=ma,mb
while _ma<410>_mb:
	ans=min(ans,dp[_ma][_mb])
	_ma+=ma
	_mb+=mb
print(ans if ans<INF else -1)

Measured memory_bytes: 49116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemD
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = new int[N];
            var Bs = new int[N];
            var dicts = new Dictionary<int, int>();

            for (int i = 0; i < N; i++)
            {
                var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                As[i] = read[0];
                Bs[i] = read[1];
                if (dicts.Keys.Contains(read[1]))
                    dicts[read[1]] += read[0];
                else
                    dicts.Add(read[1], read[0]);
            }
            var dictList = dicts.OrderBy(x => x.Key).ToList();
            var sums = 0;
            var isYes = true;
            foreach(var d in dictList)
            {
                sums += d.Value;
                if (d.Key < sums)
                {
                    isYes = false;
                    break;
                }
            }
            Console.WriteLine(isYes ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 33420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    for(int i=0;i<S.size();i++){
        if(i%2==0){
            if(S[i] == 'L'){
                cout << NO << endl;
                return;
            }
        }else{
            if(S[i] == 'R'){
                cout << NO <<endl;
                return;
            }
        }
    }
    cout <<YES << endl;

}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,k = map(int, input().split())
p = list(map(int, input().split()))

s = [0] * (n + 1)
for i in range(n):
    a = p[i] * (p[i] + 1) // 2
    e = a / p[i]
    s[i + 1] = s[i] + e

ans = 0
for i in range(n - k + 1):
    ans = max(ans, s[i + k] - s[i])
print('{:.12f}'.format(ans))


Measured memory_bytes: 31688
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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 ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vector<vector<P>> G;
vl ans;
void dfs(int v, int p=-1, int c=-1){
  int k=1;
  for(auto nv:G[v]){
    int next=nv.first,id=nv.second;
    if(next==p)continue;
    if(k==c)k++;
    ans[id]=k;
    k++;
    dfs(next,v,ans[id]);
  }
}
    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  int a,b;
  cin >> a >> b;
  string s[100];
  rep(i,100){
    rep(j,100){
      if(i<50)s[i].push_back('.');
      else s[i].push_back('#');
    }
  }
  int cnt=0;
  for(int i=0;i<50;i+=2){
    if(cnt==b-1)break;
    for(int j=0;j<100;j+=2){
      if(cnt==b-1)break;
      s[i][j]='#';
      cnt++;
    }
  }
  cnt=0;
  for(int i=51;i<100;i+=2){
    if(cnt==a-1)break;
    for(int j=0;j<100;j+=2){
      if(cnt==a-1)break;
      s[i][j]='.';
      cnt++;
    }
  }
  cout << 100 << " "<<100 << endl;
  rep(i,100) cout << s[i] << endl;
  
}


Measured memory_bytes: 12288
/*
ABHIJEET BISWAS
CSE (2017-2021)
MNNIT ALLAHBAD
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e15
#define ll long long
#define ld long double
#define int ll
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define F first
#define S second
#define popi __builtin_popcount
#define popll __builtin_popcountll
#define grp vector<int> graph[MAX];
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//////////////////////TEMPLATE ENDS///////////////////////////////////////////////////////////////////////
ll power(ll,ll);
ll mpower(ll,ll);
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int h[MAX];
int arr[MAX];
int BIT[MAX];
int n;
int query(int x)      //returns the sum of first x elements in given array a[]
{
     int sum = 0;
     for(; x > 0; x -= x&-x)
         sum = max(sum,BIT[x]);
     return sum;
}
void update(int x, int delta)
{
      for(; x <= n; x += x&-x)
        BIT[x] = max(BIT[x],delta);
}
int32_t main() {
	fastIO
	

	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> h[i];

	for(int j=1;j<=n;j++)
		cin >> arr[j];

	int ans = 0;

	for(int i=1;i<=n;i++)
	{
		int curr = query(h[i]-1) + arr[i];
		update(h[i],curr);
		ans = max(ans,curr); 
	}
	
	cout << ans << endl; 

	return 0;
}







/*_________________________________________________Utility Functions HERE_______________________________*/

ll power(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b%2==1)
		res=res*a;
		a=a*a;
		b=b/2;
	}
	return res;
}
ll mpower(ll a ,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return res;
}

Measured memory_bytes: 9984
import Control.Monad
import Data.List


main = do
    [n, m] <- fmap (map read . words) $ getLine
    a <- fmap (map (map read . words)) $ replicateM n getLine
    b <- fmap (map read) $ replicateM m getLine
    mapM_ print $ map (foldr1 (+) . map (uncurry (*)) . zip b) a

Measured memory_bytes: 7500
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
typedef long long ll;
const int INF = 1e9 + 7;
using namespace std;

int main(){
    int H,A; cin >> H >> A;
    int ans;
    if (H%A!=0){
        ans=H/A+1;
    }else{
        ans=H/A;
    }
    cout << ans;
}



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

#define int 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 (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n;
	cin >> n;

	int a[100010];
	for(int i = 0;i < n+1;i++) cin >> a[i];

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

	int now = 1;

	int ans = 0;
	for(int i = 0;i < n+1;i++){
		ans += now;
		now -= a[i];
		sum -= a[i]; 
		if(now < 0){
			cout << -1 << endl;
			return 0;
		}
		now = min(now*2, sum);
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main() {
	int n;
	char str[112];

	scanf("%d", &n);
	scanf(" %s", str);

	int a = 0, f = 0;

	for (int i=0; i<n; ++i) {
		if (str[i] == '(') {
			++f;
		}
		if (str[i] == ')'){
			if (f) 
				--f;
			else 
				++a;
		}
	}

	while (a--) 
		printf("(");
	printf("%s", str);
	while (f--)
		printf(")");

	return 0;
}

Measured memory_bytes: 256
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
    return divisors


def F(a, b):
    return max(len(str(a)), len(str(b)))


ans = []
for n in make_divisors(N):
    n2 = N // n
    ans.append(F(n, n2))
print(min(ans))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{

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

        // input
        int num = scan.nextInt();
        long[] initial = new long[5];
        for(int i = 0; i < num; i++){
            String temp = scan.next();
            switch(temp.charAt(0)){
                case 'M':
                    initial[0] += 1;
                    break;
                case 'A':
                    initial[1] += 1;
                    break;
                case 'R':
                    initial[2] += 1;
                    break;
                case 'C':
                    initial[3] += 1;
                    break;
                case 'H':
                    initial[4] += 1;
            }
        }

        // search
        long sum = 0;
        for(int a = 0; a < 3; a++){
            for(int b = a + 1; b < 4; b++){
                for(int c = b + 1; c < 5; c++){
                    if(initial[a] == 0 || initial[b] == 0 || initial[c] == 0){
                        continue;
                    }
                    sum += initial[a] * initial[b] * initial[c];
                }
            }
        }

        // answer
        System.out.println(sum);

    }
}

Measured memory_bytes: 46588
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

string s;

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

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    ll n=s.size();
    s="."+s;
    if(s[1]=='0' || s[n]=='1'){
        cout << -1;
        return 0;
    }
    for(ll i=1; i<n; i++){
        if(s[i]!=s[n-i]){
            cout << -1;
            return 0;
        }
    }
    ll p=n;
    for(ll i=n-1; i>=1; i--){
        cout << p << " " << i << "\n";
        if(s[i]=='1') p=i;
    }
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
int main(void)
{
	int rc[5],ac[5];
	int r,a;
	int i,j;
	int hit,blow;
	
	scanf("%d %d",&r,&a);
	while(r!=0 && a!=0){
		hit=0;
		blow=0;
		for(i=3;i>=0;i--){
			rc[i]=r%10;
			r=r/10;
			ac[i]=a%10;
			a=a/10;
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(rc[i]==ac[j]){
					blow++;
				}
			}
			if(rc[i]==ac[i]){
				hit++;
			}
	}
		blow=blow-hit;
		printf("%d %d\n",hit,blow);
		scanf("%d %d",&r,&a);
	}
	return 0;
}

Measured memory_bytes: 600
def tax( p, x )
	p * ( 100 + x ) / 100
end

while ( x, y, s = gets.strip.split.map( &:to_i ) ) != [ 0, 0, 0 ]
	res = 0
	for a in 1...s
		for b in 1...s
			if tax( a, x ) + tax( b, x ) == s
				res = [ res, tax( a, y ) + tax( b, y ) ].max
			end
		end
	end
	puts res
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;
 
using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void solve()
{
    int x=0;
    int n;
    cin>>n;
    vector<char> v(n+1),vv(n+1);
    repu(i,1,n)
    {
        cin>>v[i];
        vv[i]=v[i];
    }
    int r=0;
    repu(i,1,n)
    {
        if(v[i]=='R')
            r++;
    }
    repd(i,n,2)
    {
        if(v[i-1]=='W' && v[i]=='R')
        {
            x++;
            v[i-1]='R';
        }
    }
    int r1=0;
    repu(i,1,r)
    {
        if(vv[i]=='R')
            r1++;
    }
    cout<<min(x,r-r1)<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}   

Measured memory_bytes: 3788
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_A() {}


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    char r, g, b; cin >> r >> g >> b;
    string s = { r,g,b };

    string ans = "NO";
    if (stoi(s) % 4 == 0) ans = "YES";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256