akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int a = cin.nextInt();
        int b = cin.nextInt();

        WriteLine(Lcm(a, b));
    }

    
    // 最小公倍数
    public static long Lcm(long a, long b) {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b) {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0) {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int n, f[10][10];

vi digits (int x) {
	vi a;
	while (x) { a.pb(x % 10); x /= 10; }
	reverse(all(a));
	return a;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	memset(f, 0, sizeof f);
	cin >> n;
	For(i, 1, n + 1) {
		vi d = digits(i);	
		f[d.front()][d.back()]++;
	}
	ll ans = 0;
	For(i, 1, n + 1) {
		vi d = digits(i);
		ans += f[d.back()][d.front()];
	}
	cout << ans << '\n';
}



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

using namespace std;

const int NMAX = 1e5;

int N, M;
int done[NMAX + 5], dp[NMAX + 5];
vector<int> ord, edg[NMAX + 5];

void DFS(int nod)
{
    if(done[nod])   return;
    done[nod] = 1;
    for(auto nxt: edg[nod])
        DFS(nxt);
    ord.push_back(nod);
}

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

    for(int i = 1; i <= M; i++)
    {
        int x, y;
        cin >> x >> y;
        edg[x].push_back(y);
    }

    for(int i = 1; i <= N; i++)
        DFS(i);
    reverse(ord.begin(), ord.end());

    int mx = -1;
    for(auto nod: ord)
    {
        for(auto nxt: edg[nod])
            dp[nxt] = max(dp[nxt], dp[nod] + 1);
        mx = max(mx, dp[nod]);
    }

    cout << mx;

    exit(0);
}

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=998244353;
int n,x,cnt[200005]; 
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;	
}
signed main(){
	scanf("%lld",&n);
	int ans=1;
	for (int i=1;i<=n;i++){
		scanf("%lld",&x);
		if (x!=0&&i==1){
			puts("0");
			return 0;
		} 
		cnt[x]++;
	}
	if (cnt[0]!=1)ans=0;
	for (int i=1;i<=n;i++)
		if (cnt[i])(ans*=ksm(cnt[i-1],cnt[i]))%=M;
	printf("%lld\n",ans);	
}

Measured memory_bytes: 1024
def divisors(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d

import numpy as np
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=np.array([a[i]^a[i-1] for i in range(0,N)])
B=np.array([b[i]^b[i-1] for i in range(0,N)])
d=divisors(N)
perioda=N
for i in range(0,len(d)):
    test=np.roll(A,-d[i])
    if all(test==A):
        perioda=min(perioda,d[i])

periodb=N
for i in range(0,len(d)):
    test=np.roll(B,-d[i])
    if all(test==B):
        periodb=min(periodb,d[i])

if perioda==periodb:
    A=A[:perioda]
    B=B[:periodb]
    kouho=[]
    for i in range(0,len(B)):
        if A[i]==B[0]:
            kouho.append(i)
    ans=-1
    for i in range(0,len(kouho)):
        test=np.roll(A,-kouho[i])
        if all(test==B):
            ans=kouho[i]
            break
    if ans!=-1:
        for i in range(0,N//perioda):
            print(ans+perioda*i,a[ans+perioda*i]^b[0])

Measured memory_bytes: 44068
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	char[] s = sc.next().toCharArray();
      	char[] goal = "CODEFESTIVAL2016".toCharArray();
      	int count = 0;
      	for(int i = 0; i < s.length; i++){
        	if(s[i] != goal[i]) count++;
        }
      	System.out.println(count);
    }
}

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

using namespace std;
//using namespace __gnu_pbds;

#define fastio                          ios::sync_with_stdio(false);   cin.tie(0);   cout.tie(0);
#define input(arr, n)                   for(int i=1; i<=n; i++) cin >> arr[i];
#define output(arr, n)                  for(int i=1; i<=n; i++) {cout << arr[i] << " "; } cout << endl;
#define print(cont)                     for(auto it : cont) {cout << it << " "; } cout << endl;
#define printpair(cont)                 for(auto it : cont) cout << it.first << " " << it.second << endl;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int M = 2e5 + 6;
const int MOD = 1e9 + 7;

int a[M];

int main(){

    fastio;

    int n;
    cin >> n;

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

    sort(a+1, a+n+1);

    int mid = a[(n+1) / 2];

    ll ans = 0;
    for(int i=1; i<=n; i++){
        ans += (ll)abs(a[i] - mid);
    }
    cout << ans;



}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n;
  cin >> n;
  if (n>999) cout << "ABD" << endl;
  else cout << "ABC" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

struct BipartiteMatching {
	int V;
	vector<vector<bool> > G;
	vector<int> match;
	vector<bool> used;

	BipartiteMatching(int v) {
		V = v;
		G = vector<vector<bool> >(v, vector<bool>(v));
		match = vector<int>(v);
		used = vector<bool>(v);
	}

	void add_edge(int v, int u) {
		G[v][u] = G[u][v] = true;
	}

	bool dfs(int v) {
		used[v] = true;
		for(int i = 0; i < V; i++) {
			if(!G[v][i]) continue;
			int u = i, w = match[u];
			if(w < 0 || (!used[w] && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}

	int calc() {
		int res = 0;
		fill(match.begin(), match.end(), -1);
		for(int v = 0; v < V; v++) {
			if(match[v] < 0) {
				fill(used.begin(), used.end(), false);
				if(dfs(v)) {
					res++;
				}
			}
		}
		return res;
	}
};


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

	int N, M;
	while(cin >> N >> M) {
		BipartiteMatching bm(N + M);
		for(int i = 0; i < N; i++) {
			int K, b;
			cin >> K;
			for(int j = 0; j < K; j++) {
				cin >> b;
				b = b - 1 + N;
				bm.add_edge(i, b);
			}
		}

		if(bm.calc() == M) {
			cout << "Bob" << endl;
		}
		else {
			cout << "Alice" << endl;
		}
	}
}

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

using namespace std;

bool comparator(string a,string b)
{
    return a<b;
}

void solve(){
    int n =0, l=0;
    cin>>n >>l;

    string str[n] ;
    
    for (int i = 0; i < n; i++) {
        /* code */
        cin>>str[i];
    }
    sort(str,str+n,comparator); 
      for(int i=0;i<n;i++)
 { cout<<str[i]<<""; 
 } 
    
}

int main() {

    solve();
	return 0;
}

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

using namespace std;

int main(){
  int all=0, a=0, b=0, c=0;
  vector<int> data(3);
  bool end = false;

  while(cin >> data[0] >> data[1] >> data[2]){
    if(end) continue;
    sort(data.begin(), data.end());

    if(data[0]+data[1] <= data[2]){
      cout << all << " " << a << " " << b << " " << c << endl;
      end = true;
      continue;
    }

    if(data[0]*data[0] + data[1]*data[1] == data[2]*data[2]) ++a;
    else if(data[0]*data[0] + data[1]*data[1] > data[2]*data[2]) ++b;
    else ++c;

    ++all;
  }
  return 0;
}

Measured memory_bytes: 1212
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,c = na()
d = max(a,b,c)*3-(a+b+c)
e = d//2 if d%2==0 else (d+3)//2

print(e)

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

const int SENTINEL = 1e9 + 1;

int merge(vector<int> &S, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> L(n1+1), R(n2+1);
  rep(i,n1) L[i] = S[left+i];
  rep(i,n2) R[i] = S[mid+i];
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  int i = 0, j = 0;
  for(int k = left; k < right; k++) {
    if(L[i] <= R[j]) {
      S[k] = L[i];
      i++;
    } else {
      S[k] = R[j];
      j++;
    }
  }
  return right - left;
}

int mergeSort(vector<int> &S, int left, int right) {
  if(left + 1 < right) {
    int mid = (left + right) / 2;
    int nl = mergeSort(S, left, mid);
    int nr = mergeSort(S, mid, right);
    int nm = merge(S, left, mid, right);
    return nl + nr + nm;
  }
  return 0;
}



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

  int c = mergeSort(S, 0, n);

  for(int i = 0; i < n; i++) {
    if(i != 0) cout << ' ';
    cout << S[i];
  }
  cout << endl << c << endl;

  return 0;
}



Measured memory_bytes: 6804
#include<stdio.h>


int main() {
	int A;
	int B;
	int N;
	int ans;

	scanf("%d", &A);
	scanf("%d", &B);

	N = A + B;

	if (N == 3) {
		printf("%d\n", 3);
	}
	else if (N == 4) {
		printf("%d\n", 2);
	}
	else {
		printf("%d\n", 1);
	}

	return 0;
}


Measured memory_bytes: 128
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val pw = new java.io.PrintWriter(System.out)
  val s = Array.fill(sc.nextInt())(sc.next()).groupMapReduce(identity)(_ => 1)(_ + _)
  val max = s.values.max
  val ans = s.filter{case (k, v) => v == max}.map{case (k, v) => k}.toList.sorted
  ans.foreach(pw.println(_))
  pw.flush()
}

Measured memory_bytes: 106628
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX 10000003
using namespace std;
ll count(ll arr[], ll n, ll i)
{
    if(i>=n-1) return 0;
    if(i<n-2) 
    {
        ll x=abs(arr[i+1]-arr[i]),y=abs(arr[i+2]-arr[i]);
        return min(x+count(arr,n,i+1),y+count(arr,n,i+2));
    }
    return abs(arr[i+1]-arr[i]);
}
void solve()
{
    ll n;  cin>>n;
    ll arr[n],dp[n]={0};
    rep(i,0,n) cin>>arr[i];
    dp[0]=0, dp[1]=abs(arr[1]-arr[0]);
    rep(i,2,n)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }cout<<dp[n-1];
}
int main()
{
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    return 0;
}

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

    divisors.sort()
    return divisors

N = int(input())

# 割らない場合
ans = make_divisors(N-1)[1:]
n_div = make_divisors(N)[1:]

for d in n_div:
    n = N
    while n % d == 0:
        n //= d
    if n % d == 1:
        ans.append(d)

print(len(ans))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		
		int start = s.indexOf("A");
		int end = s.lastIndexOf("Z");
		
		String papapa = s.substring(start, end + 1);
		System.out.println(papapa.length());
	}
}



Measured memory_bytes: 39956
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

a = ri()
print((a * (a - 1)) // 2)


Measured memory_bytes: 13472
#include<cstdio>
#define NIL -1
#define MAX 100000

typedef struct{int parent, left, right;} Node;

Node T[MAX];
int D[MAX];

int findRoot(void){
	int u = 0;
	while(T[u].parent != NIL)
		u = T[u].parent;
	return u;
}

void setDepth(int u, int p){
	D[u] = p;
	if(T[u].right != NIL)
		setDepth(T[u].right, p);
	if(T[u].left != NIL)
		setDepth(T[u].left, p+1);
}

void printChildren(int u){
	int i = 0, c = T[u].left;
	while(c != NIL){
		if(i)
			printf(", ");
		i++;
		printf("%d", c);
		c = T[c].right;
	}
}

int main(void){
	int n, i, id, k, j, a, b;
	scanf("%d", &n);
	for(i=0;i<n;i++)
		T[i].parent = T[i].left = T[i].right = NIL;
	for(i=0;i<n;i++){
		scanf("%d %d", &id, &k);
		if(k){
			scanf("%d", &a);
			T[id].left = a;
			T[a].parent = id;
			for(j=1;j<k;j++){
				b = a;
				scanf("%d", &a);
				T[a].parent = id;
				T[b].right = a;
			}
		}
	}
	setDepth(findRoot(), 0);
	for(i=0;i<n;i++){
		printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);
		if(T[i].parent == NIL)
			printf("root, ");
		else if(T[i].left == NIL)
			printf("leaf, ");
		else
			printf("internal node, ");
		printf("[");
		printChildren(i);
		printf("]\n");
	}
	return 0;
}

Measured memory_bytes: 7332
s = input()
if len(set(s)) == 1:
    print('0')
else:
    word_list = list(set(s))
    cnt = 10**5
    for word in word_list:
        t = s[:]
        for i in range(1, len(s)):
            tmp = ''
            for j in range(len(t)-1):
                if t[j] == word or t[j+1] == word:
                    tmp += word
                else:
                    tmp += t[j]
            if len(set(tmp)) == 1:
                cnt = min(cnt, i)
                break
            t = tmp[:]
    print(cnt)


Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[1024][1024];
char pat[8][8];
char cs[]="JOI";
int mj[1024][1024];
int has;
int a,b;
int calc(int p,int q){
	int ret=has;
	for(int i=p-1;i<=p;i++){
		for(int j=q-1;j<=q;j++){
			if(i<0||i>=a-1)continue;
			if(j<0||j>=b-1)continue;
			bool ok=true;
			for(int k=0;k<2;k++)
				for(int l=0;l<2;l++)
					if(str[i+k][j+l]!=pat[k][l])ok=false;
			if(ok&&!mj[i][j])ret++;
			if(!ok&&mj[i][j])ret--;
		}
	}
	return ret;
}
int main(){
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",str[i]);
	}
	for(int i=0;i<2;i++)scanf("%s",pat[i]);
	int ret=0;
	for(int i=0;i<a-1;i++){
		for(int j=0;j<b-1;j++){
			bool ok=true;
			for(int k=0;k<2;k++)
				for(int l=0;l<2;l++)
					if(str[i+k][j+l]!=pat[k][l])ok=false;
			if(ok){mj[i][j]=true;has++;}
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			for(int k=0;k<3;k++){
				char rev=str[i][j];
				str[i][j]=cs[k];
				ret=max(ret,calc(i,j));
				str[i][j]=rev;
			}
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 6124
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <numeric>
#include <string>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int n, k;
	cin >> n;
	cin >> k;
	vector<int> x(n);
	vector<int> gap(n);

	int dist = 0;

	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	for (int i = 0; i < n; i++) {
		if (x[i] <= std::abs(k - x[i])) {
			dist += 2 * x[i];
		}
		else {
			dist += 2 * std::abs(k - x[i]);
		}
	}

	cout << dist;
	return 0;
}


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

int sumdigit(int a) {
    int ret = 0;
    while(a) {
        ret += a % 10;
        a/=10;
    }
    return ret;
}
int main(void) {
    int N;
    cin >> N;    
    if((N%sumdigit(N)) == 0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    map<string, int> mp;
    rep(i, N){
        string s;
        cin >> s;
        mp[s]++;
    }
    int M = 0;
    for(auto &e: mp){
        M = max(M, e.second);
    }
    for(auto &e: mp){
        if(e.second == M) cout << e.first << endl;
    }
}

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

using namespace std;

char s[110];

int main() {
  set<char> t;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char c;
    scanf(" %c", &c);
    t.emplace(c);
  }
  if ((int) t.size() == 3) {
    puts("Three");
  } else {
    puts("Four");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;


int main()
{
  int n, a, r[9]={0}, flag=1, idx, sumv=0, minv;

  cin >> n;
  for (int i=0; i<n; i++){
    cin >> a;
    idx = a/400;
    if (idx < 8){
      r[idx] = 1;
      flag = 0;
    } else{
      r[8]++;
    }
  }

  for (int i=0; i<9; i++) sumv += r[i];

  if (flag) minv = 1;
  else minv = sumv - r[8];

  cout << minv << ' ' << sumv << endl;  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int P = 1e9 + 7 ; 
const int N = 2000 + 5 ; 
int n, K, f[N] ;  
signed main()
{
	n = gi(), K = gi() ; int ans = 1 ; 
	for( re int i = 1; i < n - K; ++ i ) ans = ans * 2 % P ; 
	f[0] = 1 ; 
	for( re int i = 1; i <= K; ++ i ) for( re int j = i; j < n; ++ j )
	f[j] = ( f[j - 1] + f[j] ) % P ; 
	printf("%lld\n", f[n - 1] * ans % P ) ; 
	return 0 ;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
 
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 2000 + 5;
int a[N], id[N], n;
bool cmp (int x, int y) { return a[x] > a[y]; }
long long dp[N][N];
void upd (long long&a, long long b) { a = max (a, b); }
int main ()
{
	read (n); for (int i = 1; i <= n; ++i) read (a[i]);
	for (int i = 1; i <= n; ++i) id[i] = i;
	sort (id + 1, id + n + 1, cmp);
	for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) dp[i][j] = LLONG_MIN;
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		int p = id[i + 1];
		for (int j = 0; j < n; ++j) {
			if (dp[i][j] == LLONG_MIN) continue;
			upd (dp[i + 1][j + 1], dp[i][j] + 1LL * a[p] * abs(p - (j + 1)));
			upd (dp[i + 1][j], dp[i][j] + 1LL * a[p] * abs (n - (i - j) - p));
		}
	}
	long long ans = LLONG_MIN;
	for (int i = 0; i <= n; ++i) upd (ans, dp[n][i]);
	printf ("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35116
#include <iostream>
#include <map>

using namespace std;

int main(void) {
  int n, q;
  std::string s;

  cin >> n >> q;
  cin >> s;

  int num[n];
  num[0] = 0;
  int count = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') count++;
    num[i] = count;
  }

  int res[q];
  for (int j = 0; j < q; j++) {
    int l, r;
    cin >> l >> r;
    if (l != 1) {
      res[j] = num[r - 1] - num[l - 2];
      if (s[l - 2] == 'A' && s[l - 1] == 'C') res[j] = res[j] - 1;
    } else {
      res[j] = num[r - 1];
    }
  }

  for (int j = 0; j < q; j++) cout << res[j] << endl;


  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args){
    	FastScanner fs = new FastScanner(System.in);
        int n = fs.nextInt(), k = fs.nextInt();
        int sum[][] = new int[2*k+1][2*k+1];
        int t[][] = new int[2*k][2*k];
        for(int i=0;i<n;i++){
            int x = fs.nextInt(), y = fs.nextInt();
            String c = fs.next();
            x %= (2*k);
            y %= (2*k);
            if(c.equals("B")){
            	x = (x + k) % (2*k);
            }
//            if(x>=k&&y>=k){
//                x-=k;
//                y-=k;
//            }
//            if(y>=k&&x<k){
//                int tmp = x;
//                x = y;
//                y = tmp;
//            }
            t[x][y]++;
        }

        
        for(int i=0;i<2*k;i++){
            for(int j=0;j<2*k;j++){
                sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] -sum[i][j] + t[i][j];
            }
        }

        int ans = 0;
        for(int i=0;i<=k;i++){
        	for(int j=0;j<=k;j++){
        		int ld = sum[i][j];
        		int rd = sum[2*k][j] - sum[i+k][j];
        		int c = sum[i+k][j+k] - sum[i+k][j] - sum[i][j+k] + sum[i][j];
        		int lu = sum[i][2*k] - sum[i][j+k];
        		int ru = sum[2*k][2*k] - sum[2*k][j+k] - sum[i+k][2*k]  + sum[i+k][j+k];
	            int t_ans =  ld + rd + c + lu + ru;
	            int r_ans = sum[2*k][2*k] - t_ans;
	            ans = Math.max(ans , t_ans);
	            ans = Math.max(ans , r_ans);
        	}
        }
        System.out.println(ans);
    }
}












//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 99024
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt

  val _A = Array.fill[(Int, Int)](N+1)((0, 0)) // (value, index)
  val _B = Array.fill[(Int, Int)](N+1)((0, 0)) // (value, index)
  for (i <- 1 to N)
    _A(i) = (in.next().toInt, i)
  for (i <- 1 to N)
    _B(i) = (in.next().toInt, i)

  val A = _A.sorted
  val B = _B.sorted

  //
  var flag = 2
  breakable {
    for (i <- 1 to N) {
      if (A(i)._1 > B(i)._1) {
        flag = 0
        break
      }

      if (i < N) {
        if (A(i+1)._1 <= B(i)._1)
          flag = 1
      }
    }
  }

  var ans = ""
  if (flag == 0)
    ans = "No"
  else if (flag == 1)
    ans = "Yes"
  else {
    val uf = new UnionFind(N+1)

    for (i <- 1 to N) {
      uf.connect(A(i)._2, B(i)._2)
    }

    if (uf.size(1) < N)
      ans = "Yes"
    else
      ans = "No"
  }

  println(ans)
}


// O(α(n)) << O(log(n))
// v は頂点数

class UnionFind(v: Int){
  // 根であれば *そのグループの要素数(負)* が、子であれば親の番号が入る。
  val uni = Array.fill(v)(-1)

  // 頂点 v の所属するグループを調べる
  def root(v: Int): Int =
    uni(v) < 0 match{
      case true  =>  // v が親の場合
        return v
      case false =>  // v が子の場合
        uni(v) = root(uni(v))  // 親のrootを調べる
        return uni(v)
    }

  // 頂点 a と頂点 b をつなぐ。もともと同じグループのとき、False を返す
  def connect(a: Int, b: Int): Boolean = {
    // まずはそれぞれ根の番号に置き換える
    var ra = root(a)
    var rb = root(b)
    if(ra == rb)
      return false  // a と b がそもそも同じグループに属しているなら即終了

    // ra を大きなグループにしたいので、逆であれば入れ替える
    if(uni(ra) > uni(rb)) {  // rbの方が要素数が多ければ
      var tmp = ra
      ra = rb
      rb = tmp
    }

    // ra と rb を結合し、rb の親を ra とする
    uni(ra) += uni(rb)
    uni(rb) = ra
    return true
  }

  // 頂点 a, b が同じグループであるかを調べる
  def isConnect(a: Int, b: Int): Boolean =
    root(a) == root(b)

  // 頂点 a を含むグループの頂点数を調べる
  def size(a: Int): Int = -uni(root(a))
}




object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 100636
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 21:16:26 2019

@author: Wataru
"""

N=int(input())

total=0
for i in range(0,N):
    x,u=input().split()
    if u=='JPY':
        total+=float(x)
    elif u=='BTC':
        total+=float(x)*380000.0

print(total)

Measured memory_bytes: 2940
#高速化heapqダイクストラ
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()


def DIJKSTRA(point,d):
    cost      = [float("inf")]*(n+1)
    Q         = []
    cost[point]=0
    heappush(Q,(point,cost[point]))
    while Q:
        prefnd,tmpC=heappop(Q)
        if cost[prefnd]<tmpC:
            continue
        for node,c in d[prefnd]:
            altC=c+tmpC
            if cost[node]>altC:
                cost[node]=altC
                heappush(Q,(node,altC))
    return cost

n=int(input())
d={}
for i in range(n-1):
    a,b=map(int,input().split())
    if a in d.keys():
        d[a].append([b,1])
    else:
        d[a]=[[b,1]]
    if b in d.keys():
        d[b].append([a,1])
    else:
        d[b]=[[a,1]]
        
x=DIJKSTRA(1,d)[1:]
y=DIJKSTRA(n,d)[1:]
#print(x)
#print(y)
F=0
S=0
for i in range(n):
    if x[i]<=y[i]:
        F+=1
    else:
        S+=1
if F<=S:
    print("Snuke")
else:
    print("Fennec")

Measured memory_bytes: 54424
import java.util.Scanner;

class Main {

	public void ab() {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		int b = sc.nextInt();

		double f = 0;

		int d = a / b;

		int r = a % b;

		f = a * 1.0 / b;

		System.out.printf("%d %d %7f",d,r,f);

	}

	public static void main(String[] args) {

		new Main().ab();

	}

}

Measured memory_bytes: 26616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;

const int mx = 2e5+5;

int n, m;
ll dp[1<<16];
int a[16][16];
ll values[1<<16];

ll fun(int mark){
    if(mark == 0) return 0;

    ll &ans = dp[mark];
    if(~ans) return ans;

    ans = LLONG_MIN;
    for(int cur=mark; cur>0; cur=(cur-1)&mark)
        ans = max(ans, values[cur]+fun(mark ^ cur));
    return ans;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(0);

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

    for(int i=1; i<=m; i++){
        vector<int> v;
        for(int j=0; j<n; j++)
            if(i & (1<<j))
                v.push_back(j);
        ll tot = 0;
        for(int j=0; j<v.size(); j++)
            for(int k=j+1; k<v.size(); k++)
                tot += a[v[j]][v[k]];
        values[i] = tot;
    }memset(dp, -1, sizeof dp);

    ll ans = fun(m);
    cout << ans << "\n";

    return 0;
}



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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

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

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;
const int INF = 1<<30;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<set<int> > v(26, set<int>({INF}));
    for (int i = 0; i < n; i++) v[s[i] - 'a'].insert(i);
    for (int i = 0; i < q; i++) {
        int type;
        cin >> type;
        if (type == 1) {
            int idx;
            char nc;
            cin >> idx >> nc;
            idx--;
            auto pc = s[idx];
            s[idx] = nc;
            v[pc - 'a'].erase(idx);
            v[nc - 'a'].insert(idx);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int res = 0;
            for (int c = 0; c < 26; c++) {
                if (v[c].empty()) continue;
                int l1 = *v[c].lower_bound(l);
                int r1 = *v[c].lower_bound(r);
                if (r1 > l1) res++;
            }
            cout << res << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] argv) throws IOException {
        //*
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int lines = Integer.parseInt(in.readLine());
        for (int i = 0; i < lines; i++) {
            String s = in.readLine();
            if (s == null) {
                break;
            }
            f(s);
        }
        /*/
        f("4 3 5");
        f("4 3 6");
        f("8 8 8");
        //*/
    }

    public static void f(String s) {
        String[] sp = s.split(" ");
        int[] a = {Integer.parseInt(sp[0]),
                   Integer.parseInt(sp[1]),
                   Integer.parseInt(sp[2])};
        Arrays.sort(a);
        System.out.println(Math.pow(a[2], 2) == Math.pow(a[0], 2) + Math.pow(a[1], 2) ? "YES" : "NO");
    }
}

Measured memory_bytes: 10000
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        int count = 1;
        for (int i=1;i<=n;i++){
            if (sc.nextInt()!=count){
                ans++;
                count--;
            }
            count++;
        }
        if (ans==n)System.out.println(-1);
        else System.out.println(ans);
    }
}


Measured memory_bytes: 58680
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 17 09:13:00 2020

@author: msaleh1
"""

def upper_bound(nums, target):
    l, r = 0, len(nums) - 1
    while l <= r:
        mid = int(l + (r - l) / 2)
        if nums[mid] > target:
            r = mid - 1
        else:
            l = mid + 1
    return l


mx = pow(10,100)
#pypy3
s = input()
t = input()

    
cnt_s = dict()
cnt_t = dict()

for c in t:
    if c in cnt_t:
        cnt_t[c]+=1
    else:
        cnt_t[c] = 1


for idx in range(len(s)):
    if s[idx] in cnt_s:
        cnt_s[s[idx]].append(idx)  
    else:
       cnt_s[s[idx]] = [idx]

#cannot
for x in cnt_t:
    if x not in cnt_s:
        print(-1)
        exit(0)
    else:
        if(cnt_t[x] > mx*len(cnt_s[x])):
            print(-1)
            exit(0)
            
cur_indx =-1
skp =0
ans = 0

for x in t:
    temp_idx = upper_bound(cnt_s[x],cur_indx)
    if(temp_idx == len(cnt_s[x])):
        skp+=1
        cur_indx = cnt_s[x][0]
    else:
        cur_indx = cnt_s[x][temp_idx];
if(skp >= mx):
    print(-1)
else:
    print(skp*len(s)+cur_indx+1)


Measured memory_bytes: 47580
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b > a - b && a + b > a * b)
        cout << a + b << endl;
    else if (a - b > a * b)
        cout << a - b << endl;
    else
        cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  bool f = true;
  for(int i = 0 ;i < n; ++i){
    int x; cin >> x;
    f &= x%2==0;
  }
  cout << (f?"second":"first") << endl;
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
)

func main() {
	var A, B, C, D int
	fmt.Scanf("%d %d %d %d", &A, &B, &C, &D)
	var turnT, turnA int
	if A%D == 0 {
		turnT = A / D

	} else {
		turnT = A/D + 1
	}

	if C%B == 0 {
		turnA = C / B

	} else {
		turnA = C/B + 1
	}
	if turnT >= turnA {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


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

using namespace std;

int n;

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

    int res = 0;
    for (int i = 1; i <= n - 1; i ++ )
    {
        int c = 0, tmp = n - i;
        for (int j = 1; j * j <= tmp; j ++ ) 
        {
            if (j * j == tmp) c ++;
            else if (tmp % j == 0) c += 2;
        }
        res += c;
    }

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

    return 0;
}

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

using namespace std;

#define ll long long

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll p = (n / (a + b)) * a;
  ll q = (n % (a + b));
  cout << (p + min(q, a));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int ans = 0;
  cin >> s;
  if(s[0] == '1') ans ++;
  if(s[1] == '1') ans ++;
  if(s[2] == '1') ans ++;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
// AOJ 2664: Shopping
// 2017.12.3 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define HASHSIZ 10007
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

int insert(char *s, int w, int id)
{
	HASH *tp = hash + (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	while (tp->s != NULL) {
		if (strcmp(tp->s, s) == 0) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

int lookup(char *s, int w)
{
	HASH *tp = hash + (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	while (tp->s != NULL) {
		if (strcmp(tp->s, s) == 0) break;
		if (++tp == hashend) tp = hash;
	}
	return tp->id;
}

#define MAX 5002
/* UNION-FIND library */
int p[MAX], rank[MAX];

void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

int x[MAX];
char s[MAX][12];

char buf[30], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, ans;
	char *q;

	fgets(bp=buf, 10, stdin), n = getint();
	for (i = 0; i < n; i++) p[i] = i;

	for (i = 0; i < n; i++) {
		fgets(bp=buf, 20, stdin);
		q = bp; while (isalpha(*bp)) bp++;
		*bp = 0, strcpy(s[i], q), insert(s[i], bp-q, i);
		bp++, x[i] = getint();
	}

	fgets(bp=buf, 10, stdin), m = getint();
	while (m--) {
		fgets(bp=buf, 30, stdin);
		q = bp; while (isalpha(*bp)) bp++;
		*bp = 0, i = lookup(q, bp-q);

		q = ++bp; while (isalpha(*bp)) bp++;
		*bp = 0, j = lookup(q, bp-q);
		union_set(i, j);
	}

	ans = 0;
	for (i = 0; i < n; i++) find_set(i);
	for (i = 0; i < n; i++) {
		j = p[i];
		if (x[i] < x[j]) x[j] = x[i];
	}

	ans = 0;
	for (i = 0; i < n; i++) j = p[i], ans += x[j];
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

#define ll long long

int n;
ll x, ans = (ll)9e18, a[200005];

int main() {
	cin >> n >> x;
	for(int i = 1; i <= n; ++i) cin >> a[i], a[i] += a[i-1];
	for(int k = 1; k <= n; ++k) {
		ll coef = 3LL, sum = 0;
		for(int i = n; i >= 1; i -= k) {
			sum += (a[i]-a[max(0, i-k)])*max(coef, 5LL), coef += 2;
			if(sum >= ans) break;
		}
		ans = min(ans, sum+(k+n)*x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import itertools
import functools
import math
from collections import Counter



K,N = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A.append(K+A[i])

sum = 0
chk = -1

for i in range(N):
    if sum < A[i+1] - A[i]:
        sum  = A[i+1] - A[i]
        chk = (i + 1) % N


print(K-sum)


Measured memory_bytes: 34096
def resolve():
    S = input()
    Q = int(input())

    rev = 0
    append_front_rev = ''
    append_rear = ''

    for i in range(Q):
        T = input().split()

        if (T[0] == "1"):
            rev ^= 1
            continue

        if (T[0] == "2" and T[1] == "1"):
            if rev == 0:
                append_front_rev += T[2]
            else:
                append_rear += T[2]
            continue

        if (T[0] == "2" and T[1] == "2"):
            if rev == 0:
                append_rear += T[2]
            else:
                append_front_rev += T[2]
            continue

    ans = append_front_rev[::-1] + S + append_rear
    if rev:
        ans = ans[::-1]

    print("".join(ans))


resolve()

Measured memory_bytes: 6644
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 3000;
const int MAXM = 3000;
const int MOD = 1000000007;

int n, m;
char s[MAXN + 1];
pair<int, int> r[MAXM];
int lim[MAXN];

int dp[MAXN][MAXN + 1]; // #ways to get to [i..lim[i]] with j zeroes
int cnt[MAXN + 1];


void run() {
	scanf("%d%d%s", &n, &m, s); REP(i, m) scanf("%d%d", &r[i].first, &r[i].second), --r[i].first, --r[i].second;
	int mm = 0;
	REP(i,m) {
		if (mm != 0 && r[i].first == r[mm - 1].first&&r[i].second > r[mm - 1].second) { r[mm - 1].second = r[i].second; continue; }
		if (mm != 0 && r[i].second <= r[mm - 1].second) continue;
		r[mm++] = r[i];
	}
	m = mm;
	REP(i, n) lim[i] = i; REP(i, m) lim[r[i].first] = r[i].second; FOR(i, 1, n) if (lim[i - 1] > lim[i]) lim[i] = lim[i - 1];
	//REP(i, n) printf("%d ", lim[i]); puts("");
	cnt[0] = 0; REP(i, n) cnt[i + 1] = cnt[i] + (s[i] == '0' ? 1 : 0);

	memset(dp, 0, sizeof(dp)); dp[0][cnt[lim[0] + 1]] = 1;
	FOR(i, 1, n) {
		int inc = cnt[lim[i] + 1] - cnt[lim[i - 1] + 1];
		FORE(j, inc, lim[i] - i + 1) {
			dp[i][j] += dp[i - 1][j - inc + 1];
			if (j - inc != lim[i - 1] - (i - 1) + 1) dp[i][j] += dp[i - 1][j - inc];
			if (dp[i][j] >= MOD) dp[i][j] -= MOD;
		}
	}
	//REP(i, n) REPE(j, n) if (dp[i][j] > 0) printf("ways %d..%d with %d = %d\n", i, lim[i], j, dp[i][j]);
	int ret = dp[n - 1][0] + dp[n - 1][1]; if (ret >= MOD) ret -= MOD; printf("%d\n", ret);

	
}


int main() {
	run();
	return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f;
bool ok[4000];
bool o2[4000];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>c>>d>>e>>f;
	ok[0]=true;
	for(int i=0;i<=f;i++){
		if(ok[i]==true&&i+c<=f){
			ok[i+c]=true;
		}
		if(ok[i]==true&&i+d<=f){
			ok[i+d]=true;
		}
	}
	o2[0]=true;
	for(int i=0;i<=f;i++){
		if(o2[i]==true&&i+a*100<=f){
			o2[i+a*100]=true;
		}
		if(o2[i]==true&&i+b*100<=f){
			o2[i+b*100]=true;
		}
	}
	long double perportion=0;
	int wat=a*100,sug=0;
	for(int i=100;i<=f;i+=100){
		if(o2[i]){
			int suger=i/100*e;
			for(int j=min(suger,f-i);j>0;j--){
				if(ok[j]&&i+j<=f){
					if(((long double)(j)/((long double)(i)+(long double)(j)))>perportion){
						perportion=((long double)(j)/((long double)(i)+(long double)(j)));
						wat=i;
						sug=j;
					}
					break;
				}
			}
		}
	}
	cout<<wat+sug<<' '<<sug<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define pb         push_back
const int W = 20,H = 20;

int vol;
bool vis[H][W];
bool liv[H][W];
int    h[H][W];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};


void dfs(int r,int c,int y,int x,int water,bool &flag){
  if (x ==0 || y == 0 || x == c-1||y==r-1||liv[y][x]){
    flag=false;
  }
  if (vis[y][x])return ;
  vol+=water-h[y][x];
  vis[y][x]=true;
  
  rep(i,4){
    int nex=x+dx[i],ney=y+dy[i];
    if (nex == -1||ney==-1||nex==c||ney==r)continue;
    if (h[ney][nex] <water){
      dfs(r,c,ney,nex,water,flag);
    }
  }
  return;
}

bool compute(int r,int c,int C,int water){
  rep(i,r)rep(j,c)vis[i][j]=false;
  REP(i,1,r-1){
    REP(j,1,c-1){
      if (!vis[i][j] && h[i][j] < water){
	bool flag=true;
	vol=0;
	dfs(r,c,i,j,water,flag);
	if (flag&&vol >=C)return true;
      }
    }
  }
  return false;
}

bool check(int r,int c,int C){
  vector<int> val(r*c);
  rep(ii,r)rep(jj,c)val[ii*c+jj]=h[ii][jj];
  sort(ALL(val));
  val.erase(unique(ALL(val)),val.end());
  rep(ii,val.size())if (compute(r,c,C,val[ii]))return true;
  return false;
}

bool solve(int r,int c,int C){
  if (check(r,c,C))return true;
  rep(i,r){
    rep(j,c){
      if (liv[i][j])continue;
      h[i][j]++;
      if (check(r,c,C))return true;
      h[i][j]--;
    }
  }
  return false;
}

main(){
  int r,c,C,R;
  while(cin>>r>>c>>C>>R && r){
    rep(i,r){
      rep(j,c){
	cin>>h[i][j];
	liv[i][j]=false;
      }
    }
    rep(i,R){
      int y,x;
      cin>>y>>x;y--;x--;
      liv[y][x]=true;
    }
    if (solve(r,c,C))cout <<"Yes"<<endl;
    else cout << "No"<<endl;
  }
  return false;
}

Measured memory_bytes: 916
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	int c=0;
	rep(i,n)
	{
		if(a[i]==i+1&&a[i+1]==i+2)
		{
			i++;
			c++;
			continue;
		}
		if(a[i]==i+1)
		{
			c++;
		}

	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(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 REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll a, b;
int main() {
	cin >> a >> b;
	cout << (abs(a - b) <= 1 ? "Brown" : "Alice") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long
#define INF 1000000000

int main()
{
	int a,b,c;
	cin >> a >> b >> c;

	cout << a*b/2 << endl;

	return 0;
}

Measured memory_bytes: 256