akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    sort(h.begin(), h.end(), greater<int>());

    ll ans = 0;
    for(int i = k; i < n; i++){
        ans += h[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
N,K = map(int, input().split())

dic = {}

for i in range(N):
    dic[i] = 0

for _ in range(K):
    d  = int(input())
    A  = map(int, input().split())
    for a in A:
        a = a - 1
        if dic[a]!=0:
            dic[a] += 1
            continue
        dic[a] = 1


ans = 0
for key in dic:
    if dic[key]==0:
        ans = ans + 1

print(ans)

Measured memory_bytes: 9200
import Data.List (intersect, nub)

main = do
  n <- readLn
  s <- getLine
  print $ maximum $ map (solve s) [1..n-1]
  where
    solve :: String -> Int -> Int
    solve s i =
      let (xs, ys) = splitAt i s
      in
        length $ nub $ intersect xs ys

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <sstream>
#include <string>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=100001;
bool vis[N];
vector <int> adj[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll binaryNum[32];
void decToBinary(ll n) 
{ 
    binaryNum[32]={0};
    int i = 0; 
    while (n > 0) { 
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
} 

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


}


int main()
{
    // cout<<1<<endl;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 6148
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int A, B, C;
/**********************************/

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

    cin>>A>>B>>C;
    int ans = 0;
    int a = A%2;
    int b = B%2;
    int c = C%2;
    if(a==b&&b!=c) {
        A++; B++;
        ans++;
    }
    else if(b==c&&a!=c) {
        B++; C++;
        ans++;
    }
    else if(c==a&&b!=c) {
        C++; A++;
        ans++;
    }
    int top = max(A, max(B, C));
    ans += (3*top-A-B-C)/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll ans1, ans2;
string sa;

inline void work(){
	getline(cin, sa);
	if (sa == "" || sa == " ") puts("");
	REP(i, 0, sa.size() - 1){
		ll x = sa[i] - '0';
		if (x != i % 2) ans1++;
		else ans2++;
	}
	printf("%lld\n", min(ans1, ans2));
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <queue>


int main()
{
	int N, K;
	std::cin >> N >> K;
	typedef std::pair<int,int> RANGE;
	std::vector<RANGE> LR(K);
	for (int i = 0; i < K; ++i) {
		std::cin >> LR[i].first >> LR[i].second;
	}

	std::vector<int64_t> memo(N+1);
	std::vector<int64_t> sum(N + 1);
	memo[N] = 1;
	sum[N] = 1;
	for (int pos = N - 1; pos >= 1; --pos) {
		int64_t count = 0;
		for (auto itr = LR.begin(); itr != LR.end(); ++itr) {
			const int begin_pos = pos + itr->first;
			if (begin_pos > N) {
				continue;
			}
			const int end_pos = pos + itr->second + 1;
			const int64_t begin_value = sum[begin_pos];
			const int64_t end_value = (end_pos > N) ? 0 : sum[end_pos];
			count += begin_value - end_value;
		}
		memo[pos] = count % 998244353;
		sum[pos] = sum[pos + 1] + memo[pos];
	}
	std::cout << memo[1] << std::endl;
	return 0;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef pair<int,int> P;
const int INF = 1e9+7;

int main(){
    int N,K,S;
    cin >> N >> K >> S;
    if(S==1e9){
        rep(i,N){
            if(i<K){
                cout << S << " ";
            }else{
                cout << 1 << " ";
            }
        }
    }else{
        rep(i,N){
            if(i<K){
                cout << S << " ";
            }else{
                cout << S+1 << " ";
            }
        }
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string n;
    cin>>n;
    int size=n.size();
    if (n.at(size-1)=='2'||n.at(size-1)=='4'||n.at(size-1)=='5'||n.at(size-1)=='7'||n.at(size-1)=='9') {
        cout<<"hon"<<endl;
    } else if (n.at(size-1)=='0'||n.at(size-1)=='1'||n.at(size-1)=='6'||n.at(size-1)=='8') {
        cout<<"pon"<<endl;
    } else if (n.at(size-1)=='3') {
        cout<<"bon"<<endl;
    }
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%MOD;
    n = n*n%MOD;
    r >>= 1;
  }
  return res;
}

int main(){
  

  ll n,K;
  cin >> n >> K;
  vector<pair<ll,ll>> v;
  ll gg = 0,pogi = 0;
  ll zero = 0;
  rep(i,n){
    ll x;cin >> x;
    if(x > 0)v.push_back(make_pair(x,1)),pogi++;
    else if(x < 0)v.push_back(make_pair(-x,-1)),gg++;
    else if(x == 0)zero++;
  }
  sort(ALL(v),greater<pair<ll,ll>>());
  ll res1 = 1;
  bool sei = true;
  if(pogi+gg < K){
    cout << 0 << endl;
    return 0;
  }
  ll cnt = 0;
  ll ln = -1,pn = -1;
  rep(i,K){
    res1 = res1*v[i].first%MOD;
    if(v[i].second < 0)cnt++,ln = v[i].first;
    else pn = v[i].first;
  }
  if(cnt & 1){
    ll t = -1,tt = -1;
    ll res2 = res1*modpow(ln,MOD-2)%MOD;
    sei = false;
    for(ll i = K;i < v.size();i++){
      if(v[i].second > 0){
        res2 = res2*v[i].first%MOD;
        t = v[i].first;
        sei = true;
        break;
      }
    }
    if(!sei)res2 = -1;
    bool sei3 = true;
    ll res3 = res1*modpow(pn,MOD-2)%MOD;
    sei3 = false;
    for(ll i = K;i < v.size();i++){
      if(v[i].second < 0){
        res3 = res3*v[i].first%MOD;
        sei3 = true;
        tt = v[i].first;
        break;
      }
    }
    if(pn < 0)sei3 = false;
    if(!sei3)res3 = -1;
    if(sei && sei3){
      if(tt*ln < t*pn)res1 = res2;
      else res1 = res3;
    }else if(sei && !sei3){
      res1 = res2;
    }else{
      res1 = res3;
    }
    sei = (sei || sei3);
  }
  res1 = (res1+MOD)%MOD;
  if(sei){
    cout << res1 << endl;
    return 0;
  }
  ll res = 1;
  sort(ALL(v));
  int jjj = 0;
  rep(i,K){
    if(v[i].second > 0)res = res*v[i].first%MOD;
    else{
      res *= -v[i].first;
      res = (res+MOD)%MOD;
      jjj++;
    }
  }
  res = (res+MOD)%MOD;
  if((jjj & 1) && zero > 0){
    cout << 0 <<  endl;
    return 0;
  }
  cout << res << endl;
  


  return 0;
}

Measured memory_bytes: 7428
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public struct Pair { public int x, y; public Pair(int a, int b) { x = a; y = b; } }
    public static void Solve()
    {
        int N = NextInt();
        int[] L = LineInt().OrderBy(v => v).ToArray();
        NX ans = 0;
        for (int x = 0; x < N; x++)
            for (int y = x + 1; y < N; y++)
            {
                int a = L[x], b = L[y];
                int ok = -1, ng = N;
                while (ng - ok != 1)
                {
                    int mid = (ok + ng) / 2;
                    if (L[mid] < (a + b))
                    {
                        ok = mid;
                    }
                    else
                    {
                        ng = mid;
                    }
                }
                int up = ok;
                int z = Math.Max(a - b, b - a);
                ok = N; ng = -1;
                while (ok - ng != 1)
                {
                    int mid = (ok + ng) / 2;
                    if (z < L[mid])
                    {
                        ok = mid;
                    }
                    else
                    {
                        ng = mid;
                    }
                }
                int low = ok;
                int box = up - low + 1;
                if (low <= x && x <= up) { box--; }
                if (low <= y && y <= up) { box--; }
                ans += Math.Max(0, box);
            }
        Console.WriteLine(ans / 3);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 13536
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>
#include <atcoder/all>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
using mint = atcoder::modint998244353;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

struct S {
    mint a, pow10;
    int size;
};

struct F {
    mint a;
    int timing;
};

vector<vector<mint>> num(10, vector<mint>(300001, 0));

S op(S s1, S s2) {
    if (s2.a == 0) return S{s1.a, s1.pow10, s1.size + s2.size};
    return S{s1.a * s2.pow10 + s2.a, s1.pow10 * s2.pow10, s1.size + s2.size};
}

S e() { return S{0, 10, 1}; }

S mapping(F f, S s) {
    if (f.a == 0) return s;
    return S{num[int(f.a.val())][s.size], s.pow10, s.size};
}

F composition(F f1, F f2) {
    return (f1.timing > f2.timing) ? f1 : f2;
}

F id() { return F{0, -1}; }

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, q, l, r, d;
    cin >> n >> q;

    for(int i=1;i<=9;++i) {
        num[i][1] = i;
        for(int j=2;j<=300000;++j) {
            num[i][j] = num[i][j-1] * mint(10) + i;
        }
    }

    vector<S> v(n);
    for(int i=0;i<n;++i) v[i] = S{1, 10, 1};

    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
    for(int i=0;i<q;++i) {
        cin >> l >> r >> d;
        seg.apply(l-1, r, F{ mint(d), i });
        cout << seg.all_prod().a.val() << endl;
    }
}


Measured memory_bytes: 25644
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int x, y;
    cin >> x >> y;

    if(x < y){
        int tmp = x;
        x = y;
        y = tmp;
    }
    
    int d, r;
    while(1){
        d = x / y;
        r = x % y;
        if(r){
            x = y;
            y = r;
        }
        else break;
    }
    cout << y << endl;


    return 0;
}


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

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")

using namespace std;

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

    int a, b; cin >> a >> b;
    if((a * 500) >= b)
        Yes();
    else No();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int n = 0;

		for (int i = 0; i < 2; i++) {
			if (a >= b) {
				n += a;
				a--;
			} else {
				n += b;
				b--;
			}
		}
		System.out.print(n);
	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
S = [list(input())[: -1] for _ in range(H)]

imoslr = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
  c = 0
  prev = 0
  for j in range(W):
    if S[i][j] == "#":
      imoslr[i][j] -= c
      imoslr[i][prev] += c
      prev = j + 1
      c = 0
    else: c += 1
  imoslr[i][prev] += c
  for j in range(W): imoslr[i][j + 1] += imoslr[i][j]

imosud = [[0] * (W) for _ in range(H + 1)]
for i in range(W):
  c = 0
  prev = 0
  for j in range(H):
    if S[j][i] == "#":
      imosud[j][i] -= c
      imosud[prev][i] += c
      prev = j + 1
      c = 0
    else: c += 1
  imosud[prev][i] += c
  for j in range(H): imosud[j + 1][i] += imosud[j][i]

res = 0
for i in range(H):
  for j in range(W): res = max(res, imoslr[i][j] + imosud[i][j] - 1)
print(res)

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

int main()
{
    string in;
    cin >> in;
    int n = (int) in.length();
    int best = n;
    set<char> chars(in.begin(), in.end());
    for (char ch : chars) {
        string s = in;
        while (true) {
            if (s == string(s.length(), ch)) {
                best = min(best, n - (int) s.length());
                break;
            }
            string t;
            for (int i = 0; i + 1 < s.length(); ++i) {
                if (s[i] == ch || s[i + 1] == ch) {
                    t.push_back(ch);
                } else {
                    t.push_back(s[i]);
                }
            }
            s = t;
        }
    }
    cout << best << endl;
}


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

const pair<int, int> vod = {1000000007, 1000000009};

void gns(int &a, int mod) {
	if(a > mod) a -= mod;
	if(a < 0) a += mod;
}

struct vint {
	pair<int, int> vum;

	void add(vint v) {
		vum.first += v.vum.first;
		vum.second += v.vum.second;
		gns(vum.first, vod.first);
		gns(vum.second, vod.second);
	}

	void sub(vint v) {
		vum.first -= v.vum.first;
		vum.second -= v.vum.second;
		gns(vum.first, vod.first);
		gns(vum.second, vod.second);
	}

	bool is0() {
		return (vum.first == 0 && vum.second == 0);
	}
};

const int N = 5003, K = 5003;
int n, k, a[N];
vint dp[K];

bool aa0(int a) {
	for(int i = a; i < k; ++i) {
		if(!dp[i].is0())
			return 0;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	dp[0].vum.first = dp[0].vum.second = 1;
	for(int i = 1; i <= n; ++i) {
		for(int j = k - 1; j >= a[i]; --j) {
			dp[j].add(dp[j - a[i]]);
		}
	}
	int fp = 0;
	for(int i = 1; i <= n; ++i) {
		if(a[i] >= k) continue;
		for(int j = a[i]; j < k; ++j) {
			dp[j].sub(dp[j - a[i]]);
		}
		fp += aa0(k - a[i]);
		for(int j = k - 1; j >= a[i]; --j) {
			dp[j].add(dp[j - a[i]]);
		}
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "Draw";
    } else if (a == 1) {
        cout << "Alice";
    } else if (b == 1) {
        cout << "Bob";
    } else if (a > b) {
        cout << "Alice";
    } else if (a < b) {
        cout << "Bob";
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  int h1 = in();
  int m1 = in();
  int v1 = h1 * 60 + m1;
  int h2 = in();
  int m2 = in();
  int v2 = h2 * 60 + m2;
  int k = in();

  printf("%d\n", v2 - v1 - k);

  return 0;
}


Measured memory_bytes: 3828
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], Q = I[1];
		var S = Str.Select(c => c == 'A' ? 0 : c == 'C' ? 1 : 2).ToArray();
		for (var i = 0; i < N; i++)
		{
			if (S[i] == 0 && (i == N - 1 || S[i + 1] != 1)) S[i] = 2;
			if (S[i] == 1 && (i == 0 || S[i - 1] != 0)) S[i] = 2;
		}
		var cnt = new int[N + 1, 2];
		for (var i = 0; i < N; i++) for (var j = 0; j < 2; j++) cnt[i + 1, j] = cnt[i, j] + (S[i] == j ? 1 : 0);
		while (Q-- > 0)
		{
			I = G;
			int l = I[0] - 1, r = I[1];
			var ans = cnt[r, 1] + cnt[r, 0] - cnt[l, 0] - cnt[l, 1];
			if (S[l] == 1 && S[r - 1] == 0) ans -= 2;
			WriteLine(ans / 2);
		}
	}
}


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


using namespace std;

struct Node{
  Node *right;
  Node *left;
  Node *parent;
  int key;
};

Node *root ,*NIL;

Node* find(Node *u ,int key){
  while(u!=NIL && key!=u->key){
    if(key < u->key){
      u=u->left;
    }else
      u=u->right;
  }
  return u;
}

Node* treeMinimum(Node *x){
  while(x->left!=NIL)x=x->left;
  return x;

}

Node* treeSuccessor(Node *x){
  if(x->right!=NIL)
    return treeMinimum(x->right);
  Node *y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node *z){
  Node *y; // node to be deleted
  Node *x; // child of y

  if(z->left==NIL || z->right==NIL){
    y=z;
  }else{
    y=treeSuccessor(z);
  }

  if(y->left != NIL){
    x=y->left;
  }else{
    x=y->right;
  }

  if(x!=NIL){
    x->parent=y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }

  if(y!=z){
    z->key=y->key;
  }

  free(y);

}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z = (Node *) malloc(sizeof(Node));

  z->key = k;
  z->left = NIL;
  z->right = NIL;


  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }


}

void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  string com;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    cin>>com;
    if ( com=="insert" ){
      cin>>x;
      insert(x);
    } else if ( com == "print" ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(com=="find"){
      cin>>x;
      Node *a=find(root ,x);
      if(a!=NIL)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }else if(com=="delete"){
      cin>>x;
      treeDelete(find(root,x));
    }
  }

  return 0;
}



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

int main(void){
    int n;
    cin >> n;
    double ans=0;
    for(int i=0; i < n; i++){
        double x;
        string s;
        cin >> x >> s;
        if(s == "JPY"){
            ans += x;
        }else{
            ans += x*380000;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	double D,a,b;
	scanf("%lf",&D);
	a=D*sqrt(2.0);
	b=(int)D+1;
	printf("%.12f\n",D<sqrt((int)D*(int)D+1.0)&&a<b?b:a);
	return 0;
}

Measured memory_bytes: 652
n,m = map(int,input().split())
mod = 1000000007
x = list(map(int,input().split()))
y = list(map(int,input().split()))
xa = 0
ya = 0
for i in range(m):
  ya += (i)*y[i] -(m-i-1) *y[i]
for i in range(n):
  xa += (i)*x[i] -(n-i-1) *x[i]
print(ya*xa%mod)

Measured memory_bytes: 18556
import java.util.Scanner;
     
    public class Main {
     
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            long a[] = new long[N];
            long all = 0;
            long x = 0;
            long ans;
            ans = Long.MAX_VALUE;
            for (int i = 0; N > i; i++) {
                a[i] = sc.nextInt();
                all += a[i];
            }
            for (int j = 0; N > j; j++) {
                x += a[j];
                if (j + 1 < N) {
                    long z=Math.abs(all - 2 * x);
                    ans = Math.min(ans, z);
                }
            }
            System.out.println(ans);
        }
    }

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll r, d, x;
  cin >> r >> d >> x;

  for (ll i = 0; i < 10; ++i) {
    x = r * x - d;
    cout << x << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [0]*n

for i in range(m):
    a, b = map(int, input().split())
    l[a-1] = max(l[a-1], h[b-1])
    l[b-1] = max(l[b-1], h[a-1])

count = 0
for i in range(n):
    if h[i] > l[i]:
        count += 1

print(count)


Measured memory_bytes: 20108
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int n,a[20],b[20],dp[1<<18][51],cnt[1<<18],ans=INF;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(int i=1;i<1<<n;i++)
		cnt[i]=cnt[i>>1]+(i&1);
	memset(dp,0x3f,sizeof(dp));
	dp[0][1]=0;
	for(int i=0;i<(1<<n)-1;i++)
	{
		for(int j=1;j<=50;j++)
		{
			if(dp[i][j]!=INF)
			{
				for(int k=0,w,c=cnt[i];k<n;k++)
				{
					w=(k&1)==(cnt[i]&1)?a[k]:b[k];
					if(i>>k&1)
						c--;
					if(!(i>>k&1)&&w>=j)
						dp[i|(1<<k)][w]=min(dp[i|(1<<k)][w],dp[i][j]+c);
				}
			}
		}
	}
	for(int i=1;i<=50;i++)
		ans=min(ans,dp[(1<<n)-1][i]);
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}


Measured memory_bytes: 53504
import java.io.*;
import java.util.*;

public class Main{
	static void main() throws Exception{
		long a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),k=sc.nextInt();
		long ans=0;
		long add=Math.min(k, a);
		ans+=add;
		k-=add;
		
		add=Math.min(b, k);
		k-=add;
		
		add=Math.min(c, k);
		ans-=add;
		
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
		while(tc-->0) main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 32888
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
	long long a,b,k;
	cin>>a>>b>>k;
	if(k<=a){
		a-=k;
		k=0;
	}
	else{
		k-=a;
		a=0;
	}

	if(k<=b){
		b-=k;
		k=0;
	}
	else{
		k-=b;
		b=0;
	}

	cout<<a<<" "<<b<<"\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
import * as fs from "fs"

function Main(input: string) {

  const r = parseInt(input.split("\n")[0], 10)

  if(r >= 1200){
    console.log("ARC")
  }
  else{
    console.log("ABC")
  }

}


fs.readFile('/dev/stdin', (err, data) => {
  if (err) {
    Main(fs.readFileSync('./input.txt', 'utf8'))
    return null
  }
  Main(data.toString())
  return null
})

Measured memory_bytes: 11468
#include <iostream>
#include <string>
#include <cstdint>

class OneCard {
public:
	OneCard() : OneCard{0} {}
	OneCard(std::uint32_t id) { set(id); }

	bool operator<(const OneCard& rhs) const {
		return m_idx < rhs.idx();
	}

	std::uint32_t idx() const { return m_idx; }
	void set(std::uint32_t id) {
		m_idx = id;
		if (m_idx == 1) { m_idx = 14; }
	}

private:
	std::uint32_t m_idx;
};

inline std::istream& operator>>(std::istream& is, OneCard& card) {
	std::uint32_t i;
	is >> i;
	card.set(i);
	return is;
}

int main()
{
	OneCard card_alice, card_bob;

	std::cin >> card_alice >> card_bob;

	if (card_bob < card_alice) {
		std::cout << "Alice" << std::endl;
	} else if (card_alice < card_bob) {
		std::cout << "Bob" << std::endl;
	} else {
		std::cout << "Draw" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;
#define MAX 100000

int n, A[MAX + 1], L[MAX];

int lis() {
    L[0] = A[0];  // 長さが1であるようなisの最後の要素の最小値
    int length = 1;  // i番目の要素までを使ったlisの長さ

    for (int i = 0; i < n; i++) {
        if (L[length - 1] < A[i]) { // length-1までの要素を使ったlisの長さがi番目の要素より短いとき
            L[length++] = A[i]; // lenghtまでの要素を使ったlisの長さをA[i]に更新，そしてlengthがインクリメント
        } else {
            *lower_bound(L, L + length, A[i]) = A[i];  // L配列の中でlength番目までの要素でA[i]よりも大きくなる最初のものにA[i]を代入する
        }
    }
    return length;
}

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

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    cout << lis() << endl;

    return 0;
}


Measured memory_bytes: 3936
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

n = k()
v = l()
v.sort()

while len(v) != 1:
    x = (v[0]+v[1])/2
    v.append(x)
    del v[0]
    del v[0]
    v.sort()

print(v[0])


Measured memory_bytes: 10076
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m,k = map(int, input().split())
    
    def find(par, x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par, par[x])
            return par[x]
    
    def unite(par, x,y):
        x = find(par,x)
        y = find(par,y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True
    
    def same(par, x,y):
        return find(par, x) == find(par, y)
    
    def size(par, x):
        return -par[find(par, x)]

    def members(par, x, n):
        root = find(par, x)
        return [i for i in range(n) if find(par, i) == root]
    
    friend = [-1]*n
    adj = [[] for _ in range(n)]
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
        unite(friend, a-1, b-1)

    block = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(k):
        a,b = map(int, input().split())
        block[a-1].append(b-1)
        block[b-1].append(a-1)

    res = []
    for i in range(n):
        p = size(friend, i) - 1 -len(adj[i])
        for q in block[i]:
            if same(friend, i, q):
                p -= 1
        res.append(p)
    print(*res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 122528
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dp[3300][3300];
void chmax(int &a,int b){
	if(a < b)a = b;
}
signed main(){
	int n,t;cin >> n >> t;
	vector<P> res(n);
	rep(i,n)cin >> res[i].first >> res[i].second;
	sort(res.begin(),res.end());
	int ret = 0;
	rep(i,n){
		int a = res[i].first,b = res[i].second;
		rep(j,3001){
			if(j < t)ret = max(ret,dp[i][j]+b);
			chmax(dp[i+1][j],dp[i][j]);
			if(j + a <= t)chmax(dp[i+1][j+a],dp[i][j] + b);
		}
	}
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 80916
#include <bits/stdc++.h>
#define inf 1e9
using namespace std;

struct data {
  int p, prep, s;
  double t;
};
struct e {
  int to, d, c;
};
bool operator<(const data &l, const data &r) {
  if(l.t != r.t) return l.t > r.t;
  return l.p > r.p;
}

int n, m, s, g;
double dis[35][35][35] = {0}, ans = 0;
vector<e> edge[55];
priority_queue<data> pq;

void solve();

int main() {
  cout << fixed << setprecision(10);
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    cin >> s >> g;
    --s, --g;
    for(int i = 0; i < m; ++i) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      --x, --y;
      edge[x].push_back({y, d, c});
      edge[y].push_back({x, d, c});
    }
    solve();
    if(ans == inf)
      cout << "unreachable" << endl;
    else
      cout << ans << endl;
    for(int i = 0; i < n; ++i)
      edge[i].erase(edge[i].begin(), edge[i].end());
  }
  return 0;
}

void solve() {
  ans = inf;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      for(int k = 0; k <= 30; ++k) dis[i][j][k] = inf;
  pq.push({s, s, 0, 0});
  dis[s][s][0] = 0;
  while(!pq.empty()) {
    data now = pq.top();
    pq.pop();
    for(int i = 0; i < edge[now.p].size(); ++i)
      if(now.prep != edge[now.p][i].to) {
        for(int j = -1; j <= 1; ++j) {
          data nextp = now;
          nextp.prep = now.p;
          nextp.p = edge[now.p][i].to;
          nextp.s += j;
          if(nextp.s > 0 && nextp.s <= edge[now.p][i].c) {
            nextp.t +=
                (long double)edge[now.p][i].d / nextp.s;
            if(dis[nextp.p][nextp.prep][nextp.s] <= nextp.t)
              continue;
            dis[nextp.p][nextp.prep][nextp.s] = nextp.t;
            pq.push(nextp);
          }
        }
      }
  }
  ans = inf;
  for(int i = 0; i < n; ++i) ans = min(ans, dis[g][i][1]);
}


Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;

  vector<double>v;
  for(int i = 0 ; i < n ; i++ ){
  	double temp;cin>>temp;v.push_back(temp);
  }
 
  vector<vector<double> > dp(n+1,vector<double>(n+1,0.0));
    dp[0][0]=1;
  for(int i = 1 ; i <= n ; i++ ){
  		for(int j = 0 ; j<=i;j++){
          if(j==0) dp[i][j]=dp[i-1][j]*(1-v[i-1]);
            else
              dp[i][j]=dp[i-1][j]*(1-v[i-1])+dp[i-1][j-1]*(v[i-1]);
          }
          
        
  }
 double ans=0.0;
  for(int i = n ; i>(n/2) ;i--)ans+=dp[n][i];
  cout<<fixed<<setprecision(10)<<ans;
  
}


Measured memory_bytes: 73792
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs( int r, int c ) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while ( !S.empty() ) {
    int u = S.top(); S.pop();
    for ( int i = 0; i < G[u].size(); i++ ) {
      int v = G[u][i];
      if ( color[v] == NIL ) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for ( int i = 0; i < n; i++ ) color[i] = NIL;
  for ( int u = 0; u < n; u++ ) {
    if ( color[u] == NIL ) dfs(u, id++);
  }
}

int main() {
  int s, t, m, q;

  cin >> n >> m;

  for ( int i = 0; i < m; i++ ) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for ( int i = 0; i < q; i++ ) {
    cin >> s >> t;
    if ( color[s] == color[t] ) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 9016
import numpy as np
i8 = np.int64
i4 = np.int32

def calc(dp1, dp2, k):
    dp2[k:] += dp1[:dp1.shape[0]-k]
    dp2[:dp2.shape[0]-k] += dp1[k:]

def solve(z, dp):
    zero = dp.shape[2] // 2
    dp[0, 0, zero + z[0, 0]] = 1
    dp[0, 0, zero - z[0, 0]] = 1
    for x in range(1, z.shape[1]):
        calc(dp[0, x - 1], dp[0, x], z[0, x])
    for y in range(1, z.shape[0]):
        calc(dp[y - 1, 0], dp[y, 0], z[y, 0])
        for x in range(1, z.shape[1]):
            calc(dp[y, x - 1], dp[y, x], z[y, x])
            calc(dp[y - 1, x], dp[y, x], z[y, x])
            if (x + y) % 10 == 0:
                dp[y, x] = dp[y, x] > 0
    for i in range(zero, dp.shape[2]):
        if dp[dp.shape[0] - 1, dp.shape[1] - 1, i] > 0:
            return i - zero
    return -1

def main2():
    stdin = open('/dev/stdin')
    H, W = map(int, stdin.readline().split())
    a = np.empty((H, W), i8)
    b = np.empty((H, W), i8)
    for i in range(H):
        for j, c in enumerate(map(int, stdin.readline().split())):
            a[i, j] = c
    for i in range(H):
        for j, c in enumerate(map(int, stdin.readline().split())):
            b[i, j] = c
    z = np.abs(a - b)
    dp = np.zeros((H, W, 80 * 80 *2 + 1), i8)
    ans = solve(z, dp)
    print(ans)


main2()

Measured memory_bytes: 654628
use std::io;
use std::usize::MAX;

type Range = (usize, usize);

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.chars().collect()
}

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (h, w) = input_tuple();
    let mut grid: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let row = input_char_vec();
        grid.push(row);
    }
    let mut l: Vec<Vec<u64>> = vec![vec![0; w]; h];
    let mut r: Vec<Vec<u64>> = vec![vec![0; w]; h];
    let mut u: Vec<Vec<u64>> = vec![vec![0; w]; h];
    let mut d: Vec<Vec<u64>> = vec![vec![0; w]; h];

    for i in 0..h {
        for j in 0..w {
            if grid[i][j] == '#' {
                l[i][j] = 0;
                continue;
            }
            if j == 0 {
                l[i][j] = 1;
            } else {
                l[i][j] = l[i][j - 1] + 1;
            }
        }
    }

    for i in 0..h {
        for j in (0..w).rev() {
            if grid[i][j] == '#' {
                r[i][j] = 0;
                continue;
            }
            if j == w - 1 {
                r[i][j] = 1;
            } else {
                r[i][j] = r[i][j + 1] + 1;
            }
        }
    }

    for j in 0..w {
        for i in 0..h {
            if grid[i][j] == '#' {
                u[i][j] = 0;
                continue;
            }
            if i == 0 {
                u[i][j] = 1;
            } else {
                u[i][j] = u[i - 1][j] + 1;
            }
        }
    }

    for j in 0..w {
        for i in (0..h).rev() {
            if grid[i][j] == '#' {
                d[i][j] = 0;
                continue;
            }
            if i == h - 1 {
                d[i][j] = 1;
            } else {
                d[i][j] = d[i + 1][j] + 1;
            }
        }
    }
    // println!("{:?}", l);
    // println!("{:?}", r);
    // println!("{:?}", u);
    // println!("{:?}", d);

    let mut max = 0;
    for i in 0..h {
        for j in 0..w {
            if grid[i][j] == '#' {
                continue;
            }
            let count = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
            if count > max {
                max = count;
            }
        }
    }
    println!("{}", max);
}

Measured memory_bytes: 184572
from sys import exit
from fractions import gcd

N, M = map(int, input().split())
A = list(map(int, input().split()))

a = A[0]
n = 1
while a % 2 == 0:
    n *= 2
    a //= 2

lcm = 1
for a in A:
    if a % n != 0 or a % (2 * n) == 0:
        print(0)
        exit()
    lcm = lcm * a // gcd(lcm, a)
    if lcm // 2 > M:
        print(0)
        exit()

print((M - lcm // 2) // lcm + 1)


Measured memory_bytes: 16320
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,f[400010],p;
vector<int> x[100010];
inline void add(int i,int j,int k,int l,int r)
{
	if(l<=j && k<=r)
	  f[i]++;
	else
	  {
	   if(l<=(j+k>>1))
	     add(i<<1,j,j+k>>1,l,r);
	   if(r>(j+k>>1))
	     add(i<<1|1,(j+k>>1)+1,k,l,r);
	  }
}
inline int query(int i,int j,int k,int p)
{
	if(j==k)
	  return f[i];
	else
	  if(p<=(j+k>>1))
	    return f[i]+query(i<<1,j,j+k>>1,p);
	  else
	    return f[i]+query(i<<1|1,(j+k>>1)+1,k,p);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++)
	  {
	   scanf("%d%d",&j,&k);
	   x[k-j+1].push_back(j);
	  }
	for(p=1;p<n;p<<=1);
	for(i=1;i<=n;i++)
	  {
	   for(j=i,k=0;j<=n;j+=i)
	     k+=query(1,1,p,j);
	   printf("%d\n",k+m);
	   for(j=0;j<x[i].size();j++,m--)
	     add(1,1,p,x[i][j],x[i][j]+i-1);
	  }
	return 0;
}


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

int main()
{
char A[ 10 ];
char B[ 10 ];
char C[ 10 ];

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

	cin >> A;
	cin >> B;
	cin >> C;

	cout << A[ 0 ] << B[ 1 ] << C[ 2 ] << endl;

	return 0;
}






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

int main()
{

    int a,b,c;
    cin>>a>>b>>c;
    int a1=a+b;
    int a2=c+b;
    int a3=a+c;
    int a4=c+b;
    int a5=b+a;
    int aa=min(a1,a2);
    int ab=min(a3,a4);
    int ac=min(a5,aa);
    int ad=min(ac,ab);
    int ans=min(ac,ad);
    cout<<ans<<endl;
    return 0;
}


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


int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("outputc.txt","w",stdout);
	// #endif
	
	//int t;
	//cin>>t;
	//while(t--)
	{
		int n;
		cin>>n;
		string s;
		cin>>s;
		int ans=0;
		int i,j;
		for(i=0,j=n-1;i<n&&j>=0;i++)
		{
			if(i>=j)break;
			if(s[i]=='W')
			{
				while(1)
				{
					if(s[j]=='R'||i>=j||j==0)break;
					j--;
				}
				if(i!=j)
				{
					swap(s[i],s[j]);
					ans++;
				}
			}
		}
		for(i=1;i<n;i++)
		{
			if(s[i]=='R'&&s[i-1]=='W')ans++;
		}
		//cout<<s;
		cout<<ans<<'\n';
		
	}
		
}



Measured memory_bytes: 3696
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int ans = 0;
    int l = 0;
    int r = s.length()-1;
    while (l <= r) {
      char lc = s.charAt(l);
      char rc = s.charAt(r);
      if (lc == rc) {
        l++;
        r--;
      } else if (lc == 'x' && rc != 'x') {
        l++;
        ans++;
      } else if (lc != 'x' && rc == 'x') {
        r--;
        ans++;
      } else {
        ans = -1;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 24280