akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define M 998244353
typedef long long ll;
ll power(int a, int b){
    ll seki = a;
    for(int i=0;i<b-1;i++){
        seki *= a;
        seki %= M;
    }
    return seki;
}
int main(void){
    int N=0;
    int dummy;
    dummy = scanf("%d",&N);
    
    int array[100001]={0};
    for(int i=0;i<100001;i++){
        array[i] = 0;
    }
    int x=0;
    int count=0;
    int flag = 0;
    for(int i=0;i<N;i++){
        dummy = scanf("%d",&x);
        if(i==0&&x!=0) flag=1;
        if(array[x]==0) count++;
        array[x]++;
    }
    
    if(array[0]!=1||flag){
        printf("0\n");
    }else{
        ll ans = 1;
        for(int i=1;i<count-1;i++){
            if(array[i]==0||array[i+1]==0){
                ans = 0;
                break;
            }
            ans *= power(array[i],array[i+1]);
            ans %= M;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 512
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string O, E;
  cin >> O;
  cin >> E;

  for (uint32_t i = 0; i < E.size(); i++) {
    cout << O[i] << E[i];
  }

  if (O.size() > E.size()) {
    cout << O[O.size() - 1];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, ans;
  scanf("%lld", &n);
  for(i = 1; i * i <= n; ++i) if(!(n % i)) ans = i;
  printf("%lld", ans + n / ans - 2);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  string s;
  cin >> n >> s;
  int x=0,ans=0;
  rep(i,n){
    if(s[i]=='I')x++;
    else x--;
    if(x>ans)ans=x;
  }
  cout << ans << endl;
  
}


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

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, a[100000];

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

    cin >> N;
    for(int i = 0; i < N; ++i) cin >> a[i];
    sort(a, a + N);
    int latte = a[N - 1], malta = a[0];
    for(int i = 0; i < N - 1; ++i) {
        if(abs(a[i] - a[N - 1] / 2) <= abs(malta  - a[N - 1] / 2)) malta = a[i];
    }
    cout << latte << " " << malta << endl;
    return 0;
}

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

int main(){
  int k, s;
  cin >> k >> s;
  
  int ans = 0;
  
  for(int i = 0; i <= k; i++){
  for(int j = 0; j <= k; j++){
  
  	if(i+j <= s && s-k <= i+j){
    ans++;
    }
  }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break


Measured memory_bytes: 3060
import sys
 
def solve():
    def dfs(idx, end, value, cost, g):
        if idx == end:
            if cost == 0:
                return

            if value not in g:
                g[value] = cost
            else:
                g[value] = min(g[value], cost)

            return

        a, b, c = table[idx]
        dfs(idx + 1, end, value + b * Ma - a * Mb, cost + c, g)
        dfs(idx + 1, end, value, cost, g)

    N, Ma, Mb = map(int, input().split())
    table = [tuple(map(int, input().split())) for i in range(N)]
 
    g1, g2 = dict(), dict()
    dfs(0, N // 2, 0, 0, g1)
    dfs(N // 2, N, 0, 0, g2)

    inf = 100*40 + 1
    ans = inf
 
    if 0 in g1:
        ans = min(ans, g1[0])
    if 0 in g2:
        ans = min(ans, g2[0])
 
    for v1, c1 in g1.items():
        if -v1 in g2:
            tmp = c1 + g2[-v1]
            ans = min(ans, tmp)
 
    if ans < inf:
        print(ans)
    else:
        print(-1)

        
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
 
 
if __name__ == '__main__':
    solve()

Measured memory_bytes: 49880
def rootT(x):
  if x == T[x]:
    return x
  x = T[x]
  return rootT(x)

def mergeT(x, y):
  a = rootT(x)
  b = rootT(y)
  if a != b:
    if NumTable[a] > NumTable[b]:
      T[b] = a
      NumTable[a] += NumTable[b]
    else:
      T[a] = b
      NumTable[b] += NumTable[a]

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]

AB.reverse()

T = [i for i in range(N + 1)]
NumTable = [1 for i in range(N + 1)]

L = []
Ans = N * (N - 1) // 2
for i in AB:
  L.append(Ans)
  a = rootT(i[0])
  b = rootT(i[1])
  if a != b:
    ta = NumTable[a]
    tb = NumTable[b]
    mergeT(a, b)
    Ans -= (ta + tb) * (ta + tb - 1) // 2  - ta * (ta - 1) // 2 - tb * (tb - 1) // 2
    mergeT(a, b)

for i in L[::-1]:
  print(i)

Measured memory_bytes: 34976
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int a, b;
    cin >> a >> b;
    if (a>b) {
        for (int i=0;i<a;i++) cout << b;
    } else {
        for (int i=0;i<b;i++) cout << a;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private static int[][] paper = new int[10][10];

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 128);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & 0x0F, sLine.charAt(2) & 0x0F, sLine.charAt(4) & 0x0F);
		}
		calcResult();
	}

	private static void droppingInk(int x, int y, int size) {
		staining(x, y - 1);
		staining(x - 1, y);
		staining(x, y);
		staining(x + 1, y);
		staining(x, y + 1);
		if (size == 1) {
			return;
		}

		staining(x - 1, y - 1);
		staining(x + 1, y - 1);
		staining(x - 1, y + 1);
		staining(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		staining(x, y - 2);
		staining(x - 2, y);
		staining(x + 2, y);
		staining(x, y + 2);
	}

	private static void staining(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			paper[x][y]++;
		}
	}

	private static void calcResult() {
		int white = 0;
		int maxnoud = 0;
		for (int[] row : paper) {
			for (int colum : row) {
				if (colum == 0) {
					white++;
				} else if (colum > maxnoud) {
					maxnoud = colum;
				}
			}
		}
		System.out.println(white);
		System.out.println(maxnoud);
	}
}

Measured memory_bytes: 16848
def main():
    N, Q = map(int, input().split())
    S = input()

    # i-th element count the number of AC in S[:i]
    prefix = [0, 0]
    prev = S[0]
    for i in range(1, N):
        if prev + S[i] == "AC":
            prefix.append(prefix[-2] + 1)
        else:
            prefix.append(prefix[-1])
        prev = S[i]

    for _ in range(Q):
        l, r = map(int, input().split())
        count = prefix[r] - prefix[l-1]
        if l > 1 and S[l-2] + S[l-1] == "AC":
            count -= 1
        print(count)

if __name__ == '__main__':
    # print(main())
    main()

Measured memory_bytes: 6124
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
flag = False
if ((T1*A1 > T1*B1) and (T1*A1 + T2*A2 <= T1*B1 + T2*B2)) or ((T1*A1 < T1*B1) and (T1*A1 + T2*A2 >= T1*B1 + T2*B2)):
  flag = True

if flag:
  a1 = abs(T1*A1 - T1*B1)
  a2 = abs(T1*A1+T2*A2-T1*B1-T2*B2)
  if a2 == 0:
    print("infinity")
  else:
    b1 = a1//a2
    b2 = a1 % a2
    if b2 == 0:
      print(a1//a2*2)
    else:
  	  print(1 + a1//a2*2)
else:
  print(0)

Measured memory_bytes: 3064
import itertools

D, G = list(map(int, input().split()))
P = [list(map(int, input().split())) for _ in range(D)]

res = 1000000
for i in itertools.product([0, 1], repeat=D):
    cost = 0
    num = 0
    for j in range(len(i)):
        cost += ((j+1)*100*P[j][0]+P[j][1])*i[j]
        num += P[j][0]*i[j]
    #print(i, cost, num, res)
    if cost >= G:
        res = min(res, num)
    else:
        for k in range(len(i)-1, -1, -1):
            if i[k] == 1:
                continue
            for l in range(P[k][0]):
                cost += 100*(k+1)
                num += 1
                if cost >= G:

                    res = min(res, num)
                    break
        else:
            continue
        break

print(res)


Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

class Point{
public:
	double x,y;

	Point(double x = 0,double y = 0):x(x),y(y){}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}
};

typedef Point Vector;
typedef vector<Point> Polygon;

int num_point,Q;

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}

Point calc_minus(Point a,Point b){
	Point ret;

	ret.x = a.x-b.x;
	ret.y = a.y-b.y;

	return ret;
}

/*
 * IN 2
 * ON 1
 * OUT 0
 *
 */
int contains(Polygon g,Point p){
	int n = g.size();
	bool x = false;
	for(int i = 0; i < n; i++){
		Point a = g[i]-p,b = g[(i+1)%n]-p;
		if(abs(cross(a,b)) < EPS && dot(a,b) < EPS)return 1;
		if(a.y > b.y)swap(a,b);
		if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
	}
	return (x ? 2:0);
}

int main(){

	scanf("%d",&num_point);
	Polygon g;

	double x,y;
	for(int loop = 0; loop < num_point; loop++){
		scanf("%lf %lf",&x,&y);
		g.push_back(Point(x,y));
	}

	scanf("%d",&Q);

	for(int loop = 0; loop < Q; loop++){
		scanf("%lf %lf",&x,&y);
		printf("%d\n",contains(g,Point(x,y)));
	}

	return 0;
}




Measured memory_bytes: 3212
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=305;
const double eps=1e-10;
double p[N][N][N],inv[N],lim;int s[5],n,x;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&x),++s[x];
	fp(i,1,n)inv[i]=1.0/i;
	fp(i,0,n)fp(j,0,n-i)fp(k,0,n-i-j)if(i+j+k==0||p[i][j][k]>eps){
		R double t=(p[i][j][k]+n*inv[i+j+k])*inv[i+j+k];
		if(i+j+k<n)p[i][j][k+1]+=(p[i][j][k]+n*inv[i+j+k+1])*inv[i+j+k+1]*(k+1);
		if(k)p[i][j+1][k-1]+=t*(j+1);
		if(j)p[i+1][j-1][k]+=t*(i+1);
	}
	printf("%.10lf\n",p[s[3]][s[2]][s[1]]);
	return 0;
}

Measured memory_bytes: 219392
s=str(input());ans=[]
for i in range(len(s)):
    if s[i]=="0":
        ans.append(0)
    elif s[i]=="1":
        ans.append(1)
    elif len(ans)!=0:
        del ans[-1]
    else:
        pass
print("".join(map(str,ans)))

Measured memory_bytes: 38256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<ctime>
const  int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double lw;
#define  pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
int n;
int main()
{
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	printf("%.6f ", w*(ll)h / 2.0);
	if (x == w / 2.0&&y == h / 2.0)
		puts("1");
	else
		puts("0");
	return 0;
}


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

int main() {
  int t;
  map<string, int> owo;
  vector<string> toout;

  int kkk = 0;

  cin >> t;
  for (int i = 0; i < t; i++) {
    string current;
    cin >> current;

    if (owo[current]) owo[current] += 1;
    else owo[current] = 1;
  }

  for (auto it = owo.begin(); it != owo.end(); it++) {
//     std::cout << it->first << ": " << it->second << std::endl;
    if (it->second > kkk) {
      toout.clear();
      kkk = it->second;
      toout.push_back(it->first);
    } else if (it->second == kkk) {
      kkk = it->second;
      toout.push_back(it->first);
    }
  }
  
  for (auto it = toout.begin(); it != toout.end(); it++)
    cout << *it << endl;
}

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

int main() {
    while(1){
        int n; cin >> n;
        if(n==0) break;
        vector<int> a(n+1), s(n+1);
        s[0]=0;
        for(int i=1; i<n+1; i++){
            cin >> a[i];
            s[i]=s[i-1]+a[i];
        }
        int ans=s[1];
        for(int i=1; i<n+1; i++){
            for(int j=i; j<n+1; j++){
                ans=max(ans, s[j]-s[i-1]);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3012
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int main(){
    int n,m;
    while(cin>>n>>m&&(n||m)){
        vector<pair<int,pii>> data;
        rep(i,m){
            int t,s,d;
            cin>>t>>s>>d;
            data.pb(make_pair(t,pii(s,d)));
        }
        sort(all(data));
        
        
        bool infected[20010];
        rep(i,20010)infected[i]=false;
        infected[1]=true;
        rep(i,data.size()){
            pii p = data[i].second;
            int s = p.first,t=p.second;
            if(infected[s]){
                infected[t]=true;
            }
        }
        int sum=0;
        rep(i,20010){
            if(infected[i])sum++;
        }
        cout<<sum<<endl;
    }
}

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

using namespace std;

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

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

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

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

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

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

ll f(vector<P> &fs, int k, ll x) {
    if (k == 0) return 0;
    return f(fs, k - 1, x) + abs(x - fs[k - 1].first) + fs[k - 1].second;
}

struct Half {

    priority_queue<ll> left;
    PQ_ASK right;

    ll left_sum = 0, right_sum = 0;

    ll half() {
        if (left.empty()) return 0;
        return left.top();
    }

    void right_push(ll v) {

        right.push(v);
        right_sum += v;
        while (left.size() < right.size()) {

            left_sum += right.top();
            right_sum -= right.top();

            left.push(right.top());
            right.pop();
        }
    }

    void left_push(ll v) {
        left.push(v);
        left_sum += v;
        while (left.size() > right.size() + 1) {
            right_sum += left.top();
            left_sum -= left.top();
            right.push(left.top());
            left.pop();
        }
    }

    void push(ll v) {
        if (v >= half()) {
            right_push(v);
        } else {
            left_push(v);
        }

    }


    ll diffSum() {
        ll rdiffsum = right_sum - half() * right.size();
        ll ldiffsum = half() * left.size() - left_sum;
        return rdiffsum + ldiffsum;
    }

};

int main() {
    vector<P> fs;

    Half as;
    ll bsum = 0;

    int q;
    cin >> q;
    rep(_, q) {
        int method;
        cin >> method;
        if (method == 1) {
            ll a, b;
            cin >> a >> b;
            as.push(a);
            bsum += b;

        } else {
            ll t = as.half();
            ll k = as.diffSum();
            printf("%lld %lld\n", t, k + bsum);
        }
    }

}


Measured memory_bytes: 5000
#include <iostream>
#include <algorithm>
using namespace std;
 
	int b[100];
 
int main(){
    int n;
    string s;
    cin >> n >> s;
    int br = n;
    for(int i = 0; i < n; i++){
        if(s[i] == s[i+1]) br--;
    }
    cout << br;
    return 0;
}

	

		


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

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

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

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

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

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

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

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N; 
    cin >> N;

    vector<ll> A(N);
    ll total = 0;
    REP(i, N){
        cin >> A[i];
        total += A[i];
    }
    
    ll ans = LINF;
    ll suml = 0;
    REP(i, N){
        suml += A[i];
        ans = min(ans, abs(total-2*suml));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
#define MOD 1000000007

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n;
    cin >> n;
    if(n==1){
        cout << 1 << endl;
        return 0;
    }else if(n==2){
        cout << 4 << endl;
        return 0;
    }
    long long sum = n + n * n;
    long long dp[1000010];
    fill_n(dp, 1000010, 0);
    dp[0] = 0;
    dp[1] = n;
    dp[2] = n*n;

    for(int i=3; i<=n; i++){
        long long tmp = (sum - dp[i-2] + MOD) % MOD;
        dp[i] = ((n-1)*(n-1) % MOD + tmp + (n-i+2)) % MOD;
        sum = (sum + dp[i]) % MOD;
    }
    cout << dp[n] << endl;

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a = 0;
    int b = 0;
    int ab = 0;
    int answer = 0;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        if(s[0] == 'B' && s[s.size()-1] == 'A'){
            ab++;
        }
        else if(s[0] == 'B'){
            b++;
        }
        else if(s[s.size()-1] == 'A'){
            a++;
        }
        for(int j=0;j<s.size()-1;j++){
            if(s[j] == 'A' && s[j+1] == 'B'){
                answer++;
            }
        }
    }
    if(ab > 1){
        answer += (ab -1);
        ab = 1;
    }
    if(a >=1 && ab == 1){
        answer++;
        a--;
    }
    if(b >=1 && ab == 1){
        answer++;
        b--;
    }
    answer += min(a, b);

    cout << answer << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))

static const ll MOD = 1e9 + 7;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;

    cin >> n >> m;

    vector<ll> x(n);
    vector<ll> y(m);

    ll i, len;

    for (i = 0; i < n; i++) cin >> x[i];
    for (i = 0; i < m; i++) cin >> y[i];

    ll w = 0;
    ll h = 0;

    len = n - 1;
    for (i = 0; i < len; i++) w = (w + ((x[i + 1] - x[i]) * (i + 1) * (n - i - 1)) % MOD) % MOD;
    len = m - 1;
    for (i = 0; i < len; i++) h = (h + ((y[i + 1] - y[i]) * (i + 1) * (m - i - 1)) % MOD) % MOD;

    cout << (w * h) % MOD << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<cstdio>
#include <cmath>
#include <string>
using namespace std;

int main()
{

	char S[4];
	int count = 0;
	cin >> S;
	for (int i = 0; i < 3; i++) {
		if (S[i] == '1') count++;
	}
	cout << count << endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  bool ar[n];
  
  for(int i = 0; i < n; i++){
    int t1,t2;
    cin >> t1 >> t2;
    
    if (t1 == t2) { ar[i] = true; }
    else { ar[i] = false; }
  }
  
  for(int i = 2; i < n; i++){
    if(ar[i] && ar[i-1] && ar[i-2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 




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

////////////////////////////////////////////////////////////////////
int n,a[210000];
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  int ans = 0, sum = 0, right = 0, res = 0;
  rep(left, n){
    while(right < n && (sum ^ a[right]) == (sum + a[right])){
      sum += a[right];right++;
    }
    res += right - left;
    if(left == right)right++;
    else{
      sum -= a[left];
    }
  }
  cout << res << endl;
}



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


void solve()
{
	
ll n,l;
cin>>n>>l;

if((4*n-l)>=0&&(4*n-l)%2==0 &&n>=(4*n-l)/2)
{
	cout<<"Yes";
}
else
cout<<"No";
	
	

}




int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 3652
raw_input1 = input()
raw_input2 = input()

l = raw_input2.split()
N = int(raw_input1)
S =list(l[0])
T = list(l[1])


for i in range(N):
        T.insert(i*2, S[i])

ans = ''.join(T)

print(ans)

Measured memory_bytes: 3060
N, X, Y = map(int, input().split())
from itertools import combinations
cmb = combinations(range(1, N+1), 2)
k = [0] * (N-1)
for i, j in cmb:
    distance = min(j-i, abs(X-i) + abs(Y-j) + 1)
    k[distance-1] += 1
for i in k:
    print(i)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int N, M;
  while(cin >> N >> M, N || M) {
    vector<Int> all(N), one(N);
    for(Int i = 0; i < M; i++) {
      Int S, k;
      cin >> S >> k;
      for(Int j = 0; j < k; j++) {
        Int c;
        cin >> c; c--;
        all[c] += S;
        if(k == 1) one[c] += S;
      }
    }
    Int idx = -1;
    Int mx = -1;
    for(Int i = 0; i < N; i++) {
      if(mx < all[i]) {
        idx = i;
        mx = all[i];
      }
    }
    Int mn = 1000000;
    for(Int i = 0; i < N; i++) {
      if(i == idx) continue;
      if(mn > one[i]) mn = one[i];
    }
    cout << mx - mn + 1 << endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
const int N=500010;
int tt;
bool vis[N];
deque <int> Q;
map <int,int> w[N];
int head[N],to[N*3],nxt[N*3],s[N*3],dis[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void lnk(int x,int y,int z,int u) {
    to[++tt]=y,nxt[tt]=head[x],s[tt]=z,head[x]=tt;
    to[++tt]=x,nxt[tt]=head[y],s[tt]=u,head[y]=tt;
}
int main() {
    int n,m;
    cin>>n>>m;
    for(int i=1,cnt=n;i<=m;i++) {
	int x=gi(),y=gi(),z=gi(),&X=w[x][z],&Y=w[y][z];
	if(!X) X=++cnt;
	if(!Y) Y=++cnt;
	lnk(X,Y,0,0),lnk(X,x,0,1),lnk(Y,y,0,1);
    }
    memset(dis,127,sizeof(dis));
    Q.push_back(1),dis[1]=0;
    while(!Q.empty()) {
	int x=Q.front();
	Q.pop_front();
	if(vis[x]) continue;
	vis[x]=1;
	if(x==n) return cout<<dis[x],0;
	for(int i=head[x];i;i=nxt[i]) {
	    int y=to[i];
	    if(dis[y]>dis[x]+s[i]) {
		dis[y]=dis[x]+s[i];
		if(s[i]) Q.push_back(y);
		else Q.push_front(y);
	    }
	}
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 64896
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();

		String arr[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

		String s = sc.next();

		for (int i = 0; i < arr.length; i++) {
			if (s.equals(arr[i])) {
				System.out.println(7 - i);
			}
		}

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int a,b,c; cin>>a>>b>>c;
  
  cout<<((a+b)<(b+c)?((a+b)<(a+c)?a+b:a+c):((b+c)<(a+c)?(b+c):(a+c)))<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;

#define _SI(arr) (sizeof(arr)/sizeof(arr[0])

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

	cout << 24 + (24 - M) << endl;
}

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

map<string, int> v;
map<string, vector<string> > l;

int main()
{
	int n;
	while (scanf("%d", &n), n){
		v.clear();
		l.clear();
		
		for (int i = 0; i < n; i++){
			string str;
			int p;
			cin >> str >> p;
			v[str] = p;
		}
		
		int m;
		scanf("%d", &m);
		for (int i = 0; i < m; i++){
			string o;
			int k;
			cin >> o >> k;
			for (int j = 0; j < k; j++){
				string q;
				cin >> q;
				l[o].push_back(q);
			}
		}
		
		while (true){
			bool update = false;
			
			typedef map<string, vector<string> >::iterator ite;
			for (ite i = l.begin(); i != l.end(); ++i){
				int sum = 0;
				for (int j = 0; j < (*i).second.size(); j++){
					sum += v[(*i).second[j]];
				}
				if (v[(*i).first] > sum){
					v[(*i).first] = sum;
					update = true;
				}
			}
			if (!update) break;
		}
		
		string t;
		cin >> t;
		cout << v[t] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  int F[N][10];
  REP(i, N)
  REP(j, 10)
  cin >> F[i][j];
  int P[N][11];
  REP(i, N)
  REP(j, 11)
  cin >> P[i][j];
  int ans = INT32_MIN;
  for (int b = 1; b < (1 << 10); b++) // b = 1 ~ 1023
  {
    int tmp = 0;
    REP(i, N)
    {
      int c = 0; // c_i
      REP(j, 10)
      {
        if ((b >> j & 1) && F[i][j])
          c++;
      }
      tmp += P[i][c];
    }
    if (ans < tmp)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;
const bool debug = 0;
//---------------------------------//

int V, E;
vector<int> g[112345];
vector<int> depth, low;
set<pii> bridge;

int dfs(int u, int p, int d) {
	depth[u] = d;
	low[u] = d;
	
	REP(i, g[u].size()) {
		int v = g[u][i];
		if (v == p) continue;
		
		if (depth[v] == -1) {
			chmin(low[u], dfs(v, u, d + 1));
			if (depth[v] == low[v]) bridge.insert(pii(min(u, v), max(u, v)));
		}
		else chmin(low[u], low[v]);
	}
	
	return low[u];
}


int main() {
	cin >> V >> E;
	REP(i, E) {
		int s, t;
		scanf("%d %d", &s, &t);
		g[s].push_back(t);
		g[t].push_back(s);
	}
	
	depth.resize(V, -1);
	low.resize(V, -1);
	
	dfs(0, -1, 0);
	
	for (set<pii>::iterator it = bridge.begin(); it != bridge.end(); ++it) {
		printf("%d %d\n", it->first, it->second);
	}
	return 0;
}

Measured memory_bytes: 7572
// D - Maximum Average Sets
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using DBL = double;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(ll i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define MAX 50

vvl nCr_table(MAX+1, vl(MAX+1, 1));

void nCr_table_create(ll N){
	rp(n,1,N+1) rp(r,1,N+1-n)
		nCr_table[n][r] = nCr_table[n-1][r] + nCr_table[n][r-1];
}

ll nCr(int n, int r){
	// if(n < r) return 0;
	int i = n - r;
	int j = r;
	return nCr_table[i][j];
}

int main(){
	int N,A,B; cin>>N>>A>>B;
	vl V(N); rpz(i, N) cin>>V[i];
	sort(allr(V));
	nCr_table_create(N);

	DBL maxave = 0.0;
	rpz(i, A) maxave += V[i];
	maxave /= A;

	int n = 0, r = 0;
	ll v = V[A-1];
	rpz(i, N){
		if(v == V[i]){
			n++;
			if(i < A) r++;
		}
	}

	ll maxcnt = 0;
	// if(r == A) rp(r, A, B+1) maxcnt += nCr(n, r);
	if(r == A) rp(r, A, min(n, B)+1) maxcnt += nCr(n, r);
	else maxcnt = nCr(n, r);

	printf("%.6f\n", maxave);
	cout<< maxcnt <<endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

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

    int b = 0;
    ll ans = 0;
    string S;
    cin >> S;
	for (int i=0;S[i];i++){
		if (S[i] == 'B') b++;
		else ans += b;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error_old(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {it++;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); }

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

enum happ{
    swim, 
    bugs,
    homework
};

void solve(){
    int n;
    cin >> n;
    vector<vi> arr(n, vi(3, 0));
    rep(i, n){
        cin >> arr[i][swim] >> arr[i][bugs] >> arr[i][homework];
    }

    vector<vi> dp(n, vi(3, 0));
    vi activity = {swim, bugs, homework};
    for(auto act : activity){
        dp[0][act] = arr[0][act];
    }
    
    repA(i, 1, n - 1){
        for(auto act : activity){
            for(auto prev_act : activity){
                if(act != prev_act)
                    dp[i][act] = max(dp[i][act], dp[i - 1][prev_act] + arr[i][act]);
            }
        }
    }
    cout << max({dp[n - 1][swim], dp[n - 1][bugs], dp[n - 1][homework]}) << endl;
}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    solve();

    return 0;
}


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

int main() {
	ll N, all = 0;
	cin >> N;
	vector<ll> X(N);
	for (int i = 0;i < N;i++) {
		cin >> X[i];
		all += X[i];
	}
	sort(X.begin(), X.end());
	ll ans = 0;
	for (int i = 1;i < N - 1;i++)
		ans += abs(X[i]);
	ans -= X[0];
	ans += X[N - 1];

	cout << ans << endl;
	for (int i = 1;i < N - 1;i++) {
		if (X[i] < 0) {
			cout << X[N - 1] << " " << X[i] << endl;
			X[N - 1] -= X[i];
		}
		else {
			cout << X[0] << " " << X[i] << endl;
			X[0] -= X[i];
		}
	}
	cout << X[N - 1] << " " << X[0] << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> c(N);
  for (int i = 0; i < M; ++i)
  {
    cin >> c.at(i);
  }
  vector<int> dp(N + 1, INF);//dp(払った額)=使った枚数
  dp.at(0) = 0;
  for (int i = 0; i < N; ++i)
  {
    if (dp.at(i) == INF)
    {
      continue;
    }
    for (int j = 0; j < M; ++j)
    {
      if (i + c.at(j) > N)
      {
        continue;
      }
      dp.at(i + c.at(j)) = min(dp.at(i + c.at(j)), dp.at(i) + 1);
    }
  }
  cout << dp.at(N) << endl;
}



Measured memory_bytes: 3236
'use strict'

function main(input) {
  input = input.trim().split('\n')
  const N = ~~input[0]
  const strs = input.slice(1).map(v =>
    v
      .split('')
      .sort()
      .join('')
  )
  let ans = 0

  const maps = new Map()
  for (let i = 0; i < strs.length; i++) {
    if (maps.has(strs[i])) { 
      ans += maps.get(strs[i])
      let count = maps.get(strs[i]) + 1 
      maps.set(strs[i], count)
    } else {
      maps.set(strs[i], 1)
    }
  } 
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 54568
#include<iostream>
#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int N;
  int A[100000] = {0};
  //int min, temp;
  long long len1 = 0;
  long long len2 = 0;

  std::cin >> N;
  for(int i = 0; i < N; i++)
    std::cin >> A[i];

  /*
  // 昇順ソート
  for(int i = 0; i < N - 1; i++){
    min = i;
    for(int j = i + 1; j < N; j++){
      if(A[min] > A[j]) min = j;
      temp = A[i];
      A[i] = A[min];
      A[min] = temp;
    }
  }
  */
  qsort(A, N, sizeof(int), compare_int);

  // 大きい方からペアを探す
  for(int i = N - 1; i > 0; i--){
    if(A[i] == A[i-1]){
      if(len1 == 0) len1 = A[i];
      else if(len2 == 0) len2 = A[i];
      i--;
    }
    if(len2 != 0) break;
  }

  std::cout << len1 * len2;

  return 0;
}


Measured memory_bytes: 1020
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true){
            String str = br.readLine();
            if(str.equals("0")){
                break;
            }
            int len = str.length();
            int Sum = 0;
            for(int i=1;i<=len;i++){
                Sum = Sum + str.charAt(i-1) - '0';
            }
        System.out.printf("%d\n",Sum);
        }
    }
}


Measured memory_bytes: 25328
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a - b)) << endl;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
/* Written by Nishant Mittal aka nishantwrp */
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define modnum 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};

//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();

/*

███╗   ██╗██╗███████╗██╗  ██╗ █████╗ ███╗   ██╗████████╗██╗    ██╗██████╗ ██████╗ 
████╗  ██║██║██╔════╝██║  ██║██╔══██╗████╗  ██║╚══██╔══╝██║    ██║██╔══██╗██╔══██╗
██╔██╗ ██║██║███████╗███████║███████║██╔██╗ ██║   ██║   ██║ █╗ ██║██████╔╝██████╔╝
██║╚██╗██║██║╚════██║██╔══██║██╔══██║██║╚██╗██║   ██║   ██║███╗██║██╔══██╗██╔═══╝ 
██║ ╚████║██║███████║██║  ██║██║  ██║██║ ╚████║   ██║   ╚███╔███╔╝██║  ██║██║     
╚═╝  ╚═══╝╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝    ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝     
                                                                                                       
*/
int ans = 0;


signed main()
{
FAST
int n;
cin>>n;
vector <int> data;
invect(data,n,)
vector <int> c;
rep(n) {
  c.pb(i+1);
}
rep(n) {
  if (c[i] != data[i])
  {
    ans++;
  }
}
if (ans == 0 || ans == 2)
{
  cout<<"YES";
} else {
  cout<<"NO";
}
return 0;
}

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

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

    double len = L / 3.0;
    double vol = len * len * len;

    printf("%.12f\n", vol);

    return 0;
}

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

int main(){
  int W, H;
  int x, y;
  cin >> W >> H;
  cin >> x >> y;

  cout << (double)W * (double)H / 2 << " ";

  if(x == (double)W / 2 && y == (double)H / 2){
    cout << 1;
  }
  else{
    cout << 0;
  }

  return 0;
}

Measured memory_bytes: 256
import Control.Monad (replicateM)
import Data.Functor ((<$>))
import Data.List (intercalate)

count :: Int -> Int -> Int -> [[Int]] -> Int
count b f r ((b':f':r':v:_):i) =
  if b' == b && f' == f && r' == r
    then count b f r i + v
    else count b f r i
count _ _ _ _ = 0


main :: IO ()
main = do
    n <- readLn
    info <- replicateM n (map read . words <$> getLine)
    let tenant = [[[ count b f r info | r <- [1..10]] | f <- [1..3]] | b <- [1..4]]
    putStrLn . intercalate "\n####################\n" . map (intercalate "\n" . map ((' ' :) . unwords . map show)) $ tenant



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

const int maxn=1e6+10;
bool prime[maxn];
int sum[maxn];

void isprime()
{
    memset(prime,true,sizeof(prime));
    for(int i=2;i<=1e3;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<1e6;j+=i)
                prime[j]=false;
        }
    }
}

void add()
{
    memset(sum,0,sizeof(sum));
    for(int i=2;i<maxn;i++)
    {
        sum[i]=sum[i-1];
        if(prime[i])
            sum[i]++;
    }
}

int main()
{
    int n;
    isprime();
    add();
    while(scanf("%d",&n)!=EOF)
        printf("%d\n",sum[n]);
    return 0;
}



Measured memory_bytes: 7976
import java.util.HashSet;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
      sc.nextLine();
      HashSet hs = new HashSet();
		for(int i = 0; i < N; i++) hs.add(sc.nextLine());
      System.out.println(hs.size());
    } 
}

Measured memory_bytes: 79820
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            int min = N + 1;
            for (int i = 0; i < N; i++)
            {
                if (r[i] < min)
                {
                    ret++;
                    min = r[i];
                }
            }
            Console.WriteLine(ret);
        }

    }
}

Measured memory_bytes: 34012
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(ll i=j;i<k;i+=in)
#define DF(i,j,k,in) for(ll i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); it++)
#define fitr(it,it1,itr2,in) for(auto it=itr1;it!=itr2;it+=in)
#define Dfeach(it,l,in) for (auto it = l.end()-1; it != l.begin()-1; it-=in)
#define Dfitr(it,it1,itr2,in) for(auto it=itr1;it!=itr2-1;it-=in)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define mkp make_pair
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef map<ll,ll> mll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll ta=c/b;
if(c%b!=0) ta++;
ll tb=a/d;
if(a%d!=0) tb++;
if(ta<=tb) cout<<"Yes";
else cout<<"No";
return 0;
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

struct Node {
  int key;
  int depth;
};

vector<vector<int>> G;  // 隣接リスト

bool isLeaf(int node) {
  if (G[node].size() == 1) {
    return true;
  } else {
    return false;
  }
}

int n;
vector<bool> flags;

queue<Node> q;

VI bfs() {
  VI dist(n);
  while (!q.empty()) {
    Node now = q.front();
    q.pop();  // キューの先頭を取り出す
    dist[now.key] = now.depth;

    // 隣接ノードを探索．進むことができればキューに格納する．
    REP(i, G[now.key].size()) {
      int next_key = G[now.key][i];
      Node next = {next_key, now.depth + 1};
      if (!flags[next_key]) {
        flags[next_key] = true;
        q.push(next);
      }
    }
  }
  return dist;
}

int main() {
  int u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  G.resize(n);
  VI dist_from_takahashi(n);
  VI dist_from_aoki(n);
  flags.resize(n);

  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  Node takahashi = {u, 0};
  q.push(takahashi);
  flags[u] = true;
  dist_from_takahashi = bfs();

  Node aoki = {v, 0};
  q.push(aoki);
  fill(flags.begin(), flags.end(), false);
  flags[v] = true;
  dist_from_aoki = bfs();

  if (isLeaf(u) && dist_from_takahashi[v]==1) {
    ANS(0);
    return 0;
  }

  int ans = 0;
  REP(i, n) {
    if (isLeaf(i)) {
      int dt = dist_from_takahashi[i];
      int da = dist_from_aoki[i];
      if (dt < da) {
        int parent = G[i][0];
        ans = max(ans, dist_from_aoki[parent]);
      }
    }
  }

  ANS(ans);

  return 0;
}


Measured memory_bytes: 7168
#include<iostream>
using namespace std;
int mp[2][31][31]={};
int sai[7][4]= {{0,0,0,0},{3,5,4,2},{1,4,6,3},{1,2,6,5},{5,6,2,1},{3,6,4,1},{2,4,5,3}};

void die(int t,int f,int x,int y){
  int i,j,x2,y2,mx=3,f2,t2,dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
  mp[1][y][x]++;
  for(i=0;i<4;i++){
    if(sai[t][i]==f){
      for(j=i;j<i+4;j++){
	int m=j%4,x1=x+dx[j-i],y1=y+dy[j-i];
	if(mp[1][y][x]-1>mp[1][y1][x1]&&sai[t][m]>mx){
	  mx=sai[t][m],x2=x1,y2=y1,t2=7-mx;
	  if(j-i==2)f2=7-t;
	  else if(j-i==0)f2=t;
	  else f2=f;
	}
      }
      break;
    }
  }
  if(mx!=3)mp[1][y][x]--,die(t2,f2,x2,y2);
  else mp[0][y][x]=t;
}

int main(){
  while(1){
    int n;cin>>n;if(n==0)break;
    int i,j,t,f,c[7]={};
    for(i=0;i<n;i++){
      cin>>t>>f;
      die(t,f,15,15);
    }
    for(i=0;i<31;i++)
      for(j=0;j<31;j++){
	c[mp[0][i][j]]++;
	mp[0][i][j]=mp[1][i][j]=0;
      }
    for(i=1;i<6;i++)cout<<c[i]<<" ";cout<<c[6]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172