akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException {
		long arr[] = new long[5]; int N = readInt(); for(int i = 1; i<=N; i++) {
			String s = next();
			if(s.charAt(0) == 'M') arr[0]++; if(s.charAt(0) == 'A') arr[1]++;
			if(s.charAt(0) == 'R') arr[2]++; if(s.charAt(0) == 'C') arr[3]++; if(s.charAt(0) == 'H') arr[4]++;
		}
		
		long ans = 0;
		for(int i = 0; i<5; i++) for(int j = i+1; j<5; j++) for(int k = j+1; k<5; k++) ans += arr[i]*arr[j]*arr[k]; println(ans);
		exit();
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;

	static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}

	static long readLong() throws IOException {
		return Long.parseLong(next());
	}

	static float readFloat() throws IOException {
		return Float.parseFloat(next());
	}

	static boolean readBoolean() throws IOException {
		return Boolean.parseBoolean(next());
	}

	static short readShort() throws IOException {
		return Short.parseShort(next());
	}

	static byte readByte() throws IOException {
		return Byte.parseByte(next());
	}

	static int readInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double readDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static char readCharacter() throws IOException {
		return next().charAt(0);
	}

	static String readLine() throws IOException {
		return br.readLine().trim();
	}

	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		br.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 34716
package main

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

var dict = make(map[string]string)

func addCollection(a string) {
	if _, ok := dict[a]; ok {
	} else {
		dict[a] = ""
	}
}

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	var p string
	if scanner.Scan() {
		p = scanner.Text()
	}
	N, _ := strconv.Atoi(p)
	for i := 0; i < N; i++ {
		if scanner.Scan() {
			addCollection(scanner.Text())
		}
	}
	fmt.Println(len(dict))
}


Measured memory_bytes: 23280
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力受け取り, 入次数も管理する
int n;
    cin >> n;
int maxi=1000000;
int data[n];
for(int i=0;i<n;i++){
cin >> data[i];
}
int flag=0;
int s1=0,s2=0;

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


for(int i=0;i<n;i++){
if(flag==0){
s1+=data[i];
}else{
s2+=data[i];
}
if(i>=r)flag=1;

}
maxi=min(maxi, abs(s1-s2));
s1=0;
s2=0;
flag=0;
}
cout << maxi;

}




Measured memory_bytes: 256
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
#define vi vector<int>
#define all(x) x.begin(),x.end()
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int fact[2000005];
int infact[2000005];

int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}

int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}

void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}

int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}

int n,m;

vector<int> adj[1000005];
bool vis[1000005];
bool vis2[1000005];
int ans[1000005];

bool poss=1;

int dfs(int c,int p){
  bool lp=1;
  int leaf=0;
  for(auto it : adj[c]){
    if(it!=p){
      lp=0;
      leaf+=dfs(it,c);
    }
  }
  if(lp) return 1;
  else{
    if(leaf<3) poss=0;
    return 0;
  }
  
}

void dfs2(int s,int val){
  if(vis2[s]) return ;
  vis2[s]=1; ans[s]=val;
  for(auto it : adj[s])
    dfs2(it,val);
}

int rev(int a){
  int r=0;
  while(a!=0){
    r+=a%10;
    r*=10;
    a/=10;
  }
  return r/10;
}
int32_t main(){ 

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  facto();
  int n; cin>>n;
  f(i,1,361) {
    if((i*n)%360==0){
      cout<<i;
      return 0;
    }
  }
  return 0;
}


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

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

	string s;
	int y,m,d;

	cin >> s;

	y = stol(s.substr(0,4));
	m = stoi(s.substr(5,2));
	d = stoi(s.substr(8,2));

	if(y<2019)
	{
		cout << "Heisei" << '\n';
	}
	else if(y>2019)
	{
		cout << "TBD" << '\n';
	}
	else
	{
		if(m<4)
		{
			cout << "Heisei" << '\n';
		}
		else if(m>4)
		{
			cout << "TBD" << '\n';
		}
		else
		{
			if(d<=30)
			{
				cout << "Heisei" << '\n';
			}
			else
			{
				cout << "TBD" << '\n';
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] a = new int[3];
    int gap = 0;

    for (int i = 0; i < 3; i++) {
      a[i] = sc.nextInt();
    }

    Arrays.sort(a);

    for (int i = 0; i < 2; i++) {
      gap += a[i+1] - a[i];
    }

    System.out.println(gap);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
long n,k;
void solve()
{
    long i,x;
    for (i=1;i<=n;i++)
        cin>>x;
    if ((n-1)%(k-1)==0) cout<<(n-1)/(k-1);
    else cout<<(n-1)/(k-1)+1;
    cout<<endl;
}
int main()
{
    while(cin>>n>>k)
        solve();
}

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

int calc(int n){
    if (n == 1) return 1;
    int count = 0;
    
    for (int i = 1; i * i <= n; i++){
        if (n % i == 0){
            count += 2;
        }
        if (i*i == n) count--;
    }
    
    return count;
}

int main(void){
    int n;
    cin >> n;
    
    int ans = 0;
    
    for (int i = 1; i <= n; i+=2){
        if (calc(i) == 8) ans++;
        //cout << calc(i) << endl;
    }
    
    cout << ans << endl;
}


/*
corner case: 1
time complexity: O(Nsqrt(N))
space complexity: O(1)
*/


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W, M;
    cin >> H >> W >> M;

    vector<ll> Mh(M);
    vector<ll> Mw(M);

    vector<ll> h(H+1, 0);
    vector<ll> w(W+1, 0);

    REP(i, M){
        ll x;
        ll y;

        cin >> x >> y;

        Mh[i] = x;
        Mw[i] = y;
        
        h[x]++;
        w[y]++;
    }

    vector<ll> hq(H+1);
    vector<ll> wq(W+1);

    REP(i, H+1){
        hq.push_back(h[i]);
    }
    REP(i, W+1){
        wq.push_back(w[i]);
    }

    sort(hq.rbegin(), hq.rend());
    sort(wq.rbegin(), wq.rend());

    ll now = hq[0];
    ll hcount = 0;

    REP(i, H){
        if(hq[i] == now) hcount++;
        else break;
    }

    now = wq[0];
    ll wcount = 0;

    REP(i, W){
        if(wq[i] == now) wcount++;
        else break;
    }
    
    ll maxcount = hcount * wcount;
    ll ans = hq[0] + wq[0];

    ll temp_count = 0;
    REP(i, M){
        if(h[Mh[i]] + w[Mw[i]] == ans) temp_count++;
    }

    if(temp_count < maxcount){
        cout << ans << endl;
    }
    else{
        cout << ans-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 21932
#segtree ライブラリ
#BITライブラリの作成
#リストの要素を1,0で長さをｎとした時に使える
class BIT:
    def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
    def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
    def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
    def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1)
n=int(input())
s=list(input())
q=int(input())
que=[]

for i in range(q):
    p=list(input().split())
    que.append(p)
alpha="abcdefghijklmnopqrstuvwxyz"
segtree={alpha[i]:BIT(n) for i in range(26)}  
for i in range(n):
    segtree[s[i]].add(i+1,1)
for q in que:
    x,y,z=q[0],q[1],q[2]
    if int(x)==1:
        #y文字目をzに変更する
        y=int(y)  
        for i in range(26):
            if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
        segtree[z].add(y,1)
    else:
        ans=0
        for i in range(26):
            if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
        print(ans)       


Measured memory_bytes: 168732
n,d = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if i==j:
            continue
        else:
            dist = 0
            for k in range(d):
                dist += (lst[j][k] - lst[i][k])**2
        if dist**0.5 == int(dist**0.5):
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    int N;
    cin>>N;
    multimap<long,int>a={};
    multimap<long,int>b={};
    multimap<long,int>c={};
    long long B[N]={};
    long long C[N]={};
    long x;
    for(int i=0;i<N;i++){
            cin >> x;
            a.insert(make_pair(x,i));
    }
    for(int i=0;i<N;i++){
            cin >> x;
            b.insert(make_pair(x,i));
    }
    for(int i=0;i<N;i++){
            cin >> x;
            c.insert(make_pair(x,i));
    }
    x=0;
    auto iter=b.begin();
    auto it=a.begin();
    auto last=a.lower_bound(iter->first);
    for(auto iter=b.begin();iter !=b.end();++iter){
        B[iter->second]+=x;
            while(it!=last){
            B[iter->second]++;
            it++;
            }
            x=B[iter->second];
            it=last;
            iter++;
            last=a.lower_bound(iter->first);
            iter--;
    }
    x=0;
    iter=c.begin();
    it=b.begin();
    last=b.lower_bound(iter->first);
    for(auto iter=c.begin();iter !=c.end();++iter){
   C[iter->second]+=x;
    while(it!=last){
        C[iter->second]+=B[it->second];
        it++;
    }
        x=C[iter->second];
        it=last;
        iter++;
        last=b.lower_bound(iter->first);
        iter--;
    }
    long long answer=0;
    for(int i=0;i<N;i++){
        answer+=C[i];
    }
    
    cout << answer <<endl;

 return 0;
}

Measured memory_bytes: 20608
using System;

namespace _046b
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int N = read[0];
            int K = read[1];
            long S = K;
            for(int i = 1; i < N; i++){
                S*=(K-1);
            }
            Console.WriteLine(S);
        }
    }
}

Measured memory_bytes: 13140
n = int(input())
dic = {i:0 for i in range(100)}
for i in range(1,n+1):
    num = str(i)
    dic[int(num[0])*10+int(num[-1])] += 1
count = 0
for i in range(1,10):
    count += dic[i*11]**2
    for j in range(i+1,10):
        count += dic[i*10+j]*dic[j*10+i]*2
print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    while(cin >> n, n){
        vs t(n),s;
        rep(i,n)cin >> t[i];
        rep(i,n){
            bool c = true;
            rep(j,n)if(i != j){
                rep(k,t[j].size()){
                    if(t[j].substr(k,t[i].size()) == t[i])c = false;
                }
            }
            if(c)s.push_back(t[i]);
        }
        n = s.size();
        vector<vi> dp(1<<n,vi(n,INF));
        rep(i,n){
            dp[1<<i][i] = s[i].size();
        }
        rep(bit,1<<n)rep(i,n)if(dp[bit][i] < INF){
            //cout << bit << " " << i << " " << dp[bit][i] << endl;
            rep(j,n){
                if(bit & 1<<j)continue;
                int cnt = 0;
                rep(k,min(s[i].size(),s[j].size())){
                    bool c = true;
                    rep(l,k)if(s[i][s[i].size()-k+l] != s[j][l])c = false;
                    if(c) cnt = k;
                }
                //cout << " " << i << " " << j << " " << cnt << endl;
                int ne = bit | (1<<j);
                dp[ne][j] = min(dp[ne][j], dp[bit][i] + (int)s[j].size() - cnt);
            }
        }
        int ans = LINF;
        rep(i,n)ans = min(ans, dp[(1<<n)-1][i]);
        cout << ans << endl;
    }
}



Measured memory_bytes: 5628
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 300001
#define MOD 1000000007ll
using namespace std;
LL a[MAXN];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    LL ans=0;
    for(LL i=1;i<=60;i++)
    {
        LL cnt1=0,cnt0=0;
        for(int j=1;j<=n;j++)
        {
            if(a[j]&(1ll<<(i-1)))cnt1++;
            else cnt0++;
        }
        ans+=((1ll<<(i-1))%MOD)*cnt1%MOD*cnt0%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    int d, n, ans;
    cin >> d >> n;
    ans = 1;
    rep (i, d)
        ans *= 100;

    ll true_ans = 0;
    rep (i, n) {
        true_ans += ans;
        if ((i + 1) % 100 == 0) true_ans += ans;
    }

    print(true_ans);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 256
/**
 *	author:   fractal
 *	timus:    288481RF
 *	created: 08/22/20 18:20:35
**/

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

#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define szc(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound 
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 1e3 + 2;
const int M = 1e5;
const int mod = 0;
const int inf = 2e9 + 3;
const ll INF = 1e16;

set <pair<ll, pii>> s;
int x, y, nx, ny, n, m, a[N][N];
ll cost, d[N][N];

bool ok(int x, int y) {
	return (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y]);
}

int main() {
	scanf("%d %d\n", &n, &m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			d[i][j] = INF;
	scanf("%d %d\n", &x, &y);
	scanf("%d %d\n", &nx, &ny);
	d[x][y] = 0;
	s.insert({0LL, {x, y}});
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			char c;
			scanf("%c", &c);
			a[i][j] = (c == '.');
		}
		scanf("\n");
	}
	while (!s.empty()) {
		x = s.begin()->S.F;
		y = s.begin()->S.S;
		cost = s.begin()->F;	
		s.erase(s.begin());
		for (int i = -2; i <= 2; ++i)
			for (int j = -2; j <= 2; ++j)
				if (ok(x + i, y + j) && d[x + i][y + j] > cost + ((abs(i) + abs(j)) != 1)) {
					d[x + i][y + j] = cost + ((abs(i) + abs(j)) != 1);
					s.insert({d[x + i][y + j], {x + i, y + j}});
				}					
	}
	
	if (d[nx][ny] >= INF)
		d[nx][ny] = -1;
	printf("%lld", d[nx][ny]);
}


Measured memory_bytes: 16156
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

struct Qur
{
	int t, f;
	char s;
	Qur(int t, int f, char s) :t(t), f(f), s(s) {}
	Qur() :Qur(0, 0, ' ') {}
};

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

	string S;
	string L, R;
	int Q;
	cin >> S >> Q;

	vector<Qur> qv(Q);
	int cnt = 0;
	rep(i, 0, Q)
	{
		cin >> qv[i].t;
		if (qv[i].t == 2)cin >> qv[i].f >> qv[i].s;
		else cnt++;
	}
	int tcnt = 0;
	rep(i, 0, Q)
	{
		if (qv[i].t == 1)tcnt++;
		else
		{
			if (qv[i].f == 1 && (cnt - tcnt) % 2 == 0 || qv[i].f == 2 && (cnt - tcnt) % 2 == 1)
			{
				L += qv[i].s;
			}
			else
			{
				R += qv[i].s;
			}
		}
	}

	reverse(all(L));
	if (cnt % 2 == 1)reverse(all(S));
	cout << L+S+R << endl;

	return 0;
}

Measured memory_bytes: 6036
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e5;

int n,m,temp,connected;
int u[N] , v[N] , ans[N];
int parent[N],size[N];

void init(){
   for(int i = 1;i <= n;i++){ parent[i] = i; size[i] = 1 ; }

}

int getparent(int k){
   while(k!=parent[k]){ parent[k] = parent[parent[k]]; k = parent[k]; }
   return k;
}

int getparent2(int x){
   while(x!=parent[x]) x = parent[x];
   return x;
}

int getsize(int x){
   return size[getparent(x)];
}

void unite(int x , int y){

   int par1 = getparent(x);
   int par2 = getparent(y);
 if(par2==par1) return;
 if(size[par1] > size[par2])
      swap(par1,par2);
  temp-=size[par1]*size[par2];
  size[par2]+=size[par1];
  size[par1] = 0;
  parent[par1] = parent[par2]; 

}

int32_t main() {
     // #ifndef ONLINE_JUDGE
     // freopen("input.txt","rb",stdin);
     // #endif   
 
  cin >> n >> m;
  temp = n*(n-1)/2;
  
init();  
for(int i = 1;i <= m; i++) cin >> u[i] >> v[i] ;
   for(int i = m; i >= 1; i--){
      ans[i] = temp;
      if(getparent2(u[i])!=getparent(v[i]))
        unite(u[i],v[i]);
      //cout << temp << " "; 
   }
 for(int i=1;i <=m;i++) cout << ans[i] << "\n";
return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int H, W; cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    int dirc[2][4] = {
        {0, -1, 0, 1},
        {1, 0, -1, 0},
    };

    int ans = 0;

    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '#') continue;

            // cout << endl;
            // cout << "i: " << i << "j: " << j << endl;
            vector<vector<int>> dstnc(H, vector<int>(W, -1));
            queue<P> tque;
            tque.push(make_pair(i, j));
            dstnc[i][j] = 0;

            while(!tque.empty()) {
                P hw_p = tque.front();
                tque.pop();

                int h = hw_p.first;
                int w = hw_p.second;
                // cout << "now: i: " << h << " j: " << w << endl;

                rep(d, 4) {
                    int nh, nw;
                    nh = h + dirc[0][d];
                    nw = w + dirc[1][d];

                    if (0 <= nh && 0 <= nw && nh < H && nw < W && dstnc[nh][nw] == -1 && S[nh][nw] == '.') {
                        tque.push(make_pair(nh, nw));
                        // cout << "push: i: " << nh << " j: " << nw << endl;
                        dstnc[nh][nw] = dstnc[h][w] + 1;
                        ans = max(ans, dstnc[nh][nw]);
                    }
                }
                /*
                rep(k, H) {
                    rep(l, W) {
                        cout << dstnc[k][l];
                    }
                    cout << endl;
                }
                */
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

#define MAX_N 2000005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r); // n * (n-1) * ... * (n-r+1)
  ans = (ans * finv[r]) % mod; // フェルマーの小定理
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  make();
  int N, K;
  cin >> N >> K;
  for(int i=1; i<=K; i++) {
    cout << comb(K-i+i-1, i-1) * comb(N-K-(i-1)+i, i) % mod << "\n";
  }
  return 0;
}


Measured memory_bytes: 50532
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), bit(60);
    rep(i,n){
        cin >> a[i];
        rep(j,60){
            if(a[i]>>j & 1) ++bit[j];
        }
    }
    rep(j,60) bit[j] %= 2;
    rep(i,n){
        ll b = 0;
        rep(j,60){
            if(a[i]>>j & 1){
                if(bit[j] == 0) b += (1LL<<j);
            }
            else{
                if(bit[j] == 1) b += (1LL<<j);
            }
        }
        cout << b << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4684
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n) cin >> c[i];

    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    ll ans = 0;
    vector<ll> b_c;
    REP(i,b.size()) {
        auto it = upper_bound(ALL(c),b[b.size()-1-i]);
        ll prev = i == 0 ? 0 : b_c.back();
        b_c.push_back(prev + distance(it,c.end()));
        //cerr << b_c.back() << endl;
    }
    reverse(ALL(b_c));
    REP(i,a.size()) {
        auto it = upper_bound(ALL(b),a[i]);
        int d = distance(b.begin(),it);
        ans += b_c[d];
        //cerr << d << endl;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;

ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}

const int N = 5e5;
// ll a[N];

signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);    
    
    ll a, b, k; cin >> a >> b >> k;
    if(k <= a) cout << a-k << " " << b << endl;
    else cout << 0 << " " << max(0ll, b-(k-a)) << endl;

 
    return 0;
    
}
    


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

int main() {
  int num;
  cin >> num;
  
  vector<long long> vec(num);
  for(int i = 0; i < num; i++) cin >> vec.at(i);
  
  long long tmpHeight =0;
  long long Max = 0;
  bool chk = true;
  for(int i = 0; i < num; i++){
    tmpHeight = vec.at(i);
    if(Max > vec.at(i) + 1){
      chk = false;
      break;
    }
    if(i == 0) continue;
    
    if(vec.at(i) >= tmpHeight){
      tmpHeight = vec.at(i);
    }else if(vec.at(i) +1 == tmpHeight){
      tmpHeight = vec.at(i);
    }else{
      chk = false;
      break;
    }
    
    Max = max(Max,tmpHeight);
  }
  
  if(chk == true) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	char S[10] = "a";

	scanf("%s", S);

	if(S[0] == 'h'&& S[1] == 'i' &&S[2] == '\0'&& S[3] == '\0'&&S[4] == '\0'&& S[5] == '\0'&&S[6] == '\0'&& S[7] == '\0'&&S[8] == '\0'&& S[9] == '\0')
		printf("Yes");
	else if(S[0] == 'h'&& S[1] == 'i' &&S[2] == 'h'&& S[3] == 'i'&&S[4] == '\0'&& S[5] == '\0'&&S[6] == '\0'&& S[7] == '\0'&&S[8] == '\0'&& S[9] == '\0')
		printf("Yes");
	else if(S[0] == 'h'&& S[1] == 'i' &&S[2] == 'h'&& S[3] == 'i'&&S[4] == 'h'&& S[5] == 'i'&&S[6] == '\0'&& S[7] == '\0'&&S[8] == '\0'&& S[9] == '\0')
		printf("Yes");
	else if(S[0] == 'h'&& S[1] == 'i' &&S[2] == 'h'&& S[3] == 'i'&&S[4] == 'h'&& S[5] == 'i'&&S[6] == 'h'&& S[7] == 'i'&&S[8] == '\0'&& S[9] == '\0')
		printf("Yes");
	else if(S[0] == 'h'&& S[1] == 'i' &&S[2] == 'h'&& S[3] == 'i'&&S[4] == 'h'&& S[5] == 'i'&&S[6] == 'h'&& S[7] == 'i'&&S[8] == 'h'&& S[9] == 'i')
		printf("Yes");
		
	else
		printf("No");
	return 0;
}

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

int N;
string str;
int solve(int i, char color){
    string sim;
    int h, t;
    sim = str;
    sim[i] = color;
    while(true){
        for(h=i;h>=0 && sim[h]==color;h--);
        h++;
        for(t=i;t<N && sim[t]==color;t++);
        if(t-h<4) break;
        sim.erase(h,t-h);
        i = h;
        color = sim[h];
    }
    return sim.size();
}
        
int main(){
    string A;
    char before;
    int diff;
    int a,b,c,d,e;
    int m;
    cin >> N;
    while(N){
        for(int i=0;i<N;i++){
            cin >> A;
            str += A;
        }
        before = '4';
        m = N;
        for(int i=0;i<N;i++){
            if(str[i] != str[i+1]){
                a = i<N-3 && str[i+3] == str[i+2];
                b = i<N-2 && str[i+2] == str[i+1];
                c = i<N-1 && i>0 && str[i-1] == str[i+1];
                d = i>1 && str[i-2] == str[i-1];
                e = i>2 && str[i-3] == str[i-2];
                if(a && b){
                    m = min(m, solve(i,str[i+1]));
                }else if(b && c){
                    m = min(m, solve(i,str[i+1]));
                }else if(c && d){
                    m = min(m, solve(i,str[i+1]));
                }
                if(d && e){
                    m = min(m, solve(i,str[i-1]));
                }
            }
        }
        str.clear();
        cout << m << endl;
        cin >> N;
    }
}

Measured memory_bytes: 1260
#include <iostream>
#include <queue>

using namespace std;

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

int main(){
	int maze[30][30];
	int wall[150][150];
	while(1){
		int w, h; cin>>w>>h;
		if(!w && !h) break;
		for(int i=0; i<h*2-1; i++){
			for(int j=0; j<w+i%2-1; j++){
				cin >> wall[i][j];
			}
		}
		fill(maze[0], maze[30],999);
		queue <pair<int, int> > q;
		q.push(make_pair(0, 0));
		maze[0][0]=1;

		while(!q.empty()){
			int y = q.front().first;
			int x = q.front().second;
			q.pop();

			for(int i=0; i<4; i++){
				int ny = y+dy[i];
				int nx = x+dx[i];
				if(ny<0||h<=ny||nx<0||w<=nx) continue;
				if((dx[i] != 1 && !wall[y*2+dy[i]][x+dx[i]]) || (dx[i] == 1 && !wall[y*2][x])){
					if(maze[ny][nx] > maze[y][x]+1){
						maze[ny][nx] = maze[y][x]+1;
						q.push(make_pair(ny, nx));
					}
				}
			}		
		}
		if(maze[h-1][w-1]==999)cout << 0 << endl;
		else cout << maze[h-1][w-1] << endl;
	}
	return 0;
}



Measured memory_bytes: 3124
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main () {
    
    int n, m;
    scanf("%d%d", &n, &m);
    int stu[51][2];
    int cp[51][2];
    
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &stu[i][0], &stu[i][1]);
        
    }
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &cp[i][0], &cp[i][1]);
    }
    
    for (int i = 1; i <= n; i++) {
        int mindis = -1;
        int minindex = -1;
        for (int j = 1; j <= m; j++) {
            int dis = abs(stu[i][0] - cp[j][0]) + abs(stu[i][1] - cp[j][1]);
            if (dis < mindis || mindis == -1) {
                mindis = dis;
                minindex = j;
            }
            else if (dis == mindis) {
                if (cp[minindex][0] > cp[j][0]) {
                    minindex = j;
                }
                else if (cp[minindex][0] == cp[j][0] && cp[minindex][1] > cp[j][1]) {
                    minindex = j;
                }
            }
        }
        printf("%d\n", minindex);
    }
    
}


Measured memory_bytes: 128
def main():
    N, M = map(int, input().split())
    A = [tuple(map(int, input().split())) for _ in range(M)]
    S = sorted(A, key=lambda x: x[1])
    count = 0
    last = 0
    for s in S:
        if last < s[0]:
            count += 1
            last = s[1] - 1
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19020
n, p = map(int, input().split())

s = input()

ruisekiwa = [0 for _ in range(0, n + 1)]
if 10 % p == 0:
    ans = 0
    for i in range(0, n):
        if (ord(s[i]) - ord('0')) % p == 0:
            ans += i + 1
    print(ans)
    exit()

ten = 1
for _i in range(0, n):
    i = n - _i - 1
    ruisekiwa[n - i] = ((ord(s[i]) - ord('0')) * ten + ruisekiwa[n - i - 1]) % p
    ten *= 10
    ten %= p

ans = 0
cnt = [0 for _ in range(0, p)]
for i in range(0, n+1):
    ans += cnt[ruisekiwa[i]]
    cnt[ruisekiwa[i]] += 1

print(ans)


Measured memory_bytes: 11284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};
//x以下の要素への最小index
template <class T> int former(const vector<T> &v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> int latter(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T1>
void cout_vec(const int n, vector<T1> &vec1){
  rep(i, n){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
ll comb(ll n,ll k){
    ll ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
ll gcd(ll a,ll b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<bool> mam_ac(n, false);
    vector<int> il_przed(n, 0);
    for (int i = 0; i < m; ++i)
    {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (s == "AC")
        {
            if (!mam_ac[p])
                mam_ac[p] = true;
        }
        else
        {
            if (!mam_ac[p])
                ++il_przed[p];
        }
    }
    int odp1 = 0, odp2 = 0;
    for (int i = 0; i < n; ++i)
    {
        if (mam_ac[i])
        {
            ++odp1;
            odp2 += il_przed[i];
        }
    }
    cout << odp1 << " " << odp2;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long MAX = 200005;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

long long fac[MAX], finv[MAX], inv[MAX]; 
 
void init_comb() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
 
long long combination(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

using mint = modint<MOD>;
mint S[MAX];

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  
  if (n>m) swap(n, m);
  rep (i, 1, MAX) S[i] = S[i-1] + i;
  init_comb();
  
  mint ans = 0;
  for(int y=1; y<=n; y++) for (int x=1; x<=m; x++) {
    mint sum = 0;
    rep (yi, y, n+1) {
      int s = abs(y-yi);
      int t = m - x, u = x - 1;
      sum += S[t+s] - S[s-1];
      if (yi!=y) sum += S[u+s] - S[s];
    }
    ans += sum;
    
  }
  ans *= combination(n*m-2, k-2);
 
    cout << ans.a << endl;

    return 0;
}


Measured memory_bytes: 9864
#include <bits/stdc++.h>
#define LL long long
#define ri register int
#define maxn 100100
using namespace std;
int n;
int a[maxn];
int tot[maxn];
int m1 = 0, a1, m2 = 0;
int m3 = 0, a3, m4 = 0;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	for(int i = 0; i < n; i += 2)
		tot[a[i]] ++;
	for(int i = 1; i <= 100000; i ++)
	{
		if(tot[i] > m1)
		{
			m2 = m1;
			m1 = tot[i];
			a1 = i;
		}
		else if(tot[i] > m2)
			m2 = tot[i];
	}
	memset(tot, 0, sizeof(tot));
	for(int i = 1; i < n; i += 2)
		tot[a[i]] ++;
	for(int i = 1; i <= 100000; i ++)
	{
		if(tot[i] > m3)
		{
			m4 = m3;
			m3 = tot[i];
			a3 = i;
		}
		else if(tot[i] > m4)
			m4 = tot[i];
	}
	if(a1 != a3)
		cout << n - (m1 + m3) << endl;
	else
		cout << n - max(m1 + m4, m2 + m3) << endl;
	return 0;
}


Measured memory_bytes: 1024
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N, P = map(int, input().split())
p_fact = factorization(P)
p_list = []
ans = 1
for p in p_fact:
    p[1] = p[1] // N
    p_list.append(p)

for p in p_list:
    ans = ans * pow(p[0], p[1])

print(ans)


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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int num = 0;
    char c = '*';
    for(int i=0; i<n; i++){
        if(c == s[i]) continue;

        num++;
        c = s[i];
    }
    cout << num << endl;
}

Measured memory_bytes: 3708
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int main(){
  string s, t;
  cin >> s;
  each(c, s){
    if (isdigit(c)) t += c;
    else if (t.size()) t.pop_back();
  }
  cout << t << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main (){ 
    ll n , m ;
    cin >> n >> m ;
    ll l = min(n, m / 2);
    ll ans = l;
    n -= l, m -= l * 2;
    ans += m / 4;
    m = m % 4;
    cout << ans << endl;

}

 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std; 
int main(){
	long long a,b=0;
	cin>>a;
	for(long long i=1;i<=a;i++){
		if(i%3!=0&&i%5!=0)b+=i;
	}
	cout<<b;
	return 0;
} 

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}

typedef pair<int,pair<int,int> > Sit;

void solve(){
	int N;
	while(cin>>N&&N){
		set<Sit> s;
		s.insert(make_pair(0,pii(1000000001,-1)));
		for(int i=0;i<N;i++){
			char ch;
			cin>>ch;
			if(ch=='W'){
				int id,secSize;
				cin>>id>>secSize;
				vector<Sit> addList;
				vector<Sit> delList;
				for(set<Sit>::iterator it=s.begin();it!=s.end();it++){
					if(it->second.second==-1){
						int curSize=it->second.first;
						if(curSize>=secSize){
							Sit s1=make_pair(it->first,pii(secSize,id));
							// ツつ?づ慊づィツ閉板閉ェ
							Sit s2=make_pair(it->first+secSize,pii(curSize-secSize,-1));
							// ツサツイツズツつェツ０ツづ按づァツ登ツ録ツつオツづ按つ「
							if(s2.second.first!=0){
								addList.push_back(s2);
								//s.insert(s2);
							}
							{
								addList.push_back(s1);
								//s.insert(s1);
							}
							{
								delList.push_back(*it);
							}
							// ツ渉堕つォツ債楪づ敖終ツ猟ケ
							break;
						}
						else{
							// ツ渉堕つォツ債楪づ淞づゥツつセツつッツ渉堕つォツ債楪づ?
							Sit st=make_pair(it->first,pii(curSize,id));
							secSize-=curSize;
							{
								addList.push_back(st);
								//s.insert(st);
							}
							{
								delList.push_back(*it);
							}
						}
					}
				}
				for(int i=0;i<addList.size();i++)
					s.insert(addList[i]);
				for(int i=0;i<delList.size();i++)
					s.erase(delList[i]);
			}
			else if(ch=='R'){
				int secter;
				cin>>secter;
				set<Sit>::iterator it=--s.upper_bound(make_pair(secter,pii(1000000010,1000000010)));
				cout<<it->second.second<<endl;
			}
			else if(ch=='D'){
				int id;
				cin>>id;
				vector<Sit> addList;
				vector<Sit> delList;
				for(set<Sit>::iterator it=s.begin();it!=s.end();it++){
					if(it->second.second==id){
						Sit add=*it;
						add.second.second=-1;
						addList.push_back(add);
						delList.push_back(*it);
					}
				}
				for(int i=0;i<addList.size();i++)
					s.insert(addList[i]);
				for(int i=0;i<delList.size();i++)
					s.erase(delList[i]);
			}
		}
		cout<<endl;
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    char S[3],T[3];
    int ans = 0;
    cin >> S >> T;
    REP(i,3){
        if (S[i] == T[i]){
            ans++;
        } 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s, t;
int i;
int main(){
	cin >> s >> t;
	for(i=0; i<s.length(); i++){
    	if(s[i] != t[i]){
        	printf("No");
            return 0;
        }
    }
    printf("Yes");
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(){
	int N;
	std::vector<int> A(N+1);
	std::vector<int> B(N+1);
	std::vector<int> C(N);

	cin >> N ;
	for (int i = 1; i <= N; i++){
		cin >> A[i];
	}
	for (int i = 1; i <= N; i++){
		cin >> B[i];	
	}
	for (int i = 1; i <= N-1; i++){
		cin >> C[i];	
	}

	int stsfy = 0;
	int meal = 0;

	for (int i = 1; i <= N; i++)
	{
		stsfy += B[A[i]];
		//cout << stsfy << endl;
		if (A[i] == meal+1)
		{
			stsfy += C[meal];
			//cout << "**"<<stsfy << "**" << endl;
		}
		meal = A[i];
	}

	cout << stsfy << endl;

	return 0;
}

Measured memory_bytes: 640
import qualified Data.ByteString.Char8 as B

main = do
    s <- B.getLine
    t <- B.getLine
    print $ answer s t

answer :: B.ByteString -> B.ByteString -> Int
answer s t = minimum $ map (count . (,) t) . take (B.length s - B.length t + 1) $ B.tails s 

count :: (B.ByteString,B.ByteString) -> Int
count (t,s) = if t == B.empty || s == B.empty
    then 0
    else if B.head s == B.head t
        then count (B.tail t, B.tail s)
        else 1 + count (B.tail t, B.tail s)

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    ll sum=0; vector<int> a(n-1);
    rep(i,0,n-1)scanf("%d",&a[i]);
    rep(i,1,n-1)sum+=min(a[i],a[i-1]);
    sum+=a[0]+a.back();
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 256