akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back()
#define M 1000000007
#define rep(i , l , r) for(ll i=l; i < r; i++)
#define repr(i , r , l) for(ll i=r; i >= l; i--)

using namespace std;

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    /*#ifndef ONLINE_JUDGE
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    #endif*/

    ll n , k;
    cin >> n;
    ll mat[n][3];
    rep(i , 0 , n) {
        rep(j , 0 , 3) cin >> mat[i][j];
    }
    repr(i , n-2 , 0) {
        rep(j , 0 , 3) {
            mat[i][j] += max(mat[i+1][(j+1)%3] , mat[i+1][(j+2)%3]);
        }
    }
    ll ans = max(max(mat[0][0] , mat[0][1]) , mat[0][2]);
    cout << ans << "\n";
    return 0;

}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

ll N, M, K;
ll fact[222222];

template<typename T> T modInverse(T a, T m = MOD)
{
  T b = m, x = 1, u = 0;
  T q, t;
  while(b > 0){
    q = a / b;
    t = u; u = x - q * u; x = t;
    t = b; b = a - q * b; a = t;
  }

  return (x + m) % m;
}

template<typename T> T modComb(T n, T k, T p = MOD, T* fact = fact)
{
  if(n < 0 || k < 0 || n < k) return 0;
  if(n - k > (T)0) minup(k, n-k);
  return fact[n] * modInverse(fact[n - k] * fact[k] % MOD) % MOD;
}

inline ll solve(ll n, ll i)
{
  return (modComb(n + 2 * i, i) * (n + 1LL) % MOD) * modInverse(n + i + 1LL) % MOD;
}

int main(int argc, char *argv[])
{
  cin >> N >> M >> K;

  fact[0] = 1LL;
  rep(i, 222220) fact[i + 1] = (fact[i] * (i + 1LL)) % MOD;

  ll res = 0LL;
  erep(i, 0, K){
    res = (res + ((((modComb(N + M + 2 * K, N + 2 * i) % MOD) * solve(N, i) % MOD) * solve(M, K - i) % MOD))) % MOD;
  }

  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 2892
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	int p[25];
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=0;i<n;i++){
		if((i!=0 and i!=n-1) and ((p[i-1]<p[i] and p[i]<p[i+1]) or (p[i-1]>p[i] and p[i]>p[i+1]))){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = [int(a)-1 for a in input().split()]
B = [int(a)-1 for a in input().split()]

LA = [0] * N + [N]
LB = [0] * N + [N]
j = 0
for i in range(N):
    LA[i] = j
    while j < N and A[j] == i:
        j += 1
j = 0
for i in range(N):
    LB[i] = j
    while j < N and B[j] == i:
        j += 1

NG = [0] * (N + 1)
for l1, r1, l2, r2 in zip(LA[:-1], LA[1:], LB[:-1], LB[1:]):
    ngl = l1-r2+1
    ngr = r1-l2
    if ngl < ngr < 0:
        NG[ngl+N] += 1
        NG[ngr+N] -= 1
    elif ngl < 0 <= ngr:
        NG[ngl+N] += 1
        NG[N] -= 1
        NG[0] += 1
        NG[ngr] -= 1
    elif 0 <= ngl < ngr:
        NG[ngl] += 1
        NG[ngr] -= 1
for i in range(N):
    NG[i+1] += NG[i]

for i in range(N):
    if NG[i]: continue
    print("Yes")
    print(*[a + 1 for a in (B[-i:] + B[:-i] if i else B)])
    break
else:
    print("No")

Measured memory_bytes: 128160
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N = int(raw_input())
K = int(raw_input())
X = int(raw_input())
Y = int(raw_input())
print X*min(K, N) + Y*max(0, N - K)


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    string s;
    cin >> n >> s;
    int res = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] != 'A') continue;
        if(i < n - 2){
            if(s[i+1] == 'B' && s[i+2] == 'C')  ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int input[2000006];
int main(void)
{
	int n;
	scanf("%d",&n);
	int initial = 1;
	int counter = 0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&input[i]);
		if(input[i] == initial)
		{
			counter++;
			initial++;
		}
	}
	if(initial == 1 )
		printf("-1\n");
	else 
	{
		printf("%d\n",(n-counter));
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>a>>b;
    if(b==1) 
    {
        cout<<"0";
        return 0;
    }
    ll ans=1;
    ll count=a;
    if(a>=b)
    {
        cout<<"1";
        return 0;
    }
    while(1)
    {
        if(count>=b) break;
        count-=1;
        count+=a;
        ans++;
    }
    cout<<ans;
    
}

Measured memory_bytes: 3572
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1200

int main() {
	int d[26] = { 0 };
	char str[N];
	char alph[2][27];
	int i, j,k,a;

	for (i = 0; i < 2; i++) {
		for (j = 0; j < 26; j++) {
			a = i == 0 ? 65 : 97;
			alph[i][j] = a + j;
		}
	}

	for (i = 0; scanf("%c",&str[i])!=EOF; i++) {
		for (j = 0; j < 2; j++) {
			for (k = 0; k < 26; k++)

				if (str[i] == alph[j][k]) d[k]++;
		}
	}
	for(i=0;i<26;i++)
		printf("%c : %d\n", 'a'+i,d[i]);

	return 0;
}

Measured memory_bytes: 544
import math
N, P = map(int, input().split())


def hpow(x, n):
    ret = 1
    while(n > 0):
        if n & 1 >= 0:
            ret = ret * x
        x = x * x
        n >>= 1
    return ret


if N >= P:
    print(1)
elif N == 1:
    print(P)
elif N >= 50:
    print(1)
else:
    mx = int(math.pow(P, 1/N)+10)
    for i in range(mx, 0, -1):
        #t = hpow(i, N)
        t = i ** N
        #print(i,t)
        if P % t == 0:
            print(i)
            import sys
            sys.exit(0)
    print(1)


#206 15742385477438336


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int t;
	cin >> t;
	map<string, int> mp;
	while(t --)
	{
		string s;
		cin >> s;
		mp[s] ++;
	}
	cout << "AC x " << mp["AC"] << '\n';
	cout << "WA x " << mp["WA"] << '\n';
		cout << "TLE x " << mp["TLE"] << '\n';
			cout << "RE x " << mp["RE"] << '\n';




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) if(!a[i])
	{
		cout << 0;
		return 0;
	}
	ll ans = 1;
	for(int i = 0; i < n; i++)
	{
		if(ans > (ll) 1e18/a[i])
		{
			cout << -1;
			return 0;
		}
		ans *= a[i];
	}
	cout << ans;

	return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  string str;
  if (n == 3 || n == 5 || n == 7) str = "YES";
  else str = "NO";

  cout << str << endl;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;



int main(void) {
  string s;
  cin >> s;
  int n = s.length();
  // greedy
  VI dp(n + 2, 0);
  dp[n + 1] = 0;
  dp[n] = 1;
  vector<VI> next(n + 1, VI(26));
  set<char> seen;
  VI tbl(26, n + 1);
  for (int i = n - 1; i >= 0; --i) {
    tbl[s[i] - 'a'] = i + 1;
    int mi = 1e8;
    REP(j, 0, 26) {
      next[i][j] = tbl[j];
      mi = min(mi, dp[next[i][j]] + 1);
    }
    dp[i] = mi;
  }
  /*
  while (pos < n) {
    seen.insert(s[pos]);
    if (seen.size() == 26) {
      seen.clear();
      res += s[pos];
    }
    pos += 1;
  }
  for (char c = 'a'; c <= 'z'; ++c) {
    if (seen.count(c) == 0) {
      res += c;
      break;
    }
  }
  */
  string res;
  int cur = dp[0];
  int pos = 0;
  while (cur > 0) {
    REP(i, 0, 26) {
      char c = 'a' + i;
      if (dp[next[pos][i]] == cur - 1) {
	res += c;
	cur -= 1;
	pos = next[pos][i];
	break;
      }
    }
  }
  if (res.length() >= 2) {
	  cout << "None" << endl;
  } else {
    cout << res << endl;
  }
}


Measured memory_bytes: 14080
N = int(input())
S = input()

rcost = 0
lcost = S.count('E')
if S[0] == 'E':
    lcost -= 1
ans = lcost

for i in range(N-1):
        if S[i] == 'W':
            rcost += 1
        if S[i+1] == 'E':
            lcost -= 1
        ans = min(ans, rcost+lcost)
    
print(ans)

Measured memory_bytes: 3700
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
#print(ca)
ans=10**18
for BIT in range(1<<n):
    l=[0]*m
    tmp=0
    t=0
    b="0"*(n-len(bin(BIT)[2:]))+bin(BIT)[2:]
    book=[]#購入する本のリスト
    for i in range(n):
        if b[-i-1]=="1":
            book.append(i)
    #print(b,book)
    for j in range(n):
        if j in book:
            for k in range(1,m+1):
                l[k-1]+=ca[j][k]
            tmp+=ca[j][0]
    #print(tmp,l,b,book)
    for z in range(m):#x以上かチェック
        if l[z]<x:
            t=1
            continue
    if t==1:
        continue
    if ans>tmp:
        ans=tmp
    #print(ans,tmp,l)
if ans==10**18:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
 
int recur( int h){ 

    if(h==1) return 1; 
    else return recur(h>>1)*2+1; 

}


int32_t main(){
  fast; 
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif 
    
  int T=1; //cin>>T; 
  while(T--){


    int h; cin>>h; 
    cout<<recur(h)<<endl; 


  






  }
    


  return 0; 
} 


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 1e5+1;
int vis[N];

void solve() {
	int n, x, m;
	cin >> n >> x >> m;
	if(n == 1) {
		cout << x << endl;
		return;
	}
	int cur[m+1], i = 1, sum[m+1] = {0};
	cur[1] = x;
	sum[1] = x;
	vis[x] = 1;
	for(i = 2; i <= n; i++) {
		cur[i] = (cur[i-1]*cur[i-1])%m;
		// cout << vis[cur[i]] << endl;
		if(vis[cur[i]]) break;
		sum[i] += cur[i]+sum[i-1];
		vis[cur[i]] = i;
	}
	// cout << vis[cur[i]] << endl;
	n -= vis[cur[i]]-1;
	int ans = sum[vis[cur[i]]-1];
	ans += (sum[i-1]-sum[vis[cur[i]]-1])*(n/(i-vis[cur[i]]));
	n %= (i-vis[cur[i]]);
	ans += (sum[vis[cur[i]]+n-1]-sum[vis[cur[i]]-1]);
	cout << ans << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

 

    int test = 1;
    // cin >> test;
    
    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


Measured memory_bytes: 5744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  
  int N; cin >>N;
  bool ok = false;
  rep(i,N) {
    char s ; cin>>s;
    if (s=='Y') ok = true;
  }
  puts(ok?"Four":"Three");
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


#define N 2000000
void insert(int);
void heapIncreaseKey(int *,int,int);
int ExtractMax(int *);
void maxHeapify(int *,int);

int Heap,A[N];

int main(){
  int aaa;
  char bbb[20];

  while(1){
    scanf("%s",bbb);
    if(bbb[0]=='e'&&bbb[1]=='n')
      break;
    if(bbb[0]=='i'){
      scanf("%d",&aaa);
      insert(aaa);
    }
    else{
      printf("%d\n",ExtractMax(A));
    }
  }
  return 0;
}
void insert(int aaa){
  Heap++;
  A[Heap]=-3;
  heapIncreaseKey(A,Heap,aaa);
}
void heapIncreaseKey(int *A,int i,int aaa){
  int m;
  if(aaa<A[i])
    return;
  A[i]=aaa;
  while(i>1&&A[i/2]<A[i]){
    m=A[i];
    A[i]=A[i/2];
    A[i/2]=m;
    i=i/2;
  }
}
int ExtractMax(int *A){
  int max;
  if(Heap<1)
    return -3;
  max=A[1];
  A[1]=A[Heap];
  Heap--;
  maxHeapify(A,1);
  return max;
}
void maxHeapify(int *A,int i){
  int l,r,largest,m;
  l=2*i;
  r=2*i+1;

  if(l<=Heap && A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=Heap && A[r]>A[largest])
    largest=r;
  if(largest!=i){
    m=A[i];
    A[i]=A[largest];
    A[largest]=m;
    maxHeapify(A,largest);
  }
}
	  



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

int main() {

	int r, c, a[100][100], column[100], row[100], sum=0;

	for (int i = 0; i < 100; i++)column[i] = 0;
	for (int i = 0; i < 100; i++)row[i] = 0;

	cin >> r >> c;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> a[i][j];
			sum += a[i][j];
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			column[i] += a[i][j];
		}
	}

	for (int j = 0; j < c; j++) {
		for (int i = 0; i < r; i++) {
			row[j] += a[i][j];
		}
	}

	for (int i = 0; i < r + 1; i++) {
		if (i < r) {
			for (int j = 0; j < c + 1; j++) {
				if (j < c) cout << a[i][j] << " ";
				else cout << column[i] << "\n";
			}
		}
		else {
			for (int j = 0; j < c + 1; j++) {
				if (j < c) cout<< row[j] << " ";
				else cout << sum << "\n";
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int n;
int main(int argc,char const* argv[])
{
  cin >> n;
  double r[n];
  for(int i=0;i<n;i++)
    {
      cin >> r[i];
    }
  double newr[n];
  memset(newr,0,sizeof(newr));
  double rmax=0;
  for(int now=0;now<n;now++)
    {
      double nowr=r[now];
      for(int bef=0;bef<now;bef++)
	{
	  nowr=max(nowr,newr[bef]+sqrt(pow(r[now]+r[bef],2)-pow(r[now]-r[bef],2)));
	}
      newr[now]=nowr;
      rmax=max(rmax,newr[now]+r[now]);
    }
  cout << fixed << setprecision(9) << rmax << endl;
  return 0;
}



Measured memory_bytes: 3288
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
int main(){
	int N,P;
	while(1){
		cin>>N>>P;
		if(N==0&&P==0){
			break;
		}
		int M=P;
		//
		int A[50];
		fill(A,A+N,0);
		int now=0;
		while(1){
			if(P>0){
				P--;
				A[now]++;
				if(A[now]==M){
					cout<<now<<endl;
					break;
				}
				now++;
			}else{
				P=A[now];
				A[now]=0;
				now++;
			}
			if(now==N){
				now=0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2992
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  s.erase(unique(s.begin(),s.end()),s.end());
  if(s.size()==4)cout<<"Yes"<<endl;
  else if(s.size()==2&&(s[0]=='N'&&s[1]=='S'||s[0]=='E'&&s[1]=='W')){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;
const LL mod = 1e9 + 7;

int main()
{
	char a,b;
	while(~scanf("%c %c",&a,&b)){
		getchar();
		if(a == 'H') a = b;
		else if(b == 'D') a = 'H';
		else a = 'D';
		printf("%c\n",a);
	}
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n),b(n);
    vector<int> ac(n+1,0);
    vector<int> bc(n+1,0);
    rep(i,n){
        cin >> a[i];
        ac[a[i]]++;
    }
    rep(i,n){
        cin >> b[i];
        bc[b[i]]++;
    }

    rep(i,n+1){
      if(ac[i]+bc[i]>n){
        cout << "No" << endl;
        return 0;
      }
    }

    rep(i,n){
        ac[i+1]+=ac[i];
        bc[i+1]+=bc[i];
    }

    int x=0;
    rep(i,n){
        x=max(x,ac[i+1]-bc[i]);
    }

    cout << "Yes" << endl;
    rep(i,n){
        printf("%d ",b[(i+n-x)%n]);
    }

return 0;
}


Measured memory_bytes: 6424
/*
********************
Author : MIHIR ARORA
********************
*/
#include <bits/stdc++.h>
using namespace std;
#define fast cin.tie(NULL); cout.tie(NULL); 
#define input int n; scanf("%d",&n); int*arr = new int[n];  for(int i=0;i<n;i++) scanf("%d",&arr[i]);  
#define inputs int n; scanf("%d",&n); char str[n];   cin>>str;   

typedef long long int ll;
const int mod=1e9+7; 
ll add(ll a, ll b)
{
    return (a%mod+b%mod)%mod;
}

ll mul(ll a, ll b)
{
    return ((a%mod)*(b%mod))%mod;
}

ll sub(ll a, ll b)
{
    return ((a%mod) - (b%mod))%mod;
}
inline int rec(int*arr , int n, int*cache, int k)
{
    if(n==0)
        return 0; 
    if(cache[n]!=-1)
        return cache[n]; 
    int ans= 1e9; 
    for(int i=1;i<=k;i++)
    {
        if(n-i>=0)
      ans = min(ans, abs(arr[i]-arr[0])+rec(arr+i,n-i,cache,k)); 
    }
    cache[n]=ans;
    
    return ans; 
}
inline void solve()
{
 int n; 
    int k; 
    cin>>n>>k; 
    int arr[n]; 
    for(int i=0;i<n;i++)
        cin>>arr[i]; 
    int cache[n]; 
    memset(cache,-1,sizeof(cache)); 
    cout<<rec(arr,n-1,cache,k); 
    
}
int main()
{ 
    fast; 

        solve();
 
    
    
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll a,b; cin>>a>>b;
	ll p1=a%b;
	p1 = min(p1,b-p1);
	cout<<p1;
	
	return 0;
}


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

char bl[5]= "([)]";

int main(){
    string str;
    while(getline(cin,str) && str[0]!='.'){
        stack<char> stk;
        for(int i=0; str[i]!='.'; i++){
            for(int j=0; j<2; j++){
                if(str[i]==bl[j]){
                    stk.push(str[i]);
                }
            }
            for(int j=2; j<4; j++){
                if(str[i]==bl[j]){
                    if(stk.empty() || stk.top()!=bl[j-2]){
                        stk.push(0);
                        break;
                    }else{
                        stk.pop();
                    }
                }
            }
        }
        
        if(stk.empty()){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	ll n, sum=0;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	sum += a[0];
	ll cnt = n-2;
	loop(i, 1, n){
		if(cnt == 0) break;
		sum+=a[i]; cnt--;
		if(cnt == 0) break;
		sum+=a[i]; cnt--;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4796
def main():
    N, Y = map(int, input().split())

    for x in range(N+1):
        for y in range(N-x+1):
            z = N - x - y
            tmp = x * 10000 + y * 5000 + z * 1000
            if tmp == Y:
                print(x, y, z)
                exit()

    print(-1, -1, -1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            boolean t=false;
            while ((line = br.readLine()) != null) {
            	String line2=br.readLine();
            	line=line+line;
            	for(int i=0;i<line.length()-line2.length();i++){
            		if(line.substring(i, i+line2.length()).equals(line2)){
            			t=true;
            			break;
            		}
            	}
            	
            	System.out.println(t?"Yes":"No");
            	break;
            }
        }
    }
}

Measured memory_bytes: 24416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    string S;
    cin >> S;
    stack<int> st;
    int ans = 0;
    for (char c : S) {
        if (!st.empty() && st.top() != c) {
            st.pop();
            ans += 2;
        } else {
            st.push(c);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define rep(i, a, N) for(int i = a; i < N; i++)
#define rrep(i, a, N) for(int i = a; i >= N; i--)

const int inf = 1000000000;

int main() {
    bool is_approved = true;
    int n;
    cin >> n;

    rep(i, 0, n) {
        int a;
        cin >> a;

        if (a & 1) continue;
        else if ((a % 3 == 0) || (a % 5 == 0)) continue;
        else {
            is_approved = false;
            break;
        }
    }

    if (is_approved) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

char a[310][310];
int s[610][310],dp[310][310];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
	int ans=0;
	for (int i=1;i<m;i++)
	{
		for (int j=-n+1;j<n;j++)
		{
			s[j+n][0]=0;
			for (int k=1;k<=n-abs(j);k++)
			{
				int x=k,y=k+j;
				if (j<0) {x+=(-j);y+=(-j);}
				s[j+n][k]=s[j+n][k-1]+(a[x][i]==a[y][i+1]);
			}
		}
		for (int j=0;j<=n;j++) dp[0][j]=dp[j][0]=0;
		for (int p=1;p<=n;p++)
			for (int q=1;q<=n;q++)
			{
				dp[p][q]=min(dp[p-1][q],dp[p][q-1]);
				int k1=q-p,k2=min(p,q);
				dp[p][q]+=s[k1+n][k2];
				//printf("%d %d %d\n",p,q,dp[p][q]);
			}
		ans+=dp[n][n];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#define dn(i,j) (a[i]<=k && a[j]<=k)
#define up(i,j) (k<a[i] && k<a[j])

int a[200005],n,l,r,mid;

inline bool judge(const int &k)
{
	if (dn(n-1,n) || dn(n,n+1)) return 1;
	if (up(n-1,n) || up(n,n+1)) return 0;
	for (int i=1;i<n-1;i++)
	{
		if (dn(n+i,n+i+1) || dn(n-i,n-i-1)) return 1;
		if (up(n+i,n+i+1) || up(n-i,n-i-1)) return 0;
	}
	return dn(1,1);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<n<<1;i++) scanf("%d",a+i);
	for (r=(n<<1)-1,mid=l+r>>1;l<r;mid=l+r>>1) if (judge(mid)) r=mid;else l=mid+1;
	printf("%d",l);
}

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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int grid[110][110] = {0};

    int j = 0, k = 0;
    bool f = true;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;

        while (a) {
            grid[j][k] = i;
            if (f) {
                if (k == w - 1) {
                    j++;
                    f = false;
                }
                else k++;
            }
            else {
                if (k == 0) {
                    j++;
                    f = true;
                }
                else k--;
            }
            a--;
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << grid[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s; cin >> s;
    int n = s.size();
    char c = s[0];
    int cnt=0;
    rep(i,1,n){
        if(c != s[i]){ cnt++; c= s[i]; }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 100010
ll a[N],b[N],c[N];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
	a[i]=-1;
    }
    for(int i=0;i<n;i++){
	if(i<=(n-1)/2){
	    a[i*2]=i;
	    b[i*2]=i+n/2;
	}
    }
    ll p=(n-1)/2+1;
    for(int i=0;i<n;i++){
	if(a[i]>=0)continue;
	a[i]=p;
	b[i]=p-(n-n/2); 
	p++;
    }
    //for(int i=0;i<n/2;i++)swap(b[i],b[n-i-1]);
    for(int i=0;i<n;i++){
	a[i]+=k;
	b[i]+=k+n; //b[i]-=n;
	c[i]=k+n+n+i;
    }
    bool ok=1;
    for(int i=0;i<n;i++){
	if(a[i]+b[i]>c[i])ok=0;
    }
    if(ok==0)cout<<-1<<endl;
    else{
	for(int i=0;i<n;i++)cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;
    }
}



Measured memory_bytes: 4608
#include <stdio.h>

int main(void) {
	int a,b,i,y,z = 0;
	while(scanf("%d%d",&a,&b) , a != 0){
		if(z) printf("\n");
		y = 0;
		for(i = a;i <= b;i++){
			if((!(i % 4))&&((i % 100)||(!(i % 400)))){
				printf("%d\n",i);
				y++;
			}
		}
		if(!(y)) printf("NA\n");
		z++;
	}
	return 0;
}

Measured memory_bytes: 616
fn solve(s1: &str, s2: &str) -> bool {
    s1 == s2.chars().rev().collect::<String>() && s1.chars().rev().collect::<String>() == s2
}

fn main() {
    let mut s1 = String::new();
    std::io::stdin().read_line(&mut s1).unwrap();
    let mut s2 = String::new();
    std::io::stdin().read_line(&mut s2).unwrap();
    let s3 = s1.trim();
    let s4 = s2.trim();

    if solve(s3, s4) {
        println!("YES")
    } else {
        println!("NO")
    }
}

#[test]
fn test_trim() {
    assert_eq!("ABC", "ABC\n".trim())
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int A[20000];
int B[4] = { 2,3,4,6 };
int main() {
	int N;
	cin >> N;
	if (N == 3) {
		cout << "2 5 63" << endl;
		return 0;
	}
	else if (N == 4) {
		cout << "2 5 20 63" << endl;
		return 0;
	}
	else if (N == 5) {
		cout << "2 5 20 30 63" << endl;
		return 0;
	}
	int p = 0, q = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		A[i] = 6 * p + B[q];
		(sum += A[i]) %= 6;
		if (q == 3) p++, q = 0;
		else q++;
	}
	if (sum == 2) {
		A[4] = 6 * (p + 1);
	}
	else if (sum == 3) {
		A[5] = 6 * (p + 1);
	}
	else if (sum == 5) {
		A[5] = 6 * p + 4;
	}
	cout << A[0];
	for (int i = 1; i < N; i++) {
		cout << " " << A[i];
	}
	cout << endl;
}

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin >> N;
    map<string, int> S;
    REP(i, 0, N){
        string s;
        cin >> s;
        S[s]++;
    }
    cout << "AC x " << S["AC"] << endl;
    cout << "WA x " << S["WA"] << endl;
    cout << "TLE x " << S["TLE"] << endl;
    cout << "RE x " << S["RE"] << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();
        int s = S.length();
        int t = T.length();
        int beginIndex = -1;
        for (int i = 0 ; i < s - t + 1 ; i++) {
            boolean match = true;
            for (int j = 0 ; j < t ; j++) {
                if (S.charAt(i + j) != '?' && S.charAt(i + j) != T.charAt(j)) {
                    match = false;
                }
            }
            if (match) {
                beginIndex = i;
            }
        }
        if (beginIndex != -1) {
            S = S.replace('?', 'a');
            StringBuilder sb = new StringBuilder(S);
            sb.replace(beginIndex, beginIndex + t, T);
            System.out.println(sb);
        } else {
            System.out.println("UNRESTORABLE");
        }

    }

}

Measured memory_bytes: 20948
m, d = map(int, input().split())
ans = 0
for i in range(1, d+1):
    d1, d10 = i%10, i//10
    if d1 >= 2 and d10 >= 2:
        judge = d1 * d10
        if judge <= m:
            ans += 1
print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

int main()
{
  int A, B;
  std::cin >> A >> B;
  if (std::abs(A - B) % 2 == 0)
  {
    std::cout << std::abs(A - B) / 2 + std::min(A, B) << std::endl;
  }
  else
    std::cout << "IMPOSSIBLE" << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<vector>
#include<algorithm>
#include<cassert>
#include<cmath>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
 
using namespace std;
int n;
string pip[5];
int state;
int ans;
int maxim;
 
void create_state()
{
  state = 1;
  REP(i,1,n)
    {
      rep(j,n)
    {
      if(i+j >= n)break;
      rep(k,5)
        {
          if(pip[k][j] == 'X' && pip[k][i+j] == 'X')
        {
          state |= (1<<i);
          goto Next;
        }
        }
    }
    Next:;
    }
}
 
void create_maxim()
{
  maxim = 0;
  rep(i,5)rep(j,n)if(pip[i][j] == 'X')maxim = max(maxim,j);
}
 
void rec(int now_state,int cnt,int value)
{
  if(value>=ans)return;
  if(cnt >= 10)
    {
      ans = min(ans,value);
      return;
    }
 
  rep(i,n+1)
    {
      if((now_state >> i) & 1)continue;
      int next_state = (now_state >> i) | state;
 
      rec(next_state,cnt+1,value+i);
    }
 
}
 
int main()
{
  while(cin >> n,n)
    {
      ans = inf;
      rep(i,5)cin >> pip[i];
      create_state();
      create_maxim();
      rec(state,1,maxim);
      cout << ans+1 << endl;
    }
  return 0;
}

Measured memory_bytes: 1204
n, q = [int(x) for x in input().split()]
s = input()
c = [s[i:i + 2] == "AC" for i in range(n - 1)]
d = [0] * n
for i in range(1, n):
    d[i] = d[i - 1] + c[i - 1]

for i in range(q):
    l, r = [int(x) for x in input().split()]
    print(d[r - 1] - d[l - 1])


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

using namespace std; 


int main(){
	
	string s; 
	
	cin >> s; 
	
	
	int cero=0,ones = 0;
	
	for(int i=0;i<s.size();i++){
		if(s[i]=='1') ones++;
		if(s[i]=='0') cero++;
	}
	
	cout << min(ones,cero) * 2 << endl;
		
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;

	vstr s(4);
	vcin(s, 4);
	sort(s);
	string ans = s[0] + s[1] + s[2] + s[3];
	YES(ans == "1479");

	please AC;
}
//参考：---

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

int main(){
  int n,res;
  int a[100];

  while(1){
    cin >> n;
    if(!n)break;

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

    res = 0;
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(a[j]>a[j+1]){
	  res++;
	  swap(a[j],a[j+1]);
	}
      }
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void)
{
 int a,b,i,n=0;
 scanf("%d%d",&a,&b);
 for(i=0;i<2;i++){
    if(a>=b)     {
       n=n+a;
       a=a-1;
    }
    else if(a<b){
       n=n+b;
       b=b-1;
    }
 }
 printf("%d\n",n);
 return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int m = 0;
	while (m * (m - 1) / 2 < n)
		m++;
	if (n != m * (m - 1) / 2)
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n%d\n", m);
	int i, j, d, ans[1003][1003], c[1003];
	for (i = 0; i < m; i++)
		c[i] = 0;
	i = 0;
	d = 1;
	for (j = 0; j < n; j++)
	{
		if (i + d < m)
		{
			ans[i][c[i]] = j + 1;
			c[i]++;
			ans[i + d][c[i + d]] = j + 1;
			c[i + d]++;
			i++;
		}
		else
		{
			d++;
			ans[0][c[0]] = j + 1;
			c[0]++;
			ans[d][c[d]] = j + 1;
			c[d]++;
			i = 1;
		}
	}
	for (i = 0; i < m; i++)
	{
		printf("%d", c[i]);
		for (j = 0; j < c[i]; j++)
			printf(" %d", ans[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>

using namespace std;

int N, a[100];

void insertionSort(){
	for(int i=1; i<N; i++){
		int j=i;
		while(a[j-1] > a[j]){
			swap(a[j-1], a[j]);
			j--;
		}
		for(int i=0; i<N; i++){
			if(i != N-1) cout << a[i] << ' ';
			else cout << a[i] << endl;
		}
	}
}

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

	for(int i=0; i<N; i++){
		if(i != N-1) cout << a[i] << ' ';
		else cout << a[i] << endl;
	}

	insertionSort();
}




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

int n, w;
int arr[101][2]; // w, v
long long int memo[101][100005];

long long int dp(int i, int curr_w) {

	if(i>=n) return 0;

	if(memo[i][curr_w]==-1)
	{
		long long int avoid = dp(i+1, curr_w);
		if(curr_w + arr[i][0] > w) memo[i][curr_w] = avoid;
		else memo[i][curr_w] = max(avoid, arr[i][1] + dp(i+1, curr_w+arr[i][0]));
	}

	return memo[i][curr_w];
}


int main() {

	cin >> n >> w;
	for(int i=0; i<n; ++i) 
	{
		cin >> arr[i][0] >> arr[i][1];
		for(int j=0; j<100005; ++j) memo[i][j] = -1;
	}
	cout << dp(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 78336
#include<stdio.h>
#define MAX 100005
#define NIL -1
void print(int);
int rec(int,int);
typedef struct{
  int p,l,r;
  }Node;

Node T[MAX];
int n,D[MAX];

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }
  rec(r,0);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
  }

  void print(int u){
    int i,c;
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].p);
    printf("depth = %d, ",D[u]);

    if(T[u].p == NIL)printf("root, ");
    else if(T[u].l == NIL)printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
      if(i)printf(", ");
      printf("%d",c);
    }
    printf("]\n");
  }

  int rec(int u,int p){
    D[u]=p;
    if(T[u].r != NIL)rec(T[u].r,p);
    if(T[u].l != NIL)rec(T[u].l,p+1);
  }
  



Measured memory_bytes: 6412