akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	for (int n, m, h, k; cin >> n >> m >> h >> k, (n | m | h | k) != 0; ) {
		vi ss(n);
		rep(i, n) cin >> ss[i];
		vi p(n);
		rep(i, n) p[i] = i;
		bool mm[1000][1000];
		memset(mm, 0, sizeof(mm));
		vector<pii> ls;
		rep(i, m) {
			int a, b; cin >> a >> b;
			ls.pb(mp(b, a));
		}
		sort(all(ls));
		rep(i, m) {
			int la = ls[i].snd;
			swap(p[la - 1], p[la]);
			mm[p[la - 1]][p[la]] = mm[p[la]][p[la - 1]] = true;
		}
		vi pp(n);
		rep(i, n) pp[p[i]] = i;
		int s = 0;
		rep(i, k) s += ss[pp[i]];
		int ans = s;
		rep(i, k) {
			int t = s - ss[pp[i]];
			REP(j, k, n - 1) if (mm[i][j] || mm[j][i]) {
//				printf("%d, %d\n", i, j);
				ans = min(ans, t + ss[pp[j]]);
//				debug(t + ss[pp[j]]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    string a;
    int n;
    cin >> n;
    cin >> a;
    int W = 0, S = 0, w = 0, s = 0;
    REP(i, sz(a)) if (a[i] == 'W') W++; else S++;
    int res = n;
    REP(i, n) {
        if (a[i] == 'W') W--; else S--;
        res = min(res, w + S);
        if (a[i] == 'W') w++; else s++;
    }
    cout << res;
}




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

int main() {
	string s;
	cin >> s;
	bool C = false;
	for (size_t i = 0; i < s.length(); i++)	{
		if (C == false && s.at(i) == 'C')C = true;
		else if (C == true && s.at(i) == 'F') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " <<  x << " " <<  y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A > 9 || B > 9)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << A * B << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
(x, y, z, k), a, b, c = [[*map(int, o.split())] for o in open(0)]
a.sort(); b.sort(); c.sort()

h = [(-(a[-1] + b[-1] + c[-1]), -1, -1, -1)]
s = set(h)

from heapq import*
def push(i, j, k):
    global s, h
    try:
        t = (- (a[i] + b[j] + c[k]), i, j, k)
    except IndexError:
        return
    if t not in s:
        heappush(h, t)
        s |= {t}

for _ in [0] * k:
    p, i, j, k = heappop(h)
    print(-p)
    push(i, j, k - 1)
    push(i, j - 1, k)
    push(i - 1, j, k)

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

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
typedef long long LL;
template<class T> int maxx(T a, T b) { return a > b ? a : b; }
template<class T> int minn(T a, T b) { return a < b ? a : b; }
template<class T> int abss(T a) { return a > 0 ? a : -a; }
#define max maxx
#define min minn
#define abs abss
const int maxn = 100010;

int n, m, q, a[maxn];

int main()
{
    scanf("%d%d%d", &n, &m, &q);
    REP(i, 1, q)
    {
        int x; scanf("%d", &x);
        ++ a[x];
    }
    REP(i, 1, n)
    {
        if ( q - a[i] < m ) puts("Yes");
        else puts("No");
    }
	return 0;
}


Measured memory_bytes: 1024
class Node:
	def __init__(self, v):
		self.v = v
		self.l = self.r = None
		self.p = -1
	def __str__(self):
		return str(self.v)

def find_pos(a, v):
	for i in range(len(a)):
		if a[i] == v:
			return i
	return -1

def add_node(root, cur, ino):
	idx = find_pos(ino, cur.v)
	st = []
	st.append(root)
	while len(st) != 0:
		node = st.pop()
		if node.p == -1:
			node.p = find_pos(ino, node.v)
		if idx < node.p:
			if node.l == None:
				node.l = cur
				return
			else:
				st.append(node.l)
		else:
			if node.r == None:
				node.r = cur
				return
			else:
				st.append(node.r)		

def post_order(root):
	st = []
	cur = root
	last = None
	ret = ''
	while cur != None or len(st) != 0:
		if cur != None:
			st.append(cur)
			cur = cur.l
		else:
			peek = st[len(st)-1]
			if peek.r != None and peek.r != last:
				cur = peek.r
			else:
				if len(ret) != 0:
					ret += ' '
				ret += str(peek)
				last = st.pop()
	return ret

n = int(input())
preo = list(map(int, input().split()))
ino = list(map(int, input().split()))

r = preo[0]
root = Node(r)
for i in range(1, n):
	cur = Node(preo[i])
	add_node(root, cur, ino)

print(post_order(root))



Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 100005

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    int n;
    cin>>n;
    map<string, int> u;
    while(n--){
        string s;
        cin>>s;
        u[s] = 1;
    }
    cout<<u.size();
}


Measured memory_bytes: 19216
#include<iostream>
#include<set>
#include<cmath>
using namespace std;
int main(void){
	int x,y;
	int i,j;
	set<int> st{1};
	cin>>x;
	for(i=2;i<32;i++){
		for(j=2;y=pow(i,j),y<=x;j++){
			st.insert(y);
		}
	}
	auto itr = st.end();
	itr--;
	cout<<*itr<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
typedef std::vector<int> vin;
const int INFN = 1e9+7;
const int MAXM = 5005;
const int MAXN = 2505;
int dist[MAXN]{ };
enum { SRC = 1 };
vin G[MAXN];
vin H[MAXN]; // Reverse of G
int M, N, P;

struct Edge {
  int A, B, C;
} E[MAXM];
bool seenG[MAXM]{ };
bool seenH[MAXM]{ };

int bellman_ford() {
  for (int i = 1; i <= N; ++i) dist[i] = INFN;
  dist[SRC] = 0;

  // Relax
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      if (dist[E[j].A] == INFN) continue;
      seenG[j] = true;
      if (dist[E[j].B] > dist[E[j].A] + E[j].C) {
        dist[E[j].B] = dist[E[j].A] + E[j].C;
      }
    }
  }

  // Cycle
  for (int j = 0; j < M; ++j) {
    if (!seenG[j] || !seenH[j]) continue;
    if (dist[E[j].B] > dist[E[j].A] + E[j].C) {
      return -1;
    }
  }
  return std::max(-dist[N], 0);
}

void dfs(int cur) {
  // Reachability from N.
  for (auto nxt: H[cur]) {
    if (seenH[nxt]) continue;
    seenH[nxt] = true;
    dfs(E[nxt].A);
  }
}

int main() {
  scanf(" %d%d%d", &N, &M, &P);
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d%d", &E[i].A, &E[i].B, &E[i].C);
    E[i].C -= P;  // Button press.
    E[i].C *= -1; // Longest path.
    G[E[i].A].push_back(i);
    H[E[i].B].push_back(i);
  }
  dfs(N);
  printf("%d\n", bellman_ford());
  return 0;
}

Measured memory_bytes: 768
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    t = input()
    bef = '!'
    s = ""
    for c in t:
        nc = c
        if c == '?':
            nc = "D"
        bef = nc
        s += nc
    print(s)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9528
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int N , T;
int A[100010];
int mx[100010];

int main(){
	scanf("%d%d" , &N , &T);
	repp(i,0,N){
		scanf("%d" , A + i);
	}
	repm(i,N-1,-1){
		mx[i] = max(mx[i+1] , A[i]);
	}
	int x = 0;
	repp(i,1,N){
		x = max(x , mx[i] - A[i-1]);
	}
	int y = 0;
	int z = 0;
	int ans = 0;
	if(mx[0] - A[0] == x) ++z;
	repp(i,1,N){
		if(mx[i-1] != mx[i]){
			ans += min(y , z);
			y = 0;
			z = 0;
		}
		if(mx[i] == A[i]) ++y;
		if(mx[i] - x == A[i]) ++z;
	}
	ans += min(y,z);
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    double l;
    cin >> l;
    cout << fixed << setprecision(12) << (l/3) * (l/3) * (l/3) << endl;
}

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

int main() {
  int n;
  cin >>n;
  string w;
  set<string> s;
  rep(i,n){
    cin>>w;
    s.insert(w);
  }
  cout << s.size()<<endl;
}


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


int main() {
  
  int x,y;
  
  cin >> x >> y;
  
  int a = (4*x-y)/2;
  int b = (y-2*x)/2;
  
  if(a<0 || b<0){
    cout << "No";
    return 0;
  }
  
  else if(a+b == x && 2*a+4*b == y){
    cout << "Yes";
    return 0;
  }
  
  else{
    cout << "No";
    return 0;
  }
    
  
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector> 
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> Vec(n);
	for(int i=0;i<n;i++)
		cin >> Vec[i];

	sort(Vec.begin(),Vec.end());
	long long sum = accumulate(Vec.begin(), Vec.end(), 0LL);
	cout << Vec.front() << " " << Vec.back() << " " << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3136
n, m = map(int, input().split())
l, r = map(int, input().split())
for i in range(m-1):
    l_c, r_c = map(int, input().split()) 
    l = max(l, l_c)
    r = min(r, r_c)
print(max(r-l+1, 0))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int L[101][101],r,c,i,j;
    cin >> r >> c;
    
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            cin >> L[i][j];
        }
    }    
    for(i=0; i<=r; i++)L[i][c]=0;
    for(j=0; j<=c; j++)L[r][j]=0;
    
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            L[i][c]+=L[i][j];
            L[r][j]+=L[i][j];
            L[r][c]+=L[i][j];
        }
    }
    for(i=0; i<=r; i++){
        for(j=0; j<=c; j++){
            if(j)cout << " ";
            cout << L[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
// ABC093_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    string N;
    cin >> N;
//    vector<ll> vec(N);
//    REP(i, N) cin >> vec[i];
    
    // calculation
    sort(N.begin(), N.end());
    if (N == "abc") {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;

int main(){
  int n;cin>>n;
  int ans=0;
  VI a(n);REP(i,n){cin>>a[i];}
  for(int i=0;i<n;i++){
    if(i%2==0&&a[i]%2==1){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3164
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class T, class U> inline T GCD_L(T a, U b){
  T r;
  while(b){
    r=a;
    a=b;
    b=r%a;
  }
  return a;
}
int N;
int A[1000000];
int cnt[1000000+1];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    cnt[A[i]]++;
  }
  int RZTsC2BF;
  int FmcKpFmN;
  if(N==0){
    FmcKpFmN = 0;
  }
  else{
    FmcKpFmN = A[0];
    for(RZTsC2BF=(1);RZTsC2BF<(N);RZTsC2BF++){
      FmcKpFmN = GCD_L(FmcKpFmN, A[RZTsC2BF]);
    }
  }
  if(FmcKpFmN!= 1){
    wt_L("not coprime");
    wt_L('\n');
    return 0;
  }
  for(i=(1);i<(1000000+1);i++){
    int j;
    for(j=(2*i);j<(1000000+1);j+=(i)){
      cnt[i] += cnt[j];
    }
  }
  for(i=(2);i<(1000000+1);i++){
    if(cnt[i] > 1){
      wt_L("setwise coprime");
      wt_L('\n');
      return 0;
    }
  }
  wt_L("pairwise coprime");
  wt_L('\n');
  return 0;
}
// cLay varsion 20200813-1 [beta]

// --- original code ---
// int N, A[1d6];
// int cnt[1d6+1];
// {
//   rd(N,A(N));
//   rep(i,N) cnt[A[i]]++;
// 
//   if(gcd(A(N)) != 1) wt("not coprime"), return 0;
// 
//   rep(i,1,1d6+1) rep(j,2*i,1d6+1,i) cnt[i] += cnt[j];
//   rep(i,2,1d6+1) if(cnt[i] > 1) wt("setwise coprime"), return 0;
// 
//   wt("pairwise coprime");
// }


Measured memory_bytes: 12468
m,k = map(int, input().split())

if k>=2**m:
    print(-1)
    exit()

if m==0:
    print(0,0)
elif m==1:
    if k==0:
        print(0,0,1,1)
    else:
        print(-1)
else:
    for i in range(2**m):
        if i!=k:
            print(i,end=' ')
    print(k,end=' ')
    for i in range(2**m-1,-1,-1):
        if i!=k:
            print(i,end=' ')
    print(k)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int cnt = 0, zero = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] < 0) ++cnt;
        if (a[i] == 0) ++zero;
    }
    if (cnt % 2 == 1 && zero == 0) {
        long long ans = 0;
        int tmp = 1e9;
        for (int i = 0; i < n; ++i) {
            if (a[i] >= 0) ans = ans + a[i];
            else ans = ans - a[i];
            tmp = min(tmp, abs(a[i]));
        }
        cout << ans - tmp - tmp;
    } else {
        long long ans = 0;
        for (int i = 0; i < n; ++i) {
            if(a[i] >= 0) ans = ans + a[i];
            else ans = ans - a[i];
        }
        cout << ans;
    }
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"
#define MAX  1000001
#define ff first
#define ss second

ll mod = 1e9 + 7;

void solve(){
  string s;
  cin >> s;
  ll i = 0;
  ll ans = 0;
  while(i < s.length()){
    ll j = i;
    while(j < s.length()){
      if(s[j] != 'R') break;
      j++;
    }
    if(i == j) i++;
    else{ 
      ans = max(ans,j - i);
      i = j;
    }
    
  }
  cout << ans << br;

}
	

int main(){
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif  
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}

Measured memory_bytes: 3612
#include<stdio.h>
int main (void)
{
    int a,b,w,s,k,m;
    scanf("%d%d",&a,&b);
    if(a+b>=a-b&&a+b>=a*b) m=a+b;
    else 
    if(a-b>=a+b&&a-b>=a*b) m=a-b;
    else
    m=a*b;
    printf("%d",m);
    return 0;
    }


Measured memory_bytes: 128
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int A,B,C,K,ans = 0;
    cin >> A >> B >> C >> K;

    if(K <= 0){
        cout << ans << endl;
        return 0;
    }
    ans += min(A, K);
    K -= min(K, A);
    if(K <= 0){
        cout << ans << endl;
        return 0;
    }
    K -= min(K, B);
    if(K <= 0){
        cout << ans << endl;
        return 0;
    }
    ans -= min(C, K);
    cout << ans << endl;
}

Measured memory_bytes: 3548
def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    N = int(input())

    d = defaultdict(int)

    def string_sort(s):
        return str(sorted(s))
        # str(sorted('cba'))
        # "['a', 'b', 'c']"

        # return ''.join(sorted(s))

    ans = 0
    for _ in range(N):
        s = string_sort(input().rstrip())
        ans += d[s]
        d[s] += 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())

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

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

	int n, k; cin >> n >> k;
	vector<int> a(n);
	trav(x, a) cin >> x;
	rep(i, 0, n - k) cout << (a[i] < a[i + k] ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

  vector<bool> col(H,false), row(W,false);
  vector< vector<char> > squares(H, vector<char>(W));
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      cin >> squares[i][j];
      if (i == 0)
      {
        if (squares[i][j] == '.') row[j] = true;
      }
      else
      {
        if (squares[i][j] == '#') row[j] = false;
      }

      if (j == 0)
      {
        if (squares[i][j] == '.') col[i] = true;
      }
      else
      {
        if (squares[i][j] == '#') col[i] = false;
      }
    }
  }

  for (int i = 0; i < H; ++i)
  {
    if (col[i] == true) continue;
    for (int j = 0; j < W; ++j)
    {
      if (row[j] == true) continue;
      cout << squares[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,ans=0,count[111111]={0};
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    count[a]++; count[a+1]++; count[a+2]++;
    ans=max(ans,count[a]);
    ans=max(ans,count[a+1]);
    ans=max(ans,count[a+2]);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,ans,b[110],a[110][30];
char c;
int main()
{
  cin>>n;
  for(int t=0;t<3;++t)
  for(int i=0;i<n;++i) cin>>c,
   	  				   a[i][c-'a']++,
    				   b[i]=max(b[i],a[i][c-'a']);
  for(int i=0;i<n;++i) ans+=3-b[i];
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;
#define dump(x) cout << (x) << '\n'
Int mod = 1e9+7;
//Int mod = 998244353; 
Int INF = 1e9+7;

vector<vector<Int>> G(200001);
Int node[200001];
bool visited[200001];
Int md;
Int dn;

void dfs(Int x, Int d) {
    if (visited[x]) return;
    visited[x] = true;
    if (d > md) {
        md = d;
        dn = x;
    }
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        //if (!visited[G[x][i]]) {
            Int to = G[x][i];
            dfs(to, d + 1);
        //}
    }
}

int main() {    
    Int n;
    cin >> n;
    for (Int i = 0; i < n - 1; i++) {
        Int a, b;
        cin >> a >> b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        node[a]++;
        node[b]++;
    }
    dfs(1, 1);
    for (Int i = 1; i <= n; i++) visited[i] = false;
    dfs(dn, 1);
    if (md % 3 != 2) {
        dump("First");
    }
    else {
        dump("Second");
    }
    return 0;  
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

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

Measured memory_bytes: 3600
import java.util.*;


public class Main{   
    
    public static void main(String[] args){            
       
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();        
        long M = sc.nextLong();                
        
        long ans = 0;
        
        if(M >= 2*N){
            ans =  N; 
            ans = (M - 2*N)/4 + ans;
        }else{
            ans = M/2;
        }
        
        System.out.println(ans);
        
        
    }                                       
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A * N, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; (i) < (n); ++(i))
#define REP3(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define REP_R(i,n) for (int i = (int)(n) - 1; (i) >= 0; --(i))
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }

template <class Monoid>
struct segment_tree {
    typedef typename Monoid::underlying_type underlying_type;
    int n;
    vector<underlying_type> a;
    const Monoid mon;
    segment_tree() = default;
    segment_tree(int a_n, underlying_type initial_value = Monoid().unit(), Monoid const & a_mon = Monoid())
            : mon(a_mon) {
        n = 1; while (n < a_n) n *= 2;
        a.resize(2 * n - 1, mon.unit());
        fill(a.begin() + (n - 1), a.begin() + ((n - 1) + a_n), initial_value);
        REP_R (i, n - 1) a[i] = mon.append(a[2 * i + 1], a[2 * i + 2]);
    }

    void point_set(int i, underlying_type z) {
        assert (0 <= i and i < n);
        a[i + n - 1] = z;
        for (i = (i + n) / 2; i > 0; i/= 2) {
            a[i - 1] = mon.append(a[2 * i - 1], a[2 * i]);
        }
    }

    underlying_type range_concat(int l, int r) {
        assert (0 <= l and l <= r and r <= n);
        underlying_type lacc = mon.unit();
        underlying_type racc = mon.unit();
        for (l += n, r += n; l < r; l /= 2, r /= 2) {
            if (l % 2 == 1) lacc = mon.append(lacc, a[(l ++) - 1]);
            if (r % 2 == 1) racc = mon.append(a[(-- r) - 1], racc);
        }
        return mon.append(lacc, racc);
    }
};

struct plus_monoid {
    typedef int underlying_type;
    int unit() const { return 0; }
    int append(int a, int b) const { return a + b; }
};

ll solve(int n, vector<int> const & a) {
    int max_a = *max_element(ALL(a));
    vector<deque<int> > indices(max_a + 1);
    REP (i, n) indices[a[i]].push_back(i);

    segment_tree<plus_monoid> segtree(n, 1);
    ll cost = 0;
    REP (a_i, max_a + 1) {
        while (not indices[a_i].empty()) {
            int cost_l = segtree.range_concat(0, indices[a_i].front());
            int cost_r = segtree.range_concat(indices[a_i].back() + 1, n);
            if (cost_l < cost_r) {
                cost += cost_l;
                segtree.point_set(indices[a_i].front(), 0);
                indices[a_i].pop_front();
            } else {
                cost += cost_r;
                segtree.point_set(indices[a_i].back(), 0);
                indices[a_i].pop_back();
            }
        }
    }

    return cost;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) cin >> a[i];
    cout << solve(n, a) << endl;
    return 0;
}



Measured memory_bytes: 71476
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/testdata.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/testData.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
            // fin.close();
            // fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver
    {

        public void solve (InputReader cin, PrintWriter cout)
        {
            try {
                int n = cin.nextInt();
                int[] a = new int[n];
                for (int i = 0; i < n; ++i) a[i] = cin.nextInt();
                int ret = 0;
                for (int i = 1; i < n; ++i) {
                    if (a[i - 1] != -1 && a[i] == a[i - 1]) {
                        a[i] = -1;
                        ret++;
                    }
                }
                cout.println(ret);
            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

    }

}

Measured memory_bytes: 21332
#include <cstddef>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
namespace loquat {
using vertex_t = size_t;
}
namespace loquat {
namespace edge_param {
struct to_ {
	vertex_t to;
	explicit to_(vertex_t t = 0)
		: to(t)
	{ }
};
}
namespace detail {
template <typename T, typename... Params>
struct edge_param_wrapper : public T, edge_param_wrapper<Params...> {
};
template <typename T>
struct edge_param_wrapper<T> : public T {
	template <typename U>
	explicit edge_param_wrapper(U&& x)
		: T(std::forward<U>(x))
	{ }
};
}
template <typename... Params>
struct edge : public detail::edge_param_wrapper<edge_param::to_, Params...> {
	template <typename... Args>
	explicit edge(Args&&... args)
		: detail::edge_param_wrapper<edge_param::to_, Params...>(
			std::forward<Args>(args)...)
	{ }
};
}
namespace loquat {
template <typename EdgeType>
class adjacency_list {
public:
	using edge_type = EdgeType;
	using edge_list = std::vector<edge_type>;
private:
	std::vector<std::vector<EdgeType>> m_edges;
public:
	explicit adjacency_list(size_t n)
		: m_edges(n)
	{ }
	edge_list& operator[](vertex_t u){
		return m_edges[u];
	}
	template <typename... Args>
	void add_edge(vertex_t from, Args&&... args){
		m_edges[from].emplace_back(std::forward<Args>(args)...);
	}
};
}
using namespace std;
using edge = loquat::edge<>;
int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	loquat::adjacency_list<edge> g(n);
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		g.add_edge(a, b);
		g.add_edge(b, a);
	}
	bool possible = true;
	for(int v = 0; v < n; ++v){
		if(g[v].size() % 2 != 0){ possible = false; }
	}
	cout << (possible ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC136_C
    std::string str;

    cin>>str;
    int N = str.size();
    vector<int> vec(N,0);

    for(int i = 0; i < N-1 ; i ++)
    {
        if((str[i]=='R')&&(str[i+1]=='L'))
        {
            for(int j = i; j >= 0; j --)
            {
            if(str[j] == 'L') break;
            vec[i+(i-j)%2]++;
            }
            for (int j = i+1; j <N; j++)
            {
                if (str[j] == 'R')
                    break;
                vec[i + (j-i)%2]++;
            }
        }
    }

    for(int i = 0; i < N ;i ++)
    {
        cout<<vec[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x;
    int count;

    while(1){
        scanf("%d %d ", &n, &x);
        if(n==0&&x==0)break;
        count=0;
        for(i=1;3*i+3<=x;i++){
            for(j=i+1;i+2*j+1<=x;j++){
                for(k=n;k>j;k--){
                    if(x==i+j+k){
                        count++;
                        break;
                    }else if(x>=i+j+k){
                        break;
                    }
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}


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

//#include <conio.h>
using namespace std;


struct P
{
    //string r;
    int x;
    long long y,z;

   /* bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
              return y>a.y;
    }*/
};


vector<P> v[5];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[5][5];

int o[255];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

int e[5][5];

long long x,y,mod=1000000007;
long long z;
int j[200];
P u[110000];
//stack<int> s;
//queue<long long> q;
queue<int> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;
string r;

//deque<int> de;

bool as(P a,P b)
{
    return max(a.y,-a.y)<max(b.y,-b.y);
}


int main()
{
    scanf("%d",&a);
    if(a==3)
    {
        printf("2 5 63");
        return 0;
    }
    for(int n=2;n<=5000;n+=2)
        for(int m=2;m<=10000;m+=2)
        if(a-n-m<=5000&&a-n-m>=0)
    {
        int x=m,y=n,z=a-n-m;
        for(int t=2;t<=30000;t++)
            if(t%6==0)
        {
            if(z>0)
            {
                z--;
                printf("%d ",t);
            }
        }
        else if(t%3==0)
        {
            if(y>0)
            {
                y--;
                printf("%d ",t);
            }
        }
        else if(t%2==0)
        {
            if(x>0)
            {
                x--;
                printf("%d ",t);
            }
        }
        return 0;
    }
}



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
ii a[N];
int l1[N], l2[N], r1[N], r2[N];
int n, t;
ll sum;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        r1[i] = r2[i] = n + 1;
    }
    for (int i = 1; i <= n; ++i) {
        cin >> t;
        a[i] = {t, i};
    }
    sort(a + 1, a + n + 1);
    set<int> lst;
    set<int> rst;
    for (int i = n; i > 0; --i) {
        int cur = a[i].second; // original index
        auto it1 = rst.lower_bound(cur);
        if (it1 != rst.end()) {
            r1[cur] = *it1;
            auto it2 = next(it1);
            if (it2 != rst.end()) {
                r2[cur] = *it2;
            }
        }
        auto it3 = lst.lower_bound(-cur);
        if (it3 != lst.end()) {
            l1[cur] = -*it3;
            auto it4 = next(it3);
            if (it4 != lst.end()) {
                l2[cur] = -*it4;
            }
        }
        rst.insert(cur);
        lst.insert(-cur);
    }
    for (int i = 1; i <= n; ++i) {
        int k = a[i].second;
        sum += 1LL * (l1[k] - l2[k]) * (r1[k] - k) * a[i].first;
        sum += 1LL * (k - l1[k]) * (r2[k] - r1[k]) * a[i].first;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 15196
#問題番号：2015 「Square Route」
#教室内の着席位置：中央*奥
#URL：http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015
#この問題の制約を見るに、O(N^2)で十分
#しかし、道と道の間の長さがN(N-1)/2あるため、これを求めるだけでO(N^2)
#従って、hとwでの比較はO(N)でしなければならない
while(True):
    tmp = list(map(int,input().split()))
    n,m = tmp[0],tmp[1]
    ans = 0
    #終了するケースを省く
    if n == 0:
        quit()
    hs, ws = [0], [0]
    #hとwについて累積和を取る(これがhsとws)
    for i in range(n):
        hs.append(hs[-1]+int(input()))
    for i in range(m):
        ws.append(ws[-1]+int(input()))
    #hとwについて、道の間の距離を差分として計算してそれぞれ記録(累積和を取っているのでsumを取る必要がなく高速)
    #工夫として、距離を直接記録して行くのではなく、「距離Lになった時にdif[L]をインクリメント」という方針
    #こうすることで最終的な計算をsum(h_dif[L]*w_dif[L])で出せる
    h_dif, w_dif = [0] * (hs[-1]+1), [0] * (ws[-1]+1)
    for i in range(n):
        for j in range(i+1,n+1):
            h_dif[hs[j]-hs[i]] += 1
    for i in range(m):
        for j in range(i+1,m+1):
            w_dif[ws[j]-ws[i]] += 1
    for i in range(1,min(len(h_dif),len(w_dif))):
        ans += h_dif[i] * w_dif[i]
    print(ans)



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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int a[n];
    rep(i, n) cin >> a[i];
    int cnt = 0, sum = 0;
    rep(i, n) sum += a[i];

    rep(i, n)
    {
        if (sum <= 4 * a[i] * m)
            cnt++;
    }
    if (cnt >= m)
        OP("Yes");
    else
        OP("No");

    return 0;
}

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

vector<vector<int>>bakudan(8, vector<int>(8));
int xp[12]{-3,-2,-1,0,0,0,0,0,0,1,2,3};
int yp[12]{0,0,0,-3,-2,-1,1,2,3,0,0,0};
void shima(int x, int y) {
	bakudan[x][y] =0;
	for (int a = 0; a < 12; a++) {
		if (x + xp[a] > -1 && x + xp[a]<8 && y + yp[a]>-1 && y + yp[a] < 8&&bakudan[x+xp[a]][y+yp[a]])shima(x + xp[a], y + yp[a]);
	}
}
int main() {
	int k;
	cin >> k;
	vector<vector<vector<int>>>sss(k);
	for (int b = 1; b <= k; b++) {
		for (int l = 0; l < 8; l++) {
			for (int r = 0; r < 8; r++)bakudan[l][r] = 0;
		}
		for (int a = 0; a < 8; a++) {
			string c;
			cin >> c;
			for (int b = 0; b < 8; b++) {
				bakudan[a][b] = c[b] - 48;
			}
		}
		int d, e;
		cin >> d >> e;
		d--; e--;
		shima(e, d);
		sss[b - 1] = bakudan;
	}
	for (int g = 0; g < k; g++) {
		cout << "Data " << g + 1 << ":" << endl;
		for (auto f : sss[g]) {
			for (int h : f) {
				cout << h;
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

int main(){

	int n; cin>>n;
	int b[n+1];
	int s[n+1]; //stores subordinates
	for(int i=1;i<=n;i++) s[i]=0;

	for(int i=2;i<=n;i++){ //boss of ID i is b[i]
		cin>>b[i];
		s[b[i]]++;
	}

	for(int i=1;i<=n;i++) cout<<s[i]<<endl;

	return 0;
}

Measured memory_bytes: 5112
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int M, N;
int arr[100];

int main() {
    while (true) {
        cin >> M >> N;
        if (M+N == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> arr[j];
        }

        int l = 0, r = 1500000;
        while (l < r) {
            int m = (l+r) / 2;
            int row = 0, acc = 0;
            bool ok = true;
            for (int j = 0; j < N; ++j) {
                if (m-acc < arr[j]) {
                    ++row;
                    acc = 0;
                }
                if (row == M || m < arr[j]) {
                    ok = false;
                    break;
                } 
                if (m-acc >= arr[j]) {
                    acc += arr[j];
                }
            }
            if (ok) {
                r = m;
            } else {
                l = m+1;
            }
        }
        cout << r << endl;
    }
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	vector<ll>mod1(s.length(),0);
	for (int i = 0; i < s.length(); i++) {
		if (i == 0)mod1.at(i) = 1;
		else mod1.at(i) = mod1.at(i-1) * 10 % 2019;
	}
	vector<ll>mod(s.length(),0);
	for (int i = 0; i < s.length(); i++) {
		int x = s.at(s.length() - 1 - i) - '0';
		if (i == 0)mod.at(i) = x * mod1.at(i);
		else {
			mod.at(i) = mod.at(i - 1) + x * mod1.at(i);
			mod.at(i) %= 2019;
		}
	}
	map<ll, ll>mods;
	mods[0] = 1;
	for (int i = 0; i < mod.size(); i++) {
		if (mods.count(mod.at(i)))mods.at(mod.at(i))++;
		else mods[mod.at(i)] = 1;
	}
	ll ans = 0;
	for (auto a : mods) {
		if (a.second == 1)continue;
		else ans += a.second * (a.second - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6832
#include <bits/stdc++.h>
// #define int long long
#define Matrix vector<vector<int> >
// #define Matrix vector<vector<int> >
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
double rad(double x){
    return x*pi/180.0;
}
 
bool isleft(pair<int,int> a, pair<int,int> b, pair<int,int> c){
    int det = (b.first-a.first)*(c.second-a.second) - (c.first-a.first)*(b.second-a.second);
    if(det>=0) return true;
    if(det<0) return false;
    return false;
}
 
int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = mod(result*a,MOD);
 
        b >>= 1;
        a = mod(a*a,MOD);
    }
    return result;
}

double memo[321][321][321];
int vet[321];
int n;
double dp(int t, int d, int u){
	if(t+d+u==0) return 0;
	double &x = memo[t][d][u];
	if(x!=-1) return x;
	x = 0;
	if(t>0)
		x+=t*dp(t-1,d+1,u);
	if(d>0)
		x+=d*dp(t,d-1,u+1);
	if(u>0){
		x+=u*dp(t,d,u-1);
	}
	x/=(t+d+u)*1.0;
	x+=n*1.0/(t+d+u);
	return x;
}
void solve(){
	cin>>n;
	int q[4] = {0,0,0};
	for(int i=0;i<n;i++){
		cin>>vet[i];
		q[vet[i]]++;
	}
	for(int i=0;i<321;i++)
		for(int j=0;j<321;j++)
			for(int k=0;k<321;k++)
				memo[i][j][k]=-1;
	cout<<fixed<<setprecision(13);
	cout<<dp(q[3],q[2],q[1])<<endl;
}

signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 520708
#include <iostream>
#include <cstdio>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

char map[50][50];
int w, h;

void solve();
int check(int, int, int);

int main(){
  while(1){
    scanf(" %d %d", &w, &h);
    if((w | h) == 0) break;
    else solve();
  }

  return 0;
}

void solve(){
  int black = 0, white = 0;

  REP(i, h){
    REP(j, w){
      scanf(" %c", &map[j][i]);
    }
  }
   
  REP(i, h){
    REP(j, w){
      if(map[j][i] == 'B'){
	check(j, i, 1);
      }
      else if(map[j][i] == 'W'){
	check(j, i, 2);
      }
    }
  }

  REP(i, h){
    REP(j, w){
      if(map[j][i] == 1) black++;
      else if(map[j][i] == 2) white++;
    }
  }
    printf("%d %d\n", black, white);
}

int check(int x, int y, int mark){
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, -1, 0, 1};
  int nx, ny;

  REP(i, 4){
    nx = x + dx[i];
    ny = y + dy[i];
    if(nx >= 0 && nx < w && ny >= 0 && ny < h){
      char point = map[nx][ny];
      if(point != 'B' && point != 'W'){
	if(map[nx][ny] == '.'){
	  map[nx][ny] = mark;
	  check(nx, ny, mark);
	}
	else{ 
	    map[nx][ny] |= mark;
	    if((mark & point) != mark) check(nx, ny, mark);
	}
      }
    }
  }
}


Measured memory_bytes: 1284
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char a;
   scanf("%c",&a);
   if(a=='A')
    printf("T");
   else if(a=='T')
   printf("A");
   else if(a=='C')
    printf("G");
    else if(a=='G')
    printf("C");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;
int INF = 1001001001;
int main(){
	int s;
	cin >> s;
	string ans = "AMBIGUOUS";
	int b = s/100;
	int a = s%100;

	if((b>12 || b==0) && (a>12 || a==0)){
		ans = "NA";
	}else if((b>12 || b==0) && 0<a && a<=12){
		ans = "YYMM";
	}else if(0<b && b<=12 && (a>12 || a==0)){
		ans = "MMYY";
	}else{ ans = "AMBIGUOUS";}
	cout << ans << endl;


	return 0;
}


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


int main() {
	string s;
	cin >> s;
	int ans = 642;
	for(int i = 0; i < s.size() - 2; i++){
		if(abs(stoi(s.substr(i, 3)) - 753) < ans){
			ans = abs(stoi(s.substr(i, 3)) - 753);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256