akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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 n;
vector<vector<pli>> g;
ll dist[100010];

int main() {
    cin >> n;

    g.resize(n);
    rep(i, n-1) {
        int u, v; ll w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].push_back(make_pair(w, v));
        g[v].push_back(make_pair(w, u));
    }

    rep(i, n) dist[i] = LLINF;
    dist[0] = 0;
    priority_queue<pli, vector<pli>, greater<pli>> que;
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        pli top = que.top();
        que.pop();
        int u = top.second;
        for (auto edge: g[u]) {
            int v = edge.second;
            ll w = edge.first;
            if (chmin(dist[v], dist[u] + w)) {
                que.push(make_pair(dist[v], v));
            }
        }
    }

    rep(i, n) {
        cout << dist[i] % 2 << endl;
    }
}


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

int solve(int n,int k,vector<int> &v)
{
    int dp[k+1];
    dp[0]=0;
    // it represents that 0 is a loosing state .......
    // v.at(1) ke pehle ke jitne bhi state hain un sabhi ko loosing state assign krna padega it means
    // ki agar koi player uss state pr chala jaega in that case vo game ko loose karega aur koi bhi player
    // hamesha dusre ko ussi loosing state mei bhejna chayega..
    for(int i=1;i<v.at(1);i++)
    {
        dp[i]=0;
    }
    for(int i=v.at(1);i<=k;i++)
    {
        int flag=1;
        for(int j=1;j<=n;j++)
        {
            if(i-v.at(j)>=0)
            {
            if(dp[i-v.at(j)]==0)
            {
                dp[i]=1;
                flag=0;
                break;
            }
            }
        }
        if(flag==1)
        {
            dp[i]=0;
            // mei kabhi bhi apne oppenet ko loosing state mei nhi bhej paya it means ki mei loosing state
            // pr hu....
        }
        
    }
    return dp[k];
    
}

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v.at(i);
    }
    solve(n,k,v)==1?(cout<<"First"):(cout<<"Second");
    return 0;
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    x=max(b*c,b*d);
    y=max(a*c,a*d);
    cout<<max(x,y);
    return 0;
}


Measured memory_bytes: 3644
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Maybe
import Control.Monad

solve :: VU.Vector Int -> Int -> Int -> Int
solve ys n x
    |  x < a = a
    |  otherwise = b
    where 
        q = n `quot` 2
        a = ys VU.! q 
        b = ys VU.! (q - 1)
        
main = do
    n <- readLn :: IO Int
    xs <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    let ys = VU.fromList $ sort xs
    forM_ xs $ \x -> print $ solve ys n x

Measured memory_bytes: 50428
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m, k;
    cin >> n >> m >> k;
    bool ok = false;
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= m; ++j)
            if (i * m + j * n - 2 * i * j == k)
                ok = true;
    if (ok)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
import heapq, math

n, m = map(int, input().split())
*a, = map(lambda x: -int(x), input().split())
heapq.heapify(a)

for i in range(m):
    tmp = heapq.heappop(a)
    tmp = math.ceil(tmp / 2)
    heapq.heappush(a, tmp)

print(-sum(a))

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

using ll = long long;

int main() {
    int N, K, Q, A;
    cin >> N >> K >> Q;
    vector<int> P(N, K - Q);
    rep(i, Q) {
        cin >> A;
        P[A - 1]++;
    }
    rep(i, N) {
        if (P[i] > 0) printf("Yes\n");
        else printf("No\n");
    }
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

ll n , m , k;
vector<ll> bt(200001);

// 二分探索法
// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (key < bt[index]) return true;
    else return false;
}
// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
    ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = m+1; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        ll mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return left;
}

int main() {
	ll		a,b,c,h,i,j,l,x,y;
	ll		ans = 0;
	cin >> n >> m >> k;

	vector<ll>	aa(n) , bb(m) , at(n+1);
	for(i=0;i<n;i++) cin >> aa[i];
	for(i=0;i<m;i++) cin >> bb[i];

	for(i=0;i<n;i++) at[i+1] = at[i] + aa[i];
	for(i=0;i<m;i++) bt[i+1] = bt[i] + bb[i];	
	
	for(i=0;i<=n;i++) {
		if(at[i]>k) break;
		l = k - at[i];
		x = binary_search(l);
		ans = max(ans , i+x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9552
import java.util.*;
// import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
  }

  int h;
  int w;
  String s[];
  int[] bomb;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      h = sc.nextInt();
      w = sc.nextInt();
      s = new String[h];
      for (int i = 0; i < h; i++) s[i] = sc.next();
      bomb = new int[h * w];
    } finally {
      sc.close();
    }
  }

  void solve() {
    update();
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        int k = bomb[y * w + x];
        System.out.print(k >= 0 ? k : "#");
      }
      System.out.println("");
    }
  }

  void update() {
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        bomb[y * w + x] = bombNum(y, x);
      }
    }
  }
  
  int bombNum(int y, int x) {
    if (s[y].charAt(x) == '#') return -1;
    int ans = 0;
    for (int dy = -1; dy < 2; dy++) {
      for (int dx = -1; dx < 2; dx++) {
        if (y + dy < 0) continue;
        if (h <= y + dy) continue;
        if (x + dx < 0) continue;
        if (w <= x + dx) continue;

        if (s[y + dy].charAt(x + dx) == '#') ans++;
      }
    }
    return ans;
  }
}


Measured memory_bytes: 36340
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N,D;
    cin >> N >> D;
    vector< vector<int> > X(N, vector<int>(D));
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            cin >> X[i][j];
        }
    }
    ll ans=0;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            ll tmp=0;
            for(int d=0; d<D; d++){
                tmp+=(X[i][d]-X[j][d])*(X[i][d]-X[j][d]);
            }
            double t=sqrt(tmp);
            
            if(t==(ll)t) ans++;
        }
    }
    cout << ans << endl;


    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];
ll w[114], v[114];
ll dp[102][114514];

signed main(){
	IOS();
	ll n, W;
	cin >> n >> W;
	for (int i = 1;i <= n;++i) {
		cin >> w[i] >> v[i];
	}
	Fill(dp, 0);	
	for (int i = 1;i <= n;++i) {
		for(int j = 0;j <= W;++j) {
			if(j >= w[i])dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	
	cout << dp[n][W] << endl;
	
}

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

int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for(int i=0;i<n-1;i++){
        if((s[i]=='O'&&s[i+1]=='X') || (s[i]=='X'&&s[i+1]=='O')){
            ans++;
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main()
{
    string s[110];
    int i = 0, j = 0, x = 0, y = 0, n = 0;
    cin >> n;
    for(i = 1; i <= n; i++)
    {
        cin >> s[i];
    }
    for(i = 1; i <= n; i++)
    {

        for(j = i + 1; j <= n; j++)
        {
           if(s[i] == s[j])
           {
                cout <<"No";
                x = 1;
                break;

           }
        }
         if(x == 1)
        {
            break;
        }
        if(i != 1)
        {
        if(s[i - 1][s[i - 1].size() - 1] != s[i][0])
        {
            cout << "No";
            x = 1;
            break;
        }
        }
    }
    if(x == 0)
    {
    	cout << "Yes";
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,w;
pair<int,int>arr[109];
int dp[109][100009];
int main(){
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>arr[i].first>>arr[i].second;
    }
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<=n;i++){
        for(int j=0;j<=100000;j++){
            dp[i][j] = 1000000009;
        }
    }
    dp[0][0] = 0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=100000;j++){
            dp[i][j] = dp[i-1][j];
            if(j-arr[i].second >= 0)dp[i][j] = min(dp[i][j],dp[i-1][j-arr[i].second] + arr[i].first);
        }
    }
    for(int i=100000;i>=0;i--){
        if(dp[n][i] != -1 && dp[n][i] <= w){
            cout<<i<<endl;
            exit(0);
        }
    }
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N, M, arr[MAXN], dp[MAXN];
map<ll, ll, greater<ll>> m;
int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    for(int i=0; i<N; i++)
    {
        ll x;
        cin >> x;
        m[x]++;
    }

    for(int i=0; i<M; i++)
    {
        ll a = m.begin()->first;
        m[a]--;
        if(m[a] == 0)
        {
            m.erase(a);
        }
        m[(a/2)]++;
    }
    ll ans = 0;
    for(auto a = m.begin(); a != m.end(); a++)
    {
        //cout << a->first << " " << a->second << "\n";
        ans += a->first * a->second;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6528
N, A, B = map(int,input().split())
S = input()
a = 0
b = 0
for s in S:
    if s == "a":
        if a + b < A + B:
            print("Yes")
            a += 1
        else:
            print("No")
    elif s == "b":
        if a + b < A + B and b < B:
            print("Yes")
            b += 1
        else:
            print("No")
    elif s == "c":
        print("No")

Measured memory_bytes: 4016
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
bool turn[3001][3001];
int main()
{
    string s1, t1;
    cin>>s1>>t1;
    char s[s1.length()],t[t1.length()];
    long dp[s1.length()+1][t1.length()+1];
    copy(s1.begin(),s1.end(),s);
    copy(t1.begin(),t1.end(),t);
    for(int i=0;i<=s1.length();i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=t1.length();i++)
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=s1.length();i++)
    {
        for(int j=1;j<=t1.length();j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                if(dp[i-1][j]>=dp[i][j-1])
                {
                    dp[i][j]=dp[i-1][j];
                }
                else
                {
                    dp[i][j]=dp[i][j-1];
                }
            }
        }
    }
    string reversed="";
    long long nextx=s1.length(),nexty=t1.length();
    while(nextx>0&&nexty>0)
    {
        //cout<<nextx<<" "<<nexty<<endl;
        if(s[nextx-1]==t[nexty-1])
        {
            reversed+=s[nextx-1];
            nextx--;
            nexty--;
        }
        else
        {
            if(dp[nextx-1][nexty]<=dp[nextx][nexty-1])
            {
                //cout<<nextx<<" "<<nexty<<" "<<dp[nextx-1][nexty]<<endl;
                nexty--;
            }
            else
            {
                //cout<<333<<endl;
                nextx--;
            }
        }
    }
    string ans="";
    for(int i=reversed.length()-1;i>=0;i--)
    {
        ans+=reversed.substr(i,1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 70656
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
	#define debug(...) 3
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using ull = uint64_t; using ld = long double;
using pii = pair<int, int>; using pll = pair<ll, ll>;

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

int a, b;

void func() {
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	} else if (b < 0) {
		if ((b - a + 1) & 1) {
			cout << "Negative" << endl;
		} else {
			cout << "Positive" << endl;
		}
	} else {
		cout << "Zero" << endl;
	}
}

int main() {
	fast_io; cout_precision;
	int t = 1; // cin >> t;
	for (int i = 1; i <= t; ++i) {
		func();
	}
}

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

int cnt(int d, int a) {
	int res = 1;
	d--;
	res += d / a;
	return res;
}

int main() {
	int n, d, x, a[110];
	cin >> n >> d >> x;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += cnt(d, a[i]);
	}
	cout << ans + x << endl;
	return 0;
}

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

main()
{
	int n;
	scanf("%d",&n);
	int bf=-1;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		if(a==bf)
		{
			ans++;
			bf=-1;
		}
		else
		{
			bf=a;	
		}
	}
	printf("%d",ans);
}

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

int main() {
   
 
    int N; cin >> N;
    int cur; cin >> cur;
  cur--;
    int data[N-1]; FOR(i, 1, N) cin >> data[i-1];
    FOR(i, 1, N) {
        int nxt = data[i-1];
        if (nxt > cur) {
            nxt--;
        }
        if (nxt < cur) {
            cout << "No" << endl;
            return 0;
        }
        cur = nxt;
    }
 
    cout << "Yes" << endl;
 
    return 0;
}

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

int main(){
  int n, ans = 0;
  string s;
  cin >> n >> s;
  for(int i = 0;i<n-2;i++){
    if("ABC" == s.substr(i,3))
      ans++;
  }
 cout << ans << endl;
}

Measured memory_bytes: 3644
N = gets.to_i
C, S, F = (1...N).map { gets.split.map &:to_i }.transpose
# cost, start , frequency

def goal_time_from_i(i, t=0)
  if i==N-1
    return t
  end
  start_time = S[i] + [0, (t-S[i]+F[i]-1)].max/F[i]*F[i]
  arrive_time = start_time + C[i]
  goal_time_from_i(i+1, arrive_time)
end


for i in 0...N
  puts goal_time_from_i(i)
end


Measured memory_bytes: 1916
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

// B - Snake Toy
// https://atcoder.jp/contests/abc067/tasks/abc067_b
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());
        Integer[] l = new Integer[N];
        for (int i = 0; i < N; i++) {
            l[i] = Integer.parseInt(scanner.next());
        }
        scanner.close();

        Arrays.sort(l, Comparator.reverseOrder());

        int ans = 0;
        for (int i = 0; i < K; i++) {
            ans += l[i];
        }

        System.out.println(ans);
    }
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int A1, A2, A3;
  std::cin >> A1 >> A2 >> A3;

  if(A1 + A2 + A3 >= 22) {
    std::cout << "bust" << '\n';
    return 0;
  } else {
    std::cout << "win" << '\n';
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    string s;
    cin>>s;
    int64 a=1,b=0;
    if(
        (s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])||
        (s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1])||
        (s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1])
    ){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int[] counts = new int[10001];
        for (int i = 1; i <= 100; i++) {
            for (int j = 1; j <= 100; j++) {
                for (int k = 1; k <= 100; k++) {
                    int num = i * i + j * j + k * k + i * j + j * k + k * i;
                    if (num <= 10000) {
                        counts[num]++;
                    }
                }
            }
        }
        List<String> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            list.add(Integer.toString(counts[i]));
        }
        String result = String.join("\r\n", list);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 36492
s,y,j=input().split()

ss=len(s)
yy=len(y)
jj=len(j)
nyan=0
if s[ss-1:ss]==y[0:1]:
    nyan+=1
    
if y[yy-1:yy]==j[0:1]:
    nyan+=1
    
    
if nyan==2:
    print('YES')
else:
    print('NO')




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main() {
  int n;
  cin >> n;
  cout << n/3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>

typedef long long int ll;
typedef std::pair<ll,ll> ii;

std::map<ll,std::vector<ll> > map[2];
std::map<ll,std::set<ll> > mmap[2];
std::map<ll,bool> is_sorted[2];
std::queue<ii> wtf;
ll ans=0;

ll x1,y11,x2,y2;
ll dist;

std::vector<ll>::iterator it1,it2;
std::set<ll>::iterator it11,it22,limit;

void add(ll x, ll y)
{
	ll coef;

	//up
	coef=x-y;
	map[0][coef].push_back(x);
	mmap[0][coef].insert(x);

	//down
	coef=x+y;
	map[1][coef].push_back(x);
	mmap[1][coef].insert(x);
}

void del(ll x, ll y)
{
	ll coef;

	//up
	coef=x-y;
	mmap[0][coef].erase(x);

	//down
	coef=x+y;
	mmap[1][coef].erase(x);
}

void int_solve(int type, ll coef, ll left, ll right)
{
	if(map[type].find(coef)==map[type].end())
		return;
	if(!is_sorted[type][coef])
	{
		std::sort(map[type][coef].begin(), map[type][coef].end());
		is_sorted[type][coef]=true;
	}
	it1=std::lower_bound(map[type][coef].begin(), map[type][coef].end(),left);
	it2=std::upper_bound(map[type][coef].begin(), map[type][coef].end(),right);
	ans+=(int)(it2-it1);

	it11=mmap[type][coef].lower_bound(left);
	limit=mmap[type][coef].end();
	while(it11!=limit && *it11<=right)
	{
		ll y, x;
		x=*it11;
		if(type==0)
			y=x-coef;
		else
			y=coef-x;


		it11++;
		//ans++;
		del(x,y);
		wtf.push(ii(x,y));
		//std::cout << "found " << x << ", " << y << '\n';
	}

}

void solve(ll x, ll y)
{
	//std::cout << "solving " << x << ", " << y << '\n';
	ll before=ans;
	ll coef;

	//up-right
	coef=x+y+dist;
	int_solve(1,coef,x,x+dist);

	//down-left
	coef=x+y-dist;
	int_solve(1,coef,x-dist+1,x-1);

	//up-left
	coef=x-y-dist;
	int_solve(0,coef,x-dist,x-1);

	//down-right
	coef=x-y+dist;
	int_solve(0,coef,x,x+dist-1);

	//std::cout << "got " << ans-before << '\n';
}


int main()
{
	int n, a, b;
	std::cin >> n >> a >> b;
	for(int i=1;i<=n;i++)
	{
		ll tx,ty;
		std::cin >> tx >> ty;
		if(i==a || i==b)
		{
			ll coef=tx-ty;
			map[0][coef].push_back(tx);

			//down
			coef=tx+ty;
			map[1][coef].push_back(tx);
		}
		if(i==a)
		{
			x1=tx;
			y11=ty;
			wtf.push(ii(x1,y11));
		}
		else if(i==b)
		{
			x2=tx;
			y2=ty;
			dist=abs(x2-x1)+abs(y2-y11);
			wtf.push(ii(x2,y2));
			//std::cout << "dist is " << dist << '\n';
		}
		else
		{
			add(tx,ty);
		}
	}

	while(!wtf.empty())
	{
		ll tx, ty;
		tx=wtf.front().first;
		ty=wtf.front().second;
		wtf.pop();
		solve(tx,ty);
	}
	std::cout << ans/2 << '\n';
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, K;
  cin >> N >> K;
  ll x[N];
  for (int i = 0; i < N; i++) scanf("%lld", x + i);

  vector<ll> minus, plus;
  for (int i = 0; i < N; i++) {
    if (x[i] < 0) minus.push_back(x[i]);
    else plus.push_back(x[i]);
  }

  ll ans = 1e18;
  reverse(minus.begin(), minus.end());
  if ((int)minus.size() >= K) ans = min(ans, -minus[K-1]);
  if ((int)plus.size() >= K) ans = min(ans, plus[K-1]);
  // マイナスから先行く
  for (int i = 0; i < min((int)minus.size(), K); i++) {
    ll tmp = -minus[i];
    int idx = K - i - 2;
    if (idx < 0) continue;
    if (idx >= plus.size()) continue;
    tmp += plus[idx] - minus[i];
    ans = min(ans, tmp);
  }
  
  // プラスから先行く
  for (int i = 0; i < min((int)plus.size(), K); i++) {
    ll tmp = plus[i];
    int idx = K - i - 2;
    if (idx < 0) continue;
    if (idx >= minus.size()) continue;
    tmp += plus[i] - minus[idx];
    ans = min(ans, tmp);
  }

  // 解答
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll a, b, c;

    cin >> a >> b >> c;

    cout << (b - a == c - b ? "YES" : "NO") << endl;

    return 0;
}

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

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			decimal ans = 0;
            for (int i = 0; i < n; i++)
            {
				var x = decimal.Parse(cin.Next());
				if (cin.Next() == "JPY") ans += x;
				else ans += x * 380000;
			}
            Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int x = 0;
        int max = 0;
        int n = s.nextInt();
        String word = s.next();
        for(int i=0;i<n;i++){
            if(word.charAt(i)=='I')x++;
            else x--;
            max = Math.max(max,x);
        }
        System.out.println(max);
    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

int main() {
    string s;
    int i, cnt=0;
    cin >> s;
    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 7*17*(1<<23) + 1;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void pop(multiset<ll> &s, ll c, ll &a) {
	while(s.size() > c) {
		a -= *s.begin();
		s.erase(s.begin());
	}
}
void add(multiset<ll> &s, ll u, ll c, ll &a) {
	s.insert(u);
	a += u;
	pop(s, c, a);
}
ll solve2(vector<pi> &z, ll x, ll y) {
	ll cur = 0;
	multiset<ll> l, r;
	vi su(z.size());
	sort(all(z), [](const pi &a, const pi &b) {return a.first-a.second > b.first-b.second;});
	for(int i = z.size(); i--;) {
		add(r, z[i].second, y, cur);
		su[i] = cur;
	}
	ll ans = LLONG_MIN;
	cur = 0;
	for(int i = 0; z.size()-i > y ; i++) {
		add(l, z[i].first, x, cur);
		if(i+1>=x)
		ans = max(ans, cur + su[i+1]);
	}
	return ans;
}
int main() { //DINIC ORZ, FFT ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll x , y, z, n;
	cin >> x >> y >> z;
	n = x+y+z;
	vi a, b, c;
	for(auto *i : {&a, &b, &c}) i->resize(n);
	ll ans = 0;
	vector<pi> zz;
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i], ans += a[i],zz.pb({b[i]-a[i],c[i]-a[i]});
	cout << ans + solve2(zz, y, z);
}


Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef set<ll> usll;
typedef map<int, usll> misll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {FIN
	
	ll h, w, n, i, j, k, x, y, t, sm;
	cin >> h >> w >> n;
	
	vvll pt(n, vll(2));
	vll pts(10);
	usll sq;
	for (i = 0; i < n; i++) {
		cin >> pt[i][0] >> pt[i][1];
		pt[i][0]--, pt[i][1]--;
		sq.insert(pt[i][0] * w + pt[i][1]);
	}
	
	misll txt;
	for (i = 0; i < n; i++) {
		for (j = pt[i][0] - 2; j <= pt[i][0]; j++) {
			for (k = pt[i][1] - 2; k <= pt[i][1]; k++) {
				if ((j >= 0 and j + 2 < h) and (k >= 0 and k + 2 < w)) {
					t = 0;
					for (x = j; x < j + 3; x++) {
						for (y = k; y < k + 3; y++) {
							if (sq.find(x * w + y) != sq.end())
								t++;
						}
					}
					txt[t].insert(j * w + k);
				}
			}
		}
	}
	
	sm = 0;
	for (auto it = txt.begin(); it != txt.end(); it++) {
		pts[it->first] = it->second.size();
		sm += it->second.size();
	}
	pts[0] = ((w - 2) * (h - 2) - sm);
	
	for (i = 0; i < (int)pts.size(); i++)
		cout << pts[i] << "\n";
	
	return 0;
}


Measured memory_bytes: 55404
#include<cstdio>
int main(){
    int n,a,odd=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        if(a%2==1)odd++;
    }
    if(odd%2==0)printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int n, l, r, a[100009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> l >> r;
		for (int j = l; j <= r; j++) a[j] = 1;
	}
	int ret = 0;
	for (int i = 0; i <= 100000; i++) ret += a[i];
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
xsum,sum=A[0],A[0]
ans,x,y=0,0,0
flag=True
while flag:
  if xsum==sum:
    ans+=(x-y+1)
    x+=1
    if x==N:
      break
    sum+=A[x]
    xsum^=A[x]
  else:
    sum-=A[y]
    xsum^=A[y]
    y+=1
print(ans)

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

int main(){
    for(int i=0;i<3000;i++){
        int x,y;
        cin >> x>>y;
        if(x==0 && y==0){
            break;
        }else if(y<x){
            cout << y <<" "<<x<<endl;
        }else{
            cout << x <<" "<<y<<endl;
        }
    }
}


Measured memory_bytes: 3052
/**
 * @file   TableTennis.cpp
 * @author Peter Züger
 * @date   21.03.2020
 * @brief  Table Tennis match maker
 */
#include <iostream>
#include <vector>
#include <algorithm>

long long least_rounds(long long N, long long A, long long B){
    if((B - A) % 2){
        return std::min((A + (((B - A) - 1) / 2)), (N - (B - (((B - A) - 1) / 2))) + 1);
    }else{
        return (B - A) / 2;
    }
}

int main(int argc, char** argv){
    long long N, A, B;

    std::cin >> N;
    std::cin >> A;
    std::cin >> B;

    std::cout << least_rounds(N, A, B);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n, i, j, min, tmp, data[101]={}, count=0;

    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        scanf("%d", &data[i]);
    }
    for( i = 0; i < n - 1; i++ ){
        min = i;
        for( j = i; j < n; j++ ){
            if( data[j] < data[min] ){
                min = j;
            }
        }
        tmp = data[i];
        data[i] = data[min];
        data[min] = tmp;
        if( i != min ) count++;
    }
    for( i = 0; i < n; i++ ){
        printf("%d", data[i]);
        if( i != n - 1 ){
            printf(" ");
        }
    }
    printf("\n%d\n", count);
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define ascii_0 48
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N;
	string S;
	vb pin1(10, 0);
	vb pin2(100, 0);
	vb pin3(1000, 0);
	cin >> N;
	cin >> S;
	rep(i, N) {
		int d = (int)S[i] - ascii_0;
		rep(j, 100) {
			if (pin2[j]) {
				pin3[j * 10 + d] = 1;
			}
		}
		rep(j, 10) {
			if (pin1[j]) {
				pin2[j * 10 + d] = 1;
			}
		}
		pin1[d] = 1;
	}
	int ans = 0;
	rep(i, 1000) {
		if (pin3[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import permutations


def distance(a, b):
    return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5


N = int(input())
cities = [tuple(map(int, input().split())) for _ in range(N)]
paths = list(permutations(range(N)))
total = 0

for path in paths:
    for i in range(len(path)-1):
        total += distance(cities[path[i]], cities[path[i+1]])

ans = total / len(paths)

print(ans)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    unordered_map<ll,int>mp;
    int n;cin >>n;
    vector<ll>a(n);
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
        mp[a[i]+i]++;
        ans+=mp[i-a[i]];
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 20108
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int>
using namespace std;
const int INF = 1e9+7;

main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin>>n;
    vector<int> a(n), b(n);
    ll sum = 0;
    bool ok = true;
    for (int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        if (a[i]!=b[i])
            ok = false;
        sum+=a[i];
    }
    ll res = 0;
    if (ok)
    {
        cout<<res;
        return 0;
    }
    for (int i=0;i<n;i++)
    {
        if (a[i]>b[i])
        {
            res = max(res, sum-a[i] + a[i]-b[i]);
        }
    }
    cout<<res;
    return 0;
}



Measured memory_bytes: 384
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();
		if((a+b)%2==1) {
			System.out.println("IMPOSSIBLE");
		}else {
			System.out.println((a+b)/2);
		}

	}

}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
		{
			var a = first.GetEnumerator();
			var b = second.GetEnumerator();
			while (a.MoveNext() && b.MoveNext())
			{
				yield return resultSelector(a.Current, b.Current);
			}
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
//			var n = reader.ReadLine();
			reader.ReadLine();
			var xx = SplitToDoubles(reader.ReadLine());
			var yy = SplitToDoubles(reader.ReadLine());
			var xy = Zip(xx, yy, (x, y) => Math.Abs(x - y)).ToArray();
			
			var D1 = xy.Aggregate(0d, (total, next) => total += next);
			var D2 = Math.Sqrt(xy.Aggregate(0d, (total, next) => total += next * next));
			var D3 = Math.Pow(xy.Aggregate(0d, (total, next) => total += next * next * next), 1d / 3d);
			var D4 = xy.Max();
			
			writer.WriteLine(D1);
			writer.WriteLine(D2);
			writer.WriteLine(D3);
			writer.WriteLine(D4);
			
		}
	}
}

Measured memory_bytes: 10196
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;
int a[100010];
int main()
{
    int n,k,i,j,x,t,f;
    cin >> n >> k;
    f=0;x=n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        if(!f && a[i]>0)
        {
            x=i;
            f=1;
        }
    }
    int s=0,mi;
    if(x==0)
        cout << a[k-1] << endl;
    else if(x==n)
        cout << abs(a[n-k]) << endl;
    else {
        if(x<k)
        {
            if(abs(a[0])<a[k-1])
                s=2*abs(a[0])+a[k-1];
            else
                s=abs(a[0])+2*a[k-1];
        }
        else if(x==k)
            s=abs(a[0]);
        else
            s=2*abs(a[x-k]);
        mi=s;
        f=0;
        for(i=max(x,k);i<x+k;i++)
        {
            if(i>=n)
                break;
            if(a[i-k+1]>0)
            {
                if(a[x+k-1]<mi)
                    mi=a[x+k-1];
                break;
            }
            if(2*abs(a[i-k+1])+a[i]<mi)
                mi=abs(2*a[i-k+1])+a[i];
            if(abs(a[i-k+1])+2*a[i]<mi)
                mi=abs(a[i-k+1])+2*a[i];
        }
        cout << mi << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main()
{
    int A[3], sum=0, i, c, d, swap;
    for(i=0; i<3; i++){
        scanf("%d", &A[i]);
    }
    for(c=0; c<2; c++){
        for(d=0 ; d<2-c; d++){
            if (A[d] > A[d+1]){
                swap       = A[d];
                A[d]   = A[d+1];
                A[d+1] = swap;
            }
        }
    }
    sum+= abs(A[1]-A[0]) + abs(A[2]-A[1]);
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int n, cntab = 0, cnta = 0, cntb = 0, cntba = 0, c = 0, a = 0;
    string s;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s;
        for (int j = 0; j < s.size() - 1; j++){
            if (s[j] == 'A' && s[j + 1] == 'B'){
                cntab++;
            }
        }
        if (s[0] == 'B' && s[s.size() - 1] == 'A'){
            c++;
        } else {
            if (s[0] == 'B'){
                cntb++;
            }
            if (s[s.size() - 1] == 'A'){
                cnta++;
            }
        }
    }

    cerr << cnta << " " << cntb << " " << cntab << " " << c << endl;

    if (cnta == 0 && cntb == 0) {
        if (c > 0) {
            cout << c - 1 + cntab << endl;
            return 0;
        } else {
            cout << cntab << endl;
            return 0;
        }
    }

    cout << min(cnta, cntb) + cntab + c<< endl;
}

Measured memory_bytes: 384
N = int(input())
hs = [int(i) for i in input().split()]
dp = [10000000] * N
for i,h in enumerate(hs):
    if i == 0:        
        # 0は初期化されている
        dp[i] = 0
        continue
    elif i == 1:
        # 1は1通りしか無い
        dp[i] = dp[i-1] + abs(hs[i-1]-h)
    else:
        # 1個前か2個前で、コストが最小になるやつ
        dp[i] = min(dp[i-1]+abs(hs[i-1]-h),dp[i-2]+abs(hs[i-2]-h))
# print(dp)
print(dp[-1])

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  
  double sum = 0;
  for (ll c = 1; c <= N; c++) {
    ll t = 1;
    while (t * c < K) t *= 2;
    sum += 1.0 / t;
  }
  cout << sum / N << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <deque>

#include <algorithm>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;
#include <string>

int main()
{

    ll N, K;

    cin >> N >> K;

    vector<ll> A(N);

    vector<ll> visit_num(N, -1);

    ll tele_num = 0;

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

        cin >> A[i];
        A[i]--;
    }

    ll now = 0;

    ll roop = 0;

    ll pre_roop = 0;

    while (-1)
    {

        if (visit_num[now] != -1)
        {

            roop = tele_num - visit_num[now];

            pre_roop = visit_num[now];

            break;
        }

        visit_num[now] = tele_num;

        now = A[now];

        tele_num++;
    }

    ll remain = 0;

    if (K >= pre_roop)
    {
        remain = (K - pre_roop) % roop;

        if (remain > 0)
        {
            for (int i = 0; i < remain; i++)
            {

                now = A[now];
            }
        }
    }
    else
    {

        remain = K;

        now = 0;

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

            now = A[now];
        }
    }

    cout << now + 1 << endl;
    return 0;
}

Measured memory_bytes: 6376
from sys import stdin
N = 8
FREE = -1
NOT_FREE = 1
row = [FREE] * N
col = [FREE] * N
dpos = [FREE] * (2 * N - 1)
dneg = [FREE] * (2 * N - 1)
X = [[False] * N for _ in range(N)]
n = int(stdin.readline())
for _ in range(0, n):
    r, c = map(int, stdin.readline().split())
    X[r][c] = True
def printBoard():
    for i in range(0, N):
        for j in range(0, N):
            if X[i][j] != 0 and row[i] != j: return
    for i in range(0, N):
        print(''.join(('Q' if row[i] == j else '.' for j in range(N))))
def recursive(i):
    if i == N:
        printBoard()
        return
    for j in range(0, N):
        if (NOT_FREE == col[j] or
            NOT_FREE == dpos[i + j] or
            NOT_FREE == dneg[i - j + N - 1]): continue
        row[i] = j
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE
        recursive(i + 1)
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE
recursive(0)

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

using namespace std;

using ll = long long;
using ld = long double;

const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld) - 1);

int main () {
	int n;
	cin >> n;
	int ar[n + 1];
	vector<int> pref(n + 1);

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

	for (int i = n - 1; i >= 0; i--) {
		pref[i] = (pref[i + 1] + ar[i + 1]) % MOD;
	}

	int sol = 0;

	for (int i = 0; i < n; i++) {
		sol += (pref[i] * 1LL * ar[i]) % MOD;
		sol %= MOD;
	}

	cout << sol << '\n';
}


Measured memory_bytes: 4812
#include <iostream>
using namespace std;
#define MAX 500000
#define Sentinel 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0;i<n1;i++){
        L[i] = A[left+i];
    }
    for (int i = 0;i<n2;i++){
        R[i] = A[mid+i];
    }
    int i = 0,j = 0;
    L[n1] = R[n2] = Sentinel;
    for (int k = left; k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k] = L[i++];
        }
        else{
            A[k] = R[j++];
        }
    }
}

void mergesort(int A[],int n,int left,int right){
    if (left+1<right){
        int mid = (right+left)/2;
        mergesort(A,n,left,mid);
        mergesort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
   
    int A[MAX],n,i;
    cnt = 0;
    cin>>n;
    for (i = 0;i<n;i++){cin>>A[i];}
    
    mergesort(A,n,0,n);
    for(i = 0;i<n;i++){
        if(i){cout<<" ";}
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}

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

int main() {
  int a,b,c,d;
  int ta,aa,amod,tmod;
  cin >> a >> b >> c >> d;
  aa = a/d;
  amod = a%d;
  if (amod!=0) aa++;
  ta = c/b;
  tmod = c%b;
  if (tmod!=0) ta++;

  if (ta<=aa) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       Scanner in = new Scanner(System.in);
       int a = in.nextInt();
       int b = in.nextInt();
       int c = in.nextInt();
       int max = Math.max(Math.max(a, b), c);
       System.out.println(a + b + c - max);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    int count = 0;
    int mini = N+1;
    REP(i,N){
        cin >> A[i];
        if(mini>A[i]){
            count ++;
            mini = A[i];
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
 * ITP1_6_B.cpp
 *
 *  Created on: Apr 20, 2018
 *      Author: 13743
 */

#include<iostream>
#include<cmath>

using namespace std;


struct card {
	char suit;
	int value;
};

void swap(card *a, int i, int j) {
	card tmp = a[i];
	a[i] = a[j];
	a[j] = tmp;
}

void printCard(card *a, int n) {
	cout << a[0].suit << a[0].value;
	for(int i=1; i<n; i++) {
		cout << " " << a[i].suit << a[i].value;
	}
	cout << endl;
}

int main() {
	int n;
	card a[36];
	card b[36];
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> a[i].suit >> a[i].value;
		b[i].suit = a[i].suit;
		b[i].value = a[i].value;
	}

	for(int i=0; i<n; i++) {
		for(int j=n-1; j>i; j--) {
			if(a[j-1].value > a[j].value) {
				swap(a, j-1, j);
			}
		}
	}
	printCard(a, n);
	cout << "Stable" << endl;

	for(int i=0; i<n; i++) {
		int mini = i;
		for(int j=i+1; j<n; j++) {
			if(b[j].value < b[mini].value) {
				mini = j;
			}
		}
		swap(b, i, mini);
	}
	printCard(b, n);
	for(int i=0; i<n; i++) {
		if(a[i].suit != b[i].suit) {
			cout << "Not stable" << endl;
			return 0;
		}
	}
	cout << "Stable" << endl;
}



Measured memory_bytes: 3084