akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int) 1e5 + 5;
const int mod = (int) 1e9 + 7;

deque<int> d;

void construct (ll x) {
        if (x == 1) {
                return;
        }
        if (x & 1) {
                construct (x - 1);
                d.push_front (d.size () + 1);
        } else {
                construct (x >> 1);
                d.push_back (d.size () + 1);
        }
}

ll n;

inline void solve () {
        scanf ("%lld", &n); n++;
        construct (n);
        printf ("%d\n", d.size () + d.size ());
        for (int i : d) {
                printf ("%d ", i);
        }
        for (int i = 1; i <= d.size (); i++) {
                printf ("%d ", i);
        }
        puts ("");
}

int tests = 1;

int main () {
//        freopen (".in", "r", stdin);
//        freopen (".out", "w", stdout);
//        scanf ("%d", &tests);
        while (tests--) {
                solve ();
        }
        return 0;
}


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

#define N 10010
int n, a[N], b[N];
bool isprime(int x) {
    for (int i = 2; 1ll * i * i <= x; ++i) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
bool ok(int p) {
    if (a[0] % p) {
        return false;
    }
    for (int i = 0; i <= n; ++i) {
        b[i] = a[i];
    }
    for (int i = n; i >= p - 1; --i) {
        (b[i - (p - 1)] += b[i]) %= p;
        b[i] = 0;
    }
    for (int i = 0; i <= n; ++i) {
        if (b[i] % p) {
            return false;
        }
    }
    return true;
}

int main() {
    while (scanf("%d", &n) != EOF) {
        int G = 0; 
        for (int i = 0; i <= n; ++i) {
            scanf("%d", a + i);
            G = gcd(G, abs(a[i]));
        }
        reverse(a, a + 1 + n); 
        vector <int> res;
        for (int i = 2; 1ll * i * i <= G; ++i) {
            if (G % i == 0) {
                res.push_back(i); 
                while (G % i == 0) {
                    G /= i;
                }
            }
        }
        if (G > 1) {
            res.push_back(G);
        }
        for (int i = 2; i <= n; ++i) {
            if (isprime(i) && ok(i)) {
                res.push_back(i);
            }
        }
        sort(res.begin(), res.end());
        res.erase(unique(res.begin(), res.end()), res.end());
        for (auto it : res) {
            printf("%d\n", it);
        }
    //  puts("------------");
    }
    return 0;
}

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

int main() {
	int N, A, count = 0;
	map<int, int> mp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		mp[A]++;
	}
	map<int, int>::iterator it;
	for (it = mp.begin(); it != mp.end(); it++) {
		if (it->first > it->second) {
			count += it->second;
		}
		else count += it->second - it->first;
	}
	cout << count;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >>a[i];
    }
    double b[n];
    double sum=0;
    for(int i=0; i<n; i++){
        b[i]=1.0/a[i];
        sum+=b[i];
    }

    double ans=1/sum;
    cout << fixed << setprecision(7) << ans <<  endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b; cin >> a >> b;
	if(a > b) swap(a, b);
	rep(i, b) cout << a << (i==b-1?"\n":"");
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Array
import Data.List
import Debug.Trace

type Image = Array (Int,Int) Int

get :: IO (Image, Image)
get = do
  [n,m] <- (map read . words) <$> getLine
  let 
    read' :: Char -> Int
    read' c = if c == '.' then 1 else if c == '#' then 0 else 2
  ns <- (listArray ((1,1),(n,n))) <$> (concat <$> (replicateM n $ map read' <$> getLine))
  ms <- (listArray ((1,1),(m,m))) <$> (concat <$> (replicateM m $ map read' <$> getLine))
  --ms <- (listArray ((1,1),(m,m))) <$> ((concat <$> (forM [1..m] $ \i -> map read')) <$> getLine)
  pure (ns, ms)

solve :: (Image, Image) -> Bool
solve (as,bs) = any (flip go $ range $ bounds bs) $ range $ bounds as
  where
    go _ [] = True
    go ai@(ay,ax) (bi@(by,bx):bis) = 
      if (inRange (bounds as) ai') && a == b then
        go ai bis
      else
        False
      where
        ai' = (ay - 1 + by, ax - 1 + bx)
        a = as ! ai'
        b = bs ! bi

solve' :: (Image, Image) -> Bool
solve' (as,bs) = f (range $ bounds as) (range $ bounds bs)
  where
    f [] _ = False
    f (a:aa) bb =
      if f' a bb then
        True
      else
        f aa bb

    f' _ [] = True
    f' a@(ay,ax) ((b@(by,bx)):bb) =
      if inRange (bounds as) ai && ac == bc  then
        f' a bb
      else
        False
      where
        ai = (ay - 1 + by, ax - 1 + bx)
        ac = as ! ai
        bc = bs ! b

      

main = do
  is <- get
  putStrLn $ 
    if solve' is then
      "Yes"
    else
      "No"


Measured memory_bytes: 1276
#include<stdio.h>

int A[2000];
int B[2000];
int n;

int solve(int, int);

int main(){

  int i,m;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&m);

  for(i=0;i<m;i++){
    scanf("%d",&B[i]);
  }
  for(i=0;i<m;i++){
  if(solve(0,B[i])==1)printf("yes\n");
  else if(solve(0,B[i])==0)printf("no\n");
  }
  return 0;
}
int solve(int i, int m){
  int res;

  if(m==0) return 1;
  if(i>=n)return 0;
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

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

typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007

void solve(){
  int h1,s1,h2,s2;cin>>h1>>s1>>h2>>s2;
  int a1,a2;
  if(h2%s1==0)a1=h2/s1;
  else a1=h2/s1+1;
  if(h1%s2==0)a2=h1/s2;
  else a2=h1/s2+1;
  //cout<<a1<<" "<<a2<<"\n";
  if(a2<a1)cout<<"No";
  else cout<<"Yes";


return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
   int t=1;
   //cin>>t;
   rep(i,0,t){
     solve();
  }
return 0;
}

Measured memory_bytes: 3652
import kotlin.math.min

fun main(args: Array<String>) {
    val (n, m) = readLongList()

    val x = if (m > 2 * n) (m - 2 * n) / 4 else 0
    println(min(n + x, (m - 2 * x) / 2))
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    
    if(A>=B&&A>=C)
    {
    cout << A*10+B+C;
    }
    else if(B>=A&&B>=C)
    {
    cout << B*10+A+C;
    }
    else 
    {
    cout << C*10+A+B;
    }

	return 0;
}

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

int main(){
  string s; cin >> s;
  
  bool ans = false;
  if(s[2]==s[3] && s[4]==s[5]) ans = true;
  
  if(ans)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

LL dfs(LL cur) {
    if (cur == 1) return 1;
    LL tmp = dfs(cur / 2);
    return tmp + tmp + 1;
}

int main() {
    LL H;
    scanf("%lld", &H);
    printf("%lld\n", dfs(H));
    return 0;
}


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

int main(){
string s;
cin>>s;
for(int i=0; i<s.size(); i++){
if(i%2==0){
if(s[i]=='L'){
  cout<<"No"<<endl;
  return 0;
}
}
else{
if(s[i]=='R'){
  cout<<"No"<<endl;
  return 0;
}
}
}
cout<<"Yes"<<endl;
  return 0;
}




Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int A = int.Parse(input[0]);
		int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);
		int R = Math.Max(C, Math.Max(A, B));
		int res = R*9 + A + B + C;

		//出力
		Console.WriteLine(res);
	}
}

Measured memory_bytes: 11092
/*
  GOOD is not Enough
  You've got to be GREAT.
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

bool isPrime(int n)
{
    if(n==2|| n==3)
        return true;
    if(n<=1)
        return false;
    fp(i,2,(int)sqrt(n))
    {
        if(n%i==0)
            return false;
    }
    return true;
}
void solve()
{
  int n;
  cin >> n;
  int ans=0;
  if(n==1)
  {
      cout << 0 << '\n';return;
  }
  if(isPrime(n))
  {
      cout << 1 << '\n';return;
  }
  fp(i,2,sqrt(n))
  {
      int cnt=0;
    //   if(i==3)
    //     cout << "h" << n << '\n';
      if((n%i)==0)
      {
        //   dbg(i);
          while(n%i==0)
          {
            cnt++;
              n/=i;
            //   dbg(n);
          }
         ans+=((int)sqrt(8*cnt + 1) - 1)/2;
      }
  }
  if(n>1)
    ans++;
  cout << ans << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3708
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=3e6;
int main (){
    int n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=1;i<=n;i++){
        int t,m;
        t=n/i,m=n%i;
        if(k==0) ans+=max(0,i-k)*t+max(0,m-k);
        else   ans+=max(0,i-k)*t+max(0,m-k+1);
     //   printf ("%lld\n",ans);
    }
    printf ("%lld\n",ans);





}


Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
ans = []
S = []
prev_score = 0
maxsi_list = []

for d in range(1, D+1):
    s = list(map(int, input().split()))
    S += [s]
    maxs = float('-inf')
    maxss = float('-inf')
    maxi = -1
    maxii = -1
    cumsump = 0
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        cumsump += tmp
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        tmp2 = s[i] + cumsump - tmp
        if tmp2 > maxs:
            maxs = tmp2
            maxi = i
        if s[i] > maxss:
            maxii = i
            maxss = s[i]
    ans += [maxi+1]
    last[maxi] = d
    prev_score += maxs
    maxsi_list += [maxii+1]
best_ans = ans
best_score = prev_score
# mergin = 1300
mergin = 13000
for tt in range(31):
    for dd in range(D):
        last = [0] * 26
        score = 0
        for d in range(1, D+1):
            if dd == (d-1):
                maxc = 0
                maxci = -1
                for i in range(26):
                    cost = c[i] * (d - last[i])
                    if maxc < cost:
                        maxc = cost
                        maxci = i+1
                prev_a = ans[dd]
                ans[dd] = maxci
            td = ans[d-1] - 1
            cumsump = 0
            for i in range(26):
                if td != i:
                    tmp = -c[i] * (d - last[i])
                    cumsump += tmp
            last[td] = d
            score += S[d-1][td]+cumsump
        # if score <= prev_score-mergin:
        if score <= best_score-mergin:
            ans[dd] = prev_a
        elif best_score < score:
            best_ans = ans
            best_score = score
            prev_score = score
        else:
            prev_score = score

    for dd in range(D):
        last = [0] * 26
        score = 0
        prev_a = ans[dd]
        ans[dd] = maxsi_list[dd]
        for d in range(1, D+1):
            td = ans[d-1] - 1
            cumsump = 0
            for i in range(26):
                if td != i:
                    tmp = -c[i] * (d - last[i])
                    cumsump += tmp
            last[td] = d
            score += S[d-1][td]+cumsump
        # if score <= prev_score-mergin:
        if score <= best_score-mergin:
            ans[dd] = prev_a
        elif best_score < score:
            best_ans = ans
            best_score = score
            prev_score = score
        else:
            prev_score = score

for a in best_ans:
    print(a)

Measured memory_bytes: 73620
#include<stdio.h>
#include<string.h>
int main()
{
   int s=0,i; char r[1000];
   while(1)
   {
       scanf("%s",&r);


       if(r[0]=='0') break;

        i=0;
       while(i<strlen(r))
       {

           s=s+r[i]-'0';
           i++;
       }
       printf("%d\n",s); s=0;
   }


}








Measured memory_bytes: 2708
import java.math.*;
import java.util.Scanner;

public class Main {

    static final int modnum = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        double ans = 0;

        // int needone = (int) Math.ceil(Math.log(K) / Math.log(2));
        // double perone = Math.pow(0.5, needone);
        // System.out.println(needone + " " + perone);
        // ans += perone;

        for (int i = 1; i <= N; i++) {
            if (i >= K) {
                ans += 1;
                continue;
            }
            int need = (int) Math.ceil(Math.log((double) K / i) / Math.log(2));
            double per = Math.pow(0.5, need);
            // System.out.println(need + " " + per);
            ans += per;
        }
        ans /= N;
        // System.out.println();
        System.out.println(ans);
    }
}

Measured memory_bytes: 21960
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}
int main(){
    ll M,N;
    cin>>N>>M;
    v A(N);
    ll sum = 0;
    rep(i,0,N){
        cin>>A[i];
        sum += A[i];
    }

    sort(all(A));
    bool ans =true;
    for(int i=N-1;i>=N-M;i--){
        if(A[i]*4*M < sum)ans = false;
    }
    YN(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
//抽象化
template <typename T> struct ReRooting {
    using F = function<T(T, int)>;
    using F2 = function<T(T, T)>;
    static const int MAX_V = 200010;
    int V;
    vector<int> E[MAX_V];
    vector<T> dp[MAX_V];
    // dp_v = g(merge(f(dp_c1,c1), f(dp_c2,c2), ..., f(dp_ck,ck)) , v)
    F f, g;
    F2 merge;
    T mi; // identity of merge

    ReRooting(
        int V_, F f_, F2 merge_, T mi_, F g_ = [](T a, int b) { return a; })
        : V(V_), f(f_), merge(merge_), mi(mi_), g(g_) {}

    void add_E(int a, int b) {
        E[a].emplace_back(b);
        E[b].emplace_back(a);
    }

    T dfs1(int p, int v) {
        T res = mi;
        for(int i = 0; i < E[v].size(); ++i) {
            if(E[v][i] == p)
                continue;
            dp[v][i] = dfs1(v, E[v][i]);
            res = merge(res, f(dp[v][i], E[v][i]));
        }
        return g(res, v);
    }

    void dfs2(int p, int v, T add) {
        for(int i = 0; i < E[v].size(); ++i) {
            if(E[v][i] == p) {
                dp[v][i] = add;
                break;
            }
        }

        vector<T> pL(E[v].size() + 1), pR(E[v].size() + 1);
        pL[0] = mi;
        for(int i = 0; i < E[v].size(); ++i)
            pL[i + 1] = merge(pL[i], f(dp[v][i], E[v][i]));
        pR[E[v].size()] = mi;
        for(int i = E[v].size(); i > 0; --i)
            pR[i - 1] = merge(pR[i], f(dp[v][i - 1], E[v][i - 1]));

        for(int i = 0; i < E[v].size(); ++i) {
            if(E[v][i] == p)
                continue;
            T val = merge(pL[i], pR[i + 1]);
            dfs2(v, E[v][i], g(val, v));
        }
    }

    void calc(int root = 0) {
        for(int i = 0; i < V; ++i)
            dp[i].resize(E[i].size());
        dfs1(-1, root);
        dfs2(-1, root, mi);
    }

    T solve(int v) {
        T ans = mi;
        for(int i = 0; i < E[v].size(); ++i)
            ans = merge(ans, f(dp[v][i], E[v][i]));
        return g(ans, v);
    }
};
int main() {
    cin >> n >> m;
    ReRooting<ll> Re(
        n, [](ll x, int y) { return (x + 1) % m; }, [](ll x, ll y) { return x * y % m; }, 1);
    rep(i, n - 1) {
        cin >> x >> y;
        x--;
        y--;
        Re.add_E(x, y);
    }

    Re.calc();
    rep(i, n) { cout << Re.solve(i) << endl; }
}

Measured memory_bytes: 38528
#include <iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i =0;i<n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
const long long int MOD = 1e9 + 7;
using namespace std;
int main(){
	int n, k; cin >> n >> k; vector<int> a(n,0);
	rep(i, n) cin >> a[i];
	vector<vector<long long int>> dp(n+1, vector<long long int>(k+1, 0));
	dp[0][0] = 1; vector<long long int> sum(k + 2, 0);
	rep(i, n) {
		sum[0] = 0;
		rep(j, k+1) sum[j+1] = (sum[j] + dp[i][j]) % MOD;
		rep(j, k+1) dp[i+1][j] = (sum[j+1] - sum[max(0, j - a[i])] + MOD) % MOD;
	}cout << dp[n][k] << endl;
}

Measured memory_bytes: 82988
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  char buf[1002];
  buf[N] = '\n';
  buf[N+1] = 0;
  if(N >= 4 && N%2 == 0) {
    char const* p[2] = {"abcc", 
                        "abdd"};
    for(int i = 0; i < N; ++i) {
      int x = (i/2)*2, y = i%2;
      std::fill_n(buf, N, '.');
      for(int j = 0; j < 4; ++j) buf[(x+j)%N] = p[y][j];
      std::cout << buf;
    }
  } else if(N%3 == 0) {
    char const* p[3] = {"aab",
                        "b.b",
                        "baa"};
    for(int i = 0; i < N; ++i) {
      int x = (i/3)*3, y = i%3;
      std::fill_n(buf, N, '.');
      for(int j = 0; j < 3; ++j) buf[(x+j)%N] = p[y][j];
      std::cout << buf;
    }
  } else if(N >= 9 || N==5) {
    char const* p[2] = {"abcc",
                        "abdd"};
    int n = N-5;
    for(int i = 0; i < n; ++i) {
      int x = (i/2)*2, y = i%2;
      std::fill_n(buf, N, '.');
      for(int j = 0; j < 4; ++j) buf[(x+j)%n] = p[y][j];
      std::cout << buf;
    }
    std::fill_n(buf, N, '.');
    char const *q[5] = {"aabba",
                        "cca.a",
                        "bbabb",
                        "..bca",
                        "..bca"};
    for(int i = 0; i < 5; ++i) {
      for(int j = 0; j < 5; ++j) buf[n+j] = q[i][j];
      std::cout << buf;
    }
  } else if(N==7) {
    std::cout << "aa.ab..\n"
                 "...aba.\n"
                 "a....ac\n"
                 "a.aa..c\n"
                 "bb..aab\n"
                 ".aa.b.b\n"
                 "..ccbaa\n";
  } else {
    std::cout << "-1\n";
  }
  return 0;
}




Measured memory_bytes: 1280
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		
		String s = "";
		int countA = 0;
		int countB = 0;
		for (int i = 0; i < a.length() + b.length(); i++) {
			if (i % 2 == 0) {
				s = s.concat(a.substring(countA, countA + 1));
				countA++;
			} else {
				s = s.concat(b.substring(countB, countB + 1));
				countB++;
			}
		}
		
		System.out.println(s);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <queue>
using namespace std;

char ma[1005][1005];int vis[1005][1005];
int w,h,n;

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

struct node
{
    int x,y,time;
};
node start;

void bfs(char ed)
{
    queue<node> que;
    que.push(start);
    vis[start.x][start.y]=1;
    while(!que.empty())
    {
        node no=que.front();
        que.pop();
        for(int i=0;i<4;i++)
        {
            int x=no.x+dx[i];
            int y=no.y+dy[i];
            if(vis[x][y]||x>=h||x<0||y>=w||y<0||ma[x][y]=='X')
                continue;
            if(ma[x][y]==ed)
            {
                start.x=x;
                start.y=y;
                start.time=no.time+1;
                return ;
            }
            vis[x][y]=1;
            node no1;
            no1.x=x;no1.y=y;no1.time=no.time+1;
            que.push(no1);
        }
    }
}

int main()
{
    while(~scanf("%d %d %d", & h, & w, & n))
    {
        for(int i=0;i<h;i++)
        {
            scanf("%s",&ma[i]);
            for(int j=0;j<w;j++)
                if(ma[i][j]=='S')
                {
                    start.x=i;
                    start.y=j;
                    start.time=0;
                }

        }
            for(int i=0;i<n;i++)
            {
                memset(vis,0,sizeof(vis));
                bfs(i+'1');
            }

            printf("%d\n",start.time);
    }
    return 0; 
}

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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int n; 
    cin >> n;

    string s1, s2;
    for(int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        s1 += c;
    }
    for(int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        s2 += c;
    }
    string cur;
    for(int i = 1; i <= n; ++i) {
        char c = '0' + i;
        cur += c;
    }
    int count = 0;
    int a, b;
    do {
        count++;
        if(cur == s1) a = count;
        if(cur == s2) b = count;
    } while(next_permutation(cur.begin(), cur.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
from bisect import bisect_right
s = input().strip()
t = input().strip()
D = {}
for i in range(len(s)):
    a = s[i]
    if a not in D:
        D[a] = []
    D[a].append(i+1)
A = sorted(list(set(list(s))))
A.append(chr(123))
B = sorted(list(set(list(t))))
cur = 0
flag = 0
for i in range(len(B)):
    while True:
        if A[cur]<B[i]:
            cur += 1
        elif A[cur]==B[i]:
            break
        else:
            flag = 1
            break
    if flag==1:break
if flag==1:
    print(-1)
else:
    C = []
    cur = -1
    for i in range(len(t)):
        b = t[i]
        ind = bisect_right(D[b],cur)%len(D[b])
        C.append(D[b][ind])
        cur = D[b][ind]
    cnt = 0
    for j in range(1,len(C)):
        if C[j]<=C[j-1]:
            cnt += 1
    print(len(s)*cnt+C[-1])

Measured memory_bytes: 56284
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
 
#define MOD (long long int)(1e9+7)
#define ll long long int


int main(void){
	int n;
	int counta=0;
	int countn=0;
	cin>>n;
	int memo;
	for(int i=0; i<n; i++){
		cin>>memo;
		if((memo%4)==0){
			countn++;
		}else if((memo%2)==1){
			counta++;
		}
	}
	cout<<(((countn>=counta)||(countn+1==counta)&&(countn+counta==n))?"Yes":"No")<<endl;


	return 0;	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  
  int a,b;
  cin>>a>>b;
  if(b==1)
  {
    cout<<0;
    return 0;
  }
  if(b<=a)
  {
    cout<<1;
    return 0;
  }
  int ans= (b-a)/(a-1) +1;
  if((b-a)%(a-1)!=0)cout<<++ans;
  else cout<<ans;





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<LL> A(N);
    rep(i,N)cin >> A[i];
    int ct = 0;
    rep(i,N)if(A[i] < 0)ct++;

    if(ct & 1){  // 奇数
        rep(i,N)A[i] = abs(A[i]);
        sort(all(A));
        A[0] *= -1;
        LL ans = 0;
        rep(i,N)ans += A[i];
        cout << ans << endl;
    }
    else{
        LL ans = 0;
        rep(i,N)ans += abs(A[i]);
        cout << ans << endl;
    }
}



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

int main() {
  string s; cin >> s;
  for (int i=0; i<s.length(); i++) {
    if (i == 5 || i == 13) cout << " ";
    else cout << s[i];
  }

  cout << endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,x,c[20],a[20][20],val[20],ans=1e9;

int main()
{
	cin>>n>>m>>x;
	rep(i,n)
	{
		cin>>c[i];
		rep(j,m) cin>>a[i][j];
	}
	rep(i,1<<n)
	{
		memset(val,0,sizeof(val));
		int res=0;
		rep(j,n)
		{
			if((i&(1<<j))==0) continue;
			res+=c[j];
			rep(k,m) val[k]+=a[j][k];
		}
		bool ok=true;
		rep(j,m) if(val[j]<x) ok=false;
		if(ok) ans=min(ans,res);
	}
	if(ans==1e9) puts("-1");
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int sec = 0, min = 0;
	
	for (int i = 0; i < 4; i++) {
		int a; 
		cin >> a;
		sec += a;
	}
	min = sec / 60;
	sec = sec - min * 60;
	
	cout << min << endl << sec << endl;
	
	return 0;
}

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

int main(){
    map<p,int>mp;
    int n;
    cin >> n;
    string s;
    char a,b;
    int ans = 0;
    for (int i = 1; i < n+1;i++){
        s = to_string(i);
        a = s[0];
        int l = s.size();
        b = s[l-1];
        int c = a - '0';
        int d = b - '0';
        p pp = {c,d};
        mp[pp]++;
    }
    for (int i = 1;i < 10;i++){
        for (int j = 1;j <= i; j++){
            if (i ==j){
                ans += mp[{i,j}]*mp[{i,j}];
            }
            else{
                ans += mp[{i,j}]*mp[{j,i}]*2;
            
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
int main()
{
	char a[100] ;
	int i;
	bool lag[3];
	memset(lag,false,sizeof(lag));
	scanf("%s",a);
	for(i = 0; a[i] != '\0'; i++)
	{
		if(a[i] == 'a')
		{
			if(lag[0])
			{
				printf("No");
				break;
			}
			else lag[0] = true;
		}
		else if(a[i] == 'b')
		{
			if(lag[1])
			{
				printf("No");
				break;
			}
			else lag[1] = true; 
		}
		else 
		{
			if(lag[2])
			{
				printf("No");
				break;
			}
			else lag[2] = true;
		}
	}
	if(i == 3)
		printf("Yes");
	return 0;
}

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

using namespace std;

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

    int n, m, odev[11], pow2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
    vector<int> chk[11];
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int t, num;
        cin >> t;
        while (t--)
            cin >> num, chk[i].push_back(num);
    }
    for (int i = 0; i < m; i++)
        cin >> odev[i];

    int ans = 0;
    for (int i = 0; i < pow2[n]; i++)
    {
        bool bulb[11] = {}, fail = false;
        int tmp = i;
        for (int j = 1; j <= n; j++, tmp /= 2)
            bulb[j] = tmp % 2;

        for (int j = 0; j < m && !fail; j++)
        {
            int cnt = 0;
            for (int k = 0; k < chk[j].size(); k++)
                if (bulb[chk[j][k]])
                    cnt++;
            if (cnt % 2 != odev[j])
                fail = true;
        }
        if (!fail)
            ans++;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());

  map<ll,int> mp;
  rep(i,N) mp[A[i]]++;
  int ans=0;
  int now=0;
  for(int i=30;i>=0;i--){
    int val=(1<<i);
    while(now<N&&A[now]>=val){
      int diff=(1<<(i+1))-A[now];
      if(diff==A[now]&&mp[A[now]]>=2){
        mp[A[now]]-=2;
        ans++;
      }
      if(diff!=A[now]&&mp[diff]>=1&&mp[A[now]]>=1){
        mp[diff]--;
        mp[A[now]]--;
        ans++;
      }
      now++;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 26752
X, Y = map(int, input().split())

def money(m,Z):
  if Z == 1:
    m += 300000
  elif Z == 2:
    m += 200000
  elif Z == 3:
    m += 100000
  return m

result = money(0,X)
result = money(result,Y)

if result == 600000:
  result += 400000

print(result)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

const int MOD = 1e9+7;

const int INF = 1e10;




int32_t main()
{
   
    IOS
    int h,n;
    cin>>h;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum<h)
        cout<<"No";
    else cout<<"Yes";


    return 0;
}


Measured memory_bytes: 256
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// 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 << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll maxn = 100005;
const ll mm = 1e+18;
void solve()
{
    string s;
    cin>>s;
    if(s.back()=='s') s+="es";
    else s+="s";
    cout<<s;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
int a[100005],n;
long long s,cnt;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		if(a[i]!=0)
			s+=a[i];
		if(a[i]==0||i==n){
			cnt+=s/2;
			s=0;
		}
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
bool check(int now,int a[150],int m,int n)
{
	int ima = 0;
	for(int i=0;i<m;i++)
	{
		int aho=now;
		for(;ima<n;ima++)
		{
			aho-=a[ima];
			if(aho<0)break;
		}
		if(ima==n)return true;
	}
	return false;
	
	
	
}


int main ()
{
	while(1){
		int n,m;int bok[150];
		cin>>m>>n;if(!m&&!n)break;
		for(int i=0;i<n;i++)cin>>bok[i];
		
		int l = 0, r = 50000000;
		while( l != r ){
			int now = (l+r) / 2;
			if( check(now,bok,m,n) ){
				r = now;
			}else{
				l = now+1;
			}
		}
		cout<<l<<endl;
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1160
def LI(): return list(map(int,input().split()))
N,K = LI()
a = LI()
ans = float('INF')
for i in range(2**(N-1)):
    bit = [i>>j&1 for j in range(N-1)]
    if K-1!=bit.count(1):
        continue
    temp,kijun = 0,a[0]
    for k in range(N-1):
        if bit[k]==0:
            kijun = max(kijun,a[k+1])
        else:
            if a[k+1]>=kijun+1:
                kijun = a[k+1]
                continue
            temp += (kijun+1)-a[k+1]
            kijun += 1
    ans = min(ans,temp)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
int n;
double a[20],w;
double dp[1<<12][12];
void Input(){
  int res=0;n=-1;
  for(int i=0;i<s.size();i++){
    if(isdigit(s[i]))res=res*10+(s[i]-'0');
    if(s[i]==' '||i==s.size()-1){
      if(n==-1)w=res,n++;
      else a[n++]=res;
      res=0;
    }
  }
}
int main(){
  while(getline(cin,s)){
    Input();
    r(i,1<<12)r(j,12)dp[i][j]=1e9;
    for(int i=0;i<n;i++)dp[1<<i][i]=a[i];
    for(int i=1;i<(1<<n);i++){
      for(int j=0;j<n;j++){
	if(dp[i][j]!=1e9&&((i>>j)&1)){
	  for(int k=0;k<n;k++){
	    if(j!=k&&!((i>>k)&1)){
	      dp[i|(1<<k)][k]=min(dp[i|(1<<k)][k],dp[i][j]+2.0*sqrt(a[j]*a[k]));
	    }
	  }
	}
      }
    }
    double ans=1e9;
    for(int i=0;i<n;i++)ans=min(ans,dp[(1<<n)-1][i]+a[i]);
    if(ans<=w)cout<<"OK"<<endl;
    else cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 3432
N=gets.to_i

constraints=N.times.map{gets.split.map(&:to_i)}

(0..100).each do |cx|
    (0..100).each do |cy|
        estimate=nil
        constraints.each do |x,y,h|
            if h!=0
                estimate=h+(x-cx).abs+(y-cy).abs
                break
            end
        end
        ok=true
        constraints.each do |x,y,h|
            ok=false if h!=[estimate-(x-cx).abs-(y-cy).abs,0].max
        end
        if ok
            puts "#{cx} #{cy} #{estimate}"
            exit
        end
    end
end

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

#define int long long

int32_t main()
{
    int n;
    cin>>n;
    
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    
    int dp[n]={0};
    dp[1]=abs(a[1]-a[0]);
    
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1];
}
                  

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma optimize("JARU SOSISONI")

using namespace std;

//#define int long long
#define fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define geometry cout.setf(ios::fixed); cout.precision(15);
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;

const int INF = 1e9 + 100;
const int MOD = 998244353;
const int MOD1 = 1e9 + 7;
const int N = 10100;
const int nul = 0;
const int SIZE = 1e6 * 3;

int ansl = -2, ansr = -2;
string a;

bool check(int l, int r) {
    if (a[l] == a[l + 1] || a[l] == a[l + 2] || a[l + 1] == a[l + 2]) return 1;
    else return 0;
}

signed main() {
#ifdef parasha
    freopen("A.in", "r", stdin);
#endif // parasha
    fast;
    cin >> a;
    int n = a.size();
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) {
            ansl = i;
            ansr = i + 1;
            break;
        }
    }
    if (ansl < 0) {
        for (int i = 0; i < n - 2; i++) {
            if (check(i, i + 2)) {
                ansl = i;
                ansr = i + 2;
                break;
            }
        }
    }
    cout << ansl + 1 << " " << ansr + 1 << endl;

}


Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	string s; cin >> s;
	vvl dp(n,vl(n+1,0));
	REP(i,1,n+1) dp[0][i] = 1;
	rep(i,n-1){
		if(s[i]=='>'){
			rep(j,i+2){
				dp[i+1][j+1] = dp[i][i+1] - dp[i][j] + mod;
			}
		}else{
			rep(j,i+2){
				dp[i+1][j+1] = dp[i][j];
			}
		}
		rep(j,n){
			dp[i+1][j+1] += dp[i+1][j];
			dp[i+1][j+1] %= mod;
		}
	}
	cout << dp[n-1][n] << endl;
}

Measured memory_bytes: 70784
#include<stdio.h>
#define N 100

int main(){
    int G[N][N];
    int n, u, k, v, i, j;

    scanf("%d", &n);

    for( i = 0; i < n; i++) {
        for( j = 0; j < n; j++) {
            G[i][j] = 0;
        }
    }

    for( i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for(j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            G[u][v] = 1;
        }
    }

    for( i = 0; i < n; i++ ) {
        for( j = 0; j < n; j++ ) {
            if( j ) printf(" ");
            printf("%d", G[i][j]);
        }
        printf("\n");
    }
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;


#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) f(i,0,n-1)cin>>a[i]
#define in1(a,n) f(i,1,n)cin>>a[i]
#define out(a,n) f(i,0,n-1)cout<<fixed<<setprecision(20)<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define f(i,a,b) for (int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

const int N=(int)3005;

double dp[N][N];//no of coins , no of heads => no of tails = no of coins - no of heads
bool vis[N][N];
double p[N];

double go(int n,int h)
{
	if (n==0)
	{
		if (h==0)
			return 1.0;
		else
			return 0.0;
	}

	if (vis[n][h])
		return dp[n][h];

	vis[n][h]=true;
	double &ans=dp[n][h];
	ans=1.0;
	ans=p[n]*go(n-1,h-1)+(1.0-p[n])*go(n-1,h);

	return ans;
}

int main(int argc, char const *argv[])
{
	crap;
	
	rep(i,N)
		rep(j,N)
			dp[i][j]=1.0,vis[i][j]=false;


	int n;
	cin>>n;
	f(i,1,n)
		cin>>p[i];

	double fans=0.0;
	int minhead=(n+1)/2;

	rf(i,n,minhead)
	{
		fans=fans + go(n,i);
		// cout<<go(n,i)<<"::"<<i<<endl;
	}

	cout<<fixed<<setprecision(15)<<fans<<endl;
	return 0;
}

Measured memory_bytes: 79872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int a,b;
	cin >> a >> b;
	if((a+b)%2) cout << "IMPOSSIBLE" << endl;
	else cout << (a+b)/2 << endl;
}


Measured memory_bytes: 256
use std::io;


fn main() {
    let n = read_one::<String>().chars().collect::<Vec<char>>();
    if n[0] == n[2] { println!("Yes"); }
    else { println!("No"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main() {
    int N;
    cin >> N;
    vector<map<string,int> > dec(5);
    for (int i = 0; i < N; i++) {
        string str;
        int n;
        cin >> str >> n;
        dec[str.size()-1][str] += n;
    }

    for (auto i : dec) {
        for (auto j : i) {
            cout << j.first << " " << j.second << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll c[30],s[370][30];
int a[370],last[30];

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

ll f(int d)
{
    ll x=0;
    memset(last,-1,sizeof(last));
    for(int i=0;i<d;i++){
        x+=s[i][a[i]];
        last[a[i]]=i;
        for(int j=0;j<26;j++){
            x-=c[j]*(ll)(i-last[j]);
        }
    }
    return x;
}

int main()
{
    auto start=chrono::high_resolution_clock::now();
    ll x=LLONG_MIN,sc=0;
    int d,ans[370];
    scanf("%d",&d);
    for(int i=0;i<26;i++){
        scanf("%lld",&c[i]);
        sc+=c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%lld",&s[i][j]);
        }
    }
    if(sc==0){
        for(int i=0;i<d;i++){
            int mx=-1,j=-1;
            for(int k=0;k<26;k++){
                if(s[i][k]>mx) mx=s[i][k],j=k;
            }
            printf("%d\n",j+1);
        }
        return 0;
    }
    while(true){
        for(int i=0;i<d;i++) a[i]=rng()%26;
        ll y=f(d);
        if(y>x) copy(a,a+d,ans),x=y;
        auto stop=chrono::high_resolution_clock::now();
        int duration=chrono::duration_cast<chrono::microseconds>(stop-start).count();
        if(2000000-duration<100000) break;
    }
    for(int i=0;i<d;i++){
        printf("%d\n",ans[i]+1);
    }
    return 0;
}

Measured memory_bytes: 3924