akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

constexpr int ALPHA = 26;
bool used[ALPHA + 1];
vector<string> ans;
string str;

void dfs(unsigned idx){
	if(idx == str.size()) {
		ans.emplace_back(str);
		return;
	}

	const int id = str[idx] - 'a';
	if(used[id]) { // 変換しなくても良い
		dfs(idx + 1);
	}
	if(!used[id + 1]) { // 変換できる
		++str[idx];
		used[id + 1] = true;
		dfs(idx + 1);
		used[id + 1] = false;
		--str[idx];
	}
}

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

	used[0] = used[ALPHA] = true;
	while(cin >> str && str != "#"){
		ans.clear();
		dfs(0);

		cout << ans.size() << endl;
		if(ans.size() <= 10) {
			for(const auto &s : ans) {
				cout << s << endl;
			}
		}
		else {
			rep(i, 5) {
				cout << ans[i] << endl;
			}

			for(int i = 5; i > 0; --i) {
				cout << ans[ans.size() - i] << endl;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2348
def luca(num):
  if num == 0:
    return 2
  
  if num == 1:
    return 1
  
  memo[0] = 2
  memo[1] = 1
  
  if memo[num] != 0:
    return memo[num]
  
  memo[num] = luca(num-1) + luca(num-2)
  
  return memo[num]

n = int(input())
memo = [0]*(n+1)
print(luca(n))


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

char s[101];
int main()
{
    scanf("%s", s);
    int res = 0;
    int n = strlen(s);
    for(int i=0; i<n; i++)
    {
        if(s[i] != s[n-1-i]) res++;
    }
    printf("%d\n", res/2);
}

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

int main(){
	int i, j, k ,n,m,l,f;
	int x, y;
	cin >> n >> k >> x >> y;

	cout << x*(min(n, k)) + y*(max(0,n-k)) << endl;
}

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

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b, c, d, e, f;
	cin>>a>>b>>c;
	d = abs(b-a) + abs(c-a);
	e = abs(a-b) + abs(c-b);
	f = abs(a-c) + abs(b-c);
	cout<<min(min(d, e), f);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second 
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
		ll n,m; cin>>n>>m;
		ll g=__gcd(n,m),b=(n*m);
		cout<<(b/g)<<endl;
	return 0;
}

Measured memory_bytes: 3652
fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).unwrap();
 
  let s = buf.trim();
  let mut stack = Vec::with_capacity(s.len());
 
  for c in s.chars() {
    match c {
      'B' => {stack.pop();},
      _ => {stack.push(c);},
    }
  }
 
  println!("{}", stack.iter().map(|&c| c).collect::<String>());
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

vector<vector<int>> to;
void bfs(int s, vvi &d) {
    d[s][0] = 0;
    queue<P> q;
    q.emplace(s, 0);
    while (!q.empty()) {
        int v = q.front().fi, t = q.front().se;
        q.pop();
        int nt = (t+1) % 3;
        for (auto u : to[v]) {
            if (d[u][nt] != -3) continue;
            d[u][nt] = d[v][t] + 1;
            q.emplace(u, nt);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;
    to.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].pb(b);
    }
    int sv, tv;
    cin >> sv >> tv;
    sv--; tv--;
    vvi d(n, vi(3, -3));
    bfs(sv, d);
    cout << d[tv][0] / 3 << endl;
}

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

int a[300000];
int main(){
	int n;cin>>n;
	set<P>se;
	rep(i,n){
		scanf("%d",&a[i]);
		se.insert(P(a[i],i));
	}
	rep(i,n){
		if(se.rbegin()->second==i){
			printf("%d\n",(++se.rbegin())->first);
		}
		else printf("%d\n",se.rbegin()->first);
	}
}

Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
int n,k;
int can[2002][2002];//用j个数字造i
int main() {
	scanf("%d%d",&n,&k);
	can[0][0]=1;
	for(int j=1; j<=n; j++) {
		int sum=0;
		for(int i=j-1; i<=n; i++) {
			can[i][j]=sum;
			sum+=can[i][j-1];
			if(sum>=P)sum-=P;
		}
	}
	for(int i=1; i<=k; i++) {
		long long ans=0;
		for(int j=i-1;j<=n-k;j++){
			ans=(ans+1ll*can[k][i]*can[j][i-1]%P*(n-k-j+1)%P)%P;
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	string S;
	cin >> S;
	map<char,int> m;
	FOR(i,0,S.size())m[S[i]]++;
	cout << S.size()-max(m['0'],m['1'])+min(m['0'],m['1']) << endl;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int[] nums = getIntArray(sc);

		int count = 0;
		boolean isOk = true;
		while (isOk) {
			for (int i = 0; i < n; i++) {
				if (nums[i] % 2 == 0) {
					nums[i] /= 2;
				} else {
					isOk = false;
					break;
				}

			}
			if (isOk) {
				count++;
			}
		}
		System.out.println(count);
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <iomanip>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")
#define fsp(c) fixed << setprecision(c)

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

double cutl(int i,double n,double r) {
  if (i<=0||n<=i) return 0;
  return r*sqrt(1-((double)i-n/2)*((double)i-n/2)*4/n/n);
}

int main(){
  int n,a[100],m=INTMAX,t;
  cin >> n;
  REP(i,n){
    cin >> a[i];
  }
  
  FOR(i,-100,101){
    t=0;
    REP(j,n){
      t+=(i-a[j])*(i-a[j]);
    }
    if (t<m) m=t;
  }
  cout << m;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define LONGMAX 1e18
#define MOD 1000000007
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define fr(a,n) for(int i=a;i<n;i++)
const ll INF=1e18 + 5;;

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

	int n,w;
	cin>>n>>w;		

	int wt[n],val[n];
	ll sum=0;

	for(int i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
		sum+=val[i];
	}
	//dp[i] is min weight of items with value i
	vector<ll> dp(sum + 1,INF);
	dp[0]=0;

	for(int i=0;i<n;i++)
	{
		for(int value=sum-val[i];value>=0;value--)
			dp[value + val[i]]=min(dp[value + val[i]],dp[value] +wt[i]);

	}
	ll ans=0;

	for(ll i=0;i<=sum;i++)
		if(dp[i]<=w)
			ans=max(ans,i);

	cout<<ans;
}


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

int sieveOfEratosthenes(int n) {
    vector<int> prime;
    vector<int> isPrime((unsigned long)n + 1, true);
    isPrime[0] = false, isPrime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            prime.push_back(i);
            for (int j = 2 * i; j <= n; j+= i)
                isPrime[j] = false;
        }
    }
    return (int)prime.size();
}

int main() {
    int n;
    while (cin >> n) {
        cout << sieveOfEratosthenes(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 7812
'use strict'
function main(input: string) {
    const n: number = Number(input.split('\n')[0]);
    const a: number[] = input.split('\n')[1].split(' ').map(Number);
    const r = a.reduce((acc, current) => {
        return acc += 1 / current;
    }, 0)
    console.log(1 / r);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  ll N;
  cin>>N;
  struct edge {ll to,cost;};
  vector<vector<edge>> G(N,vector<edge>());
  for(ll i(0);i<N-1;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  ll Q,K;
  cin>>Q>>K;
  K--;
  vector<ll> x(Q),y(Q);
  for(ll i(0);i<Q;i++){
    cin>>x[i]>>y[i];
    x[i]--;
    y[i]--;
  }

  vector<ll> d(N,INFll);
  d[K] = 0;

  // first: cont, second: node number 
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
  q.push({0,K});
  while(!q.empty()){
    pair<ll,ll> p = q.top();q.pop();
    ll v = p.second;
    if (d[v] < p.first) continue;
    for (ll i(0);i<ll(G[v].size());i++){
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        q.push({d[e.to],e.to});
      }
    }
  } 
  // for(ll i(0);i<N;i++){
  //   cout << d[i] << " ";
  // }
  // cout << endl;
  for(ll i(0);i<Q;i++){
    cout << d[x[i]] + d[y[i]] << endl;
  } 
  return 0;
}



Measured memory_bytes: 12656
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
    int n; cin >> n;
    int h[100100];
    int ans = 0, res = 0;
    rep(i, n) {
        cin >> h[i];
    }
    rep(i, n - 1) {
        if(h[i] >= h[i + 1]) {
            res ++;
        }
        if(h[i] < h[i + 1] || i == n - 2) {
            ans = max(ans, res);
            res = 0;
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 640
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            var s = int.Parse(line[2]);
            if (x == 0 && y == 0 && s == 0) break;
            var maxret = 0;
            for (int i = 1; i <= s - 1; i++)
            {
                var ret = calcAB(i, x, y, s);
                if (ret != -1) maxret = Math.Max(maxret, ret);
                else break;
            }
            Console.WriteLine(maxret);
        }
    }
    public static int calcAB(int a, int x, int y, int s)
    {
        var ret = 0;
        var w = new int[3];
        var az = a * (100 + x) / 100;
        var bz = s - az;
        if (bz <= 0) return -1;
        w[1] = bz * 100 / (100 + x);
        w[0] = w[1] - 1; w[2] = w[1] + 1; 
        var az2 = a * (100 + y) / 100;
        for (int i = 0; i < 3; i++)
        {
            var bzw = w[i] * (100 + x) / 100;
            if (az + bzw == s) ret = az2 + w[i] * (100 + y) / 100;
        }
        return ret;
    }
}


Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
       int k;cin>>k;
       string s;cin>>s;
       if(s.length()<=k) cout<<s<<endl;
       else{
           for(int i=0;i<k;i++) cout<<s[i];
          cout<<"...";
       }
}

Measured memory_bytes: 3564
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut ans = 0;
    let mut last_a = 0;
    let mut first_b = 0;
    let mut loop_flag = true;
    for _ in 0..N {
        let s: String = read();
        let first_str = &s[0..1];
        let last_str = &s[s.len() - 1..s.len()];

        if first_str == "B" {
            first_b += 1;
            if last_str != "A" {
                loop_flag = false;
            }
        }
        if last_str == "A" {
            last_a += 1;
            if first_str != "B" {
                loop_flag = false;
            }
        }

        for s2 in s.chars().collect::<Vec<char>>().windows(2) {
            if s2 == &(vec!['A', 'B'][..]) {
                ans += 1;
            }
        }
    }
    ans += std::cmp::min(last_a, first_b);
    if first_b == 0 && last_a == 0 {
        loop_flag = false;
    }
    ans += if loop_flag { -1 } else { 0 };
    println!("{}", ans)
}


Measured memory_bytes: 4352
import sys
N = int(input())
for i in range(int(N/4) + 1):
    amount = i * 4
    for j in range(int(N/7) + 1):
        if(j == 0):
            pass
        else:
            amount += 7
        if(amount == N):
            print('Yes')
            sys.exit()
print('No')


Measured memory_bytes: 2940
def count(S, m, n): 
    if n < 100:
        return 0

    table = [False for k in range(n+1)]   
    table[100:106] = [True] * 6

    for i in range(106, n+1):
        table[i] = any([table[i-j] for j in range(S[0], S[-1]+1)])
  
    return 1 if table[n] else 0
  
def main():
    X = int(input())
    S = [100, 101, 102, 103, 104, 105] 
    print(count(S, len(S), X))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3864
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final StringBuilder S1 = new StringBuilder(sc.next());
        final int N = S1.length();
        final StringBuilder S2 = new StringBuilder(S1.substring(0, (N-1) / 2));
        final StringBuilder S3 = new StringBuilder(S1.substring((N+3)/2 - 1, N));

        final boolean cond1 = S1.toString().equals(S1.reverse().toString());
        final boolean cond2 = S2.toString().equals(S2.reverse().toString());
        final boolean cond3 = S3.toString().equals(S3.reverse().toString());

        if (cond1 && cond2 && cond3) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (s == u) {
        cout << a - 1 << ' ' << b << '\n';
    } else {
        cout << a << ' ' << b - 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,M,x;
  cin>>N>>M;
  vector<int> a(N+1);
  for(int i=0;i<2*M;i++)
  {
    cin>>x;
    a.at(x)++;
  }
  for(int j=1;j<=N;j++)
  {
    cout<<a.at(j)<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100][1000005];
ll n;
ll knapsack(vector<ll> &v,vector<ll> &w,ll W,ll i){
    if(i>n-1){
        return 0;
    }
    if(W-w[i]<0){
        return knapsack(v,w,W,i+1);
    }
    //cout<<v[i]<<w[i];

    if(dp[i][W]!=-1){
        return dp[i][W];
    }

    ll op1=knapsack(v,w,W-w[i],i+1)+v[i];
    ll op2=knapsack(v,w,W,i+1);
    return dp[i][W]=max(op1,op2);
    

    

}
int main()
{
    ll N,W;
    cin>>N>>W;
    vector<ll> v;
    vector<ll> w;
    for(ll i=0;i<N;i++){
        ll a,b;
        cin>>a>>b;
        w.push_back(a);
        v.push_back(b);
    }
    n=N;
    memset(dp,-1,sizeof(dp));
    cout<<knapsack(v,w,W,0);
    
}


Measured memory_bytes: 784856
n=int(input())
a=list(map(int,input().split()))
if n%2==1:
    dp=[[0 for j in range(3)] for i in range(n//2)]
    dp[0][0]=a[0]
    dp[0][1]=a[1]
    dp[0][2]=a[2]
    for i in range(n//2-1):
        dp[i+1][0]=(dp[i][0]+a[2*(i+1)])
        dp[i+1][1]=max(dp[i][0],dp[i][1])+a[2*(i+1)+1]
        dp[i+1][2]=max(dp[i])+a[2*(i+1)+2]
    print(max(dp[-1]))
if n%2==0:
    dp=[[0 for j in range(2)] for i in range(n//2)]
    dp[0][0]=a[0]
    dp[0][1]=a[1]
    for i in range(n//2-1):
        dp[i+1][0]=(dp[i][0]+a[2*(i+1)])
        dp[i+1][1]=max(dp[i][0],dp[i][1])+a[2*(i+1)+1]
        #dp[i+1][2]=max(dp[i])+a[2*(i+2)+2]
    print(max(dp[-1]))   


Measured memory_bytes: 42724
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 2e5 + 42;
ll n, m;
struct ppolls {
  pair<ll, ll> mns;
  pair<ll, ll> mxs;
  pair<ll, ll> mnd;
  pair<ll, ll> mxd;
};
ppolls emp;
ppolls comb(ppolls a, ppolls b) {
  ppolls res;
  res.mns = (a.mns.fi + a.mns.se < b.mns.fi + b.mns.se ? a.mns : b.mns);
  res.mxs = (a.mxs.fi + a.mxs.se > b.mxs.fi + b.mxs.se ? a.mxs : b.mxs);
  res.mnd = (a.mnd.fi - a.mnd.se < b.mnd.fi - b.mnd.se ? a.mnd : b.mnd);
  res.mxd = (a.mxd.fi - a.mxd.se > b.mxd.fi - b.mxd.se ? a.mxd : b.mxd);
  return res;
}
ppolls st[4 * N];
vector<pair<ll, ll> > a;
void build(ll v, ll tl, ll tr) {
  if(tl == tr) {
    st[v].mns = a[tl];
    st[v].mxs = a[tl];
    st[v].mnd = a[tl];
    st[v].mxd = a[tl];
    return;
  }
  ll tm = ((tl + tr) >> 1);
  build((v << 1), tl, tm);
  build((v << 1) + 1,  tm + 1, tr);
  st[v] = comb(st[(v << 1)], st[(v << 1) + 1]);
}
ppolls get(ll v, ll tl, ll tr, ll l, ll r) {
  if(l > r) {
    ppolls emp;
    emp.mns = mp(1e9 + 42, 1e9 + 42);
    emp.mxs = mp(-1e9 + 42, -1e9 + 42);
    emp.mnd = mp(1e9 + 42, 0);
    emp.mxd = mp(0, 1e9 + 42);
    return emp;
  }
  if(l == tl && r == tr) return st[v];
  ll tm = ((tl + tr) >> 1);
  return comb(get((v << 1), tl, tm, l, min(r, tm)), get((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
}
void upd(ll v, ll tl, ll tr, ll pos, pair<ll, ll> new_v) {
  if(tl == tr) {
    st[v].mns = new_v;
    st[v].mxs = new_v;
    st[v].mnd = new_v;
    st[v].mxd = new_v;
    return;
  }
  ll tm = ((tl + tr) >> 1);
  if(pos <= tm) upd((v << 1), tl, tm, pos, new_v);
  else upd((v << 1) + 1, tm + 1, tr, pos, new_v);
  st[v] = comb(st[(v << 1)], st[(v << 1) + 1]);
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  cin >> n;

  //yay

  a.resize(n);

  for(ll i = 0; i < n; i++) cin >> a[i].fi >> a[i].se;

  build(1, 0, n - 1);

  auto ans = st[1];

  cout << max(ans.mxs.fi + ans.mxs.se - (ans.mns.fi + ans.mns.se), ans.mxd.fi - ans.mxd.se - (ans.mnd.fi - ans.mnd.se)) << endl;

  return 0;
}
/*

*/


Measured memory_bytes: 39152
def f(mn, n, sm):
    if n == 0 and sm == 0:
        return 1
    if mn == 10 or n == 0:
        return 0
    ct = 0
    for i in range(mn, min(10, sm + 1)):
        ct += f(i + 1, n - 1, sm - i)
    return ct

while True:
    n, sm = map(int, raw_input().split())
    if n == 0 and sm == 0:
        break
    print f(0, n, sm)

Measured memory_bytes: 4212
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 1..(n + 1) {
        if dp1[0][i] < INF {
            println!("{}", i - 1);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, flag: bool) -> Vec<i64> {
    assert_eq!(child1.len(), child2.len());
    let child_cuts = child1.len() - 1;
    let mut ans = vec![INF; dp.len() + child_cuts];
    for i in 0..dp.len() {
        if dp[i] == INF { continue; }
        for j in 0..child1.len() {
            if i + j >= 1 {
                if child1[j] != INF {
                    ans[i + j - 1] = cmp::min(ans[i + j - 1], dp[i] + child1[j]);
                }
                if child2[j] != INF && !flag {
                    ans[i + j - 1] = cmp::min(ans[i + j - 1], dp[i] + child2[j]);
                }
            }
            if child1[j] != INF || child2[j] < 0 {
                ans[i + j] = cmp::min(ans[i + j], dp[i]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 211836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll s[100050];
ll ans = 0;
ll used[100050];
void f(ll delta) {
    ll score = 0;
    for(ll i = 1; ; i++) {
        ll now = N - 1 - i * delta;
        if(now < delta) break;
        if(used[now] == delta) break;
        score += s[now];
        used[now] = delta;
        now = i * delta;
        if(used[now] == delta) break;
        score += s[now];
        used[now] = delta;
        chmax(ans, score);
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> s[i];
    for(ll delta = 1; delta <= N - 1; delta++) {
        f(delta);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer y;
  y = nil->next;

  while(y->key != key){
    if(y == nil) break;
    y = y->next;
  }

  return y;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  t->prev->next = t->next;
  t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer x = nil->prev;
  if(x == nil) return;
  deleteNode(x);

}

void delete(int key){
  /* your code */
  NodePointer x;
  x = listSearch(key);
  if(x == nil) return;
  deleteNode(x);

}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* your code                                                                  
  */
  x->next = nil->next;
  x->prev = nil;
  nil->next = x;
  x->next->prev = x;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
        else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0, sum2 = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }

    ll ans = sum;
    rep(i, n){
        sum2 += a[i];
        ans = min(ans, abs(sum2 - (sum - sum2)));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>


int main()
{
    int w,a,b;
    scanf("%d%d%d",&w,&a,&b);
    if(b>a+w)
    {
        printf("%d\n",b-(a+w));
    }
    else if(b+w<a)
    {
        printf("%d\n",a-(b+w));

    }
    else
        printf("0\n");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j;
  cin>>n;
  int height[n];
  for(i=0;i<n;i++)
    cin>>height[i];
  vector<int> dp(n,INT_MAX);
 // memset(dp,INT_MAX,sizeof(dp));
  dp[0]=0;
  for(i=0;i<n;i++)
  {
      for(j=i+1;j<=i+2;j++)
      if(j<n)
       dp[j]=min(dp[j],dp[i]+abs(height[j]-height[i]));
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;scanf("%d%d",&n,&m);
    vector<int> dp((1<<n),1e9);
    dp[0]=0;
    for(int i=0;i<m;i++){
        int a,b;scanf("%d%d",&a,&b);
        int key=0;
        for(int j=0;j<b;j++){
            int p;scanf("%d",&p);p--;
            key+=(1<<p);
        }
        for(int j=0;j<(1<<n);j++){
            dp[j|key]=min(dp[j|key],dp[j]+a);
        }
    }
    if(dp[(1<<n)-1]==1e9)puts("-1");
    else printf("%d\n",dp[(1<<n)-1]);
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,x,t = get_all_int()

    print((n+x-1)//x * t)

main()

Measured memory_bytes: 67508
n=input()
arares=input().split()
d = {'P': 0,
    'Y': 0,
    'W': 0,
    'G': 0}

for arare in arares:
  if arare in d:
    if d[arare]==0:
      d[arare]=1

colors = sum(d.values())
if colors == 3:
  print("Three")
elif colors == 4:
  print("Four")

Measured memory_bytes: 9128
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]

g = csr_matrix(c)
dist = floyd_warshall(g)

ans = 0
for row in a:
    for e in row:
        if e == -1:
            continue

        else:
            ans += dist[e][1]

ans = int(ans)
print(ans)


Measured memory_bytes: 17424
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main() {
    double x1, x2, y1, y2, d;
    cin >> x1 >> x2 >> y1 >> y2;

    d = pow((y1 - x1) * (y1 - x1) + (y2 - x2) * (y2 - x2), 0.5);
    cout << fixed << setprecision(10) << d << endl;
    return 0;
}


Measured memory_bytes: 3408
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pr;

ll binpow(ll x, ll p)
{
	if (p == 0)
		return 1;
	if (p % 2)
		return (binpow(x, p - 1) * x) % MOD;
	else
	{
		ll xx = binpow(x, p / 2);
		return (xx * xx) % MOD;
	}
}

inline void solve()
{
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	/*int q = 1;
	//cin >> q;
	while (q--)
	{*/
		solve();
		//cout << '\n';
	//}
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);

    int arr[100];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
        int ans=0;
    for(int i=0;i<n;i++){
        int cnt=0;
        for(int j=0;j<i;j++){
            if(arr[j]<=arr[i])
                cnt++;
        }
        if(cnt==i)
            ans++;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3600
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
		int n = scan.nextInt();

		for(int i = 0 ; i < n ; i++) {
			for(int j = 0 ; j < 10 ; j++) {
				int ballNum = scan.nextInt();
				if(0 < ballNum && ballNum < 11) {
					queue.add(ballNum);
				}
			}

			int bNum = 0,cNum = 0;

			while(queue.peekFirst() != null) {
				int ball = queue.poll();
				if(ball > bNum) {
					bNum = ball;
				}else if(ball > cNum) {
					cNum = ball;
				}else {
					System.out.println("NO");
					break;
				}
			}
			if(queue.isEmpty()) {
				System.out.println("YES");
			}
		}

	}

}


Measured memory_bytes: 26336
import java.util.*;

class Main{
	static int[] nums;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		nums = new int[num];
		for(int i = 0; i < num; i++)nums[i] = sc.nextInt();

		int ans = divZero(0, num-1);
		System.out.println(ans);
	}

	static public int divZero(int start, int end){
		if(start == end)return nums[end];
		if(start > end)return 0;

		for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		}

		int min = 101;
		for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i];
		for(int i = start; i <= end; i++)nums[i] -= min;
		return min + divZero(start, end);
	}
}

Measured memory_bytes: 21972
#include<stdio.h>

int main(void)
{
	int n,i;
	int ans=0;
	scanf("%d",&n);
	char s[(n+1)];
	scanf("%s",s);
	for(i=0;s[i];i++)
	{
		if(s[i]=='A')
		{
			if(s[i+1]=='B')
			{
				if(s[i+2]=='C')
				{
					ans++;
				}
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int N,M;
  int A[1000];
  int sum=0, count=0;
  
  scanf("%d %d", &N, &M);

  for(int i=0;i<N;i++)
    scanf("%d", &A[i]);
  for(int i=0;i<N;i++)
    sum += A[i];
  for(int i=0;i<N;i++)
    if( A[i]*4*M >= sum)
      count++;

  if(count>=M)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a==0 || b==0 || (a<0 && b>0)){
    cout << "Zero" << endl;
  }else if(a<0 && abs(a+b)%2==0){
    cout << "Negative" << endl;
  }else{
    cout << "Positive" << endl;
  }
  return 0;
}


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

typedef pair<int, int> P;
int w,h;

void dfs(int x, int y, vector<vector<bool>> &maze){
    queue<P> q;
    q.push({x, y});
    maze[x][y] = false;
    while(q.size() > 0){
        int nx = q.front().first;
        int ny = q.front().second;
        q.pop();
        for (int i = -1; i <= 1; i++){
            for (int j = -1; j <= 1; j++){
                if (0 <= nx+i && nx+i < h && 0 <= ny+j && ny+j < w && maze[nx+i][ny+j]){
                    maze[nx+i][ny+j] = false;
                    q.push({nx+i, ny+j});
                }
            }
        }
    }
}

int main(){
    int x;
    int ans;
    while(1){
        cin >> w >> h;
        if (w == 0 || h == 0) break;
        vector<vector<bool>> maze(h, vector<bool>(w));
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                cin >> x;
                maze[i][j] = x;
            }
        }
        
        ans = 0;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                if (maze[i][j]){
                    dfs(i, j, maze);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3012
#include<stdio.h>

int main(){
  int a,b,i,ans[7];
  
  for(i=0;i<7;i++){
    scanf("%d %d",&a,&b);
    ans[i] = a-b;
  }

  for(i=0;i<7;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}



Measured memory_bytes: 2708
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())

c = ["!", "3", "5", "7"]
def shichigosan_numbers():
    x = 0
    while True:
        x += 1
        s = ""
        y = x
        while y > 0:
            s = c[y%4] + s
            y = y // 4
        if "!" not in s and "3" in s and "5" in s and "7" in s: 
            yield int(s)

ans = 0
for x in shichigosan_numbers():
    if x <= n:
        ans += 1
    else: 
        print(ans)
        exit()

Measured memory_bytes: 42348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define sc(val) scanf("%d",&val)
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int main(){
  int n;
  cin >> n;
  vector<vector<int>> arr(n,vector<int>(3,0));
  vector<vector<int>> dp(n+1,vector<int>(3,0));
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin >> arr[i][j];
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j!=k){
          dp[i][j] = max(dp[i][j],dp[i-1][k]+arr[i-1][k]);
        }
      }
    }
  }
  cout << max(dp[n][0],max(dp[n][1],dp[n][2]));
  return 0;
}





Measured memory_bytes: 14060
import math


class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def roll_east(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def roll_north(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def roll_south(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def roll_west(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def spin_left(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp

    def check(self, dice2):
        ans = False
        for x in range(4):
            if dice2.south == self.south:
                if dice2.east == self.east and dice2.west == self.west and \
                        dice2.north == self.north and dice2.bottom == self.bottom:
                    ans = True
            self.spin_left()
        return ans

    def top_check(self, dice2):
        ans = False
        if dice2.top == self.top:
            ans |= self.check(dice2)
        if dice2.top == self.south:
            self.roll_north()
            ans |= self.check(dice2)
        if dice2.top == self.east:
            self.roll_west()
            ans |= self.check(dice2)
        if dice2.top == self.west:
            self.roll_east()
            ans |= self.check(dice2)
        if dice2.top == self.north:
            self.roll_south()
            ans |= self.check(dice2)
        if dice2.top == self.bottom:
            self.roll_south()
            self.roll_south()
            ans |= self.check(dice2)
        return ans


num = int(input())
dices = []
ans = True
for x in range(num):
    a, b, c, d, e, f = map(int, input().split())
    dices.append(Dice(a, b, c, d, e, f))
for x in range(num):
    for y in range(x + 1, num):
        if dices[x].top_check(dices[y]):
            ans = False
if ans:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5676
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
void insertionSort(int A[],int n,int g){
 for(int i=g;i<n;i++){
  int v=A[i];
  int j=i-g;
  while(j>=0&&A[j]>v){
   A[j+g]=A[j];
   j-=g;
   cnt++;
  }
  A[j+g]=v;
 }
}
void shellSort(int A[],int n){
 for(int h=1;;){
  if(h>n)break;
  G.push_back(h);
  h=3*h+1;
 }
 for(int i=G.size()-1;i>=0;i--){
  insertionSort(A,n,G[i]);
 }
}
int main(){
 cin>>n;
 for(int i=0;i<n;i++)scanf("%d",&A[i]);
 cnt=0;
 shellSort(A,n);
 cout<<G.size()<<endl;
 for(int i=G.size()-1;i>=0;i--){
  printf("%d",G[i]);
  if(i)printf(" ");
 }
 printf("\n");
 printf("%d\n",cnt);
 for(int i=0;i<n;i++)printf("%d\n",A[i]);
 return 0;
}


Measured memory_bytes: 7144
n = int(input())
array = [int(input()) for x in range(n)]
sorted_array = sorted(array)
max_array1 = sorted_array[-1]
max_array2 = sorted_array[-2]

for i in array:
    if i == max_array1:
        print(max_array2)
    else:
        print(max_array1)


Measured memory_bytes: 14108
#include <stdio.h>
int main() {
	char S[17];
	char title[17] = "CODEFESTIVAL2016";
	int i, count;
	count = 0;
	scanf("%s", S);
	for (i = 0; i < 17; i++) {
		if(S[i] != title[i]) { count++; }
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = Array(N) {readLine()!!.toInt()}
    val (max0,max1) = A.sortedDescending().take(2)
    val list = mutableListOf<Int>()
    for (a in A)
        list.add(if(max0 != a) max0 else max1)
    println(list.joinToString("\n"))
}

Measured memory_bytes: 64924