akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++) 
typedef long long ll;
using namespace std;

//---------- UnionFind ----------//

vector<int> parent; //親ノード
vector<int> Siz; //集合の大きさ

// n要素で初期化
void init(int n) {
    parent.resize(n);
    Siz.assign(n, 1);
    rep(i, n) {
        parent[i] = i;
    }
}

// xの属する集合の根を求める
int root(int x) {
    if(parent[x] == x) {
        return x;
    }
    else {
        return parent[x] = root(parent[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y) {

    x = root(x);
    y = root(y);
    if(x == y) {
        return;
    }

    if(Siz[x] < Siz[y]) {
        swap(x, y);
    }

    Siz[x] += Siz[y];
    parent[y] = x;
}

// xとyが同じ集合に属するかどうか
bool same(int x, int y) {
    return root(x) == root(y);
}

// xの属する集合の要素数を求める
int size(int x) {
    return Siz[root(x)];
}

//--------------------------------//

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

    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    init(n);

    vector<ll> ans(m);
    ans[m-1] = (ll)n*(n-1)/2;
    for(int i = m-1; i >= 1; i--) {

        if(same(a[i], b[i])) {
            ans[i-1] = ans[i];
        }
        else {
            ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
            unite(a[i], b[i]);
        }
    }

    rep(i, m) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3712
N = int(input())
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
c = sum(list_a)

for i in range(1,len(list_a)):
    temp = list_a[i] - min((list_a[i-1] - list_b[i-1]),0)*(-1)
    if list_a[i-1] - list_b[i-1] <= 0:
        list_a[i-1] = 0
    else:
        list_a[i-1] -= list_b[i-1]
    if temp != list_a[i] and temp >= 0:
        list_a[i] = temp
    elif temp <= 0:
        list_a[i] = 0

del_c = sum(list_a)

ans = c - del_c
print(ans)

Measured memory_bytes: 24232
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define vel vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int r, g, b, n; cin >> r >> g >> b >> n;
	int ans = 0;
	rep(i, (n/r)+2) {
		rep(j, (n/g)+2) {
			int ex = n - (i*r) - (j*g);
			if (ex>=0 and ex%b==0) { ans++; }
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N)
    {
        cin >> a[i];
    }
    if ((N - 1) % (K - 1) != 0)
    {

        cout << (N - 1) / (K - 1) + 1 << endl;
    }
    else
    {
        cout << (N - 1) / (K - 1) << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
//nが[l,r)の範囲にあるか判定する
#define isR(l,r,n) ((l<=n)&&(n<r))

char mine[50][50+1];
int H,W;
const int dx[8]={1,1,1,0,0,-1,-1,-1};
const int dy[8]={1,0,-1,1,-1,1,0,-1};
int main(){
  cin >> H >> W;
  for(int i=0;i<H;i++){
    for(int k=0;k<W;k++){
      cin >> mine[i][k];
    }
  }
  for(int i=0;i<H;i++){
    for(int k=0;k<W;k++){
      if(mine[i][k]=='#')cout << "#";
      else {
        int cnt=0;
        for(int p=0;p<8;p++){
          int nx=k+dx[p],ny=i+dy[p];
          if(isR(0,W,nx)&&isR(0,H,ny))
            if(mine[ny][nx]=='#')cnt++;
        }
        cout << cnt;
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int N, M = 1e9+7;
  cin >> N;
  vector<int> V(N + 1);
  for (int i = 2; i <= N; i++)
    for (int j = 2, tmp = i; j <= N; j++)
      while (tmp % j == 0) tmp /= j, V.at(j)++;
  long ans = 1;
  for (int i = 2; i < N + 1; i++)
    if (V.at(i)) (ans *= V.at(i) + 1) %= M;
  cout << ans << "\n";
}

Measured memory_bytes: 256
list = gets.chomp.split(" ").map{|aa| aa.to_i}
n = list[0]
q = list[1]
k = list[2]

list_a = []
for i in 1..k
  a = gets.chomp.to_i
  list_a.push(a)
end

if q - k > 0
  n.times{puts "Yes"}
  exit
else
  result = list_a.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h
end

for i in 1..n
  unless result.include?(i)
    result.store(i, 0)
  end
end

for i in 1..n
  if result[i] + q - k >0
    puts "Yes"
  else
    puts "No"
  end
end

Measured memory_bytes: 23420
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s; cin>>s;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] == '9') cout << '1';
    else if(s[i] == '1') cout << '9';
    else cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
from math import ceil
N, Q = map(int, input().split())
A = [int(a) for a in input().split()]
AltTake = [0 for a in range(N)]
GetAll = [0 for a in range(N)]
AltTake[0], AltTake[1] = A[0], A[1]
GetAll[-1] = A[-1]
BlockList = [0 for i in range(ceil(N/2))]
maxBlock = ceil(N/2)

for i in range(2, N):
    AltTake[i] = A[i] + AltTake[i-2]
for i in reversed(range(N-1)):
    GetAll[i] = GetAll[i+1] + A[i]
for i in range(ceil(N/2) - 1):
        BlockList[-i-1] = (A[-i-2] + A[-2*i - 3]) // 2 + 1

def BSearch(x, L):
    left, right = 0, len(L)
    while right - left > 1:
        mid = (right + left)//2
        if L[mid] > x:
            right = mid
        else:
            left = mid
    return left

for _ in range(Q):
    block = maxBlock - BSearch(int(input()), BlockList)
    if block == maxBlock: print(GetAll[-block])
    else: print(GetAll[-block] + AltTake[N - block * 2 -1])

Measured memory_bytes: 20136
#include <iostream>

int main()
{
    using namespace std;

    int H, W;

    while (1)
    {
        cin >> H >> W;

        if (H == 0 && W == 0)
        {
            return 0;
        }

        string width = string(W, '#');

        for (int i = 0; i < H; i++)
        {
            cout << width << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3140
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner input = new Scanner(System.in);
    
    int n = input.nextInt();
    int m = input.nextInt();
    
    Map<Integer, List<Integer>> map = new HashMap<>();
    for (int i = 0; i < m; i++) {
      int a = input.nextInt();
      int b = input.nextInt();
     
      map.computeIfAbsent(a, key -> new ArrayList<>()).add(b);
      map.computeIfAbsent(b, key -> new ArrayList<>()).add(a);
    }
    
    Queue<Integer> queue = new LinkedList<>();
    queue.offer(1);

    int[] dist = new int[n + 1];
    dist[0] = 0;
    Arrays.fill(dist, -1);
    int[] parent = new int[n + 1];
    
    while (!queue.isEmpty()) {
      int cur = queue.poll();
      
      for (int next : map.get(cur)) {
        if (dist[next] == -1) {
          dist[next] = dist[cur] + 1;
          parent[next] = cur;
          queue.offer(next);
        }
      }
    }
    
    boolean good = true;
    for (int i = 1; i <= n && good; i++) {
      good = (dist[i] != -1);
    }
    
    if (good) {
      System.out.println("Yes");
      for (int i = 2; i <= n; i++) {
        System.out.println(parent[i]);
      }
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 79792
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i, _ := range as {
		fmt.Scan(&as[i])
	}

	min := as[0]
	max := as[0]
	for _, a := range as {
		if a < min {
			min = a
		}
		if a > max {
			max = a
		}
	}
	fmt.Println(max - min)
}


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

int main(){
  string a;
  
  cin >> a ;
  if ( a.size() != 19) return 0;

  for(int i=0; i<a.size(); i++){
    if ( i == 5 || i == 13) a.at(i) = ' ';
    cout << a.at(i);
  }
  cout << endl;
  
  return 0;
}


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

int main() {
	int A, B, C, D;
	int L, R;
	cin >> A >> B >> C >> D;

	L = A + B;
	R = C + D;

	if (L > R) {
		cout << "Left" << endl;
	}
	else if (L == R) {
		cout << "Balanced" << endl;
	}
	else if (L < R) {
		cout << "Right" << endl;
	}
}

Measured memory_bytes: 256
/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num,int pos);
ll setbitt(ll num,ll pos);
ll resetbitt(ll num,int pos);
const ll mod =       1e9 + 7;
const ll N =     1e6 + 10;


 //.................___Start from here___.................//
//.................._____________________................//




int solve(){
    int a,b;
    cin>>a>>b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible";
    else cout<<"Impossible";
    cout<<endl;


    return 0;
}
int main(){
#ifndef ONLINE_JUDGE
  input;
  output;
#endif
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#endif
    int cs=1;
    int cn=1;
    //cin>>cs;
    while(cs--){
        solve();
        
    }
}


bool checkbitt(ll num,int pos){return (num>>pos) & 1;}
ll setbitt(ll num,ll pos){return (1<<pos) | num;}
ll resetbitt(ll num,int pos){if(!checkbitt(num,pos)) return num;else return (1<<pos)^num;}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin>>N;
    vi dp(N+1, -1);
    dp[0]=2;
    dp[1]=1;
    FOR(i,2,N+1){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int n;
    cin >> n;
    ll l[86];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        l[i] = l[i - 1] + l[i - 2];
    }
    cout << l[n] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#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 MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	char c[3][4];

	FOR(i, 1, 2) {
		cin >> c[i];
	}

	if (c[1][2] == c[2][0] && c[1][1] == c[2][1] && c[1][0] == c[2][2]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

class Edge {
public:
    ll t;
    ll w;
    Edge() {}
    Edge(ll t, ll w): t(t), w(w) {}
};

ll N, M;
vector<ll> G[MAX];
vector<ll> ans;
bool visited[MAX];
bool flag;
void dfs(ll u) {
    ans.push_back(u);
    visited[u]=true;
    
    for(ll i=0; i<G[u].size(); i++) {
        ll v=G[u][i];
        if(!visited[v]) {
            dfs(v);
            return;
        }
    }
    return;
}


int main(void) {
    string s;
    ll N;
    cin >> N;
    cin >> s;
    stack<char> stk;
    ll i;
    ll left=0, right=0;
    for(i=0; i<s.size(); i++) {
        if(stk.size()!=0 && s[i]==')') {
            stk.pop();
        }else if(s[i]==')') {
            left++;
        }else if(s[i]=='(') {
            stk.push(s[i]);
        }
    }
    right=stk.size();
    
    for(i=0; i<left; i++) {
        s='('+s;
    }
    for(i=0; i<right; i++) {
        s+=')';
    }
    
    cout << s << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	rep(i, n)	cin >> x[i];
	sort(x.begin(), x.end());

	int result=1000000;
	for(int i=x[0]; i<=x[x.size()-1]; i++){
		int cost = 0;
		rep(ii, x.size())	cost += (x[ii] - i)*(x[ii] - i);
		result = min(result, cost);
	}
	cout << result << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, a, b;
    cin >> n >> a >> b;
    while(true) {
        if(a < b - 1) {
            a += 1;
        } else if(a > 1) {
            a -= 1;
        } else {
            cout << "Borys" << endl;
            break;
        }
        if(b > a + 1) {
            b -= 1;
        } else if(b < n) {
            b += 1;
        } else {
            cout << "Alice" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
t=0
f=0
for i in range(n-1):
    if h[i]<=h[i+1]+1 and t<h[i]:
        h[i]-=1
        t=h[i]
    elif h[i]<=h[i+1] and t==h[i]:
        t=h[i]
    else:
        f=1
        break
if f==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14704
#include<iostream>

int main() {
  int N; std::cin >> N;
  int X = N*25/27;
  for(;;++X) {
    int n = 27*X/25;
    if(n == N) break;
    if(n > N) { std::cout << ":(" << std::endl; return 0; }
  }
  std::cout << X << std::endl;
  return 0;
}


Measured memory_bytes: 256
type SortDataType=Longint;
function SortCmp(const a,b:SortDataType):Boolean;forward;
procedure SortImpl(var A:Array of SortDataType;L,R:Longint);
var
	tmp:SortDataType;
	mid,il,ir:Longint;
begin
	if R-L=2 then begin
		if SortCmp(A[L+1],A[L])then begin
			tmp:=A[L];
			A[L]:=A[L+1];
			A[L+1]:=tmp;
		end;
	end else if R-L>2 then begin
		mid:=(L+R)div 2;
		if SortCmp(A[mid],A[L])then begin
			tmp:=A[mid];
			A[mid]:=A[L];
			A[L]:=tmp;
		end;
		if SortCmp(A[R-1],A[mid])then begin
			tmp:=A[R-1];
			A[R-1]:=A[mid];
			A[mid]:=tmp;
			if SortCmp(A[mid],A[L])then begin
				tmp:=A[mid];
				A[mid]:=A[L];
				A[L]:=tmp;
			end;
		end;
		il:=L;
		ir:=R-1;
		while il<=ir do begin
			while SortCmp(A[il],A[mid])do inc(il);
			while SortCmp(A[mid],A[ir])do dec(ir);
			if il<ir then begin
				tmp:=A[il];
				A[il]:=A[ir];
				A[ir]:=tmp;
				if mid=il then mid:=ir else if mid=ir then mid:=il;
				inc(il);
				dec(ir);
			end else if il=ir then begin
				inc(il);
				dec(ir);
			end;
		end;
		SortImpl(A,L,il);
		SortImpl(A,il,R);
	end;
end;
procedure Sort(var A:Array of SortDataType;size:Longint);
begin
	SortImpl(A,0,size);
end;
function SortCmp(const a,b:SortDataType):Boolean;
begin
	SortCmp:=a<b;
end;
var
	N,i:Longint;
	A:Array[1..300000]of Longint;
	ans:int64;
begin
	read(N);
	for i:=1 to 3*N do read(A[i]);
	Sort(A,3*N);
	for i:=1 to N do inc(ans,A[N+i*2-1]);
	writeln(ans);
end.


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

using namespace std;

typedef long long ll;

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

  string S;
  cin >> S;

  string s1 = S.substr(0, N);
  string s2 = S.substr(N, 2 * N);
  reverse(s2.begin(), s2.end());

  unordered_map<string, ll> m1, m2;
  for (ll i = 0; i < (1ll << N); i++) {
    pair<string, string> p1, p2;

    for (ll j = 0; j < N; j++) {
      if (i & (1ll << j)) {
        p1.first += s1[j];
        p2.first += s2[j];
      } else {
        p1.second += s1[j];
        p2.second += s2[j];
      }
    }


    m1[p1.first + "," + p1.second] += 1;
    m2[p2.first + "," + p2.second] += 1;
  }

  ll ans = 0;
  for (auto p: m1) {
    ans += p.second * m2[p.first];
  }

  cout << ans << endl;
}


Measured memory_bytes: 87528
// O(sqrt(A_max) * N)で間に合うはず
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}

struct UF{
    vector<int> p;
    UF(int siz){
        p.resize(siz);
        for(int i = 0; i < siz; i++)    p[i] = i;
    }

    int findSet(int x){
        if(p[x] != x)   p[x] = findSet(p[x]);
        return p[x];
    }

    void unite(int x, int y){
        x = findSet(x), y = findSet(y);
        p[y] = x;
    }
    
    bool isSame(int x, int y){
        return findSet(x)==findSet(y);
    }
};

int main(){
    vector<bool> np(100001, 0);
    vector<int> p;
    for(int i = 2; i < 100001; i++){
        if(np[i])   continue;
        p.push_back(i);
        for(int j = i+i; j < 100001; j += i){
            np[j] = true;
        }
    }
    int base = p.size();
    UF uf(base + 100001);
    auto pos = [&](int val)->int{
        return lower_bound(p.begin(), p.end(), val)-p.begin();
    };
    int n;  cin >> n;
    vector<int> v(n), x(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];    x[i] = v[i];
        for(int j = 2; j*j <= x[i]; j++){
            if(x[i]%j > 0)   continue;
            while(x[i]%j == 0)  x[i] /= j;
            uf.unite(pos(j), base+v[i]);
        }
        if(x[i] != 1)   uf.unite(pos(x[i]), base+v[i]);
        x[i] = v[i];
    }

    sort(x.begin(), x.end());
    bool ok = true;
    for(int i = 0; i < n; i++){
        ok &= uf.isSame(base+v[i], base+x[i]);
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 4216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
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; }

vector<ll> sum;
void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(ll i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}

int main(){
    ll N,C;cin>>N>>C;
    vector<ll> need(200010,0);
    
    vector<vector<P>> p(C);
    rep(i,N){
        ll s,t,c;cin>>s>>t>>c;c--;
        p[c].push_back({s,t});
    }
    rep(i,C) sort(p[i].begin(),p[i].end());


    rep(i,C){
        rep(j,p[i].size()){
            need[2*p[i][j].first-1]++;
            need[2*p[i][j].second]--;
        }
    }

    pre_process(need,sum);

    rep(i,C){
        rep(j,(ll)(p[i].size())-1){
            if(p[i][j].second==p[i][j+1].first){
                sum[2*p[i][j].second]--;
            }
        }
    }

    ll ans=1;
    rep(i,200011){
        chmax(ans,sum[i]);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8772
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin

#import time
#fd = open('b.txt')
#stdin = fd
#start=time.time()

############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])

data = []
write = stdin.readline().split()
for i in range(N):
    data.append(int(write[i]))

count = 0
for i in range(N-2):
    array = sorted(data[i:i+3])
    if data[i+1]==array[1]:
        count += 1
        
print(count)

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


int main()
{
  int n;
  cin >> n;
  std::vector<int> v(n);
  std::vector<int> w(n);
  for(int i=0; i<n; i++)
  {
    int tmp;
    cin >> tmp;
    v[i] = tmp;
    w[i] = tmp;
  }
  sort(v.begin(),v.end());
  int c = 0;
  for(int i=0; i<n; i++)
  {
    if(v[i]!=w[i]) c++;
  }
  if(c<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    }
}


Measured memory_bytes: 62912
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

char b[2002][2002];
int l[2002][2002];
int r[2002][2002];
int d[2002][2002];
int u[2002][2002];

int main(){
    int H, W;
    cin >> H >> W;
    rep(i, 0, H+2){
        rep(j, 0, W+2){
            l[i][j] = -1;
            r[i][j] = -1;
            d[i][j] = -1;
            u[i][j] = -1;
        }
    }

    rep(i, 1, H+1){
        string s;
        cin >> s;
        for(int k=0; k<s.length(); k++){
            int j = k+1;
            b[i][j] = s[k];
        }
    }

    rep(row, 1, H+1){
        rep(col, 1, W+1){
            if(b[row][col] == '#') continue;
            l[row][col] = l[row][col-1] + 1;
            u[row][col] = u[row-1][col] + 1;
        }
    }
    for(int row=H; row>=1; row--){
        for(int col=W; col>=1; col--){
            if(b[row][col] == '#') continue;
            r[row][col] = r[row][col+1] + 1;
            d[row][col] = d[row+1][col] + 1;
        }
    }
    int ans = 0;
    rep(row, 1, H+1){
        rep(col, 1, W+1){
            int su = l[row][col] + r[row][col] + u[row][col] + d[row][col] + 1;
            /*
            DEBUG(row);
            DEBUG(col);
            DEBUG(l[row][col]);
            DEBUG(r[row][col]);
            DEBUG(u[row][col]);
            DEBUG(d[row][col]);
            DEBUG(su);
            cout << endl;
            */
            ans = max(ans, su);

        }
    }
    cout << ans << endl;
    return 0;
}




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

const int N = 1e4;
const int M = 2e5;

typedef int intF;
typedef int intW;

namespace mcmf {

const intF infF = 1e9;
const intW infW = 1e9;

struct E { int nxt, v; intW w; intF f; } e[M]; int eh[N], ec;
int s, t, nc;
int cur[N];
queue<int> q; 
bool inq[N]; 
intW dis[N];

void clear (int n) { fill_n(eh + 1, nc = n, ec = -1); }

void adde (int u, int v, intW w, intF f) {
  e[++ ec] = { eh[u], v, w, f }; eh[u] = ec;
  e[++ ec] = { eh[v], u, - w, 0 }; eh[v] = ec;
}

bool spfa (void) {
  fill_n(dis + 1, nc, - infW); dis[s] = 0;
  q.push(s); inq[s] = 1;
  while (!q.empty()) {
    int u = q.front(); q.pop(); inq[u] = 0;
    for (int i = eh[u], v; ~ i; i = e[i].nxt) if (e[i].f > 0 && dis[v = e[i].v] < dis[u] + e[i].w) {
      dis[v] = dis[u] + e[i].w;
      if (!inq[v]) { q.push(v); inq[v] = 1; }
    }
  }
  return dis[t] != - infW;
}

intF dfs (int u, intF f) {
  if (u == t) return f;
  intF sf = 0; 
  inq[u] = 1;
  for (int & i = cur[u]; ~ i; i = e[i].nxt) if (e[i].f > 0 && dis[e[i].v] == dis[u] + e[i].w && !inq[e[i].v]) {
    intF df = dfs(e[i].v, min(f, e[i].f));
    sf += df; e[i].f -= df; e[i ^ 1].f += df; f -= df;
    if (f == 0) break;
  }
  inq[u] = 0; 
  return sf;
}

pair<intW, intF> mcmf (int _s, int _t, intF f = infF) {
  s = _s, t = _t;

  intW sc = 0; intF sf = 0, df;
  while (spfa()) {
    for (int i = 1; i <= nc; i ++)
      cur[i] = eh[i];
    df = dfs(s, f - sf);
    sc += df * dis[t];
    sf += df;
  }
  return { sc, sf };
}

};

char s[50 + 5][50 + 5];
int id[50 + 5][50 + 5], idc;

int main (void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++)
    scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++)
    id[i][j] = ++ idc;
  int S = ++ idc;
  int T = ++ idc;
  mcmf::clear(idc);
  for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) {
    if (s[i][j] == 'o')
      mcmf::adde(S, id[i][j], 0, 1);
    if (i < n && s[i + 1][j] != '#')
      mcmf::adde(id[i][j], id[i + 1][j], 1, mcmf::infF);
    if (j < m && s[i][j + 1] != '#')
      mcmf::adde(id[i][j], id[i][j + 1], 1, mcmf::infF);
    mcmf::adde(id[i][j], T, 0, 1);
  }
  pair<int, int> res = mcmf::mcmf(S, T);
  printf("%d\n", res.first);
}



Measured memory_bytes: 4048
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

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

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#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 all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;

int n;
string s;
bool check = false;
char ans[maxn]; //s;ひつじ w;狼

void dfs(int count) {
	if (s[count-1] == 'o'&&ans[count - 1] == 'S')ans[count] = ans[count - 2];
	else if (s[count-1] == 'x'&&ans[count - 1] == 'S')ans[count] = ans[count - 2]=='S'?'W':'S';
	else if (s[count-1] == 'o'&&ans[count - 1] == 'W')ans[count] = ans[count - 2]=='S'?'W':'S';
	else if (s[count-1] == 'x'&&ans[count - 1] == 'W')ans[count] = ans[count - 2];

	if (count == n)
	{
		char tmp;
		count = 1;
		if (s[count - 1] == 'o'&&ans[count - 1] == 'S')tmp = ans[count];
		else if (s[count - 1] == 'x'&&ans[count - 1] == 'S')tmp = ans[count] == 'S' ? 'W' : 'S';
		else if (s[count - 1] == 'o'&&ans[count - 1] == 'W')tmp = ans[count] == 'S' ? 'W' : 'S';
		else if (s[count - 1] == 'x'&&ans[count - 1] == 'W')tmp = ans[count];

		if (ans[n - 1] == tmp && ans[n] == ans[0]) check = true;
		else check = false;

		return;
	}

	count++;
	dfs(count);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	cin >> n >> s;

	
	char animal[2];
	animal[0] = 'S';
	animal[1] = 'W';

	int test = 0;
	rep(i, 4)
	{
		ans[0] = animal[i / 2];
		ans[1] = animal[i % 2];
		dfs(2);
		if (check) break;
	}

	if (!check) cout << -1;
	else rep(i, n) cout << ans[i];
	cout << endl;
	// your code finished
	return 0;

}

Measured memory_bytes: 720
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#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

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    double a,b,x;
    cin >> a >> b >> x;

    if(x <= a*a*b/2){ 
	double c = 2*x/(a*b);
	double ans = atan2(b,c) * 180 / pi;

	printf("%.10f\n",ans);
    }else{
	double c = 2* (b- (x/(a*a)));
	double ans = atan2(a,c) * 180 / pi;

	printf("%.10f\n",90.0 - ans);
    }
    
    return  0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0519>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

vector<ll> ans;
void rec(ll n,vector<int>& flag,vector<vector<ll>>& G){
    if(flag[n]) return;
    flag[n] = true;
    for(auto next:G[n]){
        rec(next,flag,G);
    }
    ans.push_back(n);
    cout << n+1 << endl;
}
void solve(){
    ll n,m; cin >> n >> m;
    vector<vector<ll>> G(n); vector<int> flag(n);
    for(int i = 0; i < m;i++){
        ll a,b; cin >> a >> b; a--; b--;
        G[b].push_back(a);
    }
    for(int i = 0; i < n;i++){
        rec(i,flag,G);
    }
    for(int i = 0; i < n-1;i++){
        ll a = ans[i+1],b = ans[i];
        if(find(G[a].begin(),G[a].end(),b) == G[a].end()){
            cout << 1 << endl;
            return;
        }
    }
    cout << 0 << endl;
    return;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 4456
n = int(input())
x = list(map(int, input().split()))

mintime = 1000000000000

for i in range(2000+1):
    tmpmin = 0
    for j in x:
        tmpmin = max(tmpmin, abs(i-j))
    if tmpmin < mintime:
        mintime = tmpmin
print(mintime)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int r;
  cin>>r;
  cout<<r*r<<'\n';
    return 0;
}

Measured memory_bytes: 256
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
    N,M=MI()
    a=[0]*N
    b=[0]*N
    c=[0]*M
    d=[0]*M
    
    for i in range(N):
        aa,bb=MI()
        a[i]=aa
        b[i]=bb
        
    for i in range(M):
        cc,dd=MI()
        c[i]=cc
        d[i]=dd
        
    def calc(x1,y1,x2,y2):
        return abs(x2-x1)+abs(y2-y1)
    
    def s_calc(x,y):
        temp=10**10
        pos=-1
        for i in range(M):
            l=calc(x,y,c[i],d[i])
            if temp>l:
                temp=l
                pos=i+1
                
        return pos
    
    for i in range(N):
        print(s_calc(a[i],b[i]))
            

main()


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    int N;cin>>N;
    multiset<int> MS;
    vector<int> A((1<<N));
    for(int i=0;i<(1<<N);i++){
        cin>>A[i];
    }
    
    sort(all(A));
    
    for(int i=0;i<(1<<N)-1;i++){
        MS.insert(-A[i]);
    }
    
    bool ok=true;
    
    vector<int> B;
    B.push_back(A[A.size()-1]);
    
    int kai=1;
    
    for(int k=0;k<N;k++){
        for(int i=0;i<kai;i++){
            auto it=MS.upper_bound(-B[i]);
            if(it==MS.end()){
                ok=false;
            }else{
                MS.erase(it);
                B.push_back(-(*it));
            }
        }
        if(!ok) break;
        kai*=2;
        sort(all(B));
        reverse(all(B));
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}



Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define LL long long
const int MOD = 1E9+7;
const int N = 50+5;
using namespace std;
int main() {
    LL n,s;
    scanf("%lld%lld",&n,&s);
    if(n==s)
        printf("%lld\n",s+1);
    else if(n<s)
        printf("-1\n");
    else {
        LL mid=sqrt(n)+1;
        bool flag=false;
        LL res;
        for(LL i=2; i<=mid; i++) {
            res=0;
            LL temp=n;
            while(temp) {
                res+=temp%i;
                temp/=i;
            }
            if(res==s) {
                printf("%lld\n",i);
                flag=true;
                break;
            }
        }
        if(!flag) {
            LL factor=n-s;
            LL res;
            mid=sqrt(factor)+1;
            for(LL i=mid; i>=1; i--) {
                if(factor%i==0) {
                    res=factor/i+1;
                    LL j=s-i;
                    if(i<res&&res>=2&&j<res&&j>=0) {
                        printf("%lld\n",res);
                        flag=true;
                        break;
                    }
                }
            }
        }
        if(!flag)
            printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

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

    vector<vector<int>> A(N);
    for (int i = 1; i < N; ++i){
        int ai;
        scanf("%d\n", &ai); --ai;
        A[ai].emplace_back(i);
    }
    vector<int> rank(N, -1);
    function<int(int)> getRank = [&](int n){
        auto& Ai = A[n];
        const int size = Ai.size();
        if (size == 0){
            return 0;
        }else if (size == 1){
            return getRank(Ai.back()) + 1;
        }else{
            vector<int> temp(size);
            for (int j = 0; j < size; ++j) temp[j] = getRank(Ai[j]);
            sort(temp.begin(), temp.end(), greater<int>());
            int ranki = 0;
            for (int j = 0; j < size; ++j) ranki = max(temp[j] + j, ranki);
            return ranki + 1;
        }
    };
    printf("%d\n", getRank(0));
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    LL ans=0;

    int N;
    cin>>N;
    LL a[N];
    REP(i,N)cin>>a[i];

    bool last=true;

    while(last){
        last=false;
        LL cnt=0;
        REP(i,N){
            cnt +=a[i]/N;
            a[i]-=(a[i]/N)*(N+1);
        }
        ans+=cnt;
        REP(i,N){
            a[i]+=cnt;
            if(a[i]>=N)last=true;
        }
    }
    cout<<ans<<endl;


    return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    if(a.at(i)==(cnt+1)){
      cnt++;
    }
  }
  if(cnt==0){
    cout<<-1;
  }else{
    cout<<n-cnt;
  }
}

Measured memory_bytes: 4024
a=int(input())
b=list(map(int,input().split()))
c=list(filter(lambda n:n<=0,b))
c=list(map(lambda n:n*-1,c))
d=list(filter(lambda n:n>0,b))
ans=sum(d)+sum(c)
ansl=c+d
if len(c)%2!=0:  
  ans-=min(ansl)*2
print(ans)

Measured memory_bytes: 14412
N = int(input())
s_list = []
ans = 0

b_head_a_tail = 0
b_head = 0
a_tail = 0

for _ in range(N):
    string= input()
    if string[0] == "B":
        if string[-1] == "A":
            b_head_a_tail += 1
        else:
            b_head += 1
    elif string[-1] == "A":
        a_tail += 1
    if "AB" in string:
        ans += string.count("AB")
        
if b_head_a_tail > 0:
    if a_tail > 0:
        if b_head > 0:
            ans += b_head_a_tail  + min(a_tail, b_head) 
        else:
            ans += b_head_a_tail
    else:
        if b_head > 0:
            ans += b_head_a_tail
        else:
            ans += b_head_a_tail - 1
else:
    ans += min(a_tail, b_head) 
    
print(ans)

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int n;
    cin >> n;
    vector<pair<pair<string,int>, int>> shop(n);
    roop(i, n){
        string a;
        int b;
        cin >> a >> b;
        shop[i].first.first = a;
        shop[i].first.second = -b;
        shop[i].second = i+1;
    }

    sort(shop.begin(), shop.end());

    roop(i, n){
        cout << shop[i].second << endl;
    }



    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vl a(n);
	rep(i, n) cin >> a[i];

	map<ll, ll> nums;
	ll sum = 0;

	nums[sum]++;
	rep(i, n) {
		sum += a[i];
		nums[sum % m]++;
	}

	ll res = 0;
	REP(i, nums) {
		res += i->second * (i->second - 1) / 2;
	}
	cout << res << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
int max(int a,int b);
int min(int a,int b);
int main(){
  int n,R[200000],i;
  int MIN,MAX;
  scanf("%d",&n);
  scanf("%d %d",&R[0],&R[1]);
  MIN=min(R[0],R[1]);
  MAX=R[1]-R[0];
  for(i=2;i<n;i++){
    scanf("%d",&R[i]);
    MAX=max(MAX,R[i]-MIN);
    MIN=min(MIN,R[i]);
  }
  printf("%d\n",MAX);
  return 0;
}
int max(int a,int b){
	return a>b?a:b;
}
int min(int a,int b){
  return a<b?a:b;
}

Measured memory_bytes: 3460
fun main(args: Array<String>) {

  val h = readLine()!!.toInt()
  val w = readLine()!!.toInt()
  val n = readLine()!!.toInt()

  val line = if (h > w) h else w

  var count = n / line
  if (n%line > 0) {
    count += 1
  }

  print(count)
}


Measured memory_bytes: 29984
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>

using namespace std;

const int mod = 1e9 + 7;

vector<long long> fact;

void make_fact(int n) {
	fact.assign(n + 1, 1);
	for (int i = 2; i <= n; i++) {
		fact[i] = fact[i - 1] * i % mod;
	}
}

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

	make_fact(n);

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

	long long ret = 1;
	stack<long long> st;
	for (auto y : x) {
		if (st.empty()) {
			st.push(1);
			continue;
		}

		auto a = st.top();
		if (y >= a + 2) {
			st.push(a + 2);
		} else {
			ret = ret * (st.size() + 1) % mod;
		}
	}

	if (!st.empty()) {
		ret = ret * fact[st.size()] % mod;
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 2304
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int a[2][100] = {};
int dp[2][100] = {};

int main() {
  ll n;
  cin >> n;
  REP(i, 2) REP(j, n) cin >> a[i][j];

  REP(i, 2)
  REP(j, n) {
    if (i != 0 && j != 0)
      dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i][j - 1]);
    else if (i != 0)
      dp[i][j] = a[i][j] + dp[i - 1][j];
    else if (j != 0)
      dp[i][j] = a[i][j] + dp[i][j - 1];
    else
      dp[i][j] = a[i][j];
  }

  cout << dp[1][n - 1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
const int MR=1e6+10;
int N;
LL M;
int a[MR];
int s[MR],temp[MR];

LL mergeSort(int l, int r){
    LL t = 0;
    if(r - l > 1){
        int m = (l + r) / 2;
        t = mergeSort(l, m) + mergeSort(m, r);
        for(int i = l; i < r; i++) temp[i] = s[i];
        int in1 = l, in2 = m, out = l;
        while(in1 < m && in2 < r){
            if(temp[in1] <= temp[in2]){
                s[out++] = temp[in1++];
            }
            else{
                s[out++] = temp[in2++];
                t += m - in1;
            }
        }
        while(in1 < m) s[out++] = temp[in1++];
        while(in2 < r) s[out++] = temp[in2++];
    }
    return t;
}


bool check(int x){
	s[0]=0;
	for(int i=1;i<=N;i++){
		if(a[i]>=x) s[i]=s[i-1]+1;
		else s[i]=s[i-1]-1;
	}
	//printf("x=%d\n",x);
	//for(int i=0;i<=N;i++)printf("%d ",s[i]);printf("\n");
	LL t=mergeSort(0,N+1);
    //for(int i=0;i<=N;i++)printf("%d ",s[i]);printf("\n");
	return M-t >= (M+1)/2;
}
int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        scanf("%d",a+i);
    }
    int l=1,r=1e9+10,m;
    M=1ll*(N+1)*N/2;
    while(l<r-1){
    	m=(l+r)/2;
    	if(check(m)){
    		l=m;
    	}
    	else{
    		r=m;
    	}
    }
    printf("%d\n",l);
    return 0;
}

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

int main(void){
    int x, a;
    cin>>x>>a;
    if (x<a){
        cout<<0;
    }
    else{
        cout<<10;
    }
}

Measured memory_bytes: 256
import math

ans = 0
K = int(input())
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = math.gcd(i,j)
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a = dp[i][j]
            ans += dp[a][k]
print(ans)


Measured memory_bytes: 9396
program welcome_to_atcoder
  implicit none
  integer :: n, m, p, wa(100000) = 0, i, a = 0, w = 0
  logical :: ac(100000) = .false.
  character(1) :: s
  read(*,*) n, m
  do i = 1, m
    read(*,*) p, s
    ac(p) = ac(p) .or. s == "A"
    if (ac(p)) cycle
    wa(p) = wa(p)+1
  end do
  do i = 1, n
    if (ac(i)) then
      a = a+1
      w = w+wa(i)
    end if
  end do
  write(*,'(i0,x,i0)') a, w
end program welcome_to_atcoder

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A,B,C;
  cin >> A >> B >> C;
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
    cout << 0;
  } else {
    cout << min(A * B,min(B * C,C * A));
  }
}

Measured memory_bytes: 256