akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    readLine()!!.toInt()
    val x = readLine()!!.split(" ").map(String::toInt)
    val y = readLine()!!.split(" ").map(String::toInt)

    println(x.zip(y) { a, b -> Math.abs(a - b)}.sum())
    println(Math.sqrt(x.zip(y) { a, b -> Math.pow(Math.abs(a - b).toDouble(), 2.0)}.sum()))
    println(Math.cbrt(x.zip(y) { a, b -> Math.pow(Math.abs(a - b).toDouble(), 3.0)}.sum()))
    println(x.zip(y) { a, b -> Math.abs(a - b)}.max())
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    L=LI()
    if L[2]==(sum(L) - min(L) - max(L)):
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 61760
def main():
  while True:
    w, h = map(int, input().split())
    if not w:
      break
  
    n = int(input())
  
    xlst = [0, w - 1]
    ylst = [0, h - 1]
    plst = []
  
    for i in range(n):
      x1, y1, x2, y2 = map(int, input().split())
      plst.append([x1,y1,x2 - 1,y2 - 1])
      xlst.append(x1)
      xlst.append(x2)
      xlst.append(x2 - 1)
      ylst.append(y1)
      ylst.append(y2)
      ylst.append(y2 - 1)
  
    xlst = list(set(xlst))
    ylst = list(set(ylst))
    xlst.sort()
    ylst.sort()
  
    xdic = {}
    ydic = {}
  
    for i, v in enumerate(xlst):
      xdic[v] = i
    for i, v in enumerate(ylst):
      ydic[v] = i
    
    neww = xdic[xlst[-1]]
    newh = ydic[ylst[-1]]

    painted = [[1] * (newh + 2)]
    for _ in range(neww):
      painted.append([1] + [0] * newh +  [1])
    painted.append([1] * (newh + 2))  
  
    for p in plst:
      x1, y1, x2, y2 = p
      x1, y1, x2, y2 = xdic[x1] + 1, ydic[y1] + 1, xdic[x2] + 1, ydic[y2] + 1
      for x in range(x1, x2 + 1):
        for y in range(y1, y2 + 1):
          painted[x][y] = 1
    
    stack = []
    app = stack.append
    pp = stack.pop
    direct = ((-1, 0), (1, 0), (0, -1), (0, 1))
    ans = 0

    for x in range(1, neww + 1):
      for y in range(1, newh + 1):
        if not painted[x][y]:
          ans += 1
          painted[x][y] = 1
          app((x,y))

          while stack:
            px, py = pp()
            for dx, dy in direct:
              tx, ty = px + dx, py + dy
              if not painted[tx][ty]:
                painted[tx][ty] = 1
                app((tx,ty))
    print(ans)

main()


Measured memory_bytes: 22108
#include <algorithm>
#include <cfloat>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int h, w;
char c[2010][2010];
int a[2][2010][2010];
signed main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w)cin >> c[i][j];
	}
	rep(i, h) {
		int cnt = 0;
		rep(j, w) {
			if (c[i][j] == '#') {
				for (int k = j - 1; c[i][k] != '#' && k >= 0; k--)a[0][i][k] = cnt;
				cnt = 0;
			}
			else cnt++;
		}
		if (c[i][w - 1] != '#') {
			for (int k = w - 1; c[i][k] != '#' && k >= 0; k--)a[0][i][k] = cnt;
		}
	}
	rep(i, w) {
		int cnt = 0;
		rep(j, h) {
			if (c[j][i] == '#') {
				for (int k = j - 1; c[k][i] != '#' && k >= 0; k--)a[1][k][i] = cnt;
				cnt = 0;
			}
			else cnt++;
		}
		if (c[h - 1][i] != '#') {
			for (int k = h - 1; c[k][i] != '#' && k >= 0; k--)a[1][k][i] = cnt;
		}
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w)ans = max(ans, a[0][i][j] + a[1][i][j]);
	}
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 67328
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll n,a,b,c,x; cin >> n >> a >> b >> c >> x;
        if(!n && !a && !b && !c && !x) break;
        vl y(n); rep(i,n) cin >> y[i];
        vl appeared(10005,-1);
        appeared[x] = 0;
        ll cur = -1;
        ll now = 1;
        ll repeat = 0;
        while(1){
            x = (a * x + b) % c;
            if(appeared[x] != -1){
                repeat = appeared[x];
                break;
            }
            appeared[x] = now;
            now++;
        }
        ll ans = 0;
        ll add = 0;
        rep(i,n){
            if(appeared[y[i]] == -1){
                ans = -1;
                break;
            }
            if(cur != -1 && appeared[cur] >= appeared[y[i]]){
                if(repeat > appeared[y[i]]){
                    ans = -1;
                    break;
                }
                add += now-repeat;
            }
            cur = y[i];
            chmax(ans,appeared[y[i]]+add);
        }
        if(ans > 10000) cout << -1 << endl;
        else cout << ans << endl;
    }
}


Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

typedef struct edge_{
	int to,cost;
}edge;

class graph{ 
	typedef long cost_type;
	typedef int edge_type;
	typedef pair<cost_type,edge_type> P; 	//first:最短経路コスト second:頂点番号
	
	
	private:
		vector<vector<edge> > gra; 	//グラフ本体
		priority_queue<P,vector<P>,greater<P> > que; 	//最短経路の値の小さいものから取り出せる
		edge_type V; 	//頂点の個数
	  vector<cost_type> dp; 	//開始地点からの最小コストを格納する配列
	
	public:
		void init(int num){
			V = num;
			dp.assign(V,0x7FFFFFFF);
			gra.assign(V,vector<edge>());
		}


		void setCost(edge_type from , edge_type to , edge_type cost){
			edge e = {to , cost};
			edge e2 = {from , cost};
			gra[from].push_back( e );
			gra[to].push_back(e2);
		}	

		
		void setDirectCost(edge_type from , edge_type to , edge_type cost){
			edge e = {to , cost};
			gra[from].push_back( e );
		}	


		void dijkstra(edge_type s){
			dp[s] = 0;
			que.push(pair<cost_type,edge_type>(0,s)); 

			while(!que.empty()){
				P p = que.top();
				que.pop();
				edge_type v = p.second;
				if( dp[v] > p.first ) continue;
				for(edge_type i = 0 ; i < gra[v].size() ; i++ ){
					edge e = gra[v][i];
					if( dp[e.to] > dp[v] + e.cost ){
						dp[e.to] = dp[v] + e.cost;
						que.push(pair<cost_type,edge_type>(dp[e.to],e.to));
					}
				}
			}
		}

		cost_type getCost(edge_type to){
			return dp[to];
		} 

};

int main(){
	graph g;
	int n;
	cin >> n;
	g.init(n);
	rep(i,0,n){
		int from , k;
		cin >> from >> k;
		rep(i,0,k){
			int to;
			long cost;
			cin >> to >> cost;
			g.setDirectCost(from,to,cost);
		}

	}

	g.dijkstra(0);

	rep(i,0,n)
		cout << i << " " << g.getCost(i) << endl;

	ret 0;
}


Measured memory_bytes: 3148
def calculate(n):
    ans = 0
    for i in range(len(str(n))):
        ans += n % 10
        n //= 10
    return ans


n = int(input())
val = 100000
num = []
for i in range(1, n):
    num.append([i, n-i])
    cal = calculate(num[i-1][0]) + calculate(num[i-1][1])
    if val > cal:
        val = cal
print(val)


Measured memory_bytes: 19468
package main

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

func main() {
	scanner := makeWordScanner()
	a := eGetInt(scanner)
	b := eGetInt(scanner)

	p := a + b
	q := a - b
	r := a * b

	max := p
	if q > max {
		max = q
	}
	if r > max {
		max = r
	}
	fmt.Println(max)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lint long long int 
using namespace std;

int main()
{
        lint k;
        cin>>k;
        vector<lint >arr(k);
        lint i;
        for(i=0;i<k;i++)
        cin>>arr[i];
        
        lint flag=0;
        if(arr[k-1]!=2)
        {
                cout<<-1<<endl;
                return 0;
        }
        lint max=3;
        lint min=2;
        for(i=k-1;i>=0;i--)
        {
                lint t1,t2;
                lint rem1,rem2;
                rem1=min%arr[i];
                if(rem1>0)
                rem1=arr[i]-rem1;
                t1=rem1+min;
                
                rem2=max%arr[i];
                t2=max-rem2;
                
                if(t2<min)
                t2=min;
                
                if(t1>max)
                t1=max;
                
                min=t1;
                max=t2+arr[i]-1;
                //cout<<min<<" "<<max<<endl;
        }lint tmax=max;
        lint tmin=min;
        for(i=0;i<k;i++)
        {
                min=min-(min%arr[i]);
                max=max-(max%arr[i]);
        }
        if(max==2 && min==2)
        cout<<tmin<<" "<<tmax<<endl;
        else
        cout<<-1<<endl;
        return 0;
}

Measured memory_bytes: 1024
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N, W; cin >> N >> W;
    VI w(N), v(N);
    REP(i, N)
    {
        cin >> w.at(i) >> v.at(i);
    }
    int max_v = accumulate(ALL(v), 0);

    VVI dp(N+1, VI(max_v+1, INF));
  
    // dpの初期化
    dp.at(0).at(0) = 0;
    int max_ans=0;
    // dpループ
    REP(i,N)
    {
        REP(j, max_v+1)
        {
            if (j-v.at(i)>=0) 
            {
                chmin(dp.at(i+1).at(j), dp.at(i).at(j-v.at(i))+w.at(i));
            }
            chmin(dp.at(i+1).at(j), dp.at(i).at(j));
            
            if (dp.at(i+1).at(j)<=W) max_ans = max(max_ans,j);
        }
    }
    cout << max_ans << endl;

    return 0;
}



Measured memory_bytes: 40192
#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
int sum;
set<pair<pair<int,int>,int> >s;
void dfs(int a,int b,int c,int n){
  if(s.count(mk(mk(a,b),c)))return;
  s.insert(mk(mk(a,b),c));
  if(n==0){
    int aa=0,bb=0,cc=0;
    if(a>=5)aa=a/5*1520;
    if(b>=4)bb=b/4*1870;
    if(c>=3)cc=c/3*2244;
    sum=min(sum,aa+bb+cc+a%5*380+b%4*550+c%3*850);
  }
  else{
    if(n-200>=0)dfs(a+1,b,c,n-200);
    if(n-300>=0)dfs(a,b+1,c,n-300);
    if(n-500>=0)dfs(a,b,c+1,n-500);
  }
}
int main(){
  int a;
  while(cin>>a,a){
    s.clear();
    sum=1e9;
    dfs(0,0,0,a);
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 3148
#include <stdio.h>
#include <iostream>
#include <cmath>
#include<vector>
#include<queue>
#include<string>
#include <ios>
#include <iomanip>
#include<algorithm>
#pragma warning( disable:4996 )
using namespace std;

struct Node {
	int key;
	Node *prev, *next;
};

Node *nil = new struct Node;

void Insert(int key) {
	Node *x = new struct Node;
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

void Delete(int key) {
	Node *x = new struct Node;
	x = nil->next;
	while ((x != nil) && (x->key != key))x = x->next;
	if (x != nil) {
		x->prev->next = x->next;
		x->next->prev = x->prev;
	}
}

void DeleteFirst() {
	Node *x = new struct Node;
	x = nil->next;
	x->prev->next = x->next;
	x->next->prev = x->prev;
}

void DeleteLast() {
	Node *x = new struct Node;
	x = nil->prev;
	x->prev->next = x->next;
	x->next->prev = x->prev;
}


int main() {
	int N;
	scanf("%d",&N);
	nil->next = nil;
	nil->prev = nil;
	char command[20];
	int key;
	for (int i = 0; i < N; i++) {
		scanf("%s",command);
		if (command[6] == 'F') {
			DeleteFirst(); continue;
		}
		else if (command[6] == 'L') {
			DeleteLast(); continue;
		}
		scanf("%d",&key);
		if (command[0] == 'i') Insert(key);
		else if (command[0] == 'd') Delete(key);
		
	}
	Node *x = new struct Node;
	x = nil->next;
	int counter = 0;
	while (x != nil)
	{
		if (!counter)printf("%d", x->key);
		else printf(" %d", x->key);
		x = x->next;
		counter++;
	}
	printf("\n");
}


Measured memory_bytes: 65704
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int M = 1e3 + 10;
const int N = 1e6 + 10;



void solve() {
    string s;
    cin >> s;
    ll sum = 0;
    fr(i, s.size())
        if (s[i] == 'W')
            sum += i;
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());
    fr(i, s.size())
    if (s[i] == 'W')
        sum -= i;
    cout << sum;

}

int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();

    return 0;

}


Measured memory_bytes: 1356
#include <stdio.h>
#include <stdlib.h>

int crescente(const void *a, const void *b){
    if (*(int*)a == *(int*)b)
        return 0;
    else if (*(int*)a > *(int*)b)
            return 1;
    else
        return -1;
}

int main(){
    int questoes;
    scanf("%d", &questoes);
    int dificuldade[questoes];
    for (int i = 0; i < questoes; i++){
        scanf("%d", &dificuldade[i]);
    }
    qsort(dificuldade, questoes, sizeof(int), crescente);
    int qtdK = dificuldade[questoes/2] - dificuldade[questoes/2-1];
    printf("%d\n", qtdK);
    return 0;
}


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

#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define all(x) x.begin(),x.end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

int main(){

    IOS;

    ll t,n,m;
    t=1;
    while(t--)
    {
        cin >> n;

        vector<ld> prob(n+1);
        for(ll i=1;i<=n;i++)
        {
            cin >> prob[i];
        }

        vector<vector<ld>> dp(n+1,vector<ld>(n+1,0.0));
        dp[0][0]=1.0;

        for(ll i=1;i<=n;i++)
        {
            for(ll j=0;j<=i;j++)
            {
                if(j==0)
                {
                    dp[i][j] = dp[i-1][j]*(1-prob[i]);
                }
                else
                {
                    dp[i][j] = dp[i-1][j]*(1-prob[i]) + dp[i-1][j-1]*prob[i];
                }
            }
        }
        
        ld ans = 0.0;

        for(ll i=(n+1)/2;i<=n;i++)
            ans += dp[n][i];

        precision(ans,10);
    }
    return 0;
}
//GFG

Measured memory_bytes: 141056
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
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)];//先祖をrootで取っておきたい。
    }
    
    //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)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n;
  cin>>n;
  int p[n];
  REP(i,n){
    cin>>p[i];
    p[i]--;
  }
  
  long long a[n],b[n];
  for(long long i=0;i<n;i++){
    a[i] = (i+1)*(long long)n;
  }
  for(long long i=0;i<n;i++){
    b[i] = ((long long)n-i)*(long long)n;
  }
  for(long long i=0;i<n;i++){
    a[p[i]] += i;
  }
  
  REP(i,n){
    cout<<a[i]<<' ';
  }
  cout<<endl;
  REP(i,n){
    cout<<b[i]<<' ';
  }
  cout<<endl;
  
  return 0;
}


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

int n;
int mat[100100][4], dp[100100][4];
bool vis[100100][4];

int func( int pos, int last ) {
  if (pos > n) return 0;
  if (vis[pos][last]) return dp[pos][last];
  vis[pos][last] = 1;

  int res = 0;
  for (int i = 1; i <= 3; ++i) {
    if (i != last) {
      res = max(res, mat[pos][i] + func(pos + 1, i));
    }
  }
  return dp[pos][last] = res;
}

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

  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 3; ++j) cin >> mat[i][j];

  cout << func(1, 0) << endl;

  return 0;
}


Measured memory_bytes: 11648
#include<bits/stdc++.h>
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
    int t=1;
  
    while(t--){
       int n;
       cin>>n;
       double ans;
       if(n%2==0){
             ans=(double)1/(double)2;
       }
       else{
             ans=(double)((n/2)+1)/(double)n;
       }
       cout<<setprecision(8)<<ans<<endl;
    }   
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int a, b, n, x, y;
	int dp[20][20];
	while (1) {
		cin >> a >> b >> n;
		if (a + b == 0) break;
		rep(i, 0, 20) {
			rep(j, 0, 20) {
				dp[i][j] = 0;
			}
		}
		rep(i, 0, n) {
			cin >> x >> y;
			x--;
			y--;
			dp[x][y] = -1;
		}
		dp[0][0] = 1;
		rep(i, 0, a) {
			rep(j, 0, b) {
				if (i != 0 && dp[i][j] != -1) {
					dp[i][j] += max((int)0, dp[i - 1][j]);
				}
				if (j != 0 && dp[i][j] != -1) {
					dp[i][j] += max((int)0, dp[i][j - 1]);
				}
			}
		}
		cout << dp[a - 1][b - 1] << endl;
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

void solve(){
    int n,m;
    cin >> n >> m;
    vvi graph(n,vi(n,0));
    for (int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        graph[a][b] = 1;
        graph[b][a] = 1;
    }

    // printmatrix(graph);
    vi row(n,0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            row[i] += graph[i][j];
        }
    }

    int ans=0;
    vi prevrow = row;
    for (int i = 0; i < n; i++) {
        if (row[i] == 1) {
            row[i] = 0;
            ans++;
            for (int j = 0; j < n; j++) {
                if (graph[i][j] == 1) {
                    graph[i][j] = 0;
                    graph[j][i] = 0;
                    row[j]--;
                }
            }
        }
    }
    while (prevrow != row) {
        prevrow = row;
        for (int i = 0; i < n; i++) {
            if (row[i] == 1) {
                ans++;
                row[i] = 0;
                for (int j = 0; j < n; j++) {
                    if (graph[i][j] == 1) {
                        graph[i][j] = 0;
                        graph[j][i] = 0;
                        row[j]--;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
n=int(input())
a={}
for _ in range(n):
    num=int(input())
    if num not in a:
        a[num]=1
    else:
        a[num]+=1
all_count=0
for _, count in a.items():
    if count%2==1:
        all_count+=1
print(all_count)

Measured memory_bytes: 15068
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1e9 as usize + 9;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut aa = a.iter().cloned().collect::<Vec<_>>();
    aa.sort();

    let mut cnt = 0;
    for i in 0..n {
        let index = aa.binary_search(&a[i]).unwrap();
        if index % 2 != i % 2 {
            cnt += 1;
        }
    }
    println!("{}", cnt / 2);
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n;cin>>n;
  vector<int> a(n, 0);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());

  ll ans = a.back() - a.front();
  for (int i=1; i<n-1; i++) {
    if (a[i]>0) ans += a[i];
    else ans -= a[i];
  }
  cout << ans << endl;
  for (int i=1; i<(int)(a.size())-1; i++) {
    if (a[i]<0) {
      printf("%d %d\n", a.back(), a[i]);
      a.back() -= a[i];
    } else {
      printf("%d %d\n", a.front(), a[i]);
      a.front() -= a[i];
    }
  }
  printf("%d %d\n", a.back(), a.front());
}

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


Measured memory_bytes: 2304
N = gets.to_i
A = gets.split.map(&:to_i)

count = 1
prev = nil

A.each_cons(2) do |a,b|
  if prev.nil? || prev.zero?
    prev = a <=> b
    next
  end

  dir = a <=> b
  if dir.zero? || dir == prev
    next
  end

  count += 1
  prev = nil
end

puts count

Measured memory_bytes: 8452
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define yorn(f) cout<< (f) ? "Yes":"No" << endl
#define YORN(f) cout<< (f) ? "YES":"NO" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
#define DB double
const int N=400010;
const int M=800010;
using namespace std;

int n;
map<LL,int> mp;
LL sz[N];
int fa[N],edge[M],lst[N],nxt[M],t=0;

struct nn{
	LL d;
	int id;
}a[N];

int cmp(nn A,nn B){
	return A.d<B.d;
}

void READ(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%lld",&a[i].d),a[i].id=i,mp[a[i].d]=i;
	sort(a+1,a+n+1,cmp);
}

void ADD(int x,int y){
	edge[++t]=y;nxt[t]=lst[x];lst[x]=t;
}

LL SEARCH(int x,int dep){
	LL res=dep;
	for(int r=lst[x];r;r=nxt[r]){
		res+=SEARCH(edge[r],dep+1);
	}
	return res;
}

int SOLVE(){
	rep(i,1,n)sz[i]=1;
	tep(i,n,2){
		int x=a[i].id;
		LL d=a[i].d;
		LL now=d+2*sz[x]-n;
		int pos=mp[now];
		if(pos==0||now>=a[i].d)return 0;
		fa[x]=pos;
		ADD(fa[x],x);
		sz[fa[x]]+=sz[x];
	}
	LL sum=SEARCH(a[1].id,0);
	if(sum!=a[1].d)return 0;
	rep(i,1,n){
		if(i==a[1].id)continue;
		printf("%d %d\n",i,fa[i]);
	}
	return 1;
}

int main(){
	READ();
	if(!SOLVE())printf("-1\n");
	return 0;
}

Measured memory_bytes: 23040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 


int main() {
    ll N, M; cin >> N >> M;
    vector<vector<int>> G(N + 1);
    int seen[100010];
    for (int i = 0; i <= N; ++i) seen[i] = -1;
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> que;
    que.push(1);
    seen[1] = 0;

    // for (int i = 0; i < N ; ++i) {
    //     cout << seen[i + 1] << " ";
    // }
    // cout << endl;
    while (!que.empty()) {
        int v = que.front();
        // cout << "look " << v << " ";
        que.pop();

        for (auto i: G[v]) {
            if (seen[i] != -1) continue;
            // cout << "next:" << i << " ";
            seen[i] = v;
            que.push(i);
        }
        // cout << endl;
        // for (int i = 0; i < N ; ++i) {
        //     cout << seen[i + 1] << " ";
        // }
        // cout << endl;
    }

    bool ok = true;
    for (int i = 2; i <= N; ++i) {
        if (seen[i] == -1) {
            ok = false;
            break;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
        for (int i = 2; i <= N; ++i) {
            cout << seen[i] << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 10344
h, w, k = gets.split.map(&:to_i)
base = 1_000_000_007

fib = Array.new(w+1, 0)
fib[1] = 1
(2..w).each{|i| fib[i] = fib[i-1] + fib[i-2]}

f = Array.new(h+1){Array.new(w+2, 0)}
f[0][k] = 1

(1..h).each{|y|
    (1..w).each{|x|
        s = f[y-1][x] * fib[x] * fib[w+1-x]
        l = f[y-1][x-1] * fib[x-1] * fib[w+1-x]
        r = f[y-1][x+1] * fib[x] * fib[w-x]
        f[y][x] = (s + l + r) % base
    }
}
p f[h][1]

Measured memory_bytes: 1788
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = true;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt() - 1;
        }
        int btn = 0;
        int cnt = 0;
        Set<Integer> set = new HashSet<>();
        do {
            set.add(btn);
            btn = a[btn];
            ++cnt;
            if (btn == 1) {
                _out.println(cnt);
                return;
            }
        } while (!set.contains(btn));
        _out.println(-1);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 51784
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
vector<int> path_length;
int rec(int cv) {
    if (path_length[cv] != -1) return path_length[cv];
    int ret = 0;
    for (auto nv: G[cv]) {
        ret = max(ret, rec(nv) + 1);
    }
    return path_length[cv] = ret;
}

int main() {
    int n, m;
    cin >> n >> m;
    G.assign(n, vector<int>());
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
    }
    path_length.assign(n, -1);
    int ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, rec(i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = a+b+c;
      if(d>=22){
      	System.out.println("bust");
      	}
      if(d<22){
      	System.out.println("win");
      	}
		
	}
}


Measured memory_bytes: 21844
import java.util.*;

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

	}
}


Measured memory_bytes: 58940
#include<bits/stdc++.h>
using namespace std;
int pfx[100002][101];
int main(){
	#ifdef EVAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int N,K;
	cin>>N>>K;
	int vet[N];
	for(int i=0;i<N;i++)cin>>vet[i];
	//start
	pfx[0][0]=1;
	for(int i=1;i<=K;i++){
		if(i<=vet[0]){
			pfx[i][0]+=pfx[i-1][0]+1;
			pfx[i][0]%=1000000007;
		}
		else
		pfx[i][0]+=pfx[i-1][0];
		pfx[i][0]%=1000000007;
	}
	//dp
	for(int i=1;i<N;i++){
		pfx[0][i]=1;
		for(int j=1;j<=K;j++){
			if(j-vet[i]-1<0)pfx[j][i]+=pfx[j][i-1];
			else pfx[j][i]+=pfx[j][i-1]-pfx[j-vet[i]-1][i-1]+1000000007;
			pfx[j][i]%=1000000007;
			pfx[j][i]+=pfx[j-1][i];
			pfx[j][i]%=1000000007;
		}
	}
	if(K!=0)
	cout<<(pfx[K][N-1]-pfx[K-1][N-1]+1000000007)%1000000007;
	else
	cout<<pfx[K][N-1];
}

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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
 
Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> res;
    for (Int i = 1; i <= n; i++) {
        double x = i;
        if ((Int)(x * 1.08) == n) {
            res.emplace_back(i);
        }
    }
    if (res.empty()) {
        dump(":(");
    }
    else {
        dump(res.front());
    }
    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    int ab = 0, ba = 0, bx = 0, xa = 0;

    for (string s: v) {
        rep(i, s.size() - 1) {
            if (s.substr(i, 2) == "AB") ab++;
        }
    }

    for (string s: v) {
        if (s.front() == 'B' && s.back() == 'A') ba++;
        else if (s.front() == 'B') bx++;
        else if (s.back() == 'A') xa++;
    }


    if (ba == 0) {
        int add = min(bx, xa);
        cout << add + ab << endl;
    } else {
        ll c = ba - 1 + ab;
        if (xa > 0) {
            xa--;
            c++;
        }
        if (bx > 0) {
            bx--;
            c++;
        }

        c += min(xa, bx);
        cout << c << endl;
    }

}


Measured memory_bytes: 3748
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools


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

N = int(input())
A = list(input())


for i in range(len(A)):
    a = ord(A[i])
    a += N
    #print(a)
    while(a > 90):
        a -= 26

    A[i] = chr(a)

print(''.join(A))


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


long long pow100(long long D) {
    long long ans = 1;
    for (int i = 0; i < D; i++) {
        ans *= 100;
    }
    return ans;
}

void solve(long long D, long long N){
    if (N == 100) {
        cout << (pow100(D) * (N + 1)) << endl;
    } else {
        cout << (pow100(D) * N) << endl;
    }
}

int main(){
    long long D;
    scanf("%lld",&D);
    long long N;
    scanf("%lld",&N);
    solve(D, N);
    return 0;
}


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

#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,a) for(long i=0;i<(a);++i)

typedef std::vector<int>  VI;
typedef std::vector< VI > VI2;
typedef std::vector< VI2 > VI3;

int N, A, B;
VI a(40), b(40), c(40);
const int inf = 1000000;
VI3 dp(41, VI2(401, VI(401, inf)));

int main() {
    std::cin >> N >> A >> B;
    REP(i, N) {
        std::cin >> a[i] >> b[i] >> c[i];
    }

    int maxcap = N*10;
    dp[0][0][0] = 0;

    REP(k, N) REP(i, maxcap) REP(j, maxcap) {
        if(dp[k][i][j] == inf) continue;
        dp[k+1][i][j]           = std::min(dp[k+1][i][j], dp[k][i][j]);
        dp[k+1][i+a[k]][j+b[k]] = std::min(dp[k+1][i+a[k]][j+b[k]], dp[k][i][j]+c[k]);
    }

    int ans = inf;
    bool f = false;
    FOR(i, 1, maxcap) FOR(j, 1, maxcap){
        if(i*B == j*A) {
            f = true;
            ans = std::min(ans, dp[N][i][j]);
        }
    }

    if(ans == inf) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << ans << std::endl;
    }
}

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

int main() {
	string a;
	cin >> a;
	unordered_map<char, bool>b;
	for (char c : a) {
		b[c] = true;
	}
	if (b['N'] == b['S'] && b['E'] == b['W'])puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    mapk = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
    
    dp = [0 for _ in range(N+1)] # ちょうどi本使ったときの最大桁数
    for i in range(1, N+1):
        tmp = []
        for k in lst:
            if (i-mapk[k])>=0:
                tmp.append(dp[i-mapk[k]] + 1)
            else:
                tmp.append(-float('inf'))
        dp[i] = max(tmp)
    #print(dp)
    
    ans = ''
    X = N
    lst = sorted(lst, reverse=True)
    for _ in range(dp[N]):
        for k in lst:
            if (X-mapk[k]>=0) and (dp[X - mapk[k]] == dp[X] - 1):
                ans += str(k)
                X -= mapk[k]
                break
    print(ans)
main()


Measured memory_bytes: 41948
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ni = (int) (n / 1.08);

        if (((int)(ni * 1.08)) == n ) {
            System.out.println(ni);
        } else if(((int) ((ni + 1) * 1.08)) == n) {
            System.out.println(ni+1);
        } else {
            System.out.println(":(");
        }

    }
}



Measured memory_bytes: 22868
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();
        
        long ans = -3000000000000000000L;
        ans = Math.max(ans, a*c);
        ans = Math.max(ans, a*d);
        ans = Math.max(ans, b*c);
        ans = Math.max(ans, b*d);
        System.out.println(ans);
    }
}


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

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

int MOD=1e9+7;
ll INF=1e18;

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

bool is_prime[1300000];
int prime[1300000];
int ans[1300000];

void eratos(int n){
    for(int i=0; i<=n; i++) is_prime[i]=true;
    is_prime[0]=false, is_prime[1]=false;

    for(int i=2; i*i<=n; i++){
        if(is_prime[i]){
            for(int j=2; i*j<=n; j++){
                is_prime[i*j]=false;
            }
        }
    }

    int cnt=1;
    for(int i=1; i<=n; i++){
        if(is_prime[i]){
            prime[cnt]=i;
            cnt++;
        }
    }

    cnt=1;
    for(int i=2; i<=n; i++){
        if(i>prime[cnt+1]) cnt++;

        if(i<=prime[cnt+1]){
            ans[i]=prime[cnt+1]-prime[cnt];
        }
    }
}

int main(){
    eratos(1299800);
    while(1){
        int n; cin>>n;
        if(n==0) return 0;
        if(n==1 || is_prime[n]) cout << 0 << endl;
        else cout << ans[n] << endl;
    }
}


Measured memory_bytes: 9756
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int summ(int num){
  if(num == 0) return 0;
  return num%10 + summ(num/10);
}
int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  int ans=MODs;
  ranges(i, 1, N){
    int a = i;
    int b = N - i;
    ans = min(summ(a)+summ(b), ans);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int n;

int main(){
	scanf("%d", &n);
	for(int i = 0; i <= n / 7; i++)
		if((n - i * 7) % 4 == 0)
			return puts("Yes"), 0;
	puts("No");
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>


int gcd(int a,int b) {
    if(b==0) return a;
    else return gcd(b,a%b);
}

int main() {
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF) {
        int g=gcd(a,b);
        int l=a/g*b;
        printf("%d %d\n",g,l);
    }
}

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

#define _GLIBCXX_DEBAC
using namespace std;
	
int findx(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

string divide[4] = { "dream","dreamer","erase","eraser" };

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q);
	for (int i = 0; i < q; i++) {
		cin >> a[i];
	}
	vector<int> b(n,k-q);
	for (int i = 0; i < q; i++) {
		b[a[i] - 1] += 1;
	}
	for (int i = 0; i < n; i++) {
		if (b[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
		return 0;
}









Measured memory_bytes: 1408