akhauriyash/Code-Regression huggingface dataset:
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int Max_N=1e5+1;

int arr[Max_N];
int n, k;
int dp[Max_N][2];
// turn = 0 (Taro) , 1 (Jiro)
int Top_Down(int stones = k, int turn = 0) {
    // Base Case
    if(stones == 0) return (dp[stones][turn]=!turn);

    if(dp[stones][turn] != -1) return dp[stones][turn];

    // Choice
    for(int i = 1; i <= n; ++i) {
        if(arr[i] <= stones) 
            if(Top_Down(stones-arr[i], !turn) == turn)  return (dp[stones][turn]=turn);
    }
    return (dp[stones][turn]=!turn);
}

int Bottom_Up() {
    dp[0][0] = 1;
    dp[0][1] = 0;

    
    for(int stones = 1; stones <= k; ++stones) {
        for(int turn : {0, 1}) {
            for(int i = 1; i <= n; ++i) {
                if(arr[i] <= stones && dp[stones-arr[i]][!turn] == turn) dp[stones][turn] = turn;
            }
            if(dp[stones][turn] != -1) dp[stones][turn] = !turn;
        }
    }

    return dp[k][0];
}


int32_t main() {
    IOS;
    memset(dp, -1, sizeof(dp));
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> arr[i];
    if(Top_Down() == 0) cout << "First" << endl;
    else cout << "Second" << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 10000001
#define int ll
int dp[maxn];
bool sieve[maxn];
int fac[maxn];
int N;
int32_t main(){
	cin>>N;
	FOR(i,1,N) sieve[i] = 1;
	FOR(i,2,N){
		if (!sieve[i]) continue;
		for (int j = i * 2; j <= N; j += i){
			sieve[j] = 0;
			fac[j] = i;
		}
	}
	//cout<<sieve[95]<<'\n';
	dp[1] = 1;
	FOR(i,2,N){
		if (sieve[i]) dp[i] = 2;
		else{
			int numfac = 0;
			int x = i;
			while (x % fac[i] == 0){ x /= fac[i]; numfac++;}
			//cout<<i<<' '<<fac[i]<<' '<<numfac<<'\n';
			dp[i] = (dp[i / fac[i]] / (numfac)) * (numfac + 1);
			
		}
		//cout<<dp[i]<<' '<<fac[i]<<'\n';
		
	}
	int ans = 0;
	FOR(i,1,N) ans += dp[i] * i;
	cout<<ans;
		
}


Measured memory_bytes: 169644
n = int(input())
a = sorted(list(map(int, input().split())))
b = [0 for _ in range(n)]

if n % 2:
    for i in range(1,n,2):
        b[i] = b[i+1] = n - i
else:
    for i in range(0,n,2):
        b[i] = b[i+1] = n - (i + 1)
b.sort()

for i, j in zip(a, b):
    if i != j:
        print(0)
        exit()

print((2**(n//2))%(10**9+7))

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

int main(){
    int N; cin >> N;
    bool flag=false;
    int size;
    for(int i=1;i<=N;i++){
        if(i*(i+1)==2*N){
            flag=true;
            size=i;
            break;
        }
    }
    if(!flag){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl; 
    cout << size+1 << endl;
    vector<int> ans[size+1];
    int tmp=1;
    for(int i=0;i<=size;i++){
        for(int j=i;j<size;j++){
            ans[i].push_back(tmp++);
        }
    }
    tmp=1;
    for(int j=0;j<size;j++){
        for(int i=j+1;i<=size;i++){
            ans[i].push_back(tmp++);
        }
    }
    for(int i=0;i<=size;i++){
        cout << ans[i].size() << " ";
        for(auto v:ans[i]){
            cout << v << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 2304
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

A_total = A[0]
if N == 2:
    print(A_total)
    exit()

for i in range(1, N//2):
    A_total += (A[i]*2)

if N%2 == 1:
    A_total += A[i+1]

print(A_total)

Measured memory_bytes: 31364
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll INF = 1e16;

ll n, mod;
vvl G;
vl dp1;  // dp1[v] : 頂点vを根とする下方向の部分木の場合の数
vl dp2;  // dp2[v] : 頂点vを根とする上方向の部分木の場合の数
vl ans;  // ans[v] : 頂点vを黒で塗るときの場合の数

void dfs1(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    ll x = 1;
    for(ll to : G[v]) {
        if(to == p) {
            continue;
        }
        dfs1(to, v);
        // 帰りの処理はこのへんに書く
        x = x * dp1[to] % mod;
    }
    dp1[v] = x + 1;
}

void dfs2(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    if(p == -1) {
        dp2[v] = 1;
    }
    vl ruiL(G[v].size(), 1);
    rep(i, (ll)G[v].size()) {
        ll to = G[v][i];
        if(i-1 >= 0) {
            ruiL[i] = ruiL[i-1];
        }
        if(to == p) {
            continue;
        }
        ruiL[i] = dp1[to] * ruiL[i] % mod;
    }
    vl ruiR(G[v].size(), 1);
    for(ll i = G[v].size()-1; i >= 0; i--) {
        ll to = G[v][i];
        if(i+1 < (ll)G[v].size()) {
            ruiR[i] = ruiR[i+1];
        }
        if(to == p) {
            continue;
        }
        ruiR[i] = dp1[to] * ruiR[i] % mod;
    }
    rep(i, (ll)G[v].size()) {
        ll to = G[v][i];
        if(to == p) {
            continue;
        }
        ll x = 1;
        if(i-1 >= 0) {
            x = x * ruiL[i-1] % mod;
        }
        if(i+1 < (ll)G[v].size()) {
            x = x * ruiR[i+1] % mod;
        }
        dp2[to] = (x * dp2[v] + 1) % mod;
        dfs2(to, v);
    }
}

void dfs3(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    ans[v] = dp2[v];
    for(ll to : G[v]) {
        if(to == p) {
            continue;
        }
        ans[v] = ans[v] * dp1[to] % mod;
        dfs3(to, v);
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    
    cin >> n >> mod;    
    
    G.resize(n);
    rep(i, n-1) {
        ll x, y;
        cin >> x >> y;
        x--;  y--;
        G[x].pb(y);
        G[y].pb(x);
    }

    dp1.resize(n);
    dp2.resize(n);
    ans.resize(n);
    dfs1(0);
    dfs2(0);
    dfs3(0);

    rep(v, n) {
        out(ans[v]);
    }

    re0;
}

Measured memory_bytes: 21328
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

def eratosthenes(n):
    res = []
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            res.append(i)
    return is_prime

is_prime = eratosthenes(10**5)
a = [0 for i in range(10**5+1)]
for i in range(10**5+1):
    if i % 2 == 0:
        continue
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] = 1

b = [0]
for i in range(10**5+1):
    b.append(b[-1] + a[i])

for i in range(Q):
    l, r = query[i]
    print(b[r+1] - b[l])

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int32 d;
int32 c[26];
int32 s[365][26];

int32 score(vector<int32> &t, int32 e = d){
  vector<int32> last(26,-1);
  int32 res = 0;
  REP(i,e){
    res += s[i][t[i]];
    last[t[i]] = i;
    REP(j,26)res -= c[j] * (i - last[j]);
    // ANS(res);
  }
  return res;
}

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

  // input
  cin >> d;
  REP(i,26)cin >> c[i];
  REP(i,d)REP(j,26)cin >> s[i][j];

  // scoring
  // vector<int32> t(d);
  // REP(i,d)cin >> t[i];
  // REP(i,d)t[i]--;
  // REP(i,d)ANS(score(t,i+1));

  vector<int32> t(d,-1);
  REP(i,d){
    int32 mx=-inf,mxj=-1;
    REP(j,26){
      t[i] = j;
      if(chmax(mx,score(t,i+1))){
        mxj = j;
      }
    }
    t[i] = mxj;
  }
  REP(i,d)ANS(t[i]+1);
  // ANS(score(t));

  return 0;
}

Measured memory_bytes: 3736
def ser_c(N):
    rec = [[0]*10 for i in range(10)]
    for l in range(1, N+1):
        k = str(l)
        i = int(k[0])
        j = int(k[-1])
        rec[i][j] += 1 
    return rec
N = int(input())
cnt = 0
rec = ser_c(N)
for i in range(10):
    for j in range(10):
        cnt += rec[i][j]*rec[j][i]
print(cnt)

Measured memory_bytes: 3316
#include<iostream>


using namespace std;

int main(){
  int h,n;
  cin >> h >> n;
  int sum=0;
  int a;
  for(int i=0;i<n;i++){
    cin >> a;
    sum += a;
    if(sum>=h) {
      cout <<"Yes" <<endl;
      return 0;
    }
  }
cout <<"No" <<endl;
      return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = 0;
l = len(A)
while(True):
  A = list(filter(lambda x: x%2==0, A))
  if len(A) is not l:
    break
  A = list([x//2 for x in A])
  ans += 1
  
print(ans)

Measured memory_bytes: 9072
INF = float('inf')
n, ma, mb = map(int, input().split())
ccmax = n * 10
t = [[INF] * (ccmax + 1) for _ in range(ccmax + 1)]
for _ in range(n):
  a, b, c = map(int, input().split())
  for aa in range(ccmax, 0, -1):
    taa = t[aa]
    for bb in range(ccmax, 0, -1):
      if taa[bb] == INF:
        continue
      if t[a + aa][b + bb] > c + taa[bb]:
        t[a + aa][b + bb] = c + taa[bb]
  if t[a][b] > c:
    t[a][b] = c
result = INF
for a in range(1, ccmax):
  ta = t[a]
  for b in range(1, ccmax):
    if a * mb == b * ma and ta[b] < result:
      result = ta[b]
if result == INF:
  result = -1
print(result)


Measured memory_bytes: 4844
N, M = map(int, input().split())
Hlist = list(map(int, input().split()))
ansdic = {}

for i in range(N):
    ansdic[i] = True

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if Hlist[a] < Hlist[b]:
        ansdic[a] = False
    elif Hlist[b] < Hlist[a]:
        ansdic[b] = False
    else:
        ansdic[a] = False
        ansdic[b] = False

ans = 0

for i in range(N):
    if ansdic[i]:
        ans += 1

print(ans)


Measured memory_bytes: 90916
/*input
1 1
1
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const int maxn=5e5+5;
vector<int> pref;
int main(){
	int n,k;
	cin>>n>>k;
	vector<pii> v;
	k=2*k;
	int cons=0,cons2=0;
	pref.pb(0);
	REP(i,n){
		char a;
		cin>>a;
		if(a=='0'){
			if(cons){
				v.pb({cons,1});
				pref.pb(pref.back()+cons);
			}
			cons=0;
			cons2++;
		}
		else{
			if(cons2){
				v.pb({cons2,0});
				pref.pb(pref.back()+cons2);
			}
			cons2=0;
			cons++;
		}
	}
			if(cons){
				v.pb({cons,1});
				pref.pb(pref.back()+cons);
			}
			if(cons2){
				v.pb({cons2,0});
				pref.pb(pref.back()+cons2);
			}
	int ans=0;
	REP(i,sz(v)){
		if(v[i].s){
			MXTO(ans,pref[min(i+k+1,sz(pref)-1)]-pref[i]);
		}
		else{
			MXTO(ans,pref[min(i+k,sz(pref)-1)]-pref[i]);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1780
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val stInput = scala.io.StdIn.readLine()
  val stArray =  stInput.split(" ")
  val s = stArray(0)
  val t = stArray(1)
  var result = ""

  (0 to (n-1)).foreach { i =>
    result += s(i).toString + t(i).toString
  }
  println(result)

}

Measured memory_bytes: 25552
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
constexpr ll MOD = 1000000007;

int main()
{
  ll n,k;
  cin>>n>>k;
  vecint hist(2001, 0);
  vecint a(n);
  REP(i,n) cin>>a[i];
  REP(i,n) ++hist[a[i]];
  ll cnt = 0;
  REP(i,n)FOR(j,i+1,n) {
    if(a[i] > a[j]) ++cnt;
  }
  cnt *= k;
  cnt %= MOD;
  ll sum = 0;
  ll tri = ((k * (k-1)) / 2) % MOD;
  REP(i,2001) {
    cnt += ((tri * sum) % MOD) * hist[i];
    cnt %= MOD;
    sum += hist[i];
    sum %= MOD;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);

    long long n,m;
    cin >> n >> m;
    long long d = __gcd(n,m);
    string s,t;
    cin >> s >> t;
    int idx = 0;
    for(int i = 0; i < n; i += n/d, idx += m/d)
    {
        if (s[i] != t[idx])
            FINAL_OUT(-1);
    }
    cout << n * m / d << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  
  if ( s % 3 == 1)
  cout << "1" << endl;
  
  if ( s % 3 == 2)
  cout << "2" << endl;
  
  if ( s % 3 == 0 && s != 000)
  cout << "3" << endl;
  
  if ( s == 000)
  cout << "0" <<endl;
}

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

nana_go_sans = [{357, 375, 537, 573, 735, 753}]

order = len(str(n))
for i in range(3, order):
    nana_go_san = set()
    nana_go_san.add(int("3" + "5" * (i - 1) + "7"))
    nana_go_san.add(int("3" + "7" * (i - 1) + "5"))
    nana_go_san.add(int("5" + "3" * (i - 1) + "7"))
    nana_go_san.add(int("5" + "7" * (i - 1) + "3"))
    nana_go_san.add(int("7" + "3" * (i - 1) + "5"))
    nana_go_san.add(int("7" + "5" * (i - 1) + "3"))
    for num in nana_go_sans[i - 3]:
        nana_go_san.add(int("3" + str(num)))
        nana_go_san.add(int("5" + str(num)))
        nana_go_san.add(int("7" + str(num)))
        nana_go_san.add(int(str(num) + "3"))
        nana_go_san.add(int(str(num) + "5"))
        nana_go_san.add(int(str(num) + "7"))
    nana_go_sans.append(nana_go_san)

count = 0
for nana_go_san in nana_go_sans:
    for num in nana_go_san:
        if num <= n:
            count += 1

print(count)


Measured memory_bytes: 5156
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 9000000000000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'


ll n, k, a[555], b[555], u, d, ans=inf, cnt, res, l, r;
vector<pll> v;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);



cin >> n >> k;

rep(i,1 , n){
cin >> a[i] >> b[i];
v.pb({a[i],b[i]})
;}

//sort(all(v));
sort(a+1, a+n+1);
sort(b+1, b+n+1);

rep(i, 1, n){

    rep(j, 1, n){

        rep(p, 1, n){

            rep(q, 1, n){
            l = a[i]; r = a[j]; d = b[p]; u = b[q];
            cnt = 0;
            res = inf;
            for(auto t: v){

                if(t.f >= l && t.f <= r && t.ss >=d && t.ss<=u )cnt++;

            }
            if(cnt>=k)
            res = (r-l)*(u-d);
            ans = min(ans, res);
            }

        }

    }

}


cout << ans << endl;

return 0;}
///....


Measured memory_bytes: 256
import bisect
N = int(input())
seq = [int(input()) for _ in range(N)]

LIS = [seq[0]]
for i in range(len(seq)):
    if seq[i] > LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i])] = seq[i]

print(len(LIS))


Measured memory_bytes: 10352
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int dp[2][3],a[3],n,i=0;
	cin >> n;
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	while (n--) {                                              
		cin >> a[0] >> a[1] >> a[2];
			dp[1 - i][0] = a[0] + max(dp[i][1] ,dp[i][2]);
			dp[1 - i][1] = a[1] + max(dp[i][0], dp[i][2]);
			dp[1 - i][2] = a[2] + max(dp[i][0], dp[i][1]);
			i = 1 - i;
	}
	cout << max(dp[i][0], max(dp[i][1], dp[i][2]));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int unsigned long long
using namespace std;
bool b[64];
int f() {
	int r = 0, p = 1;
	for (int i = 0; i < 64; i++) {
		r += p * (int)b[i];
		p *= 2;
	}
	return r;
}
signed main() {
	int q; cin >> q;
	int k = 0;
	for (int i = 0; i < q; i++) {
		int p, t; cin >> p;
		if (p == 0) {
			cin >> t;
			cout << b[t] << endl;
		}
		else if (p == 1) {
			cin >> t;
			if (!b[t])k++;
			b[t] = 1;
		}
		else if (p == 2) {
			cin >> t;
			if (b[t])k--;
			b[t] = 0;
		}
		else if (p == 3) {
			cin >> t;
			if (b[t])k--; else k++;
			b[t] = !b[t];
		}
		else if (p == 4) {
			cout << (k == 64) << endl;
		}
		else if (p == 5) {
			cout << (bool)k << endl;
		}
		else if (p == 6) {
			cout << (k ? 0 : 1) << endl;
		}
		else if (p == 7)cout << k << endl;
		else cout << f() << endl;
	}
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=5e5+5;
int f[N],a[N];
bool ans[N];
int main(){
	int n=read(),m=read();
	For(i,1,n) a[i]=read();
	f[n+1]=1;
	Rep(i,n,1){
		if(f[i+1]<=a[i]/2) f[i]=f[i+1];
		else f[i]=f[i+1]+a[i];
	}
	For(i,1,n) ans[i]=(f[i+1]<=m),m=min(m,abs(m-a[i]));
	int Q=read();
	while(Q--){
		int x=read();
		if(ans[x]) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 7924
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;

int main(void) {
  long long int n, k;
  cin >> n >> k;
  vector< pair<int, int> > p(n);
  for(int i=0; i<n; i++) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  long long int cnt = 0;
  for(int i=0; i<n; i++){
    cnt += p[i].second;
    if( cnt >= k ){
      cout << p[i].first << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int r; cin>>r;
	ote(r*r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; };
	bool operator > (const edge& e) const { return cost > e.cost; }
};

struct rec{ int w, h, t; };
int main()
{
	int w, h, t;
	while (cin >> h >> w, w)
	{
		t = h*h + w*w;
		int tar = t;
		while (1)
		{
			FOR(i, 1, 151)FOR(j, i+1, 151)
			{
				if (i*i + j*j == tar)
				{
					if (tar == t&&i <= h) continue;
					else
					{
						cout << i << " " << j << endl;
						goto end;
					}
				}
				else if (i*i + j*j > tar) break;
			}
			tar++;
		}
	end:;
	}
}

Measured memory_bytes: 1160
use std::fmt::Debug;
use std::cmp::*;
use std::io::{stdin, Read};
use std::str::FromStr;

//mod lib;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    return token.parse().ok().expect("failed to parse token");
}

fn read_vec1<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

fn read_vec2<T: FromStr>(n: usize, m: usize) -> Vec<Vec<T>> {
    return (0..n).map(|_| read_vec1(m)).collect();
}

static MOD: i64 = 1_000_000_007;

fn add_by_mod(a: &i64, b: &i64) -> i64 {
    return (a % MOD + b % MOD) % MOD;
}

pub trait Monoid {
    type T: Clone + Debug;
    fn op(lhs: &Self::T, rhs: &Self::T) -> Self::T;
    fn identity() -> Self::T;
}

#[derive(Debug)]
pub struct SegmentTree<M: Monoid> {
    size: usize,
    node: Vec<M::T>,
}

impl<M: Monoid> SegmentTree<M> {
    pub fn new(n: usize) -> SegmentTree<M> {
        let mut size = 1;
        while size < n {
            size *= 2;
        }

        SegmentTree {
            size: size,
            node: vec![M::identity(); size * 2],
        }
    }

    pub fn set(&mut self, a: usize, v: M::T) {
        self.node[a + self.size] = v;
    }

    pub fn build(&mut self) {
        for k in self.size - 1..0 {
            self.node[k] = M::op(&self.node[k * 2], &self.node[k * 2 + 1]);
        }
    }

    pub fn update(&mut self, a: usize, v: M::T) {
        let mut k = a + self.size;
        self.node[k] = v;
        while k > 1 {
            k >>= 1;
            self.node[k] = M::op(&self.node[k * 2], &self.node[k * 2 + 1]);
        }
    }

    pub fn query(&self, a: usize, b: usize) -> M::T {
        let mut vleft = M::identity();
        let mut vright = M::identity();
        let mut left = self.size + a;
        let mut right = self.size + b;

        while left < right {
            if (left & 1) == 1 {
                vleft = M::op(&vleft, &self.node[left]);
                left += 1;
            }

            if (right & 1) == 1 {
                right -= 1;
                vright = M::op(&self.node[right], &vright);
            }

            left >>= 1;
            right >>= 1;
        }

        return M::op(&vleft, &vright);
    }

    pub fn debug(&self) {
        println!("{:?}", self.node);
    }
}

#[derive(Clone)]
struct Sum;

impl Monoid for Sum {
    type T = i64;
    fn identity() -> Self::T {
        return 0;
    }

    fn op(a: &Self::T, b: &Self::T) -> Self::T {
        return a + b;
    }
}

fn main() {
    let (n, q) = (read::<usize>(), read::<usize>());

    let mut seg: SegmentTree<Sum> = SegmentTree::new(n);
    for _ in 0..q {
        let vec = read_vec1::<usize>(3);
        if vec[0] == 0 {
            let tmp = seg.query(vec[1] - 1, vec[1]) + vec[2] as i64;
            seg.update(vec[1] - 1, tmp);
        } else {
            println!("{}", seg.query(vec[1] - 1, vec[2]));
        }
    }
}



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

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

  vector<ll> a(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  // b[0] = (1+2+...+n-1)
  // b[1] = (2+3+...+n-1)
  // b[n-1] = 0
  vector<ll> b(n);
  b.at(0) = sum - a.at(0);
  for (int i = 1; i < n; i++) {
    b.at(i) = b.at(i-1) - a.at(i);
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll w = b.at(i) % 1000000007;
    ll x = a.at(i) * w;
    // cout << i << " " << a.at(i) << " " << b.at(i) << " " << x << endl;
    ll y = x % 1000000007;
    ans += y;
  }

  ans = ans % 1000000007;
  cout << ans << endl;
  return 0;
}


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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }
template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}
// -------------------------------------------------------------------

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    print(b % a ? b - a : a + b);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, k;
	cin >> n >> k;
	
	vi h(n);
	for(int i = 0; i < n; i++) cin >> h[i];	
	
	vi dp(n, inf);
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <= k; j++) if(i + j < n) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
	}
	
	cout << dp[n - 1] << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

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

int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    while(n) {
        ans++;
        n /= k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;

char s[100];
char t[100];
string k[10000];
int vis[100];
int sum = 0,s_len,t_len;

int chick(int q){
	int tot = 1;
	for(int i = q;i <= s_len;i++){
		if(s[i] == t[tot] || s[i] == '?'){
			vis[i] = tot;
		}
		else{
			return false;
		}
		tot++;
		if(tot == t_len +1)return true;
	}
}


int main(){
	cin >> s+1;
	cin >> t+1;
	s_len = strlen(s+1);
	t_len = strlen(t+1);
//	cout << s_len << t_len;
	if(t_len > s_len){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	else{
		for(int i = 1; i <= s_len - t_len+1 ;i++){
			memset(vis,0,sizeof(vis));
			if(chick(i)){
				//cout << i << endl;
				sum++;
				//cout << sum<<endl;
				//int tot = 1;
				for(int j = 1;j <= s_len;j++){
					if(s[j] == '?' && vis[j] == 0){
						k[sum] += 'a';
					}
					else if(vis[j] != 0){
						k[sum]+= t[vis[j]];
					}
					else{
						k[sum] += s[j];
					}
				}
			}
			
		}
		sort(k+1,k+sum+1);
		if(sum == 0)cout <<"UNRESTORABLE" << endl;
		else cout << k[1] << endl;
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

long long A,B,K;

long long calc(const string& s){

  long long a = A, b = B, c = 0, borrow = 0;
  int base = 1;
  int N = (int)log10(A)+1;

  for(int i = 0; i < N; i++){
    long long tmpA = a%10;
    long long tmpB = b%10;
    a /= 10;
    b /= 10;

    if(tmpA - borrow >= tmpB){
      c += (tmpA-borrow-tmpB)*base;
      borrow = 0;
      base*=10;
    }else{
      c += (tmpA - borrow + 10 - tmpB)*base;
      if(s[i] == '1') borrow = 0;
      else borrow = 1;
      base*=10;
    }
  }
  return c;
}

long long rec(long long k, const string& s){
  if(s.length() == ((int)log10(A)+1)) return calc(s);
  if(k) return max(rec(k-1,s+"1"),rec(k,s+"0"));
  return rec(k,s+"0");
}

int main(){
  cin >> A >> B >> K;
  cout << rec(K,"") << endl;
  return 0;
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N + 1];
    for (int i = 1; i <= N; i++) a[i] = scanner.nextInt();

    int[] b = new int[N + 1];
    for (int i = N; i >= 1; i--) {
      b[i] ^= a[i];
      if (i > 1) b[1] ^= b[i];
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) {
          b[j] ^= b[i];
          if (j * j != i) b[i / j] ^= b[i];
        }
      }
    }
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      if (b[i] == 1) {
        sb.append(i).append(' ');
        count++;
      }
    }
    System.out.println(count);
    if (sb.length() > 0) {
      sb.setLength(sb.length() - 1);
      System.out.println(sb);
    }
  }
}


Measured memory_bytes: 77444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int s =k;
		
		while(true) {
			if(a<=k && k <= b) {
				System.out.println("OK");
				break;
			}else if(b<k) {
				System.out.println("NG");
				break;
			}
			k+=s;
		}
	}
	
}

Measured memory_bytes: 27088
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


int main(){
	init();
	ll N,M;cin>>N>>M;
	vector<ll>data(N+1,0);
	for(int i=0;i<M;i++){
		ll l,r;cin>>l>>r;
		l--;r--;
		data[l]++;
		data[r+1]--;
	}
	vector<ll>sum(N+2,0);
	for(int i=0;i<N;i++){
		sum[i+1]=sum[i]+data[i];
	}
	ll ans=0;
	for(auto&&i:sum){
		if(i==M)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

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

	int n, m, x, p, q;
	cin >> n >> m >> x;
	vector <int> row(n), col(m);
	map <pair <int, int>, bool> target;
	ffor(x) {
		cin >> p >> q;
		p--; q--;
		row[p] += 1;
		col[q] += 1;
		target[{p, q}] = true;
	}
	vector <int> maximum_row, maximum_col; int size_row = 0, size_col = 0;
	for (int i = 0; i < n; i++) {
		if (row[i] == size_row) {
			maximum_row.push_back(i);
		}
		else if (row[i] > size_row) {
			maximum_row = { i };
			size_row = row[i];
		}
	}
	for (int i = 0; i < m; i++) {
		if (col[i] == size_col) {
			maximum_col.push_back(i);
		}
		else if (col[i] > size_col) {
			maximum_col = { i };
			size_col = col[i];
		}
	}
	bool flag = false;
	for (auto e : maximum_row) {
		for (auto ee : maximum_col) {
			if (target[{e, ee}] == false) {
				flag = true;
				break;
			}
		}
		if (flag) break;
	}
	if (flag) cout << size_col + size_row;
	else cout << size_col + size_row - 1;
}
	




/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

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

// product.cpp
// author: Seong Yong-ju ( @sei40kr )
// Copyright (c) 2018 Seong Yong-ju

#define DEBUG(x) cout << #x << ": " << x << endl

#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)

#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    int a, b;
    cin >> a >> b;
    
    cout << (a % 2 == 1 && b % 2 == 1 ? "Odd" : "Even") << endl;
}


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

int main () {
    string str;
    while (cin >> str) {
        bool f = false;
        for (auto i : str) if (i != '0') f = true;

        if (!f) break;

        f = false;
        for (auto i : str) if (i != str[0]) f = true;

        if (!f) {
            cout << "NA" << endl;
            continue;
        }

        int count = 0;
        int now;
        stringstream org;
        org << str;
        org >> now;
        while (1) {
            if (now == 6174) {
                cout << count << endl;
                break;
            }
            count++;
            sort(str.begin(), str.end());
            auto rstr = str;
            reverse(rstr.begin(), rstr.end());

            stringstream ss;
            ss << rstr << " " << str;
            int A, B;
            ss >> A >> B;
            now = A - B;
            stringstream next;
            next << now;
            next >> str;
            while (str.size() < 4) str = "0" + str;
        }
    }

    return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    int2(a, b);
    Rep(i, n) {
        int2(c, d);
        int tmp = max(a/c + ((a % c)?1:0), b/d + ((b % d)?1:0));
        //cout << tmp << endl;
        a = c * tmp;
        b = d * tmp;
        //cout << a << " " << b << endl;
    }
    cout << a + b << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main() {
    string S;
    cin >> S;
    if (S=="Sunny") out("Cloudy");
    else if (S=="Cloudy") out("Rainy");
    else out("Sunny");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    int data[255][255];
    int rec[255][255];
    char buf[512];
    int n;
    int i, j, k;
    int max;
    int dx[4] = {-1, 0, -1, 1};
    int dy[4] = {0, -1, -1, -1};
    
    while (scanf("%d", &n), n){
        for (i = 0; i < n; i++){
            scanf("%s", buf);
            for (j = 0; j < n; j++){
                data[i][j] = buf[j] - '0';
            }
        }
        
        max = 0;
        for (i = 0; i < 4; i++){
            memset(rec, 0, sizeof(rec));
            for (j = 0; j < n; j++){
                for (k = 0; k < n; k++){
                    rec[j][k] = data[j][k];
                    if (0 <= k + dx[i] && k + dx[i] < n &&
                            0 <= j + dy[i] && j + dy[i] < n && rec[j][k] == 1){
                        rec[j][k] += rec[j + dy[i]][k + dx[i]];
                    }
                    max = max > rec[j][k] ? max : rec[j][k];
                }
            }
        }
        
        printf("%d\n", max);
    }
    
    return (0);
}

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

using namespace std;

void trace(int A[], int N) {
    for(int i = 0; i < N - 1; i++) cout << A[i] << " ";
    cout << A[N-1];
    cout << endl;
}

void insertion_sort(int A[], int N) {
    for(int i = 1; i < N; i++) {
        int key = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > key) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        trace(A, N);
    }
}

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    trace(A, N);
    insertion_sort(A, N);
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define N 100005
#define ll long long
using namespace std;
int a,b,c;
int main(){
   // freopen("A.inp","r",stdin);
  //  freopen("A.out","w",stdout);
    cin>>a>>b>>c;
    if (a+b==c) {cout<<b+c;exit(0);}
    if (a+b<c) {cout<<a+2*b+1; exit(0);}
    cout<<b+c;
}


Measured memory_bytes: 256
def identify(x:str, y:str):
    if (x == "lu" and y == "ru") or (x == "ru" and y == "lu"):
        return True
    if (x == "ld" and y == "rd") or (x == "rd" and y == "ld"):
        return True

while True:
    num = int(input())
    if num != 0:
        udlr = input()
        list_udlr = udlr.split()
        count = 0
        for i in range(num - 1):
            if identify(list_udlr[i], list_udlr[i + 1]):
                count += 1
                i += 2
        print(count)
    else:
        break


Measured memory_bytes: 5620
# coding:utf-8


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


M = inpl()
M.sort()

sub1 = M[2] - M[1]
sub2 = M[1] - M[0]

if sub2 % 2 == 0:
	ans = sub1 + sub2 // 2
else:
	ans = sub1 + (sub2 + 1) // 2 + 1

print(ans)

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

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

    if (s == t.substr(0, t.length() - 1)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	long a = read.to!long;
	long b = read.to!long;
	long c = read.to!long;
	
	int count = 0;
	while(count < 10000){
		if(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
			long a2 = b / 2 + c / 2;
			long b2 = a / 2 + c / 2;
			long c2 = a / 2 + b / 2;
			a = a2, b = b2, c = c2;
			count += 1;
			}
		else break;
		}
	
	int ans;
	if(count > 1000) ans = -1;
	else ans = count;
	
	ans.writeln;
	}

Measured memory_bytes: 256
#include <cstdio>
#include <unordered_map>
#include <algorithm>
using namespace std;
int n, m;
int ans;
const int mod = 1e9 + 7;
unordered_map<int, int>A, B;
int a[1001], b[1001];
int main()
{
    ans = 1;
    scanf("%d %d", &n, &m);
    for (int i = 1 ;i <= n ; i++) {
        int x;
        scanf("%d", &x);
        A[x] ++;
        a[i] = x;
    }

    for (int i = 1 ;i <= m ; i++) {
        int x;
        scanf("%d", &x);
        B[x] ++;
        b[i ] =x;
    }
    sort(a + 1 , a + n + 1);
    sort(b + 1 , b + m + 1);
    for (int i = 1; i <= n * m;  i++)
        if (A[i] > 1 || B[i] > 1)
        {
            printf("0");
            return 0;
        } else
            if (A[i] && B[i])
            {
                continue;
            } else
                if (A[i])
                {
                    while (b[0] <= m && b[b[0]] < i) b[0] ++;
                    ans = (long long) ans * (m - b[0] + 1) % mod;
                } else
                    if (B[i])
                    {
                        while (a[0] <= n &&  a[a[0]] < i ) a[0] ++;
                        ans = (long long) ans * (n - a[0] + 1) % mod;
                    } else {
                        while (b[0] <= m && b[b[0]] < i) b[0] ++;
                        while (a[0] <= n &&  a[a[0]] < i ) a[0] ++;
                        ans = (long long) ans * max(0, (m - b[0] + 1 ) * (n - a[0] + 1) - (n * m - i)) % mod;
                    }
    printf("%d\n", (int)ans);
    return 0;
}

Measured memory_bytes: 79264
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n>>s;
    int i=0;
    int count=0;
    while (i+2<n) {
        if ( (s.at(i)=='A')&&(s.at(i+1)=='B')&&(s.at(i+2)=='C') ) {
            count++;
            i++;
        } else {
            i++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		int K[] = new int[N];
		int A[][] = new int[N][M];
		int food[] = new int[M];
		int a[] = new int[M];
		for (int i = 0; i < M; i++) {
			food[i] = i + 1;
			a[i] = 0;
		}

		for (int i = 0; i < N; i++) {
			K[i] = sc.nextInt();
			for (int j = 0; j < K[i]; j++) {
				A[i][j] = sc.nextInt();
				for (int k = 0; k < M; k++) {
					if (A[i][j] == food[k]) {
						a[k]++;
					}
				}

			}
		}
		sc.close();
		int ans = 0;
		for (int i = 0; i < M; i++) {
			if (a[i] == N) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
S = input()
T=[s for s in S]
N = len(S)-1
ans=0
for i in range(1<<N):
    T=[s for s in S]
    U=''
    b=[]
    for j in range(N,-1,-1):
        if (i>>j)&1:
            b.append(j)
    for B in b:
        T.insert(B+1,'+')
    for t in T:
        U+=t
    ans += eval(U)
print(ans)


Measured memory_bytes: 3064
package main

import (
    "fmt"
    "bufio"
    "os"
    "strings"
    "sort"
    "strconv"
)

func main() {
    var str string
    scanner := bufio.NewScanner(os.Stdin)

    if scanner.Scan() {
        str = scanner.Text()
        str_slice := strings.Split(str, " ")
        int_slice := strToIntSlice(str_slice)
        sort.Sort(sort.IntSlice(int_slice))

        if int_slice[0] == 5 && int_slice[1] == 5 && int_slice[2] == 7 {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

func strToIntSlice(arr []string) []int {
    retval := make([]int, len(arr))

    for i := range arr {
        retval[i], _ = strconv.Atoi(arr[i])
    }

    return retval
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000001
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;

int main()
{
  int N;
  char ch;

  int Nr = 0;
  int Nb;

  scanf("%d\n",&N);
  
  REP(i,N)
    {
      scanf("%c",&ch);
      
      if( ch == 'R' )
	{
	  ++ Nr;
	  
	}
    }

  Nb = N - Nr;

  if( Nr > Nb )
    {
      cout << "Yes" << endl;
      
    }
  else
    {
      cout << "No" << endl;
      
    }
  
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100001;
int main()
{
  int n,m,i,a,b,t,res=0;
  int c[N_MAX];
  cin >> n >> m;
  fill(c+1,c+n+1,n+1);
  for(i=0;i<m;i++){
    cin >> a >> b;
    c[a]=min(c[a],b);
  }
  t=n+1;
  for(i=1;i<n;i++){
    t=min(t,c[i]);
    if(t==i+1){
      res++;
      t=n+1;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3996