akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main () {
  int N, K;
  cin >> N >> K;
  int gc;
  cin >> gc;
  int ma = gc;
  for (int i = 0; i < N - 1; i ++) {
    int a;
    cin >> a;
    if (ma < a) ma = a;
    gc = gcd(gc, a);
    //cout << gc << endl;
  }
  //cout << K % gc << ' ' << ma << endl;
  if (!(K % gc) && K <= ma) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}



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

using namespace std;
typedef long long ll;

ll a[200001];

int main() {
    ios_base::sync_with_stdio(false);
    
    int n; cin>>n;

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

    cout << ans <<'\n'; 
}



Measured memory_bytes: 5176
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;

	int ans=0;
	rep(i, 0, s.size())
		if (s[i] != t[i])
			ans++;
	cout << ans << endl;
}


Measured memory_bytes: 3916
import math
from functools import reduce

def gcd_list(numbers):
    gcd = reduce(math.gcd, numbers)
    return gcd

K = int(input())
numberslist = []
sumgcd = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j == k:
                sumgcd += gcd_list([i,j,k])
            elif i == j or j == k or k == i:
                sumgcd += gcd_list([i,j,k])*3
            else:
                sumgcd += gcd_list([i,j,k])*6
                 
print(sumgcd)

Measured memory_bytes: 9628
#include <bits/stdc++.h>
#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;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    //約数の個数、lastの数
    ll cnt = n / i;
    ll last = i * cnt;
    //cout << cnt << last << '\n';
    ans += (i + last) * cnt / 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3580
import java.util.BitSet;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			int m = in.nextInt();
			if(n == 0) break;
			int[] c = new int[m];
			int[] x = new int[n];
			for(int i=0; i<m; i++){
				c[i] = in.nextInt();
			}
			for(int i=0; i<n; i++){
				x[i] = in.nextInt();
			}
			long[] dp = new long[256];
			BitSet used = new BitSet(256);
			long[] next = new long[256];
			BitSet nused = new BitSet(256);
			used.set(128);
			for(int i=0; i<n; i++){
				memset(next, 1L<<60);
				nused.clear(0, 256);
				for(int j=used.nextSetBit(0)
						; j!=-1
						; j=used.nextSetBit(j+1)){
					for(int k=0; k<m; k++){
						int nh = j + c[k];
						if(nh > 255) nh = 255;
						else if(nh < 0) nh = 0;
						nused.set(nh);
						long val = dp[j] + sq(nh-x[i]);
						if(val < next[nh])
							next[nh] = val;
					}
				}
				memcpy(dp, next);
				memcpy(used, nused, 256);
			}
			long res = 1L<<60;
			for(int i=used.nextSetBit(0)
					; i!=-1
					; i=used.nextSetBit(i+1)){
				res = Math.min(res, dp[i]);
			}
			System.out.println(res);
		}
	}
	
	public static void memset(long[] a, long val){
		for(int i=0; i<a.length; i++){
			a[i] = val;
		}
	}
	
	public static void memcpy(long[] a, long[] b){
		for(int i=0; i<a.length; i++){
			a[i] = b[i];
		}
	}
	
	public static void memcpy(BitSet a, BitSet b, int len){
		a.clear(0, len);
		a.or(b);
	}
	
	public static int sq(int a){
		return a*a;
	}
}

Measured memory_bytes: 65972
#pragma GCC optimize ("Ofast")

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING

#include <bits/stdc++.h>
using namespace std;


typedef long long ll;

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

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	int n;
	cin >> n;
	vector<int> v(n);
	for (auto& c : v)
		cin >> c;

	sort(v.rbegin(), v.rend());

	ll sum = v[0];
	for (int i = 1, cnt = 1; cnt < n-1; ++i) {
		sum += v[i]; ++cnt;
		if (cnt == n - 1) break;
		
		sum += v[i]; ++cnt;
	}
	cout << sum << '\n';

	return 0;
}

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

namespace AOJ1_7_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            int[] nm = new int[2];
            nm[0] = int.Parse(NM[0]);
            nm[1] = int.Parse(NM[1]);
            int[,] Answer = new int[nm[0] + 1, nm[1] + 1];

            for (int i = 0; i < nm[0]; i++)
            {
                string[] STR = Console.ReadLine().Split(' ');

                for (int k = 0; k < nm[1]; k++)
                {
                    Answer[i, k] = int.Parse(STR[k]);
                    Answer[i, nm[1]] += Answer[i, k];
                    Answer[nm[0], k] += Answer[i, k];
                }
                Answer[nm[0], nm[1]] += Answer[i, nm[1]];
            }

            for (int i = 0; i < nm[0]+1; i++)
            {
                for (int k = 0; k < nm[1] + 1; k++)
                {
                    Console.Write(Answer[i, k]);
                    if (!( k == nm[1]))
                    {
                        Console.Write(" ");
                    }
                }
                    Console.Write("\n");
            }
        }
    }
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>m;
    if(n==1&&m==1)ans=1;
    else if(n==1)ans=m-2;
    else if(m==1)ans=n-2;
    else ans=(n-2)*(m-2);
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
int a, b, h;
int main(void)
{
	cin>>a>>b>>h;
	cout<<(a*h+b*h)/2;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String moji=sc.next();
		String[] aa=moji.split("-");
		if(aa.length==2 && aa[0].length()==mae && aa[1].length()==ato) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int a = 0;
    int b = 0;

    for (auto x : s)
    {
        if (x == 'A')
            a++;
        else
            b++;
    }

    if (a != 3 && b != 3)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main() {
  int N;
  int A;
  cin >> N >> A;
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  } 
  else if (N % 500 > A) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k; cin >> k;

    cout << a[k-1] << endl;

    return 0;
}

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

const ll MAX = 1000001; 

ll factor[MAX] = { 0 }; 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 

    for (ll i = 2; i < MAX; i++) 
        factor[i] = i; 
  

    for (ll i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    for (ll i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (ll j = i * i; j < MAX; j += i) { 

                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 

ll factCount(ll n) 
{ 
    if (n == 1) 
        return 1; 
  
    ll ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    ll dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    ll c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    ll j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 

int main() {
	generatePrimeFactors();
	ll n;
	cin>>n;
	ll c =0;
	for(ll i=1;i<n;i++){
		c = c +  factCount(i);
		
	}
	cout<<c<<" ";
	return 0;
}

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

int main(){
string str1,str2;
cin>>str1>>str2;
int n=str1.length();

int m=str2.length();
int count=0;
for(int i=0;i<n;i++){
	if(str1[i]!=str2[i]){
		count++;
	}
}
cout<<count;
return 0;

}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> a(n);
    vector<int> c(n);
    
    fori(n){
        cin>>c[i];
        a[i].resize(m);
        forj(m) cin>>a[i][j];
    }
    lli mask=0;
    lli tc=0;
    lli minans=LLONG_MAX;
    for(lli mask=0;mask<=(1<<n);mask++){
        tc=0;
        bitset<13> temp(mask);
        vector<int> know(m,0);
        forj(n){
            
            if(temp[j]){
                tc+=c[j];
                for(int k=0;k<m;k++){
                    know[k]+=a[j][k];
                }
            }
        }
        bool con=true;
        forj(m){
            if(know[j]<x){
                con=false;

                break;
            }
        }
        if(con){
            minans=min(tc,minans);
        }
    }
    if(minans==LLONG_MAX) cout<<-1<<endl;
    else cout<<minans<<endl;

       
}

Measured memory_bytes: 3600
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

use proconio::input;

fn main() {
    input! {
        n: usize,
        s: String
    }
    let mut cnt = 0;
    let mut l = 0;
    let mut r = n - 1;
    let s: Vec<_> = s.bytes().collect();
    loop {
        while l < n - 1 && s[l] != b'W' {
            l += 1;
        }

        while r > 0 && s[r] != b'R' {
            r -= 1;
        }

        eprintln!("{}, {}", l, r);

        if l >= r {
            break;
        }

        l += 1;
        r -= 1;
        

        cnt += 1;
    }

    println!("{}", cnt);
}


Measured memory_bytes: 2692
import sys

X, Y = map(int, input().split())

if X * 4 < Y or X * 2 > Y:
    print("No")
    sys.exit()

while (1):
    if Y % 4 == 0:
        Y = Y - 4
    elif Y % 2 == 0:
        Y = Y - 2
    else:
        print("No")
        break

    if Y == 0:
        print("Yes")
        break


Measured memory_bytes: 9176
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;
 
void main()
{
    int n;
    long k;
    readVars(n, k);

    alias Pair = Tuple!(int, "v", int, "c");
    auto a = new Pair[](n);

    int ai, bi;

    foreach(i ; 0 .. n) {
        readVars(ai, bi);
        a[i] = Pair(ai, bi);
    }

    sort(a);

    long cnt;

    foreach(aj ; a) {
        cnt += aj.c;

        if (cnt >= k) {
            writeln(aj.v);
            return;
        }
    }
}
 
void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

Measured memory_bytes: 3580
n = int(input())
A = list(map(int,input().split()))

buf = i = j = 0
x = A[n-1]
for j in range(n-1):
    if A[j] <= x:
        buf = A[i]
        A[i] = A[j]
        A[j] = buf
        i += 1
A[n-1] = A[i]
A[i] = x
k = 0
[print(A[k],"",end="") if k != i else print("[",A[k],"]",sep="",end=" ") for k in range(n-1)]
print(A[n-1])





Measured memory_bytes: 16388
while True:
    a, b = [int(x) for x in input().split()]
    if a | b == 0:
        break

    n = int(input())

    dp = [
        [0] * (b + 1)
        for x in range(a + 1)
    ]
    dp[0][1] = 1

    for i in range(n):
        x, y = [int(x) for x in input().split()]
        dp[x][y] = -1

    for i in range(1, a + 1):
        for j in range(1, b + 1):
            if dp[i][j] == -1:
                dp[i][j] = 0
            else:
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

    print(dp[a][b])


Measured memory_bytes: 5600
H, W = (int(i) for i in input().split(" "))
status = []
for i in range(H):
    status.append([k for k in input()])
new_status = [["#" for k in range(W)] for i in range(H)]
for i in range(H):
    for k in range(W):
        if status[i][k] == ".":
            count = 0
            if i - 1 >= 0 and k - 1 >= 0:
                if status[i - 1][k - 1] == "#":
                    count += 1
            if i - 1 >= 0:
                if status[i - 1][k] == "#":
                    count += 1
            if i - 1 >= 0 and k + 1 < W:
                if status[i - 1][k + 1] == "#":
                    count += 1
            if k - 1 >= 0:
                if status[i][k - 1] == "#":
                    count += 1
            if k + 1 < W:
                if status[i][k + 1] == "#":
                    count += 1
            if i + 1 < H and k - 1 >= 0:
                if status[i + 1][k - 1] == "#":
                    count += 1
            if i + 1 < H:
                if status[i + 1][k] == "#":
                    count += 1
            if i + 1 < H and k + 1 < W:
                if status[i + 1][k + 1] == "#":
                    count += 1
            new_status[i][k] = str(count)
for i in new_status:
    print("".join(i))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;cin>>n;
   long long sum=0;
   for(int i=1;i<=n;i++)
   {
   	if(i%3==0|i%5==0)continue;
   	else
   	sum+=i;
   }
   cout<<sum<<endl;
	return 0;
 } 

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;


char buf1[2*100+1];

int n;

bool f=1;

string check(string s){
    int cnt = 0;
    for(int i = 0;i < s.length();i++){
        int WhereToI= i;
        if(cnt == 0) WhereToI= 0;

        if(s[i] == '('){
            cnt++;
        }else{
            cnt--;
        }
        if(cnt<0){
            s.insert( WhereToI, "(" );
            return s;
        }
    }
    if(cnt>=0){
        for(int i = 0;i < cnt;i++){
            s.insert( s.length(), ")" );
        }
        f=0;
    }
    return s;
}


signed main(){
    scanf("%d", &n);
    scanf("%s", buf1);
    string s(buf1);

    while(f){
        s=check(s);
    }

    cout<< s << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];map<int,int> m;
  for(int i=1;i<=n;i++){
    cin>>a[i-1];
    m[a[i-1]]=i;
  }
  for(auto it=m.begin();it!=m.end();it++)
    cout<<it->second<<" ";
}
 
    

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

#define INF 1120000000
#define long long long // for codeforces

int num[105];
vector<int> tree[105];
pair<int,int> range[105][105];

bool dfs(int v){
  num[v] = 1;
  for(int to : tree[v]){
    if(num[to]==-1){ if(!dfs(to)) return false; }
    else if(num[to]==1) return false;
  }
  num[v]=0;
  return true;
}

bool solve(){
  int m,n;
  cin>>m>>n;
  rep(i,m){
    int k;
    cin>>k;
    rep(j,n) range[i][j] = mp(0,101);
    rep(j,k){
      int s,t;
      string str;
      cin>>s>>str>>t;
      s--;
      if(str[0]=='>') range[i][s].fi = max(range[i][s].fi, t);
      else range[i][s].se = min(range[i][s].se, t+1);
    }
    rep(j,n) if(range[i][j].se - range[i][j].fi <= 0) return false;
  }

  rep(i,m) rep(j,i){
    rep(k,n){
      if(range[i][k].se <= range[j][k].fi) tree[i].pb(j);
      if(range[j][k].se <= range[i][k].fi) tree[j].pb(i);
    }
  }

  fill(num, num+m, -1);

  rep(i,m) if(num[i]==-1){
    if(!dfs(i)) return false;
  }

  return true;
}

int main(){
  if(solve()) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

const int MAX_N = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(MAX_N);

vector<int> to[MAX_N];

struct DP {
  mint dp;
  int t;
  DP(mint dp=1, int t=0):dp(dp),t(t) {}
  DP operator+(const DP& a) const {
    return DP(dp*a.dp*comb(t+a.t, t), t+a.t);
  }
  DP addRoot() const {
    return DP(dp, t+1);
  }
};

vector<DP> dp[MAX_N];
DP ans[MAX_N];

DP dfs(int v, int p=-1) {
  DP dpSum;
  dp[v] = vector<DP>(to[v].size());
  rep(i,to[v].size()) {
    int u = to[v][i];
    if (u == p) continue;
    dp[v][i] = dfs(u,v);
    dpSum = dpSum + dp[v][i];
  }
  return dpSum.addRoot();
}
void bfs(int v, const DP& dpP=DP(), int p=-1) {
  int deg = to[v].size();
  rep(i,deg) if (to[v][i] == p) dp[v][i] = dpP;

  vector<DP> dpLeft(deg+1);
  rep(i,deg) dpLeft[i+1] = dpLeft[i] + dp[v][i];
  
  vector<DP> dpRight(deg+1);
  for (int i = deg-1; i >= 0; --i)
    dpRight[i] = dpRight[i+1] + dp[v][i];
  
  ans[v] = dpLeft[deg].addRoot();

  rep(i,deg) {
    int u = to[v][i];
    if (u == p) continue;
    DP d = dpLeft[i] + dpRight[i+1];
    bfs(u, d.addRoot(), v);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  bfs(0);
  rep(i,n) cout << ans[i].dp << endl;
  return 0;
}


Measured memory_bytes: 38516
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N;
	int sum = 0;

	cin >> N;
	vector<int> T(N);
	for(int i = 0; i < N; i++) {
		cin >> T[i];
		sum += T[i];
	}

	int M;
	cin >> M;
	vector<int> P(M);
	vector<int> X(M);
	for(int i = 0; i < M; i++) {
		cin >> P[i] >> X[i];
	}

	for(int i = 0; i < M; i++) {
		cout << (sum - T[P[i] - 1] + X[i]) << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

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

typedef long long ll;

const ll INFLL = 1e18;


int main() {
	ll A,B,Q;
	cin>>A>>B>>Q;
	vector<ll> s(A+2),t(B+2);
	s[0] = t[0] = -INFLL;
	s[A+1] = t[B+1] = INFLL;
	rep1(i,A+1)cin>>s[i];
	rep1(i,B+1)cin>>t[i];
	rep(i,Q){
		ll x; cin>>x;
		ll ans =  INFLL;
		int si = lower_bound(all(s), x) - s.begin();
		int ti = lower_bound(all(t), x) - t.begin();
		for(int j = si-1; j <= si; j++){
			for(int k = ti-1; k <= ti; k++){
				ll S = s[j];
				ll T = t[k];
				chmin(ans, abs(S - x) + abs(S - T));
				chmin(ans, abs(T - x) + abs(T - S));
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2944
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n; readV(n);
  string[] s; readC(n, s);

  auto c = new int[][](26, n);
  foreach (i, si; s)
    foreach (ch; si)
      c[ch-'a'][i]++;

  foreach (i; 0..26)
    write((cast(dchar)('a'+i)).repeat.take(c[i].reduce!min));
  writeln;
}


Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
a,b,c,d = gi
ans = array 101,0
repl a+1,b do |i|
ans[i] += 1
end

repl c+1,d do |i|
ans[i] += 1
end

puts ans.select{|s|s == 2}.size


Measured memory_bytes: 2428
#include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
    int n, max = 0, sum;
    string s;
    cin >> n >> s;
    unordered_map <char, int> arr1, arr2;
    
    arr1[ s[0] ]++;
    for(int i = 1; i < n; i++)
        arr2[ s[i] ]++;
        
    for(auto x: arr1)
        if( arr1[x.first] > 0 and arr2[x.first] > 0 )
            max++;
            
    for(int i = 1; i < n-1; i++)
    {
        sum = 0;
        arr1[ s[i] ]++;
        arr2[ s[i] ]--;
        for(auto x: arr1)
            if( arr1[x.first] > 0 and arr2[x.first] > 0 )
                sum++;
        if( sum > max )
            max = sum;
    }
    cout << max;
}

Measured memory_bytes: 3600
using System;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var S = int.Parse(Console.ReadLine());
            var l = S / 100;
            var r = S % 100;

            if (1 <= l && l <= 12)
            {
                if (1 <= r && r <= 12)
                {
                    Console.WriteLine("AMBIGUOUS");
                }
                else
                {
                    Console.WriteLine("MMYY");
                }
            }
            else if (1 <= r && r <= 12)
            {
                Console.WriteLine("YYMM");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n;
	cin >> n;
	vector <int> x(n),y(n);
	for(int i = 0;i < n;++i){
		cin >> x[i] >> y[i];
	}
	vector <lli> plus(n),minus(n);
	for(int i = 0;i < n;++i){
		plus[i] = x[i] + y[i];
		minus[i] = x[i] - y[i];
	}
	sort(plus.begin(),plus.end());
	sort(minus.begin(),minus.end());
	cout << max({plus[n - 1] - plus[0],plus[0] - plus[n - 1],minus[0] - minus[n - 1],minus[n - 1] - minus[0]}) << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 7920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum = 0;
		for (int i = 1; i <= n; ++i) {
			if (i % 3 != 0 && i % 5 != 0) {
				sum += i;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 35696
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadLongArray();
	long a = tmp[0], b = tmp[1], c = tmp[2], k = tmp[3];

	long ans = a - b;
	if ((k&1) == 1) ans = - ans;

	if (Math.Abs(ans) > (long) 1e18) WriteLine("Unfair");
	else WriteLine(ans);
    }
}


Measured memory_bytes: 13396
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}

char a[59];

map<pair<int,int>,int> mp;
int vis[159];
int main()
{
    fast;
    string s;
    cin>>s;
    bool ok=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7') ok=1;
    }
    cout<<(ok?"Yes\n":"No\n");
    return 0;

}




Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all($) begin($), end($)
#define rall($) rbegin($), rend($)

bool visited[202020];

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

  int n, m; cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    int a, b; cin >> a >> b; --a; --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  int ans = 0;

  auto bfs = [&](int root) -> int {
    queue<int> que;
    que.emplace(root);
    int sz = 1;
    visited[root] = true;
    while (!que.empty()) {
      int cur = que.front(); que.pop();
      for (int nxt : g[cur]) {
        if (visited[nxt]) continue;
        visited[nxt] = true;
        ++sz;
        que.emplace(nxt);
      }
    }
    return sz;
  };

  for (int i = 0; i < n; ++i) {
    if (visited[i]) continue;
    ans = max(ans, bfs(i));
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 14940
N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
    

n = int('9'*N)
if N > 1:
    start = int('1' + '0'*(N-1))
else:
    start = 0
ans = []

for i in range(start, n+1):
    I = str(i)
    for m in range(M):
        if N >= 2 and S[m] == 1 and C[m] == 0:
            break
        if S[m] <= len(I):
            if I[S[m]-1] != str(C[m]):
                break
    else:
        ans.append(I)

if len(ans) == 0:
    print(-1)
    exit()

ans_map = list(map(int,ans))

print(min(ans_map))


Measured memory_bytes: 9172
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int N, A, B, C;
int cost = INF;
vector<int> l;


void dfs(int i, int curCost, int curA, int curB, int curC) {
    if (curA > 0 && curB > 0 && curC > 0) {
        int totalCost = curCost;
        totalCost += abs(A - curA);
        totalCost += abs(B - curB);
        totalCost += abs(C - curC);
        cost = min (totalCost, cost);
    }

    if (i >= N) return;

    dfs(i + 1, curA > 0 ? curCost + 10 : curCost, curA + l[i], curB, curC);
    dfs(i + 1, curB > 0 ? curCost + 10 : curCost, curA, curB + l[i], curC);
    dfs(i + 1, curC > 0 ? curCost + 10 : curCost, curA, curB, curC + l[i]);
    dfs(i + 1, curCost, curA, curB, curC); // 使わない
}

int main() {
    cin >> N >> A >> B >> C;

    rep(i, N) {
        int li;
        cin >> li;
        l.pb(li);
    }

    dfs(0,0,0,0,0);

    cout << cost << endl;
}

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

public class Main {

	public static void main(String[] args) {
		
		String CMD = null ;
		BufferedReader BR = null;
		BR = new BufferedReader(new InputStreamReader(System.in));
		try {CMD = BR.readLine();
		} 
		catch (IOException e) {e.printStackTrace();
		}
		
		double time = Double.parseDouble(CMD);
		double jikan = time;
		jikan = jikan /3600;
		int jikan2 = (int) Math.floor(jikan);
		
		double amari = time % 3600;
		double hun = amari / 60;
		int hun2 = (int) Math.floor(hun);
		
		double byou = amari%60;
		int byou2 = (int) Math.floor(byou);
		
		
		
		System.out.println(jikan2+":"+hun2+":"+byou2);
	}

}

Measured memory_bytes: 24456
# #! /usr/bin/env python
# # -*- coding: utf-8 -*-
def main():
    unko_ans = 0
    is_unko = True
    unko_n = int(input())
    unko_a = list(map(int, input().split()))
    while is_unko:
        for j in range(len(unko_a)):
            if unko_a[j] % 2 == 0:
                unko_a[j] = unko_a[j] / 2
            else:
                is_unko = False
                print(unko_ans)
                break
        unko_ans = unko_ans + 1
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	h := scanInt()
	n := scanInt()

	as := scanInts(n)

	sum := 0
	for _, e := range as {
		sum += e
	}

	if sum <h {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}

}


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

int main(){
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  vector<vector<int>>vec(b,vector<int>(2));
  for(int i=0;i<b;i++){
    cin>>vec.at(i).at(0)>>vec.at(i).at(1);
  }
  
  int count=0;
  vector<int>veccount(a+1,0);
  for(int i=1;i<a;i++){
    if(s.at(i-1)=='A'&&s.at(i)=='C'){
      count++;
    }
    veccount.at(i)=count;
  }
  veccount.at(a)=count;
  
  for(int i=0;i<b;i++){
    cout<<veccount.at(vec.at(i).at(1)-1)
         -veccount.at(vec.at(i).at(0)-1)<<endl;
  }
}
                               

Measured memory_bytes: 6784
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int i,j,k,n,m,x,y,z,xx,yy;
struct node{
	int x,y;
} a[20000];
struct egde{
	int x,y;
	double z;
} b[500000];

int fa[20000];
double sum,now;

double dist(int x,int y)
{
	return  sqrt( (a[x].x-a[y].x)*(a[x].x-a[y].x)*1.0+  (a[x].y-a[y].y)*(a[x].y-a[y].y)*1.0 );
}

bool cmp(struct egde a,struct egde b)
{
	if (a.z>b.z) return true;
 	return false;
}

int getf(int x)
{
	if (x==fa[x]) return x;
	return (fa[x]=getf(fa[x]));
}

int main()
{
	scanf("%d%d",&n,&m);
	
	for(i=1;i<=n;i++) fa[i]=i;
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	sum=0;
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		b[i].x=x;
		b[i].y=y;
		b[i].z=dist(x,y);
		sum+=b[i].z;
	}
	now=0;
	sort(b,b+m,cmp);
	
	for(i=0;i<m;i++)
	{
		xx=getf(b[i].x);
		yy=getf(b[i].y);
		if (xx!=yy)
		{
			now+=b[i].z;
			fa[xx]=yy;
		}
	}
	
	printf("%.3lf\n",sum-now);
	
	return 0;
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
using namespace std;
signed  main()
{
  string s;
  int a=0;
  cin>>s;
  if(s[0]==s[1]){
    a++;
  }
  if(s[1]==s[2]){
    a++;
  }
  if(s[2]==s[3]){
    a++;
  }
  if(a>0){
    cout<<"Bad\n";
  }else{
    cout<<"Good\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

//using ll = long long;
//const ll mod = LLONG_MAX;

int main(){
  int N,count = 0;
  string v;

  cin>>N;

  REP(i,N){
    cin>>v;
    if(v == "A") count++;
    else if(v == "Un") count--;

    if(count < 0){
      cout<<"NO"<<endl;
      return 0;
    }
  }

  if(count == 0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 3160
s=input()
for i in range(len(s)):
    if i%2==0:
        if s[i]=="R" or s[i]=="U" or s[i]=="D":
            pass
        else:
            print("No")
            exit()
    else:
        if s[i]=="L" or s[i]=="U" or s[i]=="D":
            pass
        else:
            print("No")
            exit()
print("Yes")

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

int main() {
  int N, M;
  cin >> N;
  map<string, int> mp;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    ++mp[s];
  }
  cin >> M;
  for (int i = 0; i < M; ++i) {
    string t;
    cin >> t;
    --mp[t];
  }
  int ans = 0;
  for (const auto& kv : mp) {
    ans = max(ans, kv.second);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n;
map<string, int> m;
map<int, V<string>> h;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(_, 0, n){
    string s;
    cin >> s;
    m[s]++;
  }
  for(auto p:m) h[p.se].pb(p.fi);
  auto v = h.rbegin()->se;
  sort(all(v));
  for(auto s:v) cout << s << endl;
}

Measured memory_bytes: 31344
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
int d, n;
char m[110][110];
signed main() {
	cin >> d;
	for (int v = 0; v < d; v++) {
		if (v)cout << endl;
		cin >> n;
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)m[i][j] = ' ';
		int x = -1, y = 0, p = n - 1, q = 0;
		while (1) {
			m[p][q] = '#';
			if (p + x < 0) {
				if (n == 1)break;
				x = 0; y = 1;
			}
			if (q + y >= n) {
				if (n == 2)break;
				x = 1; y = 0;
			}
			if (p + x >= n) {
				if (n == 3)break;
				x = 0; y = -1;
			}
			if (y == -1 && m[p][q - 2] == '#') {
				if (m[p - 1][q + 1] == '#')break;
				x = -1; y = 0;
				if (m[p - 2][q] == '#')break;
			}
			if (x == -1 && m[p - 2][q] == '#') {
				if (m[p + 1][q + 1] == '#')break;
				x = 0; y = 1;
				if (m[p][q + 2] == '#')break;
			}
			if (y == 1 && m[p][q + 2] == '#') {
				if (m[p + 1][q - 1] == '#')break;
				x = 1; y = 0;
				if (m[p + 2][q] == '#')break;
			}
			if (x == 1 && m[p + 2][q] == '#') {
				if (m[p - 1][q - 1] == '#')break;
				x = 0; y = -1;
				if (m[p][q - 2] == '#')break;
			}
			p += x; q += y;
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)cout << m[i][j];
			cout << endl;
		}
	}
}


Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int n,dp[1001][8];
string str;
int change(char ch){
  if(ch=='J')return 0;
  if(ch=='O')return 1;
  else return 2;
}
int main(){
  cin>>n>>str;
  for(int i=0;i<1001;i++){
    for(int j=0;j<8;j++){
    dp[i][j]=0;
    }
  }
  //j=0 o=1 i=2
  dp[0][4]=1;
  for(int i=0;i<n;i++){
    if(str[i]=='J'){
      dp[i+1][1]=0;//I
      dp[i+1][2]=0;//O
      dp[i+1][3]=0;//OI
      dp[i+1][4]=dp[i][7]+dp[i][6]+dp[i][5]+dp[i][4];//J
      dp[i+1][5]=dp[i][1]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];//JI I&#227;&#129;&#8249;J&#227;&#129;&#338;&#233;&#141;&#181;&#227;&#8218;’&#229;‰&#141;&#230;—\&#227;&#8218;&#8218;&#227;&#129;&#161;&#227;&#129;&#8249;&#227;&#129;&#710;&#227;&#129;£&#227;&#129;&#376;
      dp[i+1][6]=dp[i][2]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];//JO
      dp[i+1][7]=dp[i][1]+dp[i][2]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];//JOI
    }else if(str[i]=='O'){
      dp[i+1][1]=0;//I
      dp[i+1][2]=dp[i][2]+dp[i][3]+dp[i][6]+dp[i][7];//O
      dp[i+1][3]=dp[i][1]+dp[i][2]+dp[i][3]+dp[i][5]+dp[i][6]+dp[i][7];//IO
      dp[i+1][4]=0;
      dp[i+1][5]=0;
      dp[i+1][6]=dp[i][2]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];
      dp[i+1][7]=dp[i][1]+dp[i][2]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];//JOI
    }else{
      dp[i+1][1]=dp[i][1]+dp[i][3]+dp[i][5]+dp[i][7];
      dp[i+1][2]=0;
      dp[i+1][3]=dp[i][1]+dp[i][2]+dp[i][3]+dp[i][5]+dp[i][6]+dp[i][7];//IO
      dp[i+1][4]=0;
      dp[i+1][5]=dp[i][1]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];
      dp[i+1][6]=0;
      dp[i+1][7]=dp[i][1]+dp[i][2]+dp[i][3]+dp[i][4]+dp[i][5]+dp[i][6]+dp[i][7];//JOI
    }
    for(int j=0;j<8;j++)dp[i+1][j]%=10007;
  }
  int sum=0;
  for(int i=0;i<8;i++)sum+=dp[n][i];
  cout<<(sum)%10007<<endl;
 
 
  
  return 0;
}

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<map<string, long long>> cnt(n + 1);
    for (int mask = 0; mask < 1 << n; mask++) {
        string t1, t2;
        for (int i = 0; i < n; i++) {
            (mask >> i & 1 ? t1 : t2) += s[i];
        }
        reverse(begin(t2), end(t2));
        cnt[t1.size()][t1 + t2]++;
    }
    long long ans = 0;
    for (int mask = 0; mask < 1 << n; mask++) {
        string t1, t2;
        for (int i = 0; i < n; i++) {
            (mask >> i & 1 ? t1 : t2) += s[n + i];
        }
        reverse(begin(t2), end(t2));
        ans += cnt[t2.size()][t2 + t1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 68224
#include <iostream>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

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

  map<int, int> m;
  rep(i, N) {
    int A; cin >> A;
    ++m[A];
  }
  if (m.size() == 1) {
    if (m.begin()->first * 2 <= N || m.begin()->first == N-1)
      cout << "Yes\n";
    else
      cout << "No\n";
    return 0;
  }
  if (m.size() > 2) {
    cout << "No\n";
    return 0;
  }

  int a = max(m.begin()->first, m.rbegin()->first);
  int alone = m[a-1];

  if (m[a] + m[a-1] != N) {
    cout << "No\n";
    return 0;
  }
  if (alone < a && 2 * (a - alone) <= m[a])
    cout << "Yes\n";
  else
    cout << "No\n";


  return 0;
}


Measured memory_bytes: 4992