akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI a(n);
    map<int,int> M;
    REP(i,n){
        scanf("%d", &a[i]);
        M[a[i]]++;
    }
    sort(a.begin(),a.end());
    bool f = 1;
    int mi = a[0];
    if (M[mi] == 1){
        if (a[n-1] > 2*mi) f = 0;
        FOR(i,mi+1,2*mi){
            if (M[i] < 2) f = 0;
        }
    }else if (M[mi] == 2){
        if (a[n-1] > 2*mi-1) f = 0;
        FOR(i,mi+1,2*mi-1){
            if (M[i] < 2) f = 0;
        }
    }else{
        f = 0;
    }

    if (f) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


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

bool isitans(int x){
     for(int i=2; i*i <x; i++){
     if(x%i ==0){
       return false;
       }      
    }
    return true; 
}

int main() {
int X;
  cin >> X;
int Y = X;
int answer = 0;
int sosuu = 0;  
  while(isitans(Y)!=true){
   Y++;
     
  }
  cout << Y;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a,b,c;
    scanf("%d",&n);
    a=n%10;
    n=n/10;
    b=n%10;
    n=n/10;
    c=n%10;
    if(a==7 || b==7 || c==7)
    {
        printf("Yes\n");
    }
    
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
typedef long long ll;
using namespace std;
#define rep(i,n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007

int main() {
	int n, d;
	cin >> n >> d;
	int w = 2 * d + 1;
	int ans = (n + (w - 1)) / w;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = 1;
        int W = 1;

        while(true) {
            H = sc.nextInt();
            W = sc.nextInt();
            if(H == 0 && W == 0) break;

            for (int i = 0; i < H; i++){
                for (int j = 0; j < W; j++) {
                    if(i == 0 || i == H-1) System.out.printf("#");
                    else {
                        if(j == 0 || j == W-1) System.out.printf("#");
                        else System.out.printf(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 58400
# -*- coding: utf-8 -*-
n = int(input())
d = [list(map(int,input().split())) for i in range(n)]

d = sorted(d,key=lambda x:(x[0],-x[1]))

n_med_min_id = (n+1)//2-1
n_med_min_ab = d[n_med_min_id]
n_med_min_ab_1 = d[n_med_min_id+1]

d = sorted(d,key=lambda x:(-x[1],x[0]))
n_med_max_ab = d[n_med_min_id]
n_med_max_ab_1 = d[n_med_min_id+1]

if n%2==1:
    print(n_med_max_ab[1]-n_med_min_ab[0]+1)
else:
    n_range = (n_med_min_ab[0],n_med_max_ab_1[1])
    n1_range = (n_med_min_ab_1[0],n_med_max_ab[1])
    ret = (n_range[1]+n1_range[1]) - (n_range[0]+n1_range[0]) + 1
    print(ret)

Measured memory_bytes: 68972
h, w = map(int, input().split())

ans1 = h * w
for i in range(1, h + 1):
    a = i * w
    b = (h - i) * (w // 2)
    c = (h - i) * (w - w // 2)
    tmp = max(a, b, c) - min(a, b, c)
    ans1 = min(ans1, tmp)
    
ans2 = h * w
for i in range(1, w + 1):
    a = i * h
    b = (w - i) * (h // 2)
    c = (w - i) * (h - h // 2)
    tmp = max(a, b, c) - min(a, b, c)
    ans2 = min(ans2, tmp)
    
ans3 = h * w
for i in range(1, h + 1):
    a = i * w
    b = (h - i) // 2 * w
    c = (h - i - (h - i) // 2) * w
    tmp = max(a, b, c) - min(a, b, c)
    ans3 = min(ans3, tmp)
    
    
ans4 = h * w
for i in range(1, h + 1):
    a = i * h
    b = (w - i) // 2 * h
    c = (w - i - (w - i) // 2) * h
    tmp = max(a, b, c) - min(a, b, c)
    ans4 = min(ans4, tmp)    
    
print(min(ans1, ans2, ans3, ans4))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

		int cnt = 0;

		int N = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		String firstLetter = "";
		String secondLetter = "";

		char[] letters = s.toCharArray();

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

			if (i < N / 2) {
				firstLetter += letters[i];
			}

			else {
				secondLetter += letters[i];
			}
		}

		if (firstLetter.equals(secondLetter)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 22868
#include<iostream>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	int a[12];
	for(int i=1;i<=12;i++)
	{
		if(i==2)
		{
			a[i]=2;
		}
		else if(i==4||i==6||i==9||i==11)
		{
			a[i]=1;
		}
		else
		{
			a[i]=0;
		}
	}
	if(a[x]==a[y])
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	w := nextString(sc)
	var cnt int
	for {
		t := nextString(sc)
		if t == "END_OF_TEXT" {
			break
		}
		if strings.ToLower(t) == w {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1108
#include <cstdio>

int main() {
	int n;
	int a[200000];

	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	int max1, max2;
	for(int i = 0; i < n; i++) {
		if(a[i] > max1) {
			max2 = max1;
			max1 = a[i];

		} else if(a[i] > max2) {
			max2 = a[i];
		}
	}

	int num_m1 = 0;
	for(int i = 0; i < n; i++) {
		if(a[i] == max1) {
			num_m1++;
		}
	}

	if(num_m1 > 1) {
		for(int i = 0; i < n; i++) {
			printf("%d\n", max1);
		}
	} else {
		for(int i = 0; i < n; i++) {
			printf("%d\n", a[i] == max1 ? max2 : max1);
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
const int MAXN = 1e5+15;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  int rst = 0x3f3f3f3f;
  for(int i=2;i<s.length();i++){
    int x = (s[i-2]-'0') *100 +(s[i-1]-'0')*10 +s[i]-'0';
    if(abs(x-753)<rst){
      rst = abs(x-753);
    }
  }
  cout<<rst<<endl;
}


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

int main() {
    int A, B; cin >> A >> B;
    if (A == 0) {
        if (1868 <= B && B <= 1911) cout << "M" << B - 1867 << endl;
        if (1912 <= B && B <= 1925) cout << "T" << B - 1911 << endl;
        if (1926 <= B && B <= 1988) cout << "S" << B - 1925 << endl;
        if (1989 <= B && B <= 2016) cout << "H" << B - 1988 << endl;
    }
    if (A == 1) cout << 1867 + B << endl;
    if (A == 2) cout << 1911 + B << endl;
    if (A == 3) cout << 1925 + B << endl;
    if (A == 4) cout << 1988 + B << endl;
    return 0;
}


Measured memory_bytes: 3112
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())

# flag = False
# for i in range(10):
#     for j in range(10):
#         if i * j == N:
#             flag = True
#             break

se = set(x * y for x in range(1, 10) for y in range(1, 10))

ans = 'Yes' if N in se else 'No'
print(ans)


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

using namespace std;

const int mmax=20;
const int nmax=50000;
const int infty=(1<<29);

int main()
{
    int n,m;
    int c[21];
    int T[nmax+1];
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>c[i];
    }
    for(int i=0;i<=nmax;i++){
        T[i]=infty;
    }
    T[0]=0;
    for(int i=1;i<=m;i++){
        for(int j=0;j+c[i]<=n;j++){
            T[j+c[i]]=min(T[j+c[i]],T[j]+1);
        }
    }
    cout<<T[n]<<endl;
    return 0;
}



Measured memory_bytes: 3316
import java.util.*;
     
    class Main{
        //149a
        static final int DIV = 100000007;
        static final int MAX = 2000000000;
        static long[] num = new long[20];
        public static void main(String args[]){
            Scanner sc = new Scanner(System.in);
            String a = sc.next();
            String b = sc.next();
            b += a;
            
            sc.close();
            System.out.println(b);    
        }
        
    }

Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>

int main()
{
    int n;
    std::cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
        std::cin >> arr[i];
    
    for (int i = n - 1; i >= 0; i--)
    {
        std::cout << arr[i];
        if (i == 0)
            std::cout << std::endl;
        else
            std::cout << ' ';
    }
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

int main()
{
  char s;cin>>s;

  if ('a' <= s && s <= 'z') {
    cout << 'a' << endl;
  } else {
    cout << 'A' << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	c := make([][]int, 3)
	for i, _ := range c {
		c[i] = make([]int, 3)
	}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			c[i][j] = nextInt()
		}
	}
	for i := 0; i <= 100; i++ {
		a := make([]int, 3)
		b := make([]int, 3)
		a[0] = i
		ok := true
		for j, _ := range c[0] {
			if c[0][j] >= i {
				b[j] = c[0][j] - i
			} else {
				ok = false
				break
			}
		}
		if ok != true {
			continue
		}
		a[1] = c[1][0] - b[0]
		for j, _ := range c[1] {
			if c[1][j]-b[j] != a[1] {
				ok = false
				break
			}
		}
		if ok != true {
			continue
		}
		a[2] = c[2][0] - b[0]
		for j, _ := range c[2] {
			if c[2][j]-b[j] != a[2] {
				ok = false
				break
			}
		}
		if ok != true {
			continue
		}
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 32128
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
 
LL Q, H, S, D, N;
LL ans;
 
int main()
{
	in >> Q >> H >> S >> D >> N;
 
	H = std::min(H, Q * 2);
	S = std::min(S, H * 2);
	D = std::min(D, S * 2);
	ans += N / 2*D;
	N -= N / 2 * 2;
	ans += N / 1 * S;
 
	out << ans << std::endl;
	return 0;
}

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

using namespace std;
int x,y,a,b; 
int h, w; 
const int INF = 10001000;
string s[1001];
vector<pair<int, int> > g[1000001];
#define mp make_pair
#define pb push_back
const int L = 1000;
int main(){
	
	cin >> h >> w;

	cin >> x>>y>>a>>b;
	x--;
	y--;
	a--;
	b--;


	for(int i = 0; i < h; i++) cin >> s[i];
	
	for(int i = 0; i < h; i++) {
		for(int j = 0;j < w; j++) {
			int dx[] = {-1,0,1,0};
			int dy[] = {0,1,0,-1};
			int v = i*L+j;
			for(int ii = 0; ii < 4; ii++) {
				int iii = i + dx[ii];
				int jjj = j + dy[ii];
				if(iii < 0 or jjj < 0 or iii >= h or jjj >= w) continue;
				if(s[iii][jjj] == '#') continue;
				int u = iii*L + jjj;
				g[v].pb(mp(0, u));
			}

			for(int p = -2; p < 3; p++) {
				for(int q = -2; q < 3; q++) {
					if(p == 0 and q == 0) continue;
					int ni = i+p;
					int nj = j+q;
					if(ni < 0 or nj < 0 or ni >= h or nj >= w) continue;
					if(s[ni][nj] == '#') continue;
					int u = ni*L + nj;
					g[v].pb(mp(1, u));
				}
			}
		}
	}

	int n = 1001*1000 + 1000;
	vector<int> d, p;
	d.assign(n, INF);
	
	int s = x*L + y;
	d[s]  = 0;
	set<pair<int, int> > q;
	q.insert(mp(0,s));
	while(!q.empty()) {
		int v = q.begin()->second;
		q.erase(q.begin());
		for(auto edge: g[v]) {
			int to = edge.second;
			int len = edge.first;
			if(d[v] + len < d[to]) {
				q.erase(mp(d[to], to));
				d[to] = d[v] + len;
				q.insert(mp(d[to], to));
			}
		}
	}

	if(d[a*L+b] >= INF) cout << -1;
	else cout << d[a*L+b] << endl;

	


}


Measured memory_bytes: 196104
#include<cstdio>
#include<iostream>
#include<queue>
#include<stack>
#define MAX_N 25

using namespace std;

long long int dp[110][MAX_N];
int n,num[110];

int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>num[i];
    }
    dp[0][num[0]]=1;

    for(int i=1;i<n;++i){
        for(int j=0;j<=20;j++){
            if(j+num[i]<=20){
                dp[i][j+num[i]]+=dp[i-1][j];
            }
            if(j-num[i]>=0){
                dp[i][j-num[i]]+=dp[i-1][j];
            }
        }
    }
    cout<<dp[n-2][num[n-1]]<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int r; cin >> r;
	int ans = 3 * pow(r, 2);
	cout << ans << endl;
}

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

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

divisors = make_divisors(n)

ans = float("inf")
for d in divisors:
    p = n // d
    ans = min(ans, max(len(str(d)),len(str(p))))

print(ans)

Measured memory_bytes: 3064
for i in range(input()):
    gx,gy=map(int,raw_input().split())
    L=[[0]*(gx+1) for i in range(gy+1)]
    p=input()
    mata=[map(int,raw_input().split()) for i in range(p)]
    mata=set(tuple(sorted(((i,j),(k,l)))) for i,j,k,l in mata)
    L[0][0]=1
    for i in range(gy+1):
        for j in range(gx+1):
            if ((j,i-1),(j,i)) in mata and ((j-1,i),(j,i)) in mata:
                L[i][j]=0
            elif ((j,i-1),(j,i)) in mata:
                L[i][j]=L[i][j-1]
            elif ((j-1,i),(j,i)) in mata:
                L[i][j]=L[i-1][j]
            elif i==0 and j==0:
                pass
            elif i==0:
                L[i][j]=L[i][j-1]
            elif j==0:
                L[i][j]=L[i-1][j]
            else:
                L[i][j]=L[i-1][j]+L[i][j-1]
    print L[gy][gx] if L[gy][gx]!=0 else "Miserable Hokusai!"

Measured memory_bytes: 4300
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}
#define inv 500000004
int cum(int n)
{
  return ((n%M*(n+1)%M)%M*inv)%M;
}
void solve()
{
 int n,k;
 cin >> n >> k;

 int an  = 0;
 
 for(int cc = k; cc <= n+1 ; cc++)
 {
   int ex = (cum(n) - cum(n-cc) - cum(cc-1) +M)%M + 1;
   an += ex;
   an%=M;
 }

 cout<<an<<endl;  

}

int32_t main()
{
  pr_init();
  fastio;
  solve();

 }
      

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 205;
const double eps = 1e-9;
int n, K;
double ans, t[N];
struct node { double x, y; }a[N];

double calc(double x, double y) {
    // printf("%lf %lf ?\n", x, y);
    rep(i, 1, n) {
        double tt = (x - a[i].x) * (x - a[i].x) + (y - a[i].y) * (y - a[i].y);
        // printf("%d %lf ...\n", i, tt);
        t[i] = sqrt(tt);
    }
    sort(t + 1, t + n + 1);
    double ret = 0;
    for (int i = n; i > n - K; i--) ret += t[i];
    // printf("%lf !\n", ret);
    return ret;
}

double solve2(double x) {
    double l = -1000, r = 1000, ans = 1e18;
    while (r - l > eps) {
        double lmid = l + (r - l) / 3;
        double rmid = r - (r - l) / 3;
        double lans = calc(x, lmid), rans = calc(x, rmid);
        if (lans <= rans) ans = lans, r = rmid;
        else ans = rans, l = lmid;
    } return ans;
}

void solve1() {
    double l = -1000, r = 1000;
    while (r - l > eps) {
        double lmid = l + (r - l) / 3;
        double rmid = r - (r - l) / 3;
        double lans = solve2(lmid), rans = solve2(rmid);
        if (lans <= rans) ans = lans, r = rmid;
        else ans = rans, l = lmid;
    }
    printf("%.5lf\n", ans);
}

int main() {
    cin >> n >> K;
    rep(i, 1, n) scanf("%lf%lf", &a[i].x, &a[i].y);
    solve1();
    return 0;
}



Measured memory_bytes: 3296
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n;
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, n)
    {
        ll a;
        cin >> a;
        mp[a]++;
        ans += a;
    }
    cin >> q;
    vector<ll> b(q), c(q);
    rep(i, q) cin >> b[i] >> c[i];
    rep(i, q)
    {
        if (mp.find(b[i]) != mp.end())
        {
            ans += c[i] * mp[b[i]] - b[i] * mp[b[i]];
            mp[c[i]] += mp[b[i]];
            mp[b[i]] = 0;
        }
        cout << ans << endl;
    }
}


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

int main(){
  int N;
  cin>>N;
  
  
  
  int res=0;
  int frontB=0;
  int backA=0;
  int hybrid=0;
  bool single=false;
  
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    int n=S.size();
    
    for(int j=0;j<n-1;j++){
      if(S.at(j)=='A' && S.at(j+1)=='B')
        res++;
    }
    
    if(S.at(0)=='B' && S.at(n-1)=='A')
      hybrid++;
    else if(S.at(0)=='B')
      frontB++;
    else if(S.at(n-1)=='A')
      backA++;
  }
  
  if(hybrid>0){
    res+=hybrid-1;
    
    if(backA>0){
      backA--;
      res++;
    }
    
    if(frontB>0){
      frontB--;
      res++;
    }
  }
  
  res+=min(frontB,backA);

  cout<<res;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
 int A;
 int B;
 int K;
 int i;
 int maxnum;
 int count=0;
 scanf("%d %d %d",&A,&B,&K);

 maxnum=A;
 if(A>B) maxnum=B;

 for(i=maxnum;i>=1;i--)
 {
   if( ((A%i)==0)&&((B%i)==0)) count++;
   if(count==K)
   {
    printf("%d\n",i);
    break;
   }
 }

 return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+500;
int A[maxn],B[maxn];
int T,n;
map<string,int> mp;

int main()
{
    cin>>n;
    int res=0;
    string str;
    getchar();
    while(n--)
    {
        cin>>str;
        if(!mp[str])
        {
            mp[str]=1;
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 19204
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}

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

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}







  


int main() {
 ll n,p;
 cin >> n >> p;
 vector<pair <ll,ll>> cnt;
 cnt = prime_factorize(p);
 ll ans = 1;
 for (auto x : cnt){
   if (x.second >= n) {
     while (x.second >= n){
     ans *= x.first;
     x.second -= n;
     }
   }
 }
 cout << ans << endl;

 
}





Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int main() {
  long int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x=0;
  for (int i=0; i<d; i++) {
    if (a != 0) {
      x++;
      a--;
    } else if (b != 0) {
      b--;
    } else {
      x--;
      c--;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 3532
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> v(n);
	int x1[100010] = { 0 }, x2[100010] = { 0 },ma=0,ma1=0,ma2=0,z1;
	for (int i = 0; i < n; i++) {
		cin >> v[i]; ma = max(ma, v[i]);
		if (i % 2 == 0)x1[v[i]]++;
		else x2[v[i]]++;
	}
	bool x = 0,y;
	for (int i = 1; i <= ma + 2; i++) {
		if (ma1 < x1[i] && ma2 < x2[i]&&x1[i]==x2[i]&&x==0) {
			if (ma1 > ma2) {
				ma2 = max(ma2, x2[i]); y = 1;
			}
			else {
				ma1 = max(ma1, x1[i]); y = 0;
			}
			z1 = i;
			x = 1;
		}
		else if (x == 1 && ma2 <= x2[i]&&y==1) {
			ma1 = max(ma1, x1[z1]);
			ma2 = max(ma2, x2[i]);
			x = 0;
		}
		else if (x == 1 && ma1 <= x1[i]&&y==0) {
			ma1 = max(ma1, x1[i]);
			ma2 = max(ma2, x2[z1]);
			x = 0;
		}
		else {
			ma1 = max(ma1, x1[i]);
			ma2 = max(ma2, x2[i]);
		}
		
	}
	if (v[0] == v[1] && ma1 == n/2 && ma2 == n/2)cout << n / 2 << endl;
	else cout << n - ma1 - ma2 << endl;
}


Measured memory_bytes: 1408
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int debt = 100;
		for (int i = 0; i < n; i++) {
			debt = (int)Math.ceil(debt * 1.05);
		}
		System.out.println(debt * 1000);
	}

}

Measured memory_bytes: 17168
import java.util.*;
class Main {
	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);

       int[][][] bingo = new int[3][3][2];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                bingo[i][j][0] = sc.nextInt();
                bingo[i][j][1] = 0;
            }
        }

        int N = sc.nextInt();
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt();
            lab: for (int k = 0; k < 3; k++) {
                for (int j = 0; j < 3; j++) {
                    if (bingo[k][j][0] == num) {
                        bingo[k][j][1] = 1;
                        break lab;
                    }
                }
            }
        }
        sc.close();

        int tate;
        int[] yoko = new int[3];
        for (int i = 0; i < 3; i++) {
            yoko[i] = 0;
        }
        for (int i = 0; i < 3; i++) {
            tate = 0;
            for (int j = 0; j < 3; j++) {
                tate += bingo[i][j][1];
                yoko[j] += bingo[i][j][1];
            }
            if (tate == 3) {
                System.out.println("Yes");
                return;
            } 
        }
        for (int i = 0; i < 3; i++) {
            if(yoko[i] == 3){
                System.out.println("Yes");
                return;
            } 
        }
        int nana1 = bingo[0][0][1] + bingo[1][1][1] + bingo[2][2][1];
        int nana2 = bingo[0][2][1] + bingo[1][1][1] + bingo[2][0][1];
        if (nana1 == 3 || nana2 == 3) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");

    }
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(){
  int i,a,b,nn;
  scanf("%d %d",&a,&b);
  nn=1001;
  int c[a],d[a];

  for(i=0;i<a;i++){
  scanf("%d %d",&c[i],&d[i]);
  if(d[i]<=b){
  if(c[i]<nn)
  nn=c[i];
  }
  }

 if(nn==1001)
   printf("TLE");

  else printf("%d",nn);

}

  


Measured memory_bytes: 128
fn main() {
    let s: String = read();
    let mut v: Vec<char> = s.chars().into_iter().collect();
    v.sort();
    if v[0] == v[1] && v[1] != v[2] && v[2] == v[3] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define F(i,j,k) for(int i=(j);i<=(k);++i)
#define _F(i,j,k) for(int i=(j);i<(k);++i)
#define D(i,j,k) for(int i=(j);i>=(k);--i)
#define _D(i,j,k) for(int i=(j);i>(k);--i)
#define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it)
#define Rep(a,s) for(auto a:s)
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template<class Type>ll quick_pow(Type x,Type y,Type Mod){
    ll res=1;
    while(y){
        if(y&1)res=res*x%Mod;
        x=x*x%Mod,y>>=1;
    }
    return res;
}
template<class Type>ll inv(Type x,Type Mod){return quick(x,Mod-2,Mod);}
namespace IO{
    template <class T>
    inline void read(T &x){
        x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
        x*=f;
    }
};
using namespace IO;
const int N=205;
int n,a[N],dp[N][N];
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    read(n);
    F(i,1,2*n)read(a[i]);
    sort(a+1,a+2*n+1);
    memset(dp,-0x3f,sizeof(dp));
    dp[2*n+1][0]=0;
    D(i,2*n,1){
        F(j,0,n-1)dp[i][j]=max(dp[i][j],dp[i+1][j+1]+a[i]);
        F(j,1,n)dp[i][j]=max(dp[i][j],dp[i+1][j-1]);
    }
    cout<<dp[1][0]<<endl;
	return 0;
}


Measured memory_bytes: 3736
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vi data(N);
    int maxnum = 0;
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
        maxnum = max(maxnum, data.at(i));
    }
    vi count(maxnum + 1, 0);
    for (int x : data) {
        count.at(x)++;
    }
    bool check = true;
    if (count.at(maxnum) > 1) {
        check = false;
    }
    int secondnum = 0;
    for (int i = maxnum - 1; i > 0; i--) {
        if (count.at(i) != 0) {
            secondnum = i;
            break;
        }
    }
    for (int i = 0; i < N; i++) {
        if (data.at(i) == maxnum && check) {
            cout << secondnum << endl;
        }
        else {
            cout << maxnum << endl;
        }
    }
}

Measured memory_bytes: 4808
#include<stdio.h>
int main()
{
    long long int a,b,s=0;
    char ch;
    scanf("%lld %c %lld",&a,&ch, &b);
    if(a>=1 &&a<=1000000000 && b>=1 && b<=1000000000)
    {
    if(ch=='+')
    {
       s=a+b;
       printf("%lld\n",s);
    }
    else if(ch=='-')
    {
        s=a-b;
        printf("%lld\n",s);
    }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  ll n, cnt = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < s.length() - 2; ++i)
  {
    if (s[i] == "A"[0] && s[i + 1] == "B"[0] && s[i + 2] == "C"[0]) ++cnt;
  }
  cout << cnt;
}


Measured memory_bytes: 256
N=int(input())
num=[3,5,7]
def dfs(s):
    if s>N:
        return 0
    a=str(s)
    if a.count("3")>=1 and a.count("5")>=1 and a.count("7")>=1:
        ret=1
    else:
        ret=0
    for i in num:
        ret+=dfs(10*s+i)
    return ret
print(dfs(0))

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    string s;
    cin >> s;
    int cnt = 0;
    int cntB = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'a'){
            if(cnt < A+B){
                cout << "Yes" << endl;
                cnt++;
            } else {
                cout << "No" << endl;
            }
        } else if(s[i] == 'b'){
            if(cnt < A+B && cntB < B){
                cout << "Yes" << endl;
                cnt++;
                cntB++;
            } else
                cout << "No" << endl;
            
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n,k;
  cin >> n >> k;
  vector<ll> cnt(k, 0); //kで割ったあまりの個数
  for (int i = 1; i <= n; ++i) cnt[i % k]++;
  ll ans = 0;
  for (int ak = 0; ak < k; ++ak) {
    int bk = (k - ak) % k;
    int ck = (k - ak) % k;
    if ((bk+ck) % k != 0) continue;
    ans += cnt[ak] * cnt[bk] * cnt[ck];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)


int main()
{
    long long int k,a,b;
    scanf("%lld%lld%lld",&k,&a,&b);
    long long int sa=b-a;
    if(b-a<=1){
        printf("%lld\n",1+k);
        return 0;
    }
    if(k<=a-1){
        printf("%lld\n",1+k);
        return 0;
    }
    k-=a-1;
    printf("%lld\n",a+sa*(k/2)+(k%2==1));
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, h = map(int, input().split())

a = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a.sort(reverse=True)
b.sort(reverse=True)
a_max = a[0]

b_nage = [i for i in b if i>a_max]

count = 0
for i in b_nage:
    h -= i
    count += 1
    if h<=0:
        print(count)
        exit()

count += -(-h//a_max)

print(count)

Measured memory_bytes: 12056
use List::Util qw/reduce/;
sub sum (@) {return reduce { $a+$b } @_;}
my $input = <stdin>; chomp($input);
my ($n) = split(' ', $input);
$input = <stdin>; chomp($input);
my @a = split(' ', $input);

my ($su, $ar) = ($a[0], sum (@a[1..$#a]));
my $min = abs($su-$ar);
for (1..$#a-1) {
    $su += $a[$_];
    $ar -= $a[$_];
    my $d = abs($su-$ar);
    $min = $d if $d < $min;
}

print $min;

Measured memory_bytes: 34944
nums = [int(e) for e in input().split()]
a = nums[0]
nums[0] = nums[1]
nums[1] = a
a=nums[0]
nums[0] = nums[2]
nums[2] = a
print(str(nums[0]) + ' ' + str(nums[1]) + ' ' + str(nums[2]))


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

int main()
{
    for (size_t i = 1; i <= 9; i++) {
        for (size_t j = 1; j <= 9; j++) {
            cout << i << 'x' << j << '=' << i * j << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1112
integer,allocatable :: a(:),b(:),c(:)
      integer :: n,i,k,ans,before
      
      
      read*,n
      allocate( a(n),b(n),c(n-1) )
      read*,a(1:n)
      read*,b(1:n)
      read*,c(1:n-1)
      
      
      ans = 0
      before = -100
      do i = 1,n
        ans = ans + b( a(i) )
        
        if( a(i)==before+1 )then
          ans = ans + c(before)
        end if
        before = a(i)
   !     print*,ans,before
      end do
      
      print*,ans
      end

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

ll n;
int main()
{
    ll d;
    cin >> n >> d;
    ll ans = 0;
    ll x, y;
    rep(i, n)
    {
        cin >> x >> y;
        if (x * x + y * y <= d * d)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,t,q,u,w,y,r;
int ret=0;
int a[100],b[100],c[100],d[100],v[100];
void dfs(int i,int x){
    v[i]=x;
    if(i==n){
        int ans=0;
        for(int j=0;j<q;j++)
            if(v[b[j]]-v[a[j]]==c[j]) ans+=d[j];
        ret=max(ret,ans);
        return;
    }
    for(int j=x;j<=m;j++)
        dfs(i+1,j);
}
int main()
{
    cin>>n>>m>>q;
    for(int i=0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    for(int i=1;i<=m;i++)
        dfs(1,i);
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 3648
mi = lambda : map(int, input().split())

k, x = mi()

if x+k>1000000 and x-k+1>=-1000000:
    ans = list(range(x_k+1, 1000001))
elif x+k<=1000000 and x-k+1<-1000000:
    ans = list(range(-1000000, x+k))
elif x+k>1000000 and x-k+1<-1000000:
    ans = list(range(-1000000, 1000001))
else:
    ans = list(range(x-k+1, x+k))

print(*ans)

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

int main() {
  int n,m;
  cin>>n>>m;

  priority_queue<int, vector<int>, less<int>> prices;
  for(int i=0; i<n; i++) {
    int a;
    cin>>a;
    prices.push(a);
  }

  for(int i=0; i<m; i++) {
    int top = prices.top();
    prices.pop();
    prices.push(top/2);
  }

  int64_t ans = 0;
  while(!prices.empty()) {
    ans += prices.top();
    prices.pop();
  }

  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main()
{
    string s;cin >> s;
    for(char c:s){
        if(c==','){
            cout<<" ";
        }else{
            cout<<c;
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#coding: utf-8

args = input().split()
K = int(args[0])
X = int(args[1])


min_x = -1000000
max_x = 1000000

mod_min_x = X - (K-1)
mod_max_x = X + (K-1)

x_list = ""
while mod_min_x <= mod_max_x:
    x_list = x_list + "%s " % mod_min_x
    mod_min_x = mod_min_x + 1

print(x_list)


Measured memory_bytes: 3060
using System;
using System.Linq;

class E
{
	static long[] Read() => Console.ReadLine().Split().Select(long.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var a = Read();
		var f = Read();
		Array.Sort(a);
		Array.Sort(f);
		Array.Reverse(f);

		Console.WriteLine(First(0, 1L << 40, m => a.Zip(f, (x, y) => Math.Max(0, x - m / y)).Sum() <= h[1]));
	}

	static long First(long l, long r, Func<long, bool> f)
	{
		long m;
		while (l < r) if (f(m = l + (r - l - 1) / 2)) r = m; else l = m + 1;
		return r;
	}
}


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

int main() {
    string s;
    cin >> s;
    int count[26];
    fill(count, count + 26, 0);

    for (int i = 0; i < s.size(); i++) {
        count[s[i] - 'a']++;
    }

    for (int i = 0; i < 26; i++) {
        if (count[i] > 1) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = dict(collections.Counter(a))
d = sorted(d.items(), key=lambda x:x[1])
l = len(d)

cnt = 0
for _, j in d:
    if l > k:
        l -= 1
        cnt += j

print(cnt)

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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


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

ll lcm(ll a, ll b)
{
  ll g = gcd(a, b);
  return a / g * b;
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if(v[i] == k){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  sort(all(v));
  int maxv = v[n-1];

  ll tmp = v[0];
  for (int i = 0; i < n; i++) {
    tmp = gcd(tmp, v[i]);
  }

  if(tmp == 1 && maxv >= k){
    cout << "POSSIBLE" << endl;
  }else if(tmp != 1 && k % tmp == 0 && maxv >= k){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}


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

int main() {
    int N; cin >> N;
    vector<ll> A(N); rep (i, N) cin >> A[i];
    vector<ll> B(N); rep (i, N) cin >> B[i];
    vector<ll> C(N); rep (i, N) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    vector<ll> sums(N+1);
    sums[0] = 0;
    rep (i, N) {
        ll b = B[i];
        auto c = upper_bound(C.begin(), C.end(), b);
        sums[i+1] = sums[i] + distance(c, C.end());
    }


    ll cnt = 0;
    rep (i, N) {
        ll a = A[i];
        auto b = upper_bound(B.begin(), B.end(), a);
        ll index = distance(B.begin(), b);
        cnt += sums[N] - sums[index];
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 6404
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 3010;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;


int n;
char S[N * 2 + 5];
int A[N + 5], B[N + 5];
char F[N * 2 + 5][N * 2 + 5], G[N + 5][N * 2 + 5];
int CntA, CntB;

int main(){
 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
  	for (int i = 1; i <= 2 * n; i++) cin >> S[i];
 	for (int i = 1; i <= n * 2; ++i)
    if (S[i] == 'a') A[++CntA] = i;
    else B[++CntB] = i;
	for (int i = n; i >= 1; --i) {
    	if (A[i] < B[i]) {
    	  F[i][1] = 'a', F[i][2] = 'b';
      	for (int j = i; j <= n; ++j) {
       	 if (j == n || A[j + 1] > B[i]) {
       	   strcpy(F[i] + 3, G[j + 1] + 1);
       	   break;
       	 }
      	}
    } else {
      for (int j = i; j <= n; ++j) {
        if (j == n || B[j + 1] > A[i]) {
          int cnt = 0;
          for (int k = i; k <= j; ++k) F[i][++cnt] = 'b';
          F[i][++cnt] = 'a';
          if (i == j) strcpy(F[i] + cnt + 1, G[i + 1] + 1);
          else strcpy(F[i] + cnt + 1, F[i + 1] + j - i + 1);
          break;
        }
      }
    }
    if (strcmp(F[i] + 1, G[i + 1] + 1) < 0) strcpy(G[i] + 1, G[i + 1] + 1);
    else strcpy(G[i] + 1, F[i] + 1);
    // printf("F[%d] = %s, G = %s\n", i, F[i] + 1, G[i] + 1);
  }
    cout << G[1] + 1;
  	return 0;
}


Measured memory_bytes: 36712
while True:
    n, p = map(int, input().split())
    pp = p
    if n == p == 0:
        break
    stones = [0] * n
    i = 0
    while True:
        er = i % n
        if p == 1 and stones[er] == pp - 1:
            print(er)
            break
        if p >= 1:
            stones[er] += 1
            p -= 1
        else:
            p += stones[er]
            stones[er] = 0
        i += 1

Measured memory_bytes: 7664
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, m, pin, ac = 0, wa = 0;
    cin >> n >> m;
    vector<vector<string>> p(n, vector<string>(0));
    vector<string> s(m);
    for(int i = 0; i < m; ++i){
        cin >> pin >> s.at(i);
        pin--;
        if(p.at(pin).size() == 0){
            if(s.at(i) == "WA") p.at(pin).push_back("WA");
            else{
                ac++;
                wa += p.at(pin).size();
                p.at(pin).push_back("AC");
            }  
        }
        else{
            if(p.at(pin).at(p.at(pin).size() - 1) == "AC") continue;
            else if(s.at(i) == "WA") p.at(pin).push_back("WA");
            else{
                ac++;
                wa += p.at(pin).size();
                p.at(pin).push_back("AC");
            }
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n, m, k;
  cin >> n >> m >> k;

  REP (i, n + 1) {
    REP (j, m + 1) {
      if (i * m + j * n - 2 * (i * j) == k) {
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	ee := make([][]int, n)

	for i := 0; i < n; i++ {
		ee[i] = make([]int, 0)
	}

	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		ee[a] = append(ee[a], b)
		ee[b] = append(ee[b], a)
	}

	used := make([]bool, n)
	used[0] = true
	used[ee[0][0]] = true
	s := 0
	t := ee[0][0]
	ss := make([]int, 1)
	ss[0] = s
	tt := make([]int, 1)
	tt[0] = t
	loop := true
	for loop {
		loop = false
		for _, to := range ee[s] {
			if used[to] {
				continue
			}
			s = to
			used[to] = true
			ss = append(ss, s)
			loop = true
			break
		}
	}
	loop = true
	for loop {
		loop = false
		for _, to := range ee[t] {
			if used[to] {
				continue
			}
			t = to
			used[to] = true
			tt = append(tt, t)
			loop = true
			break
		}
	}

	fmt.Fprintln(writer, len(ss)+len(tt))
	for i := len(ss) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, ss[i]+1)
	}
	for i := 0; i < len(tt); i++ {
		fmt.Fprintln(writer, tt[i]+1)
	}
}


Measured memory_bytes: 11520
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int N;
    scanf("%d",&N);
    int L[2*N];
    for (int i=0; i<2*N; i++) {
        scanf("%d",&L[i]);
    }
    sort(L,L+2*N);
    int x=0;
    for (static int i=0; i<2*N; i++) {
        x+=min(L[i],L[i++]);
    }
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 256