akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Main{
	char [][] data;
	int w,h;
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	
	class State implements Comparable<State>{
		int nowx,nowy, cost;

		public State(int nowx, int nowy, int cost) {
			this.nowx = nowx;
			this.nowy = nowy;
			this.cost = cost;
		}

		@Override
		public int compareTo(State o) {
			return this.cost - o.cost;
		}

		@Override
		public String toString() {
			return "State [nowx=" + nowx + ", nowy=" + nowy + ", cost=" + cost
					+ "]";
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			data = new char[h][w];
			int sx = -1, sy = -1;
			for(int i = 0; i < h; i++){
				String s = sc.next();
				data[i] = s.toCharArray();
				int res = s.indexOf('&');
				if(res >= 0){
					sy = i;
					sx = res;
				}
			}
			int res = solve(sx,sy);
			System.out.println(res);
		}
	}

	private int solve(int sx, int sy) {
		int INF = 1 << 24;
		PriorityQueue<State> open = new PriorityQueue<State>();
		open.add(new State(sx, sy, 0));
		int[][] close = new int[h][w];
		for(int i = 0; i < h; i++){
			Arrays.fill(close[i], INF);
		}
		close[sy][sx] = 0;
		int ans = INF;
		while(! open.isEmpty()){
			State now = open.poll();
			if(isGoal(now)){
				ans = now.cost;
				break;
			}
			for(int i = 0; i < 4; i++){
				int xx = now.nowx + vx[i];
				int yy = now.nowy + vy[i];
				int nextcost = now.cost;
				if(data[now.nowy][now.nowx] != '#' && data[yy][xx] == '#'){
					nextcost++;
				}
				if(close[yy][xx] <= nextcost) continue;
				open.add(new State(xx, yy, nextcost));
				close[yy][xx] = nextcost;
			}
		}
		return ans;
	}

	private boolean isGoal(State now) {
		if(now.nowx == 0 || now.nowy == 0 || now.nowx == w-1 || now.nowy == h-1) return true;
		return false;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 28392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int w,a,b;
    cin >> w >> a >> b;
    if (a+w <= b)
    {
        cout << b-(a+w) << endl;
    }
    else if (b+w <= a)
    {
        cout << a-(b+w) << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    int cnt=1, in=a;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    while(in<b){
        in+=(a-1);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

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

    int b[n] = {0};

    for(int i=n-1; i>=0; i--) {
        int tot = 0;
        for (int j= 2*(i+1)-1; j<n; j += i+1) {
            tot += b[j];
            tot %= 2;
        }
        tot += a[i];
        tot %= 2;
        b[i] = tot;
    }

    int m = 0;
    rep(i,n) m += b[i];
    cout << m << endl;
    rep(i,n) {
        if(b[i] == 1) printf("%d%c", i+1, i==n-1? '\n' : ' ');
    }
}


Measured memory_bytes: 2432
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a,b=map(int, input().split())
    uf.union(a-1,b-1)
cnt = 0
for i in range(N-1):
    if(not uf.same(i,i+1)):
        cnt += 1
        uf.union(i+1,i)
print(cnt)

Measured memory_bytes: 10680
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

int x, y,cvp;

int mutlak(int c){
	if(c<0)return -c;
	return c;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>x>>y;
	if(x==0&&y<0)cvp=1-y;
	else if(x==0)cvp=y;
	else if(y==0&&x<0)cvp=-x;
	else if(y==0)cvp=1+x;
	else if(-y==x)cvp=1;
	else if(x<y){
		if(x<0&&y<0)cvp=y-x;
		if(x<0&&y>0)cvp=mutlak(y+x)+1;
		if(x>0)cvp=y-x;
	}else if(y<x){
		if(y<0&&x<0)cvp=1-y+x+1;
		if(y<0&&x>0)cvp=1+mutlak(y+x);
		if(y>0)cvp=1+x-y+1;
	}
	cout<<cvp;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import heapq

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


#a : heapq.heappop(s,v.popleft())
#b : heapq.heappop(s,v.pop())
#c : v.appendleft(heapq.heappop(s))
#d : v.append(heapq.heappop(s))
ans = 0
for i in range(1,min(n,k)+1):
    for j in range(i+1):
        s = []
        heapq.heapify(s)
        res = 0
        num = 0
        for _ in range(j):
            heapq.heappush(s,v[num])
            res += v[num]
            num += 1
        num = 1
        for _ in range(j,i):
            heapq.heappush(s,v[-num])
            res += v[-num]
            num += 1

        for j in range(k-i):
            if len(s) == 0:
                break
            if s[0] < 0:
                res -= heapq.heappop(s)
            else:
                break
        if ans < res:
            ans = res
    #print(i,ans)
print(ans)


Measured memory_bytes: 3436
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 4000000000000000000
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  int n,k;
  ll x[50],y[50];
  vector<ll> arx,ary;
  ll ans;
  int cnt[51][51]={};
  cin>>n>>k;

  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    arx.push_back(x[i]);
    ary.push_back(y[i]);
  }
  sort(arx.begin(),arx.end());
  sort(ary.begin(),ary.end());
  ans=(arx[n-1]-arx[0])*(ary[n-1]-ary[0]);
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      ll tx,ty;
      tx=arx[i];ty=ary[j];
      for(int idx=0;idx<n;idx++){
        if(tx==x[idx] && ty==y[idx])cnt[i+1][j+1]++;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      cnt[i+1][j+2]+=cnt[i+1][j+1];
    }
  }
  for(int j=0;j<n;j++){
    for(int i=0;i<n-1;i++){
      cnt[i+2][j+1]+=cnt[i+1][j+1];
    }
  }
  for(int xl=0;xl<n-1;xl++){
    for(int xr=xl+1;xr<n;xr++){
      for(int yb=0;yb<n-1;yb++){
        for(int yu=yb+1;yu<n;yu++){
          int kk;
          kk=cnt[xr+1][yu+1]+cnt[xl][yb]\
             -cnt[xl][yu+1]-cnt[xr+1][yb];
          if(kk>=k){
            ans=\
            min(ans,(arx[xr]-arx[xl])*(ary[yu]-ary[yb]));
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N, K;
    scan(N, K);
    auto a = readln.split.to!(int[]);
    auto am = new int[](N + 1);
    am[0] = 0;
    foreach (i ; 1 .. N + 1) {
        am[i] = max(am[i - 1], a[i - 1]);
    }

    long ans = infl;

    foreach (mask ; 0 .. 1 << N) {
        if (mask.popcnt < K) continue;
        int pre;
        long cost;
        foreach (i ; 0 .. N) if ((mask >> i) & 1) {
            if (max(pre, am[i]) >= a[i]) {
                cost += max(pre, am[i]) - a[i] + 1;
                pre = max(pre, am[i]) + 1;
            }
            else {
                pre = a[i];
            }
        }

        debug {
            writefln("%08b", mask);
            writeln(cost);
        }
        chmin(ans, cost);
    }

    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
vector<ll>G[1<<17];
inline void solve(void){
  ll N,M;
  in(N,M);
  vector<ll>H(N);
  ins(H);
  rep(i,M){
    ll a,b;
    in(a,b);
    a--;b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  ll cnt=0;
  rep(i,N){
    bool f=true;
    for(auto e:G[i]){
      if(H[i]<=H[e]){
        f=false;
        break;
      }
    }
    if(f)cnt++;
  }
  out(cnt);
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 10592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<double, int>;
using Pt = complex<double>;
const int MX = 1005;
int n, f;
double x, y, r[MX], d[MX], c;
Pt p[MX];

vector<P> G[MX];
priority_queue<P, vector<P>, greater<P>> qu;
void dijkstra(){
	fill(d, d+n+2, -1);
	qu.push(P(0,0));
	while(!qu.empty()){
		tie(c,f) = qu.top(); qu.pop();
		if(d[f] == -1){
			d[f] = c;
			rep(i,n+2) if(i != f) qu.push(P(c+max(0.0,abs(p[i]-p[f])-r[i]-r[f]), i));
		}
	}
}

int main(){
	rep(i,2){
		scanf("%lf%lf", &x, &y);
		p[i] = Pt(x,y);
	}
	scanf("%d", &n);
	rep(i,n){
		scanf("%lf%lf%lf", &x, &y, r+i+2);
		p[i+2] = Pt(x,y);
	}
	dijkstra();
	printf("%.10f\n", d[1]);
}

Measured memory_bytes: 18792
n = int(input())

ans = []
def dfs(A):
    if len(A) == n:
        ans.append(''.join(A))
        return
    for i in range(len(set(A))+1):
        v = chr(i+ord('a'))
        A.append(v)
        dfs(A)
        A.pop()

dfs([])
ans.sort()
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 83264
dp = {100: 1, 101: 1, 102: 1, 103: 1, 104: 1, 105: 1}
l = [100, 101, 102, 103, 104, 105]
for i in range(100001):
  if i == 0:
    dp[0] = 1
  elif i < 100:
    dp[i] = 0
  elif i >= 106:
    dp[i] = 0
    for cost in l:
      dp[i] += dp[i-cost]

n = int(input())
if dp[n] >= 1:
  print(1)
else:
  print(0)
    


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

/* 再帰な全探索 */
// 入力
long long N;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったかを表すビット, counter: 答え
void func(long long cur, int use, long long &counter){
    if (cur > N) return; // ベースケース
    if (use == 0b111) ++counter; // 答えを増やす

    // 7 を付け加える
    func(cur * 10 + 7, use | 0b001, counter);

    // 5 を付け加える
    func(cur * 10 + 5, use | 0b010, counter);

    // 3 を付け加える
    func(cur * 10 + 3, use | 0b100, counter);
}

int main() {
    cin >> N;
    long long res = 0;
    func(0, 0, res);
    cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  string s;
  cin >> s;

  int64_t result = 0;
  int cnt = 0;
  rep(i, s.size()) {
    if (s[i] == 'W') {
      result += i - cnt;
      cnt++;
    }
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 3e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double r;
main() {
    file("balance");
    ios;
    cin>>r;
    cout<<r*1.0*3*r;
    return 0;
}
/**

*/


Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int main(){
    int i,n,S[10000],q,T[10000],sum=0;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>S[i];
    }
    cin>>q;
    for(i=0; i<q; i++){
        cin>>T[i];
    }
    for (int i=0;i<q;i++){
        for (int j=0;j<n;j++){
            if (T[i]==S[j]){
                sum++;
                break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}   

Measured memory_bytes: 3080
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
  int n; cin>>n;
  int t[n], a[n]; rep(i,n) cin>>t[i]; rep(i,n) cin>>a[i];
  ll dp[n+1]; dp[0] = 1; // dp[i]:i番目の山まで見たときの場合の数
  if(t[n-1]!=a[0]) return cout << 0 << endl, 0;
  if(n==1) return cout << 1 << endl, 0;
  reps(i,n-2){ // i番目(0-indexed)の山について考える
    dp[i] = dp[i-1];
    if(t[i]>t[i-1]&&a[i]>a[i+1]&&t[i]!=a[i]) return cout << 0 << endl, 0;
    if(t[i]==t[i-1]&&a[i]>a[i+1]&&t[i]<a[i]) return cout << 0 << endl, 0;
    if(t[i]>t[i-1]&&a[i]==a[i+1]&&t[i]>a[i]) return cout << 0 << endl, 0;
    if(t[i]==t[i-1]){ // Tの最高が変わらないならあり得るのはt[i]までの全通り
      if(a[i]>a[i+1]) continue; // Aが更新されてたら一通りに収束
      dp[i] *= min(t[i],a[i]); // 両方更新されないなら小さい方の数の通りがある
      dp[i] %= MOD;
    } // Tの最高が更新されてたら一通りだから特に何もしない
  }
  // 最後の山(n-1番目)についてはそのひとつ前のdpまでと場合の数は変わらないのでn-2までで十分
  rep(i,n-2) cerr << dp[i] << ' ';
  cerr << endl;
  cout << dp[n-2] << endl;
  return 0;
}


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

int main() {
	int x[5];
	rep(i, 5) {
		cin >> x[i];
		if (x[i] == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int ap = 0;
    int bp = 0;
    int cp = 0;

    for (int i = 0;; i++) {
      if (((a % 2) != 0) || ((b % 2) != 0) || ((c % 2) != 0)) {
        System.out.println(i);
        return;
      } else if ((a == b) && (b == c)) {
        System.out.println(-1);
        return;
      }
      ap = (b + c) / 2;
      bp = (c + a) / 2;
      cp = (a + b) / 2;
      a = ap;
      b = bp;
      c = cp;
    }

  }
}

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

int main() {
  char x, y;
  cin >> x >> y;

  int xx, yy;
  xx = int(x);
  yy = int(y);

  if (xx < yy) {
    cout << "<" << endl;
  } else if (xx > yy) {
    cout << ">" << endl;
  } else {
    cout << "=" << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int m=t.size();
    int ans=1e9;
    for(int i=0;i<=n-m;i++){
    	int cnt=0;
    	for(int j=i,k=0;k<m;j++,k++){
    		if(s[j]!=t[k]) cnt++;
    	}
    	ans=min(ans,cnt);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

int main(){
  int n; cin >> n;
  vector<int> b(n-1);
  rep(i, n-1) cin >> b[i];
  ll ans = b[0] + b[n-2];
  for(int i=1; i<=n-2; i++) {
    ans += min(b[i-1], b[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >>n>>k;
  int count =0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a<k)count++;
  }
  cout<<n-count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
long a,b,c,x,y,z;
while(cin>>z,z){
a=0;
b=z*z*z;
for(x=1;x<z;x++){
for(y=x;y<z;y++){
c=x*x*x+y*y*y;
if(c<=b&&a<c)a=c;
}
}
cout<<z*z*z-a<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
string s;
int main(void){
  cin >> s;
  if(s[0] == s[s.size()-1]){
    cout << (s.size()%2?"Second":"First") << endl;
  }else{
    cout << (s.size()%2?"First":"Second") << endl;
  }
}


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

int main() {
    string S[3];
    cin >> S[0] >> S[1] >> S[2];

    int pos = 0;
    string Snow = S[pos];

    while (!Snow.empty()) {
        char choice = Snow[0];

        S[pos].erase(0,1);
        if (choice == 'a') pos = 0;
        else if (choice == 'b') pos = 1;
        else if (choice == 'c') pos = 2;

        Snow = S[pos];
    }

    if (pos == 0) cout << 'A' << endl;
    else if (pos == 1) cout << 'B' << endl;
    else if (pos == 2) cout << 'C' << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long INF = (1LL << 60);

int main() {
	long long n, m, k;
	std::cin >> n >> m >> k;
	std::vector<long long> a(n), b(m), sa(n + 1, 0), sb(m + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sa[i + 1] = sa[i] + a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		sb[i + 1] = sb[i] + b[i];
	}
	
	sb.push_back(INF);
	
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		if (k < sa[i]) continue;
		long long res = k - sa[i];
		int cnt = prev(upper_bound(sb.begin(), sb.end(), res)) - sb.begin();
		chmax(ans, i + cnt);
	}
	
	std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 11064
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define rep(i,x) for(int i=0;i<x;i++)
#include<string>
 
using namespace std;
 
int main(){
 long long N;
  cin>>N;
  string S;
  cin>>S;
  
  long long count=N;
  for(long long i=0;i<(N-1);i++){
  	if(S[i]==S[i+1]){
    	count--;
    }
  }
  cout<<count;
  
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int ans=0,i;
  char s[5];
  scanf("%s",s);
  for(i=0;i<4;i++)
    {
      if(s[i] == '-')
	{
	  ans--;
	}
      else
	{
	  ans++;
	}
    }
  printf("%d\n",ans);
  return 0;
}



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

int main(){
    bool flag=0;
int n;
cin >>n;
int ary[n];
for (int i = 0; i <n; i++){
    cin >>ary[i];
}
for (int i = 0; i <n; i++){
    if(ary[i]%2==0){//偶数である
        if((ary[i]%3==0) or (ary[i]%5==0)) ;//3or5で割れれば何もしない
        else flag=1;//割れない時flagを立てる
}
}
if(flag==0) cout <<"APPROVED" <<endl;
else cout <<"DENIED" <<endl;


return 0;
}

Measured memory_bytes: 256
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
B = [int(input()) for i in range(N)]

ans = []
for i in range(3):
    a = [A1[i],A2[i],A3[i]]
    ans.append(a)
ans.append(A1)
ans.append(A2)
ans.append(A3)
ans.append([A1[0],A2[1],A3[2]])
ans.append([A3[0],A2[1],A1[2]])

for i in range(len(ans)):
    for j in range(N):
        if B[j] in ans[i]:
            ans[i].remove(B[j])

# print(ans)
if [] in ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

X = int(sys.stdin.buffer.readline())



def get_primes(max=None, count=None):
    """
    素数列挙
    昇順にソートされています
    https://qiita.com/Ishotihadus/items/73e107271275611f05f2
    :param int max:
    :param int count:
    :return:
    """
    assert max or count
    if count:
        raise NotImplementedError()
    if max <= 1:
        return []

    primes = [2]
    sieve = [False for _ in range(max + 1)]
    p = 3
    while p <= max:
        primes.append(p)
        sieve[p] = True
        if p <= math.sqrt(max):
            for i in range(p * (p | 1), max + 1, p * 2):
                sieve[i] = True
        while p <= max and sieve[p]:
            p += 2

    return primes

primes = get_primes(max=X+1000)
for p in primes:
    if p < X:
        continue
    print(p)
    exit()


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

using namespace std;
int h, w;
char m[30][30];
int vis[30][30];

int dr[] = {1,0,-1,0};
int dc[] = {0,1,0,-1};

bool inRange(pair<int, int> p){
    int r = p.first, c = p.second;
    return  r>=0&&r<h&&c>=0&&c<w&&m[r][c]!='#';
}


int bfs(int si, int sj, int ei, int ej){
    pair<int, int> s(si, sj);
    pair<int, int> e(ei, ej);

    if(s==e)
        return 0;

    queue<pair<int, int>> q;
    q.push(s);

    while(q.size()>0){
        pair<int, int> cur = q.front();q.pop();

        for(int i=0;i<4;i++){
            pair<int, int>nxt(cur.first + dr[i], cur.second + dc[i]);
            if(inRange(nxt) && vis[nxt.first][nxt.second] == 0){
                vis[nxt.first][nxt.second] = vis[cur.first][cur.second]+1;
                if(nxt == e)
                    return vis[nxt.first][nxt.second];

                q.push(nxt);
            }
        }
    }
    return -1;
}

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

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

    int ans=0;

    for(int si=0;si<h;si++){
        for(int sj=0;sj<w;sj++){
            if(m[si][sj] == '#')
                continue;
            for(int ei=0;ei<h;ei++){
                for(int ej=0;ej<w;ej++){
                    if(m[ei][ej] == '#')
                        continue;

                    memset(vis, 0, sizeof(vis));
                    ans = max(ans, bfs(si, sj, ei, ej));
                }
            }
        }
    }

    cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const int MOD = 1000000007;

class mint
{
  ll x;

public:
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const
  {
    return mint(-x);
  }

  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator-=(const mint &a)
  {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+(const mint &a)
  {
    mint res(*this);
    return res += a;
  }

  mint operator-(const mint &a)
  {
    mint res(*this);
    return res -= a;
  }

  mint operator*(const mint &a)
  {
    mint res(*this);
    return res *= a;
  }

  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(MOD - 2);
  }

  mint &operator/=(const mint &a)
  {
    return (*this) *= a.inv();
  }

  mint operator/(const mint &a)
  {
    mint res(*this);
    return res /= a;
  }

  friend ostream &operator<<(ostream &os, const mint &m)
  {
    os << m.x;
    return os;
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  mint ans = 0;
  vector<vector<mint>> dp(S.size() + 1, vector<mint>(13, 0));
  dp[0][0] = 1;
  for (int i = 0; i < S.size(); i++)
  {
    for (int j = 0; j < 13; j++)
    {
      if (S[i] == '?')
      {
        for (int k = 0; k < 10; k++)
        {
          dp[i + 1][(10 * j + k) % 13] += dp[i][j];
        }
      }
      else
      {
        int k = S[i] - '0';
        dp[i + 1][(10 * j + k) % 13] += dp[i][j];
      }
    }
  }
  cout << dp[S.size()][5] << endl;
  return 0;
}


Measured memory_bytes: 13648
using System;
 
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
 
        string[] card = Console.ReadLine().Split(' ');
 
        BubbleSort(card);
 
        SelectSort(card);
    }
 
    static void BubbleSort(string[] card)
    {
        string[] a =  new string[card.Length];
        Array.Copy(card, a, card.Length);
 
        bool flag = true;
        while (flag)
        {
            flag = false;
            for (int i = a.Length-1; i > 0; i--)
            { 
                int n0 = int.Parse(a[i].Substring(1, 1));
                int n1 = int.Parse(a[i - 1].Substring(1, 1));
                if (n0 < n1)
                {
                    string buf = a[i - 1];
                    a[i - 1] = a[i];
                    a[i] = buf;
                    flag = true;
                }
            }
        }
 
        Output(card, a);
    }
 
    static void SelectSort(string[] card)
    {
        string[] a =  new string[card.Length];
        Array.Copy(card, a, card.Length);
 
        for (int i = 0; i < a.Length; i++)
        {
            int min = i;
 
            for (int j = i+1; j < a.Length; j++)
            {
                int n0 = int.Parse(a[j].Substring(1, 1));
                int n1 = int.Parse(a[min].Substring(1, 1));
                if (n0 < n1)
                {
                    min = j;
                }
            }
 
            if (i != min)
            { 
                string buf = a[i];
                a[i] = a[min];
                a[min] = buf;
            }
        }
        Output(card, a);
    }
 
    static void Output(string[] card, string[] a)
    {
        string output = "";
        bool stable = true;
 
        for (int i = 0; i < a.Length; i++)
        {
            output += a[i] + ((i == a.Length-1) ? "" : " ");
 
            if (i > 0)
            {
                int n = int.Parse(a[i].Substring(1, 1));
                int m = int.Parse(a[i-1].Substring(1, 1));
 
                if (stable && n == m)
                {
                    for (int j = 0; j < card.Length; j++)
                    {   
                        if (a[i] == card[j])
                        {
                            stable = false;
                            break;
                        }
                        else if (a[i - 1] == card[j])
                        {
                            break;
                        }
                    }
                }
            }
        }
  
        Console.WriteLine(output);
        Console.WriteLine(stable ? "Stable" : "Not stable");
    }
}


Measured memory_bytes: 15944
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  string S,T;
  cin>>S;
  T=S;
  reverse(T.begin(),T.end());
  FOR(i,0,(int)T.size()){
    if(T[i]=='b'){
      T[i]='d';
    }else if(T[i]=='d'){
      T[i]='b';
    }else if(T[i]=='p'){
      T[i]='q';
    }else if(T[i]=='q'){
      T[i]='p';
    }
  }
  if(S==T){
    Yes(1);
  }else{
    Yes(0);
  }
  return 0;
}


Measured memory_bytes: 512
$N = gets.chomp.to_i
$DEBT = 100000

while $N > 0 do
  $DEBT = $DEBT * 1.05;
  if 0 != $DEBT % 1000
    $DEBT = (($DEBT / 1000).to_i + 1) * 1000
  end

  $N -= 1
end

puts $DEBT

Measured memory_bytes: 6112
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
const long long INF=20000000000;
typedef pair<long long,int> Pa;
int main(){
	int N;
	long long A[100005],ans=0,C[4],cou=0;
	priority_queue<long long> que;
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>A[i];
		que.push(A[i]);
	}
	long long b=que.top();que.pop();
	C[0]=b;
	while(!que.empty()){
		long long b=que.top();que.pop();
		if(C[cou]==b){
			C[cou+1]=b;
			if(cou==2){
				ans=C[0]*C[2];
				break;
			}
			cou=2;
			long long d=que.top();que.pop();
			C[cou]=d;
		}else C[cou]=b;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1912
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        double x=Math.PI;
        double r = sc.nextDouble();
        System.out.println(String.format("%.6f",r*r*x));
        System.out.println(String.format("%.6f",2*r*x));
   }
}


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

int n;

vector<int> a[1010];

int main() {
	scanf("%d",&n);
	for (int x=1;x*x<=n*4;x++) if (x * (x-1) == n*2) {
		printf("Yes\n%d\n",x);
		int cnt = 0;
		for (int i=1;i<=x;i++) for (int j=i+1;j<=x;j++) {
			++cnt;
			a[i].push_back(cnt);
			a[j].push_back(cnt);
		}
		for (int i=1;i<=x;i++) {
			printf("%d ",a[i].size());
			for (int j=0;j<a[i].size();j++) printf("%d ",a[i][j]);
			putchar(10);
		}
		return 0;
	}
	puts("No");
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE






ll n;
cin>>n;
ve <ll> v(n);
FOR(i,0,n)cin>>v[i];
srt(v);

ve <ll> fa(3*n);
fa[0]=1;
//fa[1]=2;
FOR(i,1,3*n){
fa[i]=2ll*fa[i-1];
fa[i]%=M;
}
ll ans=0;
ll c=1;
FOR(i,0,n){
	ll k=n-i;
	ans+=(fa[2*k-2]*(k-1)+fa[2*k-1])%M*v[i]%M*c%M;
	ans%=M;
	c=c*4;
	c%=M;
}
cout<<ans;









return 0;
 }


Measured memory_bytes: 9512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

const int N_MAX = 100;
int N;

int F[N_MAX][5][2];
ll P[N_MAX][11];

int c[N_MAX];
bitset<10> b;
int cc;

int main()
{
    cin >> N;

    for(int i =0;i < N;i++)
    {
        for(int j = 0;j <5;j++)
        {
            for(int k =0;k < 2;k++)
            {
                cin >> F[i][j][k];
            }
        }
    }

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

    ll ans = -10000000000;
    for(int i = 1;i <= 1023;i++)
    {
        for(int j =0;j < N;j++)
        {
            c[j] = 0;
        }

        bitset<10> bs((unsigned long)i);
        for(int j = 0;j < 10;j++)
        {
            if(bs[j])
            {
                for(int k =0;k < N;k++)
                {
                    c[k]+=F[k][j / 2][j % 2];
                }
            }
        }
        ll a = 0;
        for(int j = 0;j < N;j++)
        {
            a += P[j][c[j]];
        }
        ans = max(a,ans);
    }
    cout << ans;
    return 0;
}

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

int main(void){
  int n;
  while(cin>>n,n){
    vector<int> p(n+1,0);
    char in;
    for(int i = 0 , h = 0 ; i < 100 ; i ++){
      cin>>in;
      if(h>=n)h=0;
      
      //cout<<i<<" "<<h<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]<<" "<<in<<endl;
      switch(in){
        case 'S' :
          p[n] += p[h] + 1; 
          p[h] = 0;
          break;
        case 'L' :
          p[h] += p[n] + 1;
          p[n] = 0;
          break;
        case 'M' :
          p[h]++;
          break;
      }
      h++;
    }
    //cout<<endl;
    sort(p.begin(),p.end()-1);
    for(int i = 0 ; i < p.size()-1 ; i ++){
      cout<<p[i]<<" ";
    }
    cout<<p[p.size()-1]<<endl;
  }
 
}

Measured memory_bytes: 1212
import operator

N = int(input())
As = list(map(int, input().split()))

A1 = [0] + As
A2 = As + [0]
costs = list(map(abs, map(operator.sub, A1, A2)))
cTotal = sum(costs)

for i in range(N):
    print(cTotal - costs[i] - costs[i + 1] + abs(A1[i] - A2[i + 1]))


Measured memory_bytes: 14296
#include <stdio.h>

int main(void) {
  int y, m, d;
  char c;
  scanf("%d%c%d%c%d",&y,&c,&m,&c,&d);
  if (y > 2019 || y == 2019 && m > 4) {
    printf("TBD");
  } else {
    printf("Heisei");
  }
  return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    if(n == m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int N;
    string S;
    bool M = 0;
    cin >> N >> S;
    if(N % 2 != 0)M = 1;
    for (int i = 0; i < N/2; i++){
        if(S.at(i) != S.at(i+(N/2)))M =1;
    }
    if(M)cout << "No" << endl;
    else cout << "Yes" << endl;
} 

Measured memory_bytes: 256
import numpy as np

N = int(input())
p_array = np.array(list(map(int, input().split())))

sorted_p = np.sort(np.copy(p_array))
diff = (p_array != sorted_p).sum()

if diff == 0:
    print('YES')
elif diff == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 14424
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  vi A;
  A.push_back(0);
  rep(i, 0, N) {
    VAR(int, Ai);
    A.push_back(Ai);
  }
  A.push_back(0);
  ll sum = 0;
  rep(i, 1, N + 2) {
    sum += abs(A[i] - A[i - 1]);
  }
  rep(i, 1, N + 1) {
    print(sum + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])));
  }
}


Measured memory_bytes: 1784
using System;

class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int r = int.Parse(s[0]);
        int c = int.Parse(s[1]);

        int[,] array = new int[r+1, c+1];
        int sum = 0, sum2 = 0;
        for(int i =0;i<r;i++)
        {
            string[] s2 = Console.ReadLine().Split(' ');
            for(int j =0;j<=c;j++)
            {
                if (j == c)
                {
                    array[i, j] = sum;
                }
                else
                {
                    array[i, j] = int.Parse(s2[j]);
                    sum += int.Parse(s2[j]);
                }
            }
            sum = 0;
        }
        for (int i = 0; i <=c; i++)
        {
            for (int j = 0; j <= r; j++)
            {
                if (j == r)
                    array[j, i] = sum2;
                else
                    sum2 += array[j, i];

            }
            sum2 = 0;
        }

        for(int i =0;i<=r;i++)
        {
            for(int j =0;j<=c;j++)
            {
                if(j==c)
                    Console.Write(array[i,j]);
                else
                Console.Write(array[i,j]+" ");
            }
            Console.WriteLine("");
        }
    }
}

Measured memory_bytes: 9244
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void readTree(string& s, int& i, vector<char>& rpn)
{
    if(s[i] != '('){
        rpn.push_back(s[i]);
        ++ i;
    }else{
        for(int j=0; j<2; ++j){
            ++ i;
            if(s[i] == '(')
                readTree(s, i, rpn);
            else
                rpn.push_back(s[i]);
            ++ i;
        }
        rpn.push_back('.');
    }
}

int main()
{
    for(;;){
        string s;
        getline(cin, s);
        if(s == "")
            getline(cin, s);
        if(s == "END")
            return 0;

        vector<char> rpn;
        int tmp = 0;
        readTree(s, tmp, rpn);

        int n;
        cin >> n;
        vector<int> sweet(n, 0);
        for(int i=0; i<n; ++i){
            for(int j=0; j<4; ++j){
                sweet[i] <<= 1;
                char c;
                cin >> c;
                if(c == '1')
                    sweet[i] |= 1;
            }
        }

        int num = count(rpn.begin(), rpn.end(), '.');
        int a = 1;
        for(int i=0; i<num; ++i)
            a *= 3;

        int ret = 0;
        for(int i=0; i<a; ++i){
            int b = i;
            stack<int> stk;
            for(unsigned j=0; j<rpn.size(); ++j){
                if(rpn[j] == '.'){
                    int x = stk.top();
                    stk.pop();
                    int y = stk.top();
                    stk.pop();
                    if(b % 3 == 0){
                        stk.push(x & y);
                    }else if(b % 3 == 1){
                        stk.push(x | y);
                    }else{
                        stk.push(x ^ y);
                    }
                    b /= 3;
                }else{
                    stk.push(sweet[rpn[j]-'1']);
                }
            }
            if(stk.top() == 15)
                ++ ret;
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int a[80];int n;
int dfs(int x)
{
	int t=0;
	if(x==n)
	{
		for(int i=0;i<n;i++) if(a[i]%2==0) return 1;return 0;
	}
	a[x]--;t+=dfs(x+1);
	a[x]++;t+=dfs(x+1);
	a[x]++;t+=dfs(x+1);
	a[x]--;return t;
}
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	;cin>>n;for(int i=0;i<n;i++) cin>>a[i];
	cout<<dfs(0);
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N= int(input())
S= [input() for _ in range(N)]

c = Counter(S)
most_cnt = 0

for v in c.values():
    most_cnt = max(most_cnt, v)
    
ans = []
for k, v in c.items():
    if v == most_cnt:
        ans.append(k)
ans.sort()
print(*ans, sep="\n")


Measured memory_bytes: 35948
#include<cstdio>
using namespace std;
int main(){
    int x,y;
    char z;
    while(1){
      scanf("%d %c %d",&x,&z,&y);
      if(z=='?'){
          return 0;
      }
      else if (z=='+'){
        printf("%d\n",x+y);
      }
      else if (z=='-'){
        printf("%d\n",x-y);
      }
      else if (z=='/'){
        printf("%d\n",x/y);
      }
      else if (z=='*'){
        printf("%d\n",x*y);
      }
    }
}


Measured memory_bytes: 2676