akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

N = int(input())

# A C G T を
# 0 1 2 3 と置く

dp = [[[[0 for i in range(4)] for j in range(4)] for k in range(4)] for l in range(101)]
dp[0][3][3][3] = 1

mod = 10**9+7

#文字列の文字数
for len in range(N):
    #最後から1文字目の文字
    for c1 in range(4):
        #最後から2文字目の文字
        for c2 in range(4):
            #最後から3文字目の文字
            for c3 in range(4):
                #新しく追加する文字
                for a in range(4):
                    if c2 == 0 and c1 == 1 and a == 2 :
                        continue #012
                    if c2 == 1 and c1 == 0 and a == 2 :
                        continue #102
                    if c2 == 0 and c1 == 2 and a == 1 :
                        continue #021
                    if c3 == 0 and c1 == 1 and a == 2 :
                        continue #0?12
                    if c3 == 0 and c2 == 1 and a == 2 :
                        continue #01?2
                    
                    dp[len + 1][c2][c1][a] += dp[len][c3][c2][c1]
                    #dp[len + 1][c2][c1][a] %= mod
        
ans = 0

#最後から1文字目の文字
for c1 in range(4):
    #最後から2文字目の文字
    for c2 in range(4):
        #最後から3文字目の文字
        for c3 in range(4): 
            ans += dp[N][c3][c2][c1]

print(ans % mod)

Measured memory_bytes: 3444
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
reds = [LI() for i in range(n)]
blues = [LI() for i in range(n)]
count = 0

blues.sort(key=lambda x: x[0])

for blue in blues:
    tmps = []
    for red in reds:
        if blue[0] > red[0]:
            tmps.append(red)
    tmps.sort(key=lambda x: x[1], reverse=True)
    for tmp in tmps:
        if blue[1] > tmp[1]:
            count += 1
            reds.pop(reds.index(tmp))
            break
print(count)


Measured memory_bytes: 3064
use proconio::*;
use proconio::marker::*;

// A からBが得られるには
// Aの末尾|B| - 1 文字がB[1..] と等しい
// かつAの末尾|B| - 1 文字以外の文字の中に B[0] がある
// O(N^2)
// 文字が長いやつからTrieに挿入、戻る時に存在する文字をbitで覚えてカウンタ更新
//

type Link = Option<Box<Node>>;

const F: usize = 26;

#[derive(Default)]
struct Node {
    cnt: [u32; F],
    next: [Link; F],
}

fn insert(node: &mut Link, s: &[u8], ans: &mut usize) -> usize {
    if node.is_none() {
        *node = Some(Box::new(Node::default()));
    }
    let node = node.as_mut().unwrap();
    if s.len() == 0 {
        0
    } else {
        let k = (s[0] - b'a') as usize;
        let mut mask = insert(&mut node.next[k], &s[1..], ans);
        if s.len() == 1 {
            *ans += node.cnt[k] as usize;
        }
        mask |= 1 << k;
        for (i, c) in node.cnt.iter_mut().enumerate() {
            *c += ((mask >> i) & 1) as u32;
        }
        mask
    }
}

fn run() {
    input! {
        n: usize,
        mut s: [Bytes; n],
    }
    s.sort_by_key(|s| s.len());
    let mut root = None;
    let mut ans = 0;
    for s in s.iter_mut().rev() {
        s.reverse();
        insert(&mut root, s, &mut ans);
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 104_857_600 << 2; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| run()).unwrap().join().unwrap();
}


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

int main() {
  int n;
  string op,ans;
  cin >> n;

  ans = "Three";
  for(int i=0;i<n;i++){
    cin >> op;
    if (op == "Y"){
      ans = "Four";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = list(map(int , input().split()))
    ans = [0]*n
    cnt = 1
    for i in a:
        ans[i-1] =cnt
        cnt += 1
    print(" ".join(map(str,ans)))

if __name__=="__main__":
    main()


Measured memory_bytes: 25240
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main() {
  
  int N, M;
  cin >> N >> M;
  vector<pair<ll,ll>> shop;
  
  for (int i = 0; i < N; i++){
    ll A,B;
    cin >> A >> B;
    shop.push_back(make_pair(A,B));
  }
  
  sort(shop.begin(),shop.end());
  
  ll money = 0;
  ll count = 0;

  for(auto const& entry: shop){    
    if(entry.second + count > M){
      money += entry.first * (M - count);
      break;
    }else{
      money += entry.first * entry.second;
      count += entry.second;
    }
  }
  cout << money;
}

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

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

    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        while (a % 2 == 0) {
            cnt++; a /= 2;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
#define INFTY 2000000001

int n,p[MAX],m[MAX][MAX];

void MatricxChainMultiplication(){
  int i,j,l,k;
  for(i=1;i<=n;i++)m[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INFTY;
      for(k=i;k<j;k++){
	int a=m[i][j],b=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=(a>b)?b:a;
      }
    }
  }
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d %d",&p[i-1],&p[i]);
  MatricxChainMultiplication();
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2104
S = list(map(str, input()))
cnt = 0
CNT = []
for i in range(len(S)):
    if S[i]=='A' or S[i]=='C' or S[i]=='G' or S[i]=='T':
        cnt += 1
        if i==len(S)-1:
            CNT.append(cnt)
    if S[i]!='A' and S[i]!='C' and S[i]!='G' and S[i]!='T':
        CNT.append(cnt)
        cnt = 0

print(max(CNT))

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

using ll = long long;
const int N = 2e5+100;
const int oo = 1e9;

int n, a[N], pre[N], suf[N];;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);	
	pre[0] = -oo;
	for(int i = 1; i <= n; i++)
		pre[i] = max(pre[i - 1], a[i]);
	suf[n + 1] = -oo;
	for(int i = n; i > 0; i--) 
		suf[i] = max(suf[i + 1], a[i]);
	for(int i = 1; i <= n; i++)
		printf("%d\n", max(pre[i - 1], suf[i + 1]));
	return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n = 5;
  int a[n];
  rep(i, n) cin >> a[i];
  int k;
  cin >> k;
  cout << (abs(a[0] - a[4]) <= k ? "Yay!" : ":(") << endl;
  return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_4_C
    {
        static void Main(string[] args)
        {
            int a, b;
            char op;
            List<string> dataSet;

            while (true)
            {
                dataSet = Console.ReadLine().Split().ToList();

                a = int.Parse(dataSet[0]);
                // op = char.Parse(dataSet[1]);
                op = dataSet[1][0];
                b = int.Parse(dataSet[2]);

                switch (op)
                {
                    case '+':
                        Console.WriteLine(a + b);
                        break;
                    case '-':
                        Console.WriteLine(a - b);
                        break;
                    case '*':
                        Console.WriteLine(a * b);
                        break;
                    case '/':
                        Console.WriteLine(a / b);
                        break;
                    case '?':
                        // Environment.Exit(0);
                        return;
                    default:
                        break;
                }
            }
        }
    }
}



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

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax =[](int &a,int b){ a = max(a, b);};
auto chmin =[](int &a,int b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1};
const int dy[4] = { 1, 0,-1, 0};

bool isDebugMode=1;
//--------------------------------------//
int h,w,a,b;

vector<ll> v;

#define MAX 200000
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve(){
	COMinit();
	rep(i,h-a){
		v.pb(COM(b-1+i,i));
	}
	ll ans=0;
	rep(i,h-a){
		ans+=(v[i]*COM(h-i-1+w-b-1,w-b-1))%MOD;
	}
	ans%=MOD;
	cout<<ans<<endl;
}

int main(){
	cin>>h>>w>>a>>b;
	solve();
	return 0;
}


Measured memory_bytes: 6136
import collections
N = int(input())
lsname = []
for i in range(N):
    name = input()
    lsname.append(name[:1])
counterN = collections.Counter(lsname)
lskey = ['M','A','R','C','H']
lsnum = []
for i in lskey:
    if i in counterN.keys():
        lsnum.append(counterN[i])
ans = 0
lenN = len(lsnum)
for i in range(lenN-2):
    for j in range(i+1,lenN-1):
        for k in range(j+1,lenN):
            ans += lsnum[i]*lsnum[j]*lsnum[k]
print(ans)

Measured memory_bytes: 10060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

ll A, B;
ll ans;

int main() {
    cin >> A >> B;

    ans = 0;
    if (A != 0) {
        ll A_ = A - 1;
        if (A_ % 2 == 0) ans ^= A_;
        if (((A_ >> 1) % 2 == 0 && A_ % 2 == 1) || ((A_ >> 1) % 2 == 1 && (A_ % 2 == 0))) ans ^= 1;
    }
    if (B != 0) {
        if (B % 2 == 0) ans ^= B;
        if (((B >> 1) % 2 == 0 && B % 2 == 1) || ((B >> 1) % 2 == 1 && (B % 2 == 0))) ans ^= 1;
    }

    write(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll> > v;
    ll a,b;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        v.pb(make_pair(a,b));
    }
    sort(be(v));
    ll ans=0,index=0;
    while(1){
        if(v[index].second>=m){
            ans+=v[index].first*m;
            cout << ans<<endl;
            return 0;
        }
        else{
            ans+=v[index].first*v[index].second;
            m-=v[index].second;
            index++;
        }
    }
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}
 
ll binpow(ll a, ll b) {ll res = 1;while (b > 0) {if (b & 1) res = res * a;a = a * a;b >>= 1;}return res;}
	
 
int main(){
	adiii
	ll n,k;cin>>n>>k;
	vector <ll> a(n);
	rep(i,0,n) cin>>a[i];
	vector <bool> mark(k+1,false);
	
	rrep(i,k,0){
		for(auto j : a){
			if(i - j >= 0 && mark[i] == false) mark[i - j]=true;
		}
	}
	cout<< (mark[0] ? "First" : "Second");
	

	 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int X, A, B;
    cin >> X >> A >> B;

    if (B <= A){
        cout << "delicious" << endl;
    }
    else if (B - A <= X){
        cout << "safe" << endl;
    }
    else{
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  for ( n = 9; n--; )
  {
    char  cn[ 16 ];
    int   am, pm;

    scanf ( " %s %d %d", cn, &am, &pm );

    printf ( "%s %d %d\n", cn, am + pm, am * 200 + pm * 300 );
  }

  return ( 0 );
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

template<typename T>
T gcd(T a, T b) {
    T r, temp;

    while(1) {
        if(a < b) {
            temp = a;
            a = b;
            b = temp;
        }
        if(b < 1) continue;

        while((r = a % b) != 0) {
            a = b;
            b = r;
        }
        return b;
    }
}

int main() {
    LL N, X;
    cin >> N >> X;
    vector<LL> x(N);
    REP(i, N) {
        cin >> x[i];
        x[i] = abs(x[i] - X);
    }
    if(N == 1) {
        cout << x[0] << endl;
        return 0;
    }

    LL res = gcd(x[0], x[1]);
    FOR(i, 2, N) {
        res = gcd(res, x[i]);
    }
    cout << res << endl;
    return 0;
}



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


using namespace std;

int main(){
  int a[5];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

  int mina = 10;
  int date = 10;

  int ans = 0;

  for (int i = 0; i < 5;i++){
    if (a[i] % 10 == 0)
      ans += a[i];
    else{
      mina = min(mina, a[i] % 10);
      ans += a[i]+10;
      ans -= a[i]%10;
    }

  }


  cout << ans+mina-10;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll d; cin >> d;
    vector<ll> c(26);
    rep(i, 26){
        cin >> c[i];
    }
    vector<vector<ll>> vec(d, vector<ll>(26));
    rep(i, d){
        rep(j, 26){
            cin >> vec[i][j];
        }
    }

    rep(i, d){
        cout << 1 << endl;
    }
    /*
    ll ans = 0;
    vector<ll> last(26);

    rep(i, d){

        ll max_value = -1;
        ll contest_type = -1;
        rep(j, 26){
            if(max_value < vec[i][j]){
                max_value = vec[i][j];
                contest_type = j;
            }

        }

        ans += max_value;

        rep(j, 26){
            if(j == contest_type){
                last[j] = 0;
            }else{
                last[j]++;
            }
        }

        rep(j, 26){
            ans -= c[j]*last[j];
        }

        cout << contest_type+1 << endl;
    }
    */


}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=1000010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int L,n=1,m=0,a[22],l=0;
struct Edge{int x,y,d;}e[70];
int main()
{
	L=read();
	int t=L-1;
	for(int i=0;(1<<i)<=t;i++)
	{
		n++;
		t-=(1<<i);
		e[++m].x=n-1,e[m].y=n,e[m].d=0;
		e[++m].x=n-1,e[m].y=n,e[m].d=(1<<i);
	}
	t=L;
	while(t)a[++l]=(t&1),t>>=1;
	int tot=(1<<(l-1));
	for(int i=l-1;i;i--)
	if(a[i])
	{
		e[++m].x=i,e[m].y=n,e[m].d=tot;
		tot+=(1<<(i-1));
	}
	printf("%d %d\n",n,m);
	for(int i=1;i<=m;i++)printf("%d %d %d\n",e[i].x,e[i].y,e[i].d);
}

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

//n
int main() {
    int n;
    cin >> n;
    vector<long long>a(n + 1);
    vector<long long>b(n);
    for(int i = 0;i < n + 1;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i++){
        cin >> b[i];
    }
    long long count = 0;
    for(int i = 0;i < a.size();i++){
        if(i != 0){
            if(a[i] >= b[i - 1]){
                a[i] -= b[i - 1];
                count += b[i - 1];
                b[i - 1] = 0;
            }else{
                b[i - 1] -= a[i];
                count += a[i];
                a[i] = 0;
            }
        }
        if(i != a.size() - 1){
            if(a[i] >= b[i]){
                a[i] -= b[i];
                count += b[i];
                b[i] = 0;
            }else{
                b[i] -= a[i];
                count += a[i];
                a[i] = 0;
            }
        }
    }
    cout << count;
}

Measured memory_bytes: 4836
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=5*1e5+1000;
const int SIZE2=5010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
 
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////
void init(){
 
}
int A[SIZE];
bool val[SIZE];
LL solve(){
	int maxim=0,sec=0;
 	cin >> N;
 	REP(i,N){
 		cin >> A[i];
 		maximize(maxim,A[i]);
 	}
 	int last=0;
 	REP(i,N){
 		if(maxim!=A[i]){
 			sec=max(sec,min(A[i],maxim-A[i]));
 			if(sec==min(A[i],maxim-A[i])) last=A[i];
 		}
 	}
 	cout << maxim <<" " << last << endl;
	return 0;
}
signed main(){
	solve();
	return 0;
}

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

int main(){
  ll N, i, K, ans;
  cin >> N >> K;
  ans = N%K;
  if(ans > K - ans){
    ans = K - ans;
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdlib>

using namespace std;
typedef long long ll;

int n;
int aa[10001];
int bb[10001];

const int MAX_N=10001;
const int MAX_Q=10001;
const int DAT_SIZE=(1<<18)-1;
//int N,Q;
//int A[MAX_N];
//char T[MAX_Q];
//int L[MAX_Q],R[MAX_Q],X[MAX_Q];

// segmentation tree
ll data[DAT_SIZE];
ll datb[DAT_SIZE];

// [a,b)ÉxðÁZ
// kÍß_ÌÔÅAæÔ[l,r)ÉÎ
void add(int a,int b,int x,int k,int l,int r){
    if(a<=l&&r<=b)
        data[k]+=x;
    else if(l<b&&a<r){
        datb[k]+=(min(b,r)-max(a,l))*x;
        add(a,b,x,k*2+1,l,(l+r)/2);
        add(a,b,x,k*2+2,(l+r)/2,r);
    }
}
// [a,b)ÌaðvZ
// kÍß_ÌÔÅAæÔ[l,r)ÉÎ
ll sum(int a,int b,int k,int l,int r){
    if(b<=l||r<=a)
        return 0;
    else if(a<=l&&r<=b)
        return data[k]*(r-l)+datb[k];
    ll res=(min(b,r)-max(a,l))*data[k];
    res+=sum(a,b,k*2+1,l,(l+r)/2);
    res+=sum(a,b,k*2+2,(l+r)/2,r);
    return res;
}

int main(){

    while(cin>>n&&n!=0){
        // [NA
        memset(data,0,sizeof(data));
        memset(datb,0,sizeof(datb));
        for(int i = 0; i < n; i++)cin>>aa[i];
        for(int i = 0; i < n; i++)cin>>bb[i];
        sort(aa,aa+n);
        sort(bb,bb+n);
        int havingZeroCow=-1;
        // »Ý0ðÂàÁÆàEÌñ
        for(int i = 0; i < n; i++){
            if(bb[i]==0)
                havingZeroCow=i;
            else
                break;
        }
        // seg treeÉúlðÁZ
        for(int i = 0; i < n; i++)
            add(i,i+1,bb[i],0,0,n);
        bool f=false;
        // àÁÆàå«¢ðÂs©çÔÉ
        for(int i = n-1; i >= 0; i--){
            // E©çÔÉßÄ¢ÁÄAÅÉóÉÈéñ
            int firstEmpty=n-aa[i]-1;
            if(firstEmpty==-1||sum(firstEmpty,firstEmpty+1,0,0,n)==0)
                add(firstEmpty+1,n,-1,0,0,n);
            else{
                f=true;
                break;
            }
        }
        if(f)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 5032
/****************************************
 
 			LostMartian
 
 ****************************************/
 #pragma GCC optimize("Ofast")  
 #pragma GCC target("avx,avx2,fma") 
 #include <iostream>
 #include <string>
 #include <vector>
 #include <algorithm>
 #include <fstream>
 #include <queue>
 #include <deque>
 #include <bitset>
 #include <iterator>
 #include <list>
 #include <stack>
 #include <map>
 #include <unordered_map>
 #include <unordered_set>
 #include <set>
 #include <functional>
 #include <utility>
 #include <climits>
 #include <numeric>
 #include <cmath>
 #include <cstdio>
 #include <cstring>
 #include <iomanip>
 #include <cassert>
 using namespace std;
 typedef long long ll;
 
 template <typename Arg1>
 void pn(Arg1&& arg1) {
 	cout << arg1 << "\n";
 }
 template <typename Arg1, typename... Args>
 void pn(Arg1&& arg1, Args&&... args) { 
 	cout << arg1 << " "; 
 	pn(args...); 
 }
 template <typename Arg1>
 void ps(Arg1&& arg1) { 
 	cout << arg1 << " ";
 }
 template <typename Arg1, typename... Args>
 void ps(Arg1&& arg1, Args&&... args) { 
 	cout << arg1 << " "; 
 	ps(args...); 
 }
 template <typename Arg1>
 void read(Arg1&& arg1) {
 	cin >> arg1; 
 }
 template <typename Arg1, typename... Args>
 void read(Arg1&& arg1, Args&&... args) { 
 	cin >> arg1; 
 	read(args...); 
 }
 
 #define rep(i,m,n) for(ll i=m; i<n; i++)
 #define repr(i,m,n) for(ll i=m; i>=n; i--)
 #define vll vector<ll >
 #define vvl vector<vector<ll > >
 #define pi pair<ll, ll >
 #define vpi vector<pi >
 #define umap unordered_map<ll, ll >
 #define pb push_back
 #define mk make_pair
 #define sz size()
 #define fi first
 #define se second
 #define all(x) x.begin(), x.end()
 #define test ll t; cin>>t; while(t--)
 #define ini(a, x) memset(a, x, sizeof(a))
 #define d(x) cout<<"Value of "#x" = "<<x<<"\n";
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define iAmSpeed ios_base::sync_with_stdio(false); cin.tie(NULL);
 void LOCAL();
 int main()
 {
 	clock_t z = clock();
 	//LOCAL();
 	iAmSpeed
 	double n, x, t;
 	cin>>n>>x>>t;
 	ll mul=ceil(n/x);
 	cout<<mul*(ll)t;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 	debug("Total Time: %.7f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
 	return 0;
 }
 void LOCAL() {
 	#ifndef ONLINE_JUDGE
 	freopen("input.txt", "r", stdin);
 	freopen("output.txt", "w", stdout);
 	#endif
 }
 


Measured memory_bytes: 3808
MOD = 998244353
s = input()
n = len(s)
R = s.count("0") * 2 + s.count("1")
B = 2*n - R
rb = [[R, B] for _ in range(2*n)]
if s[0] == "0":
	rb[0] = [2, 0]
elif s[0] == "1":
	rb[0] = [1, 1]
else:
	rb[0] = [0, 2]
for i in range(1, n):
	if s[i] == "0":
		rb[i] = [rb[i-1][0] + 2, rb[i-1][1] + 0]
	elif s[i] == "1":
		rb[i] = [rb[i-1][0] + 1, rb[i-1][1] + 1]
	else:
		rb[i] = [rb[i-1][0] + 0, rb[i-1][1] + 2]

dp = [[0 for _ in range(R+1)] for _ in range(2*n)]
if rb[0][0] >= 1:
	dp[0][1] = 1
if rb[0][1] >= 1:
	dp[0][0] = 1
for i in range(1, 2*n):
	for j in range(R+1):
		if j > 0 and rb[i][0] >= j:
			dp[i][j] += dp[i-1][j-1]
			dp[i][j] %= MOD
		if j != i+1 and rb[i][1] >= i+1 - j:
			dp[i][j] += dp[i-1][j]
			dp[i][j] %= MOD

print(dp[2*n-1][R])

Measured memory_bytes: 168456
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String s = scan.next();
    String t = scan.next();
    int ans = 0;
    for (int i = 0; i < s.length(); i++){
      if (s.charAt(i) != t.charAt(i)){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 41188
x,y=map(int,input().split())

if x*y<0:
    ans=abs(abs(y)-abs(x))+1
elif x==0:
    ans=abs(y)
    if y<0:
        ans+=1
elif y==0:
    ans=abs(x)
    if x>0:
        ans+=1
else:
    ans=abs(abs(y)-abs(x))
    if x>y:
        ans+=2

print(ans)

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

const int INF = 1001001001;
const int NV=100100;

int main() {
  int K,X;
  cin>>K>>X;
  if(K*500>=X){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int n;
  cin >> n;
  map<int,int> a;
  rep(i,n) {
    int b;
    cin >> b;
    a[b] ++;
  }
  int count = 0;
  for(auto p:a){
    if(p.second <= 1);
    else if(p.second%2 == 0) p.second = 2;
    else p.second = 1;
    
    if(p.second > 1) count ++;
  }
  if(count%2 == 0) cout << a.size() << endl;
  else cout << a.size()-1 << endl;
  
  return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin >> n >> t;
  int c[n],s[n];
  int m=99999;
  for(int i=0;i<n;i++){
    cin >> c[i] >> s[i];
    if(s[i]<=t){
      if(m>c[i])m=c[i];
    }
  }
  if(m==99999)cout << "TLE";
  else cout << m;
}

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

int	main()
{
	const static int	inf = static_cast<int>(1e+9 + 1);
	int	N, M, P;
	cin >> N >> M >> P;
	vector<int>	v_score(N, -inf);
	vector<tuple<int, int, int>> e_score(M);
	int	A, B, C;
	for (int i = 0; i < M; ++i) {
		cin >> A >> B >> C;
		--A; --B;
		e_score.at(i) = make_tuple(A, B, C - P);
	}
	v_score.at(0) = 0;
	int		score;
	bool	updated;
	for (int i = 0; i < N; ++i) {
		updated = false;
		for (int j = 0; j < M; ++j) {
			tie(A, B, C) = e_score.at(j);
			if (v_score.at(A) == -inf)
				continue;
			score = v_score.at(A) + C;
			if (score > v_score.at(B)) {
				v_score.at(B) = score;
				updated = true;
			}
		}
		if (!updated)
			break;
	}
	if (!updated) {
		if (v_score.at(N - 1) > 0)
			cout << v_score.at(N - 1) << endl;
		else
			cout << 0 << endl;
		return 0;
	}
	vector<bool>	has_upper(N, true);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			tie(A, B, C) = e_score.at(j);
			if (v_score.at(A) == -inf)
				continue;
			score = v_score.at(A) + C;
			if (score > v_score.at(B)) {
				v_score.at(B) = score;
				has_upper.at(B) = false;
			}
			if (!has_upper.at(A))
				has_upper.at(B) = false;
		}
	}
	if (has_upper.at(N - 1)) {
		if (v_score.at(N - 1) > 0)
			cout << v_score.at(N - 1) << endl;
		else
			cout << 0 << endl;
	} else
		cout << -1 << endl;
	return 0;
}


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

int main()
{
	ll a,b,k;
	cin>>a>>b>>k;
	if(a+b<=k)
		cout<<"0 0\n";
	else if(a>=k)
		printf("%lld %lld\n",a-k,b);
	else printf("0 %lld\n",b-(k-a));
	
}

Measured memory_bytes: 256
n = int(input())
x, y = [], []
for i in range(n):
  x_, y_ = map(int, input().split())
  x.append(x_)
  y.append(y_)
for i in range(n-2):
  if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
struct SegmentTree{
    int n=1;
    vector<int> dat;
    SegmentTree(int N){
        while(n<N)n*=2;
        dat.resize(n*2,0);
    }
    SegmentTree(){}
    void init(int N){
        n=1;
        while(n<N)n*=2;
        dat.resize(n*2,0);
    }
    void update(int x,int a){
        x+=n-1;
        dat[x]+=a;
        while(x>0){
            x=(x-1)/2;
            dat[x]+=a;
        }
    }
    int query2(int a,int b,int x,int l,int r){
        if(r<=a || b<=l)return 0;
        if(a<=l && r<=b)return dat[x];
        return query2(a,b,x*2+1,l,(l+r)/2)+query2(a,b,x*2+2,(l+r)/2,r);
    }
    int query(int a,int b){
        return query2(a,b+1,0,0,n);
    }
};
signed main(){
  int N,Q;
  string S;
  cin>>N>>S>>Q;
  vector<SegmentTree> A(26);
  for(int i=0;i<26;i++)A[i].init(N);
  for(int i=0;i<N;i++)A[S[i]-'a'].update(i,1);
  while(Q--){
    int a;
    cin>>a;
    if(a==1){
      int i;
      char c;
      cin>>i>>c;
      i--;
      A[S[i]-'a'].update(i,-1);
      A[c-'a'].update(i,1);
      S[i]=c;
    }else{
      int l,r,ans=0;
      cin>>l>>r;
      l--,r--;
      for(int i=0;i<26;i++)
        if(A[i].query(l,r))ans++;
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 110360
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int m,n,a[111][111];
int h,Y[30],X[30];
int dy[]={0,1,0,-1};
int dx[]={1,0,-1,0};

map<int,int> M;

const int LIM = 15;

int f(int cur,int mask){
	if(__builtin_popcount(mask)<=LIM){
		if(M.find(cur<<24|mask)!=M.end())return M[cur<<24|mask];
	}
	int res=0;
	rep(d,4){
		int y=Y[cur],x=X[cur];
		while(1){
			y+=dy[d];
			x+=dx[d];
			if(y<0 || y>=n || x<0 || x>=m)break;
			if(a[y][x]==0){
				if(mask==(1<<h)-2)res++;
			}
			if(a[y][x]>=1){
				if((mask>>a[y][x]&1)==0){
					res+=f(a[y][x],mask|1<<a[y][x]);
					break;
				}
			}
		}
	}
	if(__builtin_popcount(mask)<=LIM){
		M[cur<<24|mask]=res;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	while(cin>>m>>n && m){
		M.clear();
		h=1;
		rep(i,n)rep(j,m){
			cin>>a[i][j];
			if(a[i][j]==0){
				a[i][j]=-1;
			}
			else if(a[i][j]==1){
				Y[h]=i,X[h]=j;
				a[i][j]=h++;
			}
			else{
				Y[0]=i,X[0]=j;
				a[i][j]=0;
			}
		}
		cout<<f(0,0)<<endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  for (int i = 0; i < 3; ++i){
    if (s[i] == 'o') ++counter;
  }
  cout << 700 + counter * 100 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define F first
#define S second
#define pb push_back
#define M 1000000007
#define inf 1e18
#define endl "\n"
#define jam(x) cout<<"Case #"<<x<<": "

void display2D( vector<vector<int> > &v ) {
	int n = v.size();
	int m = v[0].size();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}
int32_t main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, cap;
	cin >> n >> cap;
	std::vector<int> wei(n);
	std::vector<int> val(n);
	std::vector<vector<int> > dp(cap + 1, vector<int>(n, 0) );

	for (int i = 0; i < n; i++) {
		cin >> wei[i];
		cin >> val[i];
	}
	for (int i = 0; i <= cap; ++i) {
		if ( i >= wei[0] ) dp[i][0] = val[0];
	}

	for (int j = 1; j < n; j++) {
		for (int i = 1; i <= cap; i++) {
			dp[i][j] = dp[i][j - 1];
			if ( wei[j] <= i ) dp[i][j] = max( dp[i][j] , val[j] + dp[i - wei[j]][j - 1] );
		}
	}

	//display2D(dp);
	cout << dp[cap][n - 1] << endl;
	return 0;
}

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

int main(){
	string s[3]={"Sunny","Cloudy","Rainy"};
	string x;	cin>>x;

	for(int i=0;i<3;i++){
		if(s[i]==x){
			cout<<s[(i+1)%3]<<endl;
		}
	}


	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    int m = 0;
    vector<int> v1(n),v2(n);
    for(int i = 0; i < n; i++){
        cin >> v1[i] >> v2[i];
    }
    for(int i = 0; i < n; i++){
        if(v1[i] == v2[i]){
            int c = 0;
            while(v1[i] == v2[i] && i < n){
                c++;
                // cout << i << " " << c << '\n';
                i++;
            }
            m = max(m,c);
        }
        if(m >=3)
            break;
    }
    if(m >= 3)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  ll ans = 0;
  rep(i, n - k) ans += h[i];
  cout << ans << endl;
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt exit(0)
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)

using namespace __gnu_pbds;
using namespace std;

#define int ll

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

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int k=0;
    while(n--)
    {
        int t;
        cin>>t;
        while(t%2==0)
            k++,t/=2;
    }
    cout<<k;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <queue>
#include <utility>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define mp make_pair

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

struct node {
    int w, x, y;
    node(int w, int x, int y) : w(w), x(x), y(y) {}
};
inline bool operator<(const node& l, const node& r) {
    return l.w!=r.w ? l.w<r.w : l.x!=r.x ? l.x<r.x : l.y<r.y;
}

int H, W;
int m, wall[32][32][4], bcost[2000][32][32], dp[2000][32][32];

void dfs(int sx, int sy, int br) {
    memset(bcost[br], -1, sizeof(bcost[br]));
    queue<node> q;
    q.push(node(0, sx, sy));
    bcost[br][sx][sy] = 0;
    while(!q.empty()) {
        const node v(q.front());
        q.pop();
        rep(d, 4) if(wall[v.x][v.y][d]>=0 && wall[v.x][v.y][d]!=br) {
            const int nx = v.x+dx[d], ny = v.y+dy[d];
            if(bcost[br][nx][ny]!=-1) continue;
            q.push(node(v.w+1, nx, ny));
            bcost[br][nx][ny] = v.w+1;
        }
    }
}

int solve() {
    memset(dp, -1, sizeof(dp));
    priority_queue<pair<int, node> > q;
    q.push(mp(0, node(0, 0, 0)));
    while(!q.empty()) {
        const pair<int, node> vv(q.top());
        q.pop();
        const int c = -vv.first;
        const int w = vv.second.w, x = vv.second.x, y = vv.second.y;
        if(dp[w][x][y]!=-1) continue;
        dp[w][x][y] = c;
        if(x==H-1 && y==W-1) return c;
        rep(d, 4) if(wall[x][y][d]>=0) {
            const int nx = x+dx[d], ny = y+dy[d];
            if(dp[w+1][nx][ny]!=-1) continue;
            const int wk = wall[x][y][d];
            if(bcost[wk][x][y]!=-1) {
                const int nc = max(c, w+bcost[wk][x][y]);
                q.push(mp(-nc, node(w+1, nx, ny)));
            }
        }
    }
    return -1;
}

int main() {
    for(;;) {
        scanf("%d%d", &H, &W);
        if(H==0 && W==0) return 0;
        memset(wall, -1, sizeof(wall));
        m = 0;
        rep(i, 2*H-1) {
            int ex;
            if(i%2==0) rep(j, W-1) {
                scanf("%d", &ex);
                wall[i/2][j][1] = wall[i/2][j+1][3] = ex ? -1 : m;
                if(ex==0) m++;
            }
            else rep(j, W) {
                scanf("%d", &ex);
                wall[i/2][j][0] = wall[i/2+1][j][2] = ex ? -1 : m;
                if(ex==0) m++;
            }
        }
        rep(i, m) dfs(H-1, W-1, i);
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,n,m,a[101]= {0},Max=0,top=0;
    cin>>n;
    for(i=0; i<n; i++)
        cin>>a[i],Max+=a[i];
    sort(a,a+n);
    if(Max%10)
        cout<<Max;
    else
    {
        for(i=0; i<n; i++)
        if((Max-a[i])%10!=0){
                cout<<Max-a[i]<<endl;
                return 0;}
        cout<<0;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(n,a) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(){
  string x,y;
  cin>>x>>y;
  int dp[1100][1100]={};
  
  rep(i,x.length()+1){
    rep(j,y.length()+1){
      if(i==0||j==0) continue;
      if(x[i-1]==y[j-1]) dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        
      
    }
  }

  cout<<dp[(int)x.length()][(int)y.length()]<<endl;
}


int main(){
  int q;
  cin>>q;
  while(q--){
    f();
  }
}


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

int main()
{
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << (( ((B+C-1) / B) <=( (D+A-1) /D) ) ?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x;
    scanf("%lld",&x);
    long long cur = 100;
    for (int i = 0; i <= 3760; i++){
        if (cur >= x){
            printf("%d",i);
            return 0;
        }
        cur += (cur/100);
    }
    if (cur >= x){
        printf("%d",3760);
        return 0;
    }
}


Measured memory_bytes: 3824
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');

            var a = int.Parse(str[0]);
            var b = str[1];
            var c = int.Parse(str[2]);

            if (b == "+")
            {
                Console.WriteLine(a + c);
            }
            else
            {
                Console.WriteLine(a - c);
            }
        }
    }
}


Measured memory_bytes: 11092
constexpr bool isDebugMode = false;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // cin >> testcase;
    while(testcase--) solve();
    return 0;
}

void solve(){
    string S; cin >> S;
    if(*--S.end() == 's') S += "es";
    else S += "s";
    pt(S);
    
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    string S;
    cin >> N >> S;
    bool ans = N % 2 == 0;
    rep(i, N / 2) {
        if (S[i] != S[N / 2 + i]) ans = false;
    }
    write(ans ? "Yes" : "No");
}

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


int getDistance(vector<string>& grid, vector<vector<int>>& visited, int x, int y)
{
	
	if(grid[x][y] == '#')
		return 0;
	visited[x][y] = 1;
	vector<int> dx{0, 0, 1, -1};
	vector<int> dy{1, -1, 0, 0};

	int distance = 0;
	int rows = grid.size();
	int cols = grid[0].length();

	queue<pair<int,int>> q;
	q.push({x, y});
	visited[x][y] = 1;

	while(!q.empty())
	{
		++distance;
		int n = q.size(); 

		for(int j = 0; j < n; ++j)
		{
			auto top = q.front(); q.pop();
			x = top.first; y = top.second;
			for(int i = 0; i < 4; ++i)
			{
				int newX = x + dx[i];
				int newY = y + dy[i];
				bool valid = (newX >= 0) and (newY >= 0) and (newX < rows) and (newY < cols) ;
				if(valid and (visited[newX][newY] == 0) and (grid[newX][newY] != '#'))
				{
					q.push({newX, newY});
					visited[newX][newY] = 1;				}
			}
		}
	}

	return distance;
}



int main()
{
	int h, w; cin >> h >> w;
	vector<string> grid(h);
	for(int i = 0; i < h; ++i)
		cin >> grid[i];
	int ans = 0;
	for(int i = 0; i < h; ++i)
	{
		for(int j = 0; j < w; ++j)
		{
			vector<vector<int>> visited(h+1, vector<int> (w+1, 0));
			ans = max(ans, getDistance(grid, visited, i, j)-1);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3644