akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;
    cin>>k;
    rep(i,k)cout<<"ACL";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3664
n = gets.to_i
arr = gets.split(' ').map(&:to_i)
flag = true
i = 0
num_swap = 0

while(flag)
  flag = false
  num_i = n - 1
  while(num_i >= (i + 1)) do
    v = arr[num_i]
    if v < arr[num_i - 1]
      arr[num_i] = arr[num_i - 1]
      arr[num_i - 1] = v
      num_swap += 1
    end
    flag = true
    num_i -= 1
  end
  i += 1
end

puts arr.join(' ')
puts num_swap



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int x, y; cin >> x >> y;
  if(x <= 8 && y <=8) cout << "Yay!"<< endl;
  else cout << ":(" << endl;

  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e3+10,Mod=1e9+7;
ll dp[maxn][maxn];
char arr[maxn][maxn];
int h,w;
ll solve(int i,int j)
{
    if(i == h && j==w)
        return 1;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll x=0,y=0;
    if(arr[i][j+1]=='.')
        x = solve(i,j+1)%Mod;
    if(arr[i+1][j]=='.')
        y = solve(i+1,j)%Mod;
    return dp[i][j]=(x+y)%Mod;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>h>>w;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin>>arr[i][j];
        }
    }
    cout<<solve(1,1)<<endl;
}


Measured memory_bytes: 9344
N, x = map(int, input().split())
As = list(map(int, input().split()))
r = 0
a = As[0]
if a > x:
  r += a-x
  p = x
else:
  p = a
#print(p)
for i in range(1, N):
  a = As[i]
  if p+a > x:
    r += p+a-x
    p = a-(p+a-x)
  else:
    p = a
  #print(p)
print(r)


Measured memory_bytes: 14592
n = int(input())
A = list(map(int, input().split()))
set_A = set(A)

ans = 1

if n%2==0:
  if n//2 != len(set(A)):
    ans = 0
else:
  if A.count(0)!=1:
    ans = 0
  
  set_A.remove(0)
  if (n-1)//2 != len(set_A):
    ans = 0
      
if ans!=0:
  ans = 2**(len(set_A))

print(ans%(10**9+7))

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

    ll x, a, b, n;cin >> x >> a >> b >> n;
    ll ans = x;
    REP(i, n){
        string str;cin >> str;
        if(str == "nobiro")ans += a;
        else if(str == "tidime")ans += b;
        else ans = 0;

        ans = max(ans, 0LL);
    }

    cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3228
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n;
string s;
Int p[1 << 18];
Int winner[19][1 << 18];
Int fight(Int a, Int b){
    if(a < b)swap(a, b);
    if(s[a-b -1] == '0')return b;
    else return a;
}

int main(){
    cin >> n;
    cin >> s;
    for(int i = 0;i < (1<<n);i++){
        cin >> p[i];
        winner[0][i] = p[i];
    }
    for(int i = 1;i <= n;i++){
        for(int j = 0;j < (1<<n);j++){
            winner[i][j] = fight(winner[i-1][j], winner[i-1][(j + (1 << (i-1))) % (1<<n)]);
            if(i == n)cout << winner[i][j] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 44388
n = int(input())
a = list(map(int, input().split()))

ans=0
while True:
  ok_flg=True
  for i in range(n):
    if a[i]%2==0:
      a[i] = a[i]//2
    else:
      ok_flg=False
  if not ok_flg:
    break
  ans+=1
print(ans)
      

Measured memory_bytes: 3060
import itertools

n,m=map(int,input().split())
g=[list(map(int,input().split())) for _ in range(m)]
v=list(itertools.permutations(range(1,n+1)))

ans=0

for x in v:
    tf=True
    if x[0]!=1:
        tf=False
    else:
        for i in range(n-1):
            if not ([x[i],x[i+1]] in g or [x[i+1],x[i]] in g):
                tf=False
                break
    if tf:
        ans+=1
print(ans)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int r;
    cin>>r;
    cout<<r*r<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "
int main()
{
    int n, k;
    cin >> n >> k;
    cout << (n-k+1) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

using ll = long long;

int N;
ll A[301][301];
ll G[301][301];
bool a = true;

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            ll elem;
            cin >> elem;
            A[i][j] = elem;
            G[i][j] = elem;
        }
    }

    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                if (i != k && j != k && A[i][k]) {
                    if (A[i][k] + A[k][j] == A[i][j]) { G[i][j] = 0; }
                    else if (A[i][k] + A[k][j] < A[i][j]) { a = false; }
                }
            }
        }
    }

    ll res = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            res += G[i][j];
        }
    }

    if (a && res >= 2) { cout << res / 2 << endl; }
    else { cout << -1 << endl; }

    return 0;
}

Measured memory_bytes: 1664
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-12;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    double a,b,x;
    cin>>a>>b>>x;
    double w=atan(b/a);
    if(x>a*a*b/2){
        double l=0,r=w;
        while(r-l>EPS){
            double h=(l+r)/2;
            if(a*a*b-a*a*tan(h)*a/2<x)r=h;
            else l=h;
        }
        cout<<shosu(9)<<l/PI*180<<endl;
    }else{
        double l=w,r=PI/2;
        while(r-l>EPS){
            double h=(l+r)/2;
            if(a*b*b*tan(PI/2-h)/2<x)r=h;
            else l=h;
        }
        cout<<shosu(9)<<l/PI*180<<endl;

    }
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3112
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

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

  ll ans = 0;
  for(ll n = 1; n * (n+1) < N; n++)
    if(N % n == 0) ans += N / n - 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int N, K;

	cin >> N >> K;

	int A[N];

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

	sort(A, A+N);

	int mi;

	for(mi = 0; mi < N; mi ++){
		if( A[mi] != A[0]) {
			mi--;
			break;
		}
	}

	cout << ( N - 2 - mi) / ( K - 1) + 1 << endl;

	return 0;
}


Measured memory_bytes: 640
def tansaku(graph,v,v_num,visited,stack):
    visited[v] = True
    stack[v] = True
    for i in range(0,v_num):
        if(graph[v][i] == 1):
            if(visited[i]==False):
                if(tansaku(graph,i,v_num,visited,stack)==True):
                    return True
            elif(stack[i]==True):
                return True
    stack[v] = False
    return False

if __name__ == '__main__':
    v_num,e_num = map(int, input().split())
    graph = [ [0] * v_num for i in range(v_num)]
    for i in range(e_num):
        s,t = map(int, input().split())
        graph[s][t] = 1
    
    closed_cycle_is_found=False
    visited = [False]*v_num
    stack = [False]*v_num
    for i in range(v_num):
        for j in range(v_num):
            if(graph[i][j]==1 and visited[j]==False):
                if(tansaku(graph,j,v_num,visited,stack) == True):
                    closed_cycle_is_found=True
                    break

    if(closed_cycle_is_found):
        print("1")
    else:
        print("0")



Measured memory_bytes: 5692
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
        int idx = 1;
        for (int x : a) {
            map.put(x, idx);
            idx++;
        }
        for (Entry<Integer, Integer> entry : map.entrySet()) {
            System.out.print(entry.getValue() + " ");
        }
    }

}


Measured memory_bytes: 72064
from functools import lru_cache

N, X = map(int, input().split())

@lru_cache(maxsize=None)
def length(level):
    if level <= 0:
        return 1
    return length(level - 1) * 2 + 3

@lru_cache(maxsize=None)
def search(level, right):
    if level == 0:
        return 1

    ret = 0
    right -= 1
    if length(level - 1) <= right:
        ret += search(level - 1, length(level - 1))
        right -= length(level - 1)

        if right > 0:
            ret += 1
        right -= 1

    if 0 < right:
        ret += search(level - 1, right)
    return ret

print(search(N, X))


Measured memory_bytes: 3932
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int a[n];

  for (int i = 0; i < n; i++) cin >> a[i];
  cout << a[n - 1];
  for (int i = n - 2; i >= 0; i--) cout << " " << a[i];
  cout << endl;

  return (0);
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	string A, B, C;
	cin >> A >> B >> C;

	int a, b;
	a = A.size();
	b = B.size();

	if (A[a-1]==B[0] && B[b-1] == C[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intAbs(x int) int {
	return int(math.Abs(float64(x)))
}

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt()
	}
	sort.Ints(A)

	index, abs := 0, intAbs((A[N-1]/2)-A[0])
	if A[N-1]%2 == 1 {
		abs = intMin(intAbs((A[N-1]/2+1)-A[0]), abs)
	}
	for i, a := range A {
		if b := intAbs((A[N-1] / 2) - a); b < abs {
			abs = b
			index = i
		}
		if A[N-1]%2 == 1 {
			if b := intAbs((A[N-1] / 2) + 1 - a); b < abs {
				abs = b
				index = i
			}
		}
	}
	fmt.Println(A[N-1], A[index])
}


Measured memory_bytes: 4268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void distinct(vector<string> &vect) {
	sort(vect.begin(), vect.end());
	vect.erase(unique(vect.begin(), vect.end()), vect.end());
	
	return;
}

int main() {
	int N;
	cin >> N;
	
	vector<string> S;
	string temp;
	
	for (int loop = 0; loop < N; loop++){
		cin >> temp;
		S.push_back(temp);
	}
	
	distinct(S);
	
	cout << S.size() << endl;
	
	return 0;
}

Measured memory_bytes: 11676
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

even = [v[i] for i in range(n) if i % 2 == 0]
odd = [v[i] for i in range(n) if i % 2 == 1]
ecnt = Counter(even).most_common() + [(0, 0)]
ocnt = Counter(odd).most_common() + [(0, 0)]

if ecnt[0][0] == ocnt[0][0]:
    print(n - max(ecnt[0][1] + ocnt[1][1], ecnt[1][1] + ocnt[0][1]))
else:
    print(n - ecnt[0][1] - ocnt[0][1])


Measured memory_bytes: 21340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int cnt = 500;
ll n;
struct Point {
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
};

vector<Point> pv;

double dist(Point p, Point q) {
  double dx = p.x - q.x, dy = p.y - q.y;
  return sqrt(dx * dx + dy * dy);
}

double f(Point p) {
  double res = 0;
  REP(i, n) { res = max(dist(p, pv[i]), res); }
  return res;
}

double g(double x) {
  double l = 0, r = 1000;
  REP(_, cnt) {
    double c1 = (2 * l + r) / 3.0, c2 = (l + 2 * r) / 3.0;
    if (f(Point(x, c1)) < f(Point(x, c2))) {
      r = c2;
    } else {
      l = c1;
    }
  }
  return f(Point(x, r));
}

int main() {
  cin >> n;
  pv = vector<Point>(n);
  REP(i, n) { cin >> pv[i].x >> pv[i].y; }

  double l = 0, r = 1000;
  REP(i, cnt) {
    double c1 = (2 * l + r) / 3.0, c2 = (l + 2 * r) / 3.0;
    if (g(c1) < g(c2)) {
      r = c2;
    } else {
      l = c1;
    }
  }

  cout << fixed << setprecision(10) << g(r) << endl;
}

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

int N, L;
string S;
char A[19], B[19];
unordered_map<
  string,
  pair<long long, long long>> C;
long long R;

int main() {
  cin >> N >> S; L = 1 << N;
  for(int s = 0; s < L; ++s) {
    int a = 0, b = 0;
    for(int i = 0, pi = 1; i < N; ++i, pi *= 2) {
      ((s & pi) ? A[a++] : B[b++]) = S[i];
    }
    A[a] = B[b] = '\0';
    ++C[string(A) + '$' + string(B)].first;
  }
  for(int s = 0; s < L; ++s) {
    int a = 0, b = 0;
    for(int i = 0, pi = 1; i < N; ++i, pi *= 2) {
      ((s & pi) ? A[a++] : B[b++]) = S[2 * N - 1 - i];
    }
    A[a] = B[b] = '\0';
    ++C[string(A) + '$' + string(B)].second;
  }
  for(auto& kv : C) {
    R += kv.second.first * kv.second.second;
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 72308
#include<iostream>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> coordinate;
#define mp make_pair

int main() {
    ll count[10] = {0};
    ll H, W, N, a, b;
    map<coordinate, ll> MP;
    cin >> H >> W >> N;
    count[0] = (H - 2) * (W - 2);
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                ll nh = a - j, nw = b - k;
                if (nh >= 1 && nh <= H - 2 && nw >= 1 && nw <= W - 2) {
                    coordinate c = mp(nh, nw);
                    count[MP[c]]--;
                    MP[c]++;
                    count[MP[c]]++;
                }
            }
        }
    }
    for (int i = 0; i < 10; i++) {
        cout << count[i] << endl;
    }
    return 0;
}

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

int main() {
  string s, ans;
  cin >> s;
  
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '0')
      ans.push_back('0');
    if(s.at(i) == '1')
      ans.push_back('1');
    if(s.at(i) == 'B'){
      if(ans.empty());
      else
        ans.pop_back();
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"


int main() {
	int N, M, X;
	vector<vector<int>> C(12, vector<int>(12));
	cin >> N >> M >> X;

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M + 1; ++j) {
			cin >> C[i][j];
		}
	}

	int minMoney = INT_MAX;
	for (int i = 0; i < pow(2, N); ++i) {
		vector<int> skill(12);
		int money = 0;
		for (int j = 0; j <= N; ++j) {
			if (i & (1 << j)) { // 列挙に i が含まれるか
				money += C[j][0];
				for (int m = 1; m <= M; ++m) {
					skill[m - 1] += C[j][m];
				}
			}
		}


		bool flags = true;
		for (int m = 0; m < M; ++m) {
			if (skill[m] < X)flags = false;
		}
		if (flags) {
			minMoney = min(money, minMoney);
		}
	}

	if (minMoney == INT_MAX) {
		cout << "-1" << endl;
	}
	else {
		cout << minMoney << endl;
	}

	return 0;
}



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

int main(){
    int total;
    for (int i = 0; i < 3; i++){
        int A;
        cin >> A;
        total = total + A;
    }
        if(total > 21){
            cout << "bust" << endl;
        }
        else{
            cout << "win" << endl;
        }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair<int, int> P;
static const int MAX_N = 200000;
static const int NIL = -1;

int N, K, L;
vector<int> Ga[MAX_N], Gb[MAX_N];
int numa[MAX_N], numb[MAX_N];

void dfs(int s, int c, vector<int> G[], int *num){
	if(num[s] == NIL) num[s] = c;
	for(int i = 0; i < G[s].size(); i++){
		if(num[G[s][i]] == NIL) dfs(G[s][i], c, G, num);
	}
	return ;
}

int main(){
	cin >> N >> K >> L;
	for(int i = 1; i <= K; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		Ga[a].push_back(b);
		Ga[b].push_back(a);
	}
	for(int i = 1; i <= L; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		Gb[a].push_back(b);
		Gb[b].push_back(a);
	}
	fill(numa, numa + N, NIL);
	fill(numb, numb + N, NIL);
	map<P, int> mpa;
	int cnta = 0, cntb = 0;
	for(int i = 0; i < N; i++){
		if(numa[i] == NIL){
			dfs(i, cnta, Ga, numa);
			cnta++;
		}
		if(numb[i] == NIL){
			dfs(i, cntb, Gb, numb);
			cntb++;
		}
		mpa[P(numa[i], numb[i])]++;
	}
	for(int i = 0; i < N; i++){
		cout << mpa[P(numa[i], numb[i])];
		if(i == N - 1) cout << endl;
		else cout << ' ';
	}
	return 0;
}

Measured memory_bytes: 27904
S = list(input())

ans = 0
for i in range(2 ** (len(S) - 1)):
    bit = format(i,  '0' + str(len(S) - 1) + 'b')
    formula = str("")
    # bitが1の場合は"+"を付与する
    for j in range(len(S) - 1):
        formula = formula + (S[j] + "+" * int(bit[j]))
    # 末尾の値を足す
    formula = formula + S[-1]
    # 数式の値を解に加算する
    ans += eval(formula)

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  x-=a;

  x -= b * (x/b);

  cout << x << endl;
}

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

using namespace std;

int W, H, N, x, y, t;

int main() {

	cin >> W >> H >> N;
	int lx = 0, rx = W, ly = 0, ry = H;

	for(int i = 0; i < N; i++) {
        cin >> x >> y >> t;
        if(t == 2){
            rx = min(rx, x);
        }else if(t == 1){
            lx = max(lx, x);
        }else if(t == 4){
            ry = min(ry, y);
        }else if(t == 3){
        ly = max(ly, y);
        }
	}

	cout << max(rx - lx, 0) * max(ry - ly, 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	cout.precision(20);
	int i,n;
	long double m = 0;
	cin >> n;
	for(i=0;i<n;i++){
		long double x; string s;
		cin >> x >> s;
		if(s[0]=='J') m += x;
		else m += 380000*x;
	}
	cout << m << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int n, m, x;
  int a[111] = {};
  int ans1 = 0, ans2 = 0;

  cin >> n >> m >> x;
  for(int i=0;i<m;i++){
    int pos;
    cin >> pos;
    a[pos] = 1;
  }
   
  for(int i=x; i<=n; i++)ans1 += a[i];   
  for(int i=0; i<=x; i++)ans2 += a[i];   
  
  cout << min(ans1, ans2) << endl;

  return 0;
}



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

std::string s;

std::string compress(const std::string s) {
    return s[0] + std::to_string( s.size()-2 ) + s[s.size()-1];
}

int main() {
    std::cin >> s;
    std::cout << compress(s) << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){
  int w,h,n;
  int x,y,a,f[100][100];
  int i,j,k;

  scanf("%d %d %d",&w ,&h,&n);
  for(j=0;j<w;j++)
    for(k=0;k<w;k++)
      f[j][k]=0;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&x,&y,&a);
    if(a==2 && w>x)w=x;
    if(a==4 && h>y)h=y;
      for(j=0;j<w;j++)
        for(k=0;k<h;k++)
          if((a==1&&j<x)||(a==3&&k<y))
                f[j][k]=1;



  }
    a=0;
    for(j=0;j<w;j++)
      for(k=0;k<h;k++){
        if(f[j][k]==0)a++;
      }
    printf("%d\n",a);

  return 0;
}



Measured memory_bytes: 256
n=int(input())
pn=list(map(int,input().split()))
sum=0
for i in range(n-2):
    if (pn[i+2]>pn[i+1] and pn[i]<pn[i+1]) or (pn[i+2]<pn[i+1] and pn[i]>pn[i+1]):
        sum+=1
print(sum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,yy;
	cin>>n>>yy;
	int x,y,z;
	for(x=0;x<=n;x++)
		for(y=0;y<=n;y++)
		{
			z=n-x-y;
			if(z>=0&&x*10000+y*5000+z*1000==yy)
			{
				cout<<x<<' '<<y<<' '<<z;
				return 0;
			}
		}
	cout<<"-1 -1 -1";
	return 0;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


def binary_search(Array, x):
    le = 0
    ri = len(Array)
    if ri == 1 or x <= Array[0]:
        return x - Array[0], Array[0] - x
    elif x >= Array[-1]:
        return x - Array[-1], Array[-1] - x
    while ri - le > 0:
        i = (le + ri) // 2
        if (Array[i] == x):
            return 0, 0
        elif (Array[i] < x):
            le = i + 1
        else:
            ri = i
    return x - Array[ri - 1], Array[ri] - x


A, B, Q = inpl()
shrine = [int(input()) for _ in range(A)]
temple = [int(input()) for _ in range(B)]
query = [int(input()) for _ in range(Q)]

# shrine.sort()
# temple.sort()
slr = [0, 0]
tlr = [0, 0]
for q in query:
    slr[0], slr[1] = binary_search(shrine, q)
    tlr[0], tlr[1] = binary_search(temple, q)

    ans = 10**15
    for sdir, tdir in zip(slr, tlr):
        if sdir < 0 or tdir < 0:
            continue
        ans = min(ans, max(sdir, tdir))
    for sdir, tdir in [[slr[0], tlr[1]], [slr[1], tlr[0]]]:
        if sdir < 0 or tdir < 0:
            continue
        ans = min(ans, sdir + tdir + min(sdir, tdir))

    print(ans)


Measured memory_bytes: 16152
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        char C[] = sc.next().toCharArray();
        sc.close();

        int cnt = 0;
        for (int i=1; i<N; i++) {
            if (C[i]==C[i-1])
                cnt++;
        }
        if (cnt+2*K>N-1) {
            cnt = N-1;
        } else {
            cnt += 2*K;
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(cnt);
        out.flush();
    }
}

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

typedef long long ll;
using vi = vector<int>;

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

  vi a(n);
  rep(i, n) cin >> a.at(i);

  ll ans = 0;
  int max = a.at(0);
  for (int i = 1; i < n; i++) {
    if (a.at(i) < max) {
      ans += max - a.at(i);
    } else {
      max = a.at(i);
    }
  }

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

Measured memory_bytes: 3984
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main ()
{
    int x;
    scanf ("%d",&x);
    if(x%2==0||x%5==0)
    {
        printf("-1\n");
        return 0;
    }
    else
    {
        long long  a=0;
        for(int i=0; ;i++)
        {
            a=(a*10+7)%x;
            if(a%x==0)
            {
                printf ("%d\n",i+1);
                break;
            }
        }
    }
    return 0;
}

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

int dp[100001];
int a[100000];
int fun(int i){
if(i<1)return 1000000;
if(i==1)return 0;
if(dp[i]!=-1)return dp[i];
return dp[i]=min(abs(a[i]-a[i-1])+fun(i-1),abs(a[i]-a[i-2])+fun(i-2));
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
memset(dp,-1,sizeof dp);
for(int i=1;i<=n;i++){
cin>>a[i];
}
cout<<fun(n);
}


Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    string s;
    int m;
    while (cin >> s) {
        if (s == "-") {
            break;
        }
        cin >> m;
        int h;
        int n = s.size();
        rep(i, m) {
            cin >> h;
            s = s.substr(h, n - h) + s.substr(0, h);
        }
        cout << s << "\n";
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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


int main() {
  string s;
  
  cin>>s;
  if((s[1]=='A'&&s[2]=='A'&&s[0]=='A')
    || (s[1]=='B'&&s[2]=='B'&&s[0]=='B')){cout<<"No";}
  else{cout<<"Yes";}
}




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

int n,s[5][105],x,ans;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&x);
            s[i][j]=s[i][j-1]+x;
        }          
    }
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,s[1][i]+s[2][n]-s[2][i-1]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{

	char input[1001];
	int length;
	int i;
	
	scanf("%s",input);
	length=strlen(input);
	
	for(i=0;i<length;i++)
	{
		if(input[i]=='A')printf("X");
		else if(input[i]=='B')printf("Y");
		else if(input[i]=='C')printf("Z");
		else printf("%c",input[i]-3);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <queue>
#include <set>

using namespace std;

int n;
int m;
vector<pair<int, int> > v[100000];
int root[100000];
int dist[100000];
int rc[100000];

int main(){
  n = getInt();
  m = getInt();
  REP(i,m){
    const int l = getInt() - 1;
    const int r = getInt() - 1;
    const int d = getInt();
    v[l].push_back(make_pair(r, d));
    rc[r]++;
  }

  REP(i,n) root[i] = -1;

  REP(i,n) if(rc[i] == 0){
    queue<int> q;
    q.push(i);
    root[i] = i;
    dist[i] = 0;
    while(q.size()){
      const int pos = q.front(); q.pop();
      for(const auto e : v[pos]){
        const int next = e.first;
        const int d = e.second;
        if(root[next] == -1){
          dist[next] = dist[pos] + d;
          root[next] = i;
          q.push(next);
        } else if(root[next] == i){
          if(dist[next] != dist[pos] + d){
            goto bad;
          }
        }
      }
    }
  }

  REP(i,n) if(root[i] == -1){
    goto bad;
  }

  puts("Yes");
  return 0;
 bad:
  puts("No");
  return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
typedef long long ll;

void ans(bool qus)
{
    if (qus == true)
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}

void Ans(bool qust)
{
    if (qust == true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

//ACしてくれ頼む


int main(){
    char a;
    cin >> a;
    bool s;
    if(a=='a' || a=='i'){
        s = true;
    }
    else if(a=='u' || a=='e'){
        s = true;
    }
    else if(a=='o'){
        s = true;
    }
    else
    {
        s = false;
    }
    ans(s);
}


Measured memory_bytes: 256
N = int(input())
G = [None for i in range(N)]
for i in range(N):
    u, k, *vs = map(int, input().split())
    G[u-1] = [e-1 for e in vs]


from collections import deque
dist = [-1]*N
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in G[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)

for i in range(N):
    print(i+1, dist[i])


Measured memory_bytes: 6028
#include<stdio.h>
int main(void){
  int q,lr[2][100000],isPrime[100001],d2017[100001],ans[100001],i,j;
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d%d",&lr[0][i],&lr[1][i]);
  for(isPrime[0]=0,isPrime[1]=0,i=0;i<100001;i++)isPrime[i]=1;
  for(isPrime[0]=0,isPrime[1]=0,i=2;i<317;i++)if(isPrime[i])for(j=(i+i);j<=100000;j+=i)isPrime[j]=0;
  for(i=0;i<100001;i++)d2017[i]=0;
  for(d2017[0]=0,d2017[1]=0,i=3;i<=100001;i+=2)if(isPrime[i]&&isPrime[(i+1)/2])d2017[i]=1;
  for(ans[0]=0,i=1;i<=100000;i++)ans[i]=ans[i-1]+d2017[i];
  for(i=0;i<q;i++)printf("%d\n",ans[lr[1][i]]-ans[lr[0][i]-1]);
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
#define x first
#define y second
#define range(x,a,b) (a)<=x&&x<=(b)
int ax[4]={0,0,1,-1};
int ay[4]={-1,1,0,0};
int main(){
	int h,w;
	pair<int,int> c,d,obj,next;
	cin>>h>>w>>c.x>>c.y>>d.x>>d.y;
	c.x--;c.y--;d.x--;d.y--;
	char maze[h][w];
	rep(i,h)rep(j,w)cin>>maze[i][j];
	int cost[h][w];
	rep(i,h)rep(j,w)cost[i][j]=inf;
	cost[c.x][c.y]=0;
	deque<pair<int,int>> q;
	q.push_front(c);
	while(q.size()){
		obj=q.front();
		q.pop_front();
		//移動a
		rep(i,4){
			next.x=obj.x+ax[i];
			next.y=obj.y+ay[i];
			if(range(next.x,0,h-1)&&range(next.y,0,w-1)&&maze[next.x][next.y]=='.'){
				if(cost[next.x][next.y]>cost[obj.x][obj.y]){
					cost[next.x][next.y]=cost[obj.x][obj.y];
					q.push_front(next);
				}
			}
		}
		//移動ｂ
		for(int x=-2;x<=2;x++)for(int y=-2;y<=2;y++){
			if(x==0&&y==0)continue;
			next.x=obj.x+x;
			next.y=obj.y+y;
			if(range(next.x,0,h-1)&&range(next.y,0,w-1)&&maze[next.x][next.y]=='.'){
				if(cost[next.x][next.y]>cost[obj.x][obj.y]+1){
					cost[next.x][next.y]=cost[obj.x][obj.y]+1;
					q.push_back(next);
				}
			}
		}
	}
	if(cost[d.x][d.y]==inf){
		cout<<-1;
		return 0;
	}
	cout<<cost[d.x][d.y];
	return 0;
}

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

int dp[3003][3003];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin >> s >> t;
	s = '-' + s; t = '-' + t;
	for (int i = 1; i < s.size(); ++i) {
		for (int j = 1; j < t.size(); ++j) {
			dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
			if (s[i] == t[j]) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
			}
		}
	}
	
	string r = "";
	int i = s.size() - 1; int j = t.size() - 1;
	while (i > 0 && j > 0) {
		if (dp[i - 1][j] == dp[i][j]) {
			--i;
			continue;
		}
		j = lower_bound(dp[i], dp[i] + j, dp[i][j]) - dp[i];
		r += t[j];
		--i; --j;
	}
	
	reverse(r.begin(), r.end());
	cout << r << "\n";
	return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2006
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define MOD 1000000007
ll dp[N][N];
int main(){
	int n,m;
    cin>>n>>m;
    vector<int> S(n);
    vector<int> T(m);
    REP(i,n){
        cin>>S[i];
    }
    REP(i,m){
        cin>>T[i];
    }
    REP(i,N){
        dp[0][i]=1;
        dp[i][0]=1;
    }
    REP(i,n){
        REP(j,m){
            if(S[i]==T[j]){
                dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%MOD;
            }
            else{
                dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j])%MOD;
            }
        }
    }
    if(dp[n][m]<0) dp[n][m]+=MOD;
    OUT(dp[n][m]);
    return 0;
}

Measured memory_bytes: 31616
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	n,a,b,c = readline() |> split |> parseMap
	l = Array{Int}(n)
	for i in 1:n
		l[i] = readline() |> parseInt
	end
	k = [0 for i in 1:n]
	m = 10^10
	while k != 0
		aa = Int[]
		bb = Int[]
		cc = Int[]
		for i in 1:n
			if k[i] == 1
				push!(aa,l[i])
			elseif k[i] == 2
				push!(bb,l[i])
			elseif k[i] == 3
				push!(cc,l[i])
			end
		end
		if !(isempty(aa) || isempty(bb) || isempty(cc))
			temp = 10*(length(aa)+length(bb)+length(cc)-3)+abs(a-sum(aa))+abs(b-sum(bb))+abs(c-sum(cc))
			m = min(temp,m)
		end
		k[n] += 1
		k = moveup(k,4)
	end
	println(m)
end
main()

Measured memory_bytes: 137092
//https://atcoder.jp/contests/agc026/tasks/agc026_e
#include<iostream>
#include<string>
#include<vector>

int n;
std::string s;
std::vector<int> cor;

std::vector<int> match; // index in s => matching index in t
bool check(std::string const& t){
	int constexpr DELETED=-1;
	match.assign(2*n,-2);

	int ti=0; // match index in t
	int si=0; // match index in s
	while(t[ti]){
		while(true){
			if(!t[ti])
				return true;
			else if(si==(int)s.size())
				return false;
			else if(match[si]==DELETED){
				++si;
				continue;
			}else if(s[si]!=t[ti]){
				match[si]=DELETED;
				if(cor[si]<si){
					si=cor[si];
					ti=match[si];
					match[si]=DELETED;
					continue;
				}else{
					match[cor[si]]=DELETED;
					++si;
					continue;
				}
			}else{
				match[si]=ti;
				++si;++ti;
				continue;
			}
		}
	}
	return true;
}

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	std::cin>>n;
	s.reserve(2*n);
	std::cin>>s;

	cor.resize(2*n);
	for(int a=-1,b=-1,_=n;_--;){
		do ++a;while(s[a]!='a');
		do ++b;while(s[b]!='b');
		cor[a]=b;cor[b]=a;
	}

	std::string ans;ans.reserve(2*n);
	while(true){
		ans+='b';
		if(!check(ans)){
			ans.back()='a';
			if(!check(ans)){
				ans.pop_back();
				break;
			}
		}
	}
	std::cout<<ans<<'\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

struct graph_t {
	int n;           // |V|, index begins with 0
	int m;           // |E|
	vector<P> edges; // E
	vector<ll> cost; // cost or distance
	vector<ll> cap;  // capacity
};

class Prim {
private:
	struct node {
		int id; bool done; vi to; vll cost; int from; ll d;
		bool operator<(const node & another) const {
			return !(d != another.d ? d < another.d : id < another.id);
		}
	};
	vector<node> nodes;
	int n;
	int root;
public:
	Prim(graph_t G, int start) {
		n = G.n;
		nodes.resize(n);
		Loop(i, n) nodes[i] = { i, false,{},{}, -1, INFLL };
		Loop(i, G.edges.size()) {
			nodes[G.edges[i].first].to.push_back(G.edges[i].second);
			nodes[G.edges[i].first].cost.push_back(G.cost[i]);
		}
		priority_queue<node> pq;
		root = start;
		nodes[root].d = 0;
		pq.push(nodes[root]);
		while (pq.size()) {
			node a = pq.top(); pq.pop();
			if (nodes[a.id].done) continue;
			nodes[a.id].done = true;
			Loop(j, a.to.size()) {
				node *b = &nodes[a.to[j]];
				if ((*b).done) continue;
				ll buf = a.cost[j];
				if (buf < (*b).d) {
					(*b).d = buf;
					(*b).from = a.id;
					pq.push(*b);
				}
			}
		}
	}
	vector<P> get_tree() {
		vector<P> ret;
		Loop(i, n) {
			if (i != root) {
				ret.push_back({ nodes[i].from, i });
			}
		}
		return ret;
	}
	ll get_weight() {
		ll ret = 0;
		Loop(i, n) {
			if (i != root) {
				ret += nodes[i].d;
			}
		}
		return ret;
	}
};

int main() {
	graph_t G;
	cin >> G.n >> G.m;
	Loop(i, G.m) {
		int s, t, c; cin >> s >> t >> c;
		G.edges.push_back({ s, t });
		G.cost.push_back(c);
		G.edges.push_back({ t, s });
		G.cost.push_back(c);
	}
	Prim prim(G, 0);
	cout << prim.get_weight() << endl;
	return 0;
}

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

using Pixel = std::vector<std::vector<char>>;

Pixel init_pixel(int width, int height) {
        Pixel pixel;

        // 高さを +1 して、0番目の配列は以後無視する
        // そうしないと、Pixel の縦位置の計算がずれてしまう
        pixel.resize(height + 1);

        for (auto &inner_pixel: pixel) {
                inner_pixel.resize(width);
        }

        char input;
        for (int i = 1; i <= height; i++) {
                for (int j = 0; j < width; j++) {
                        std::cin >> input;
                        pixel[i][j] = input;
                }
        }
        return pixel;
}

void height_twice_pixel(Pixel &orig, int width, int height) {
        orig.resize((height * 2) + 1);  // ここも高さを+1
        for (auto &orig_inner: orig) {
                orig_inner.resize(width);
        }
}

Pixel paint(Pixel &orig, int width, int height) {
        Pixel result(orig);

        // 縦の位置計算は1番目から始める
        for (int i = 1; i <= height * 2; i++) {   
                for (int j = 0; j < width; j++) {
                        result[i][j] = orig[(i + 1) / 2][j];
                }
        }
        return result;
}

void output(Pixel &pixel, int width, int height) {

        // 出力も1番目から始める
        // 一貫して0番目は無視している点に注意
        for (int i = 1; i <= height * 2; i++) {
                for (int j = 0; j < width; j++) {
                        std::cout << pixel[i][j];
                }
                std::cout << std::endl;
        }
}

int main(int argc, char *argv[]) {
        int height = 0;
        int width = 0;

        std::cin >> height;
        std::cin >> width;

        Pixel pixel(init_pixel(width, height));

        height_twice_pixel(pixel, width, height);
        Pixel result = paint(pixel, width, height);
        output(result, width, height);

        return 0;
}


Measured memory_bytes: 256
H,W = map (int, input ().split ())
x = 1
L = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range (H):
  A = input ().split ()
  for j in range (W):
    if A[j] == 'snuke':
      print (L[j]+str(i+1))
      x = 0
    if x == 0:
      break
  if x == 0:
    break

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

void printFrame( int h, int w ) {
    for (int j = 0; j < w; j++) {
        cout << '#';
    }
    cout << endl;

    for (int i = 1; i < h - 1; i++) {
        cout << '#';
        for(int j = 1; j < w - 1; j++) {
            cout << '.';
        }
        cout << '#';
        cout << endl;
    }

    for (int j = 0; j < w; j++) {
        cout << '#';
    }
    cout << endl;
}

  
int main() {
    int h, w;
    while (1) {
        cin >> h >> w;
        if (h == 0 && w == 0) return 0;
        printFrame( h, w );
        cout << endl;
    }
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

int N; string S;
void input()
{
    cin>>N>>S;
}

void solve()
{
    vi R_cnt(N,0),G_cnt(N,0),B_cnt(N,0);
    if(S[0]=='R') R_cnt[0]=1;
    else if(S[0]=='G') G_cnt[0]=1;
    else if(S[0]=='B') B_cnt[0]=1;
    for(int i=1;i<N;++i){
        R_cnt[i]=R_cnt[i-1];G_cnt[i]=G_cnt[i-1];B_cnt[i]=B_cnt[i-1];
        if(S[i]=='R') R_cnt[i]++;
        else if(S[i]=='G') G_cnt[i]++;
        else if(S[i]=='B') B_cnt[i]++;
    }
    ll ans=0;
    for(int i=0;i<N-2;++i){
        for(int j=i+1;j<N-1;++j){
            if((S[i]=='R' && S[j]=='G') || (S[j]=='R' && S[i]=='G')){
                ans+=B_cnt[N-1]-B_cnt[j];
                if(j-i+j<N && S[j-i+j]=='B') --ans;
            }
            else if((S[i]=='G' && S[j]=='B') || (S[j]=='G' && S[i]=='B')){
                ans+=R_cnt[N-1]-R_cnt[j];
                if(j-i+j<N && S[j-i+j]=='R') --ans;
            }
            else if((S[i]=='R' && S[j]=='B') || (S[j]=='R' && S[i]=='B')){
                ans+=G_cnt[N-1]-G_cnt[j];
                if(j-i+j<N && S[j-i+j]=='G') --ans;
            }
        }
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3660
#!/usr/bin/env python3
#ABC139 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
print(n*(n-1)//2)


Measured memory_bytes: 38384
n, m = map(int, raw_input().split())

a = [[0 for i in xrange(m)] for j in xrange(n)]
b = [0 for i in xrange(m)]

for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        a[i][j] = tmp[j]
for k in xrange(m):
    b[k] = int(raw_input())

for i in xrange(n):
    ans = 0
    for j in xrange(m):
        ans += a[i][j]*b[j]
    print ans

Measured memory_bytes: 6468