akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

template <class T> void read (T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  string s;
  cin >> s;
  if (s.size() <= 7)
    return puts("YES"), 0;
  for (int i = 0, cnt = 0; i < s.size(); i++) {
    if (s[i] == 'o') {
      if (++cnt + 15 - s.size() >= 8)
        return puts("YES"), 0;
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    int N = S.size();
    vector<pair<char, int>> run;
    int cnt = 1;
    rep(i, N - 1)
    {
        if (S[i] == S[i + 1])
        {
            cnt++;
        }
        else
        {
            run.push_back({S[i], cnt});
            cnt = 1;
        }
    }
    run.push_back({S.back(), cnt});
    int j = 0;
    rep(i, N)
    {
        if (!(S[i] == 'R' and S[i + 1] == 'L'))
        {
            cout << 0 << " ";
        }
        else
        {
            cout << (run[j].second + 1) / 2 + (run[j + 1].second) / 2 << " " << run[j].second / 2 + (run[j + 1].second + 1) / 2 << " ";
            i++;
            j += 2;
        }
    }
    return 0;
}

Measured memory_bytes: 1480
import fractions
A,B,C,D=map(int,input().split())
CD=(C*D)//(fractions.gcd(C,D))
A=A-1
num_B=B-B//C-B//D+B//CD
num_A=A-A//C-A//D+A//CD
print(int(num_B-num_A))

Measured memory_bytes: 5048
inp = list(map(int,input().split(" ")))
location = abs(inp[0])
times = inp[1]
distance = inp[2]

x = float(abs(location / distance))


if x >= times:
    print(abs(location - (times*distance)))
elif (times-int(x))%2==0:
    print(abs(location-abs(int(x)*distance)))
else:
    print(abs(location-abs(int(x)*distance)-distance))

Measured memory_bytes: 9108
<?php
    fscanf(STDIN,"%d%d%d",$N,$K,$Q);
    
    $array_a = array_fill(1,$N,0);
    
    for($i=1;$i<=$Q;$i++){
        $a = intval(trim(fgets(STDIN)));
        
        $array_a[$a]++;
    }
    //その人が何回正解しているのか
    // var_dump($array_a);
    
    $sum = array_sum($array_a);
    
    //自分の正解数ー全員の正解数＋＄Ｋが自分のスコアになる
    for($j=1;$j<=$N;$j++){
        $ans = $K + ($array_a[$j]-$sum);
        // echo $ans;
        if($ans<=0){
            echo "No\n";
        }else{
            echo "Yes\n";
        }
    }
    

?>

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

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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false); 
    int i,j;
    int h,w;
    cin >> h >> w;
    int ch, dh, cw, dw;
    cin >> ch >> cw >> dh >> dw;
    --ch, --cw, --dh, --dw;
    vector<string> s(h);
    rep(i,h) cin >> s.at(i);

    int INF = (1 << 30);

    vector<vector<int>> dp(h,vector<int>(w,INF));
    priority_queue<pair<int,pair<int,int>>> pq;

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

    pair<int,int> top = make_pair(ch, cw); //開始点
    dp.at(ch).at(cw) = 0;
    pq.emplace(0, top);
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        int nx = x.second.first;
        int ny = x.second.second;
        int dist = -x.first;
        if(dp.at(nx).at(ny) < dist) continue;

        rep(i,4){
            int x = nx + dx[i];
            int y = ny + dy[i];
            if(x < 0 || x >= h || y < 0 || y >= w) continue;
            if(s.at(x).at(y) == '#') continue;
            if(dp.at(x).at(y) > dist){
                dp.at(x).at(y) = dist;
                pq.emplace(-dist, make_pair(x, y));
            }
        }

        int nd = dist + 1;
        for(i = -2;i < 3;++i){
            for(j = -2;j < 3;++j){
                int x = nx + i;
                int y = ny + j;
                if(x < 0 || x >= h || y < 0 || y >= w) continue;
                if(s.at(x).at(y) == '#') continue;
                if(dp.at(x).at(y) > nd){
                    dp.at(x).at(y) = nd;
                    pq.emplace(-nd, make_pair(x, y));
                }
            }
        }
    }
    if(dp.at(dh).at(dw) == INF) cout << -1 << endl;
    else cout << dp.at(dh).at(dw) << endl;

    return 0;
}

Measured memory_bytes: 8504
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;




int main(){
    int n; ll k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    rep(i,n) A[i]--;
    
    vector<pii> count(n);
    
    int cur = 0;
    count[cur].first = 1;
    count[cur].second = 0;
    int ltime;
    bool done = false;
    for(int t = 0; t < n; t++){
        
        cur = A[cur];
        if (t+1 == k){
            cout << cur + 1;
            done = true;
            break;
        }
        if (count[cur].first == 1){
            ltime = t+1;
            break;
        }
        count[cur].first++;
        count[cur].second = t+1;
    }
    
    int looptime = ltime - count[cur].second;
    k -= ltime;
    k %= looptime;
    
    for(int t = 0; t < k; t++){
        cur = A[cur];
    }
    if (!done) cout << cur+1;
}










Measured memory_bytes: 5636
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

#define MAX 100000

struct TRAMP{
    char mark;
    int number,inputed_order;
};

TRAMP cards[MAX];

int n;

int Partition(int left,int right){
    int i = left-1,pivot = cards[right].number;
    for(int start = left; start < right; start++){
        if(cards[start].number <= pivot){
                i++;
                std::swap(cards[i],cards[start]);
        }
    }

    std::swap(cards[i+1],cards[right]);

    return i+1;
}

void quickSort(int left,int right){
    if(left < right){
        int q = Partition(left,right);
        quickSort(left,q-1);
        quickSort(q+1,right);
    }
}


int main(){

    bool stableFLG = true;
    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%s %d",&cards[i].mark,&cards[i].number);
        cards[i].inputed_order = i;
    }

    quickSort(0,n-1);

    for(int i = 1; i < n; i++){
        if(cards[i].number == cards[i-1].number && cards[i].inputed_order < cards[i-1].inputed_order){
        	stableFLG = false;
        	break;
        }
    }

    if(stableFLG){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    for(int i = 0; i < n; i++)   printf("%c %d\n",cards[i].mark,cards[i].number);
}



Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for(ll i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(ll i=0;i<(n);i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
struct mobile{
    ll rc;
    ll lc;
    ll l;
    ll r;
    ll w; 
};

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

int main(){
    while(true){
	ll n;
	cin >> n;
	if(n == 0) break;
	ll ans =0 ;
	vector< struct mobile > v(n);
	REP(i,n){
	    ll l,r,lc,rc;
	    cin >> l >> r >> lc >> rc;
	    v[i].l = l;
	    v[i].r = r;
	    v[i].lc = lc;
	    v[i].rc = rc;
	    v[i].w = 0;
	}
	bool flg = true;
	while(flg){
	    flg = false;
	    REP(i,n){
		if(v[i].w == 0 && v[i].rc == 0 && v[i].lc == 0){
		    ll r = v[i].r;
		    ll l = v[i].l;
		    v[i].r /= gcd(r,l);
		    v[i].l /= gcd(r,l);
		    v[i].w = v[i].r + v[i].l;
		    flg = true;
		}else{
		    ll lw,rw;
		    if(v[i].w > 0) continue;
		    if(v[i].lc == 0){
			lw = 1;
		    }else if(v[v[i].lc-1].w > 0){
			lw = v[v[i].lc-1].w;
		    }else continue;

		    if(v[i].rc == 0){
			rw = 1;
		    }else if(v[v[i].rc-1].w > 0){
			rw = v[v[i].rc-1].w;
		    }else continue;
		    ll r,l;
		    r = v[i].r;
		    l = v[i].l;
		    v[i].r /= gcd(r,l);
		    v[i].l /= gcd(r,l);
		    ll w = 1000000000000000;
		    
		    FOR(j,1,1000000){
			if((lw*v[i].l*j) % v[i].r == 0){
			    if(((lw*v[i].l*j)/v[i].r ) % rw == 0){
				w =  lw*j + (lw*v[i].l*j)/v[i].r;
				/*
				printf("l = %d r = %d\n",v[i].l,v[i].r);
				printf("lw = %d rw = %d\n",lw*j,(lw*v[i].l*j)/v[i].r);
				printf("w = %d j = %d\n",w,j);
				*/
				break;
			    }
			}
			if(w < (1<<31)) break;
		    }
		    v[i].w = w;
		    flg = true;
		}
		ans = max(ans,v[i].w);
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{    
    int n;
    cin >> n;
    vector<int> a(n-1);
    vector<int> b(n-1);
    vector<vector<pair<int,int>>> g(n);
    rep(i,n-1)
    {
        int ai, bi;
        cin >> ai >> bi;
        a[i] = ai-1;
        b[i] = bi-1;
        g[ai-1].push_back({bi-1, -1});
        g[bi-1].push_back({ai-1, -1});
    }
    int k = 0;

    bool seen[n] = {false};
    queue<int> que;
    que.push(0);

    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        if(seen[v]) continue;
        seen[v] = true;

        k = max(k, (int)g[v].size());
        bool used[k] = {false};
        int m = g[v].size();

        rep(i,m)
        {
            int ci = g[v][i].second;
            if(ci >= 0) used[ci] = true;
        }

        int next_c = 0;
        rep(i,m)
        {
            int ci = g[v][i].second;
            if(ci >= 0) continue;

            while(used[next_c]) next_c++;

            int nv = g[v][i].first;
            g[v][i].second = next_c;
            rep(j,g[nv].size()) 
            {
                if(g[nv][j].first == v)
                {
                    g[nv][j].second = next_c;
                    break;
                }                
            }

            next_c++;
            que.push(nv);
        }       
    }

    cout << k << endl;
    rep(i,n-1)
    {
        int ai = a[i];
        int bi = b[i];
        rep(j,g[ai].size())
        {
            if(g[ai][j].first == bi)
            {
                cout << g[ai][j].second + 1 << endl;
                break;
            }
        }
    }
    return 0;
}

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

const int INF = 1e9;
int main(){
	int n,m;
	cin >> n >> m;
	
	vector<pair<int,int>> key(m);
	rep(i,m){
		int a,b;
		cin >> a >> b;
		int s = 0;
		rep(j,b){
			int c;
			cin >> c;
			--c;
			s |= 1<<c;
		}
		key[i] = make_pair(s,a);
	}

	vector<int> dp(1<<n, INF);
	dp[0] = 0;
	rep(s,1<<n){
		rep(i,m){
			int t = s | key[i].first;
			dp[t] = min( dp[t] , dp[s] + key[i].second );
		}
	}
	int res = dp.back();
	if(res==INF) res = -1;
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var s string

func main() {
	fmt.Scan(&s)
	ans := make([]string, 0, len(s))

	for i := 0; i < len(s); i++ {
		if string(s[i]) != "B" {
			ans = append(ans, string(s[i]))
		} else {
			if 0 <= len(ans)-1 {
				ans = ans[0 : len(ans)-1]
			}
		}
	}
	for _, value := range ans {
		fmt.Printf("%s", value)
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  cin >> n;
  vector<uint64_t> a(n);

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

  uint64_t sum = a[0];
  for (int i = 1; i < n; i++) {
    sum ^= a[i];
  }

  vector<uint64_t> ans(n);
  for (int i = 0; i < n; i++) {
    ans[i] = sum ^ a[i];
  }

  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << ' ';
  }
  cout << ans[n - 1] << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 6320
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

void dfs(vector<vector<int>> &G, vector<int> &d, int par = -1, int cur = 0, int depth = 0){
    d[cur] = depth;
    for(int v: G[cur]){
        if(v != par){
            dfs(G, d, cur, v, depth + 1);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, K;
    cin >> N >> K;
    vector<vector<int>> G(N);
    rep(i, N - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b), G[b].pb(a);
    }
    
    vector<vector<int>> d(N, vector<int>(N, 0));
    
    rep(i, N) dfs(G, d[i], -1, i);
    
    int m = 0;
    rep(i, N) rep(j, N) m = max(m, d[i][j]);
    if(m <= K){
        output(0, 0);
        return 0;
    }
    
    int ret = inf;
    rep(i, N) rep(j, N) {
        if(d[i][j] == K){
//            cout << i << ", " << j << endl;
            int cnt = 0;
            rep(k, N) if(d[i][k] > K || d[j][k] > K) cnt++;
            ret = min(ret, cnt);
        }
    }
    output(ret, 0);
    
    
    
    return 0;
}

Measured memory_bytes: 16256
n, m = map(int, input().split())
red = [0]*n
ball = [1]*n
red[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    if red[x-1] == 1:
        red[y-1] = 1
        if ball[x-1] == 1:
            red[x-1] = 0
    ball[y-1] += 1
    ball[x-1] -= 1
print(sum(red))


Measured memory_bytes: 10372
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

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


Measured memory_bytes: 3072
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    P = list(map(int, sys.stdin.buffer.readline().split()))

    ret = 0
    tmp = float('inf')
    for p in P:
        if tmp > p:
            ret += 1
            tmp = p

    print(ret)


if __name__ == '__main__':
    main()


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

vector<int> n;
void mkn(){
  n.push_back(1);
  for(int i=2;n[i-2]<1005000;i++){
    n.push_back(i*(i+1)*(i+2)/6);
  }
}


vector<int> dp;
vector<int> dp2;
void mktable(){
  dp.resize(1000100);
  dp2.resize(1000100);
  for(int i=0;i<dp.size();i++){
    dp[i]=1000100;
    dp2[i]=1000100;
  }
  dp[0]=dp2[0]=0;
  for(int i=0;i<n.size();i++){
    for(int j=0;j<dp.size();j++){
      if(n[i]%2==1){
        if(j-n[i]>=0){
          dp2[j]=min(dp2[j],dp2[j-n[i]]+1);
        }else{
          dp2[j]=dp2[j];
        }
      }
      if(j-n[i]>=0){
        dp[j]=min(dp[j],dp[j-n[i]]+1);
      }else{
        dp[j]=dp[j];
      }
    }
  }
}

void init(){
  n.clear();
  dp.clear();
  mkn();
  mktable();
}

bool solve(){
  int a;
  cin>>a;
  if(a==0){
    return false;
  }
  cout<<dp[a]<<" "<<dp2[a]<<endl;
  return true;
}
int main(){
  init();
  while(solve());
}

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

int N,K;
int i,cnt;//for

int main(){
  cin>>N>>K;
  vector<int> p(N);
  for(i=0;i<N;i++)
    cin>>p.at(i);

  sort(p.begin(),p.end());
  for(i=0;i<K;i++){
    cnt+=p.at(i);
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3588
//FINISH WHAT YOU START!
#include<bits/stdc++.h>

#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define inf ((long long) 1e18 )
#define mod 1000000007
#define int long long
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x << " = " << x << " & "<< #y <<" = "<< y << '\n';

using namespace std;

const int N = 1e5 + 7;

int32_t main() {
	IOS
#ifndef ONLINE_JUDGE
	fileIO
#endif
	auto start = std::chrono::high_resolution_clock::now();
	int test;
	test = 1;
	// cin >> test;
	while (test--) {
		int n;
		cin >> n;
		int a[n];
		for (auto &i : a)
			cin >> i;
		int pre[n] = {0};
		pre[n - 1] = a[n - 1];
		for (int i = n - 2; i >= 0 ; i--)
			pre[i] = (a[i] + pre[i + 1]) % mod;
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			ans = (ans + (a[i] * pre[i + 1]) % mod ) % mod;
		}
		cout << ans << endl;
	}

	auto stop = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);

	cerr << "Time taken : " << ((long double)duration.count()) / ((long double) 1e9) << "s " << endl;

	return 0;
}


Measured memory_bytes: 6920
#include<stdio.h>

int main(){

    int N;
    scanf("%d", &N);

    char S[N+1], T[N+1];
    scanf("%s %s", S, T);

    for (int i = 0; i < N; i+=1){
        printf("%c",S[i]);
        printf("%c",T[i]);
    }

    return 0;
}

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

int main(void)
{
  int n;
  cin >> n;
  
  vector<int> x, d;
  for(int i=0; i<n+1; i++){
      int tmp;
      cin >> tmp;
      x.push_back(tmp);
  }
  sort(x.begin(), x.end());
  
  for(int i=0; i<n; i++){
      d.push_back(abs(x[i] - x[i+1]));
  }
  sort(d.begin(), d.end());
  
  for(int val=d[0]; val>0; val--){
    int i;
    for(i=0; i<n; i++){
        if(d[i] % val != 0)
          break;
    }  
    if(i==n){
        cout << val << endl;
        return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;

static const int MAX = 100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];

void floyd(){
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if(d[j][i]==INFTY)continue;
for(int k=0;k<n;k++){
if(d[i][k]==INFTY)continue;
d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
}
}
}

int main(){
int times,a,b,now;

cin>>n>>times;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if(i==j)d[i][j] = 0;
else d[i][j] = INFTY;
}

while(times--){
cin>>a>>b>>now;
d[a][b] = now;
}
floyd();

bool negative = false;

for(int i=0;i<n;i++)
if(d[i][i]<0)negative = true;
if(negative)cout<<"NEGATIVE CYCLE"<<endl;

else{
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(j)cout<<" ";
if(d[i][j]==INFTY)cout<<"INF";
else cout<<d[i][j];
}
cout<<endl;
}
}
return 0;
}



Measured memory_bytes: 3164
#include <iostream>
using namespace std;
string S;
int ne[200010][26] = {{0}};
int dp[200010] = {0},inf = 1e9;

int main(){
	cin >> S;
	int N = S.size();
	for(int i=0;i<=N+1;i++){
		dp[i] = inf;
		for(int j=0;j<26;j++){
			ne[i][j] = N;
		}
	}
	dp[N] = 1;
	dp[N+1] = 0;
	for(int i=N-1;i>=0;i--){
		for(char c='a';c<='z';c++){
			if(S[i]==c) ne[i][c-'a'] = i;
			else ne[i][c-'a'] = ne[i+1][c-'a'];
		}
	}
	for(int i=N-1;i>=0;i--){
		for(int j=0;j<26;j++){
			dp[i] = min(dp[i],dp[ne[i][j]+1]+1);
		}
	}
	string ans = "";
	int id = 0;
	while(ans.size()<dp[0]){
		for(char c='a';c<='z';c++){
			if(dp[id]==dp[ne[id][c-'a']+1]+1){
				ans = ans+c;
				id = ne[id][c-'a']+1;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 21636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string o, s;
  cin >> o >> s;
  
  int n=o.size();
  int m=s.size();
  for(int j=0; j<n-1; j++){
    cout << o[j] << s[j];
  }
  
  if(n==m){
    cout << o[n-1] << s[n-1];
  }
  else{
    cout << o[n-1];
  }
  
}

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

using namespace std;

int main() {

	string str;
	int count[27] = { 0 };
	int i = 0;

	getline(cin,str);

	while (str[0] != 0) {

		i = 0;

		while (str[i] != 0) {

			if (str[i] >= 65 && str[i] <= 90) {

				count[str[i] - 65]++;

			}
			else if (str[i] >= 97 && str[i] <= 122) {

				count[str[i] - 97]++;

			}

			i++;

		}

		getline(cin, str);

	}

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

		cout << char(97 + i) << " : " << count[i] << endl;

	}


	return 0;

}


Measured memory_bytes: 3184
import java.util.Scanner;
 
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x%500;
    int c = b%5;
    System.out.println(a*1000+b-c);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
int main(){
	string s;cin>>s;
	int n=s.size();
	int ans=1001;
	for(int i=0;i+2<n;++i){
		int curr=s[i]-'0';
		curr*=100;
		curr+=(s[i+1]-'0')*10;
		curr+=(s[i+2]-'0');
		ans=min(ans,abs(curr-753));
	}
	cout<<ans<<"\n";
	return 0;
}



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

h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]


dp = [0] * -~w
dp[0] = 1 << 6400
for i in range(h):
    for j in range(w):
        t = dp[j]
        if j:
            t |= dp[j-1]
        x = abs(a[i][j] - b[i][j])
        dp[j] = (t << x) | (t >> x)

for i, x in enumerate(bin(dp[w-1])[-6401:]):
    if int(x):
        print(i)
        exit(0)
















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

#include <cstdio>
#include <stack>

using namespace std;

const int MAX_W = 103, MAX_H = 103;

int num[10];
bool res = false;
stack<int> left, right;

void dfs(int i){
    if(i == 10){
        res = true;

        return;
    }

    if(num[i] > left.top()) {
        left.push(num[i]);
        dfs(i+1);
        left.pop();
    }

    if(num[i] > right.top()){
        right.push(num[i]);
        dfs(i+1);
        right.pop();
    }
}

void solve(){

    left.push(0);
    right.push(0);
    dfs(0);
    if(res) printf("YES\n");
    else printf("NO\n");
}

int main(){
    int T;
    scanf("%d", &T);
    while(T--){

        for(int i = 0;i < 10;i++){
            scanf("%d", &num[i]);
        }
        res = false;
        solve();
    }
    return 0;
}

/*
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
 */


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

void solve(long long N)
{
    cout << (N <= 999 ? "ABC" : "ABD") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,sum;
int main()
{
	fast;
	cin>>n;
	int n1=n;
	while (n1!=0)
	{
		sum+=n1%10;
		n1/=10;
	}
	if (n%sum==0)
	   cout<<"Yes";
	else
	   cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define M_PI			3.1415926535897932384626433832795		// 円周率
#define D_TRY_CNT		100										// 試行回数

// 内部変数
static FILE *szpFpI;											// 入力
static double sdSize;											// １辺サイズ
static double sdH;												// 高さ
static double sdWater;											// 水

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 水取得 - 三角形
double
fGetWaterT(
	double pdH					// <I> 高さ
)
{
	return sdH * pdH / 2.0 * sdSize;
}

// 水取得 - 台形
double
fGetWaterD(
	double pdU					// <I> 上底
)
{
	return (pdU + sdH) * sdSize / 2.0 * sdSize;
}

// 実行メイン
double
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 条件 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lf%lf%lf", &sdSize, &sdH, &sdWater);

	// 高さ０時の水
	double ldZero = fGetWaterT(sdSize);

	// 初期範囲
	double ldMin = 0.0;
	double ldMax;
	if (sdWater < ldZero) {
		ldMax = sdSize;
	}
	else {
		ldMax = sdH;
	}

	// 範囲を絞る
	double ldAvg;
	for (i = 0; i < D_TRY_CNT; i++) {
		ldAvg = (ldMin + ldMax) / 2.0;

		// 水の量
		double ldWater;
		if (sdWater < ldZero) {
			ldWater = fGetWaterT(ldAvg);
		}
		else {
			ldWater = fGetWaterD(ldAvg);
		}

		// 範囲を絞る
		if (sdWater < ldWater) {
			ldMax = ldAvg;
		}
		else {
			ldMin = ldAvg;
		}
	}

	// 高さ
	if (sdWater >= ldZero) {
		ldAvg = sdSize * sdH / (sdH - ldAvg);
	}

	// 角度
	return atan2(sdH, ldAvg) / M_PI * 180.0;
}

// １回実行
int
fOne(
)
{
	double ldRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	ldRet = fMain();

	// 出力
	sprintf(lc1Buf, "%.7lf\n", ldRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main(){
    int a,b,c;
    int cnt5 =0;
    int cnt7 = 0;
    scanf("%d %d %d", &a, &b, &c);
    
    if (a == 5)
        cnt5++;
    if (a == 7)
        cnt7++;
    if (b == 5)
        cnt5++;
    if (b == 7)
        cnt7++;
    if (c == 5)
        cnt5++;
    if (c == 7)
        cnt7++;
    if (cnt5 == 2 && cnt7 == 1)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};




int main(){

  int n,m,Q;
  cin >> n >> m >> Q;
  vector<vector<int>> s(n+1,vector<int>(n+1,0));
  vector<vector<int>> a(n+1,vector<int>(n+1,0));
  REP(i,m){
    int l,r;cin >> l >> r;
    a[l][r]++;
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + a[i+1][j+1];
    }
  }
  REP(i,Q){
    int l,r;cin >> l >> r;
    cout << s[r][r] - s[r][l-1] - s[l-1][r] + s[l-1][l-1] << endl;
  }






  



  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define inf    0x3f3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef vector<int>      vi;
typedef vector<bool>     vb;
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

  int main(){

   int n; cin>>n;
   string s; cin>>s;

   ll r=0,cnt=0;

   for(int i=0;i<n;i++){
      if(s[i] == 'R')
            r++;
   }

   for(int j=0;j<r;j++){
      if(s[j] == 'W')
      cnt++; }

    cout<<cnt<<endl;

  return 0;
  }

Measured memory_bytes: 3700
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
	long long x, n, sum=0, tmp=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		tmp+=x;
		if(x==0||i==n-1){
			sum+=tmp/2;
			tmp=0;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
group_of_s = []
for _ in range(M):
    s = list(map(int,input().split()))[1:]
    group_of_s.append(s)
p = list(map(int,input().split()))
# print("長さは",len(group_of_s))
def lighton(n,s,p):
    on_num = 0
    for si in s:
        # print("n,si,s,pは",n,si,s,p)
        if n>>(si-1)&1 == 1:
            on_num +=1
        else:
            continue
    if on_num%2 == p:
        # print("true")
        return True
    else:
        # print("false")
        return False
ans = 0
for i in range(2**N):
    dummy = 0
    # print(i)
    for j in range(len(group_of_s)):
        # print(i,j)
        if lighton(i,group_of_s[j],p[j])==True:
            # print(i,k[j],p[j])
            dummy += 1
        else:
            break
    if dummy == M:
        ans += 1

print(ans)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
//#define int long long


inline void solve(){

    ll l, r;

    cin >> l >> r;
    ll mini = LINF;
    for(ll i = l; i < r; i++) {
        for(ll j = i+1; j <= r; j++) {
            ll tmp = i*j%2019;
            chmin(mini,tmp);
            if(tmp==0) {
                i = j = r+10;
            }
        }
    }

    cout << mini fin;
    
}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {

    input!{
        s: String,
    };

    let pt = ["eraser", "erase", "dreamer", "dream"];
    let s = pt.iter().fold(s, |s,x| s.replace(x,""));

    println!("{}", if s.is_empty(){"YES"}else{"NO"});

}


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

int main(){
	int n, k, num, max, ksum, i;
	while(true){
		cin>>n>>k;if(n==0&&k==0)break;
		queue<int> q;
		max=0;
		for(i=0;i<k;i++){
			cin>>num;
			q.push(num);
			max+=num;
			
		}
		ksum=max;
		for(i=k;i<n;i++){
			cin>>num;
			q.push(num);
			ksum -= q.front();
			q.pop();
			ksum += num;
			if(max<ksum) max = ksum;
		}
		cout<<max<<endl;
	}
	return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n, tail_a = 0, head_b = 0, both = 0;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  fi(0, n) {
    cin >> s;
    int len = s.size();
    if(s[0] == 'B' && s[len - 1] == 'A')
      both++;
    else if(s[0] == 'B')
      head_b++;
    else if(s[len - 1] == 'A')
      tail_a++;
    fi(0, len - 1) {
      if(s[i] == 'A' && s[i + 1] == 'B') {
        ans++;
        i++;
      }
    }
  }
  // A both both ... both B
  // A B
  // A B
  // A B
  // A
  // A
  ans += min(tail_a, head_b) + both;
  if(tail_a == 0 && head_b == 0 && both) ans--;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if (a == c) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  string S;
  cin >>S;
  int sum=0;
  for(int i=0;i<4;i++){
    if(S[i]=='+') sum++;
    else sum--;
  }
  cout << sum<<endl;
}


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

const int MAX = 1000000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
  ios::sync_with_stdio(false);
  int X, Y;
  cin >> X >> Y;
  if ((X + Y) % 3) {
    cout << 0 << endl;
    return 0;
  }

  int M = (2 * X - Y) / 3;
  int N = (2 * Y - X) / 3;
  // cout << "M=" << M << " N=" << N << endl;
  if (M < 0 || N < 0) {
    cout << 0 << endl;
    return 0;
  }
  COMinit();
  cout << COM(M + N, N) << endl;
  return 0;
}


Measured memory_bytes: 23680
main :: IO ()
main = do
  [a,b,c] <- words <$> getLine
  if partShiritori a b && partShiritori b c then
    putStrLn "YES"
    else
    putStrLn "NO"    
    where
      partShiritori :: String -> String -> Bool
      partShiritori a b = last a == head b


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

using namespace std;

#define fr first
#define sc second
#define pb push_back

typedef pair<int, int> Pii;

int h, w, d, n;
char mp[51][51];
int r[11];
int data[51][51] = {{0}};
int sx, sy;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

int bfs(int gy, int gx)
{
  bool used[51][51] = {{0}};
  queue<Pii> q;
  q.push(Pii(sy, sx));

  while ( !q.empty() ) {
    Pii p = q.front(); q.pop();
    int y = p.fr, x = p.sc;

    // cout << y << " " << x << endl;
    
    if ( y == gy && x == gx ) {
      return true;
    }

    if ( used[y][x] ) continue;
    used[y][x] = true;

    for ( int i = 0; i < 4; i++ ) {
      int ny = y + dy[i], nx = x + dx[i];
      if ( nx < 0 || ny < 0 || nx >= w || ny >= h || mp[ny][nx] == '#' ) continue;
      q.push(Pii(ny, nx));
    }
  }

  return false;
}

int main()
{
  cin >> h >> w >> d >> n;

  for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      cin >> mp[i][j];
      if ( mp[i][j] == 'D' ) {
	sx = j;
	sy = i;
      }
    }
  }

  for ( int i = 0; i < d; i++ ) cin >> r[i];
  r[d] = 51;

  for ( int k = 0; k < n; k++ ) {
    int x, y, s;
    cin >> x >> y >> s;
    for ( int i = max(0, y - r[s]); i <= min(h-1, y + r[s]); i++ ) {
      for ( int j = max(0, x - r[s]); j <= min(w-1, x + r[s]); j++ ) {
	if ( s > 0 && (i >= y - r[s - 1] && j >= x - r[s - 1] && i <= y + r[s - 1] && j <= x + r[s - 1]) ) continue;
	data[i][j]++;
      }
    }
  }

  /*for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      cout << data[i][j];
    }
    cout << endl;
    }*/

  vector<Pii> gl;
  for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      if ( data[i][j] == n && mp[i][j] != '#' ) gl.pb(Pii(i, j));
    }
  }

  if ( gl.size() == 0 ) {
    cout << "Broken" << endl;
    return 0;
  }

  //cout << gl.size() << endl;
  int cnt = 0;
  for ( int i = 0; i < gl.size(); i++ ) {
    if ( bfs(gl[i].fr, gl[i].sc) ) cnt++;
  }

  if ( cnt == gl.size() ) cout << "Yes" << endl;
  else if ( cnt == 0 ) cout << "No" << endl;
  else cout << "Unknown" << endl;

  return 0;  
}

Measured memory_bytes: 3184
H, W, K = map(int, input().split())

mp = [input() for _ in range(H)]

memo = [[0]*W for _ in range(H)]

cnt = 0
for i in range(H):
  if '#' in mp[i]:
    cnt += 1
    tmp = 0
    for j in range(W):
      if mp[i][j] == '#':
        if tmp > 0:
          cnt += 1
        tmp += 1
      memo[i][j] = cnt
  else:
    if i > 0:
      memo[i] = memo[i-1]
      
nz = 0
for i in range(H):
  if memo[i][0] > 0:
    nz = i
    break
    
if nz > 0:
  for i in range(nz, 0, -1):
    memo[i-1] = memo[i]
  
for i in range(H):
  print(" ".join(map(str, memo[i])))

Measured memory_bytes: 74732
#include <stdio.h>

int main(){
    int a, b, k;
    int i, j = 0;

    scanf("%d %d %d",&a,&b,&k);

    i = (a < b) ? a : b;
    while(1){
        if(a%i == 0 && b%i == 0) { 
            j++;
            if(k == j) {
                printf("%d", i);
                break;
            }
        }
        i--;
    }
    
}

Measured memory_bytes: 128
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__
N,*a=$<.map &:to_i;
a.map{x,y=a.pop 2;a.unshift x==y ?x:(x-y).abs}while a[1];
p *a
__END__


Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1, ans = 0;
	// cin >> t;
	while (t--)
	{
		int n, a, b;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			a -= b;
			if (a == 0) ans++;
			else {
				ans = 0;
			}
			if (ans >= 3) break;
		}
		if (ans >= 3) cout << "Yes\n";
		else cout << "No\n";

	}
	return 0;
}

Measured memory_bytes: 3648