akhauriyash/Code-Regression huggingface dataset:
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

/*-------------------------------------------------------------------------------------------------------------------------*/
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> ii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<ii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
/*-------------------------------------------------------------------------------------------------------------------------*/
#define MAXN (ll)(1e5 + 5)
#define NIL (ll)(1e18 + 5)

ll dp[MAXN][3];
vector<char> op;
vi arr;
ll n;

ll solve(ll i, ll t)
{
    if (i == n - 1)
    {
        if (t == 0 || t == 2)
            return arr[i];
        else
            return -arr[i];
    }

    if (dp[i][t] == NIL)
    {
        if (t == 0)
        {
            if (op[i] == '-')
                dp[i][t] = solve(i + 1, 1) + arr[i];
            else
                dp[i][t] = solve(i + 1, 0) + arr[i];
        }
        else if (t == 1)
        {
            if (op[i] == '-')
                dp[i][t] = max(solve(i + 1, 1) - arr[i], solve(i + 1, 2) - arr[i]);
            else
                dp[i][t] = max(solve(i + 1, 1) - arr[i], solve(i + 1, 0) - arr[i]);
        }
        else
        {
            if (op[i] == '-')
                dp[i][t] = solve(i + 1, 2) + arr[i];
            else
                dp[i][t] = max(solve(i + 1, 2), max(solve(i + 1, 1), solve(i + 1, 0))) + arr[i];
        }
    }
    return dp[i][t];
}

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

    for (int i = 0; i < MAXN; i++)
        for (int j = 0; j < 3; j++)
            dp[i][j] = NIL;

    cin >> n;

    arr.resize(n);
    op.resize(n - 1);
    cin >> arr[0];

    for (int i = 1; i < n; i++)
        cin >> op[i - 1] >> arr[i];

    cout << solve(0, 0) << "\n";
}


Measured memory_bytes: 8192
using System;

namespace AOJ0503
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                int N = int.Parse(input);

                if (N == 0) break;

                int[] current = new int[6];
                int[] next = new int[6];
                int total = 1;

                current[0] = 1; current[1] = 6; current[2] = 3; current[3] = 4; current[4] = 2; current[5] = 5;
                next[0] = 1; next[1] = 6; next[2] = 3; next[3] = 4; next[4] = 2; next[5] = 5;

                for (int i = 0; i < N; i++)
                {

                    input = Console.ReadLine();

                    switch (input)
                    {
                        case "North":
                            next[5] = current[0]; next[4] = current[1]; next[0] = current[4]; next[1] = current[5];
                            break;

                        case "East":
                            next[2] = current[0]; next[3] = current[1]; next[1] = current[2]; next[0] = current[3];
                            break;

                        case "West":
                            next[3] = current[0]; next[2] = current[1]; next[0] = current[2]; next[1] = current[3];
                            break;

                        case "South":
                            next[4] = current[0]; next[5] = current[1]; next[1] = current[4]; next[0] = current[5];
                            break;

                        case "Right":
                            next[4] = current[2]; next[5] = current[3]; next[3] = current[4]; next[2] = current[5];
                            break;

                        case "Left":
                            next[5] = current[2]; next[4] = current[3]; next[2] = current[4]; next[3] = current[5];
                            break;
                    }

                    for (int j = 0; j < 6; j++)
                    {
                        current[j] = next[j];
                    }

                    total += current[0];

                }

                Console.WriteLine(total);

            }
        }
    }
}

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

int c(int k) {
  int ans = 1;
  int c = 7;
  set<int> exist;
  while(true) {
    c %= k;
    if(c == 0) {
      return ans;
    }
    if(exist.find(c) != exist.end()) {
      return -1;
    }
    exist.insert(c);
    c *= 10;
    c += 7;
    ans++;
  }

  return -1;
}

int main() {
  int k;
  cin >> k;
  cout << c(k);
}

Measured memory_bytes: 50316
import java.util.Arrays;
import java.util.Scanner;

/*
絶対値の和の最小
|x−B1|+|x−B2|+⋯+|x−BN| を最小にする x は、B1,B2,…,BN のメディアン *式変形
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[(int)N];
        int[] b = new int[(int)N];
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            b[i] = a[i] - i;
        }
        Arrays.sort(b);
        int mid = b[N/2];
        long min = 0;
        for(int i = 0; i < N; i++) {
            min += Math.abs(mid - b[i]);
        }
        System.out.println(min);

    }
}


Measured memory_bytes: 62332
require "scanf"
line = gets
items = line.split(" ")
$n = items[0].to_i
$w = items[1].to_i
$data = Array.new($n+1)
$data[0] = Array.new(2, 0)
$n.times do |i|
  if line = gets
    $data[i+1] = line.split(" ")
    $data[i+1].map!{|item| item.to_i}
  else
    break
  end
end
$dp = Hash.new
def knapsack(i, k)
  key = "#{i} #{k}"
  if $dp[key] != nil
    return $dp[key]
  end
  max = 0
  if i == $n
    $dp[key] = 0
    return 0
  else
    node = knapsack(i+1, k)
    max = node if max < node
  end
  if k + $data[i+1][0] > $w
    $dp[key] = max
    return max
  else
    node = knapsack(i+1, k + $data[i+1][0]) + $data[i+1][1]
    max = node if max < node
  end
  $dp[key] = max
  return max
end
p knapsack(0,0) 

Measured memory_bytes: 15356
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0)
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  IO;
  int n; ll W; cin>>n>>W;
  vector<ll> dp(n*1000+1, 1e15);
  dp[0] = 0;

  for (int i = 1; i <= n; i++) {
    ll w, v; cin>>w>>v;
    for (int tval = n*1000 - v; tval >= 0; tval--) {
      dp[tval + v] = min(dp[tval + v], dp[tval] + w);
    }
  }

  for (int tval = n*1000; tval >= 0; tval--) if (dp[tval] <= W) return cout<<tval<<"\n", 0;
}

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int n,m;
  cin>>n>>m;
  int ans=1;
  if(abs(n-m)==1){
    for(int i=n;i>=1;i--)ans=ans*i%MOD;
    for(int i=m;i>=1;i--)ans=ans*i%MOD;
    cout<<ans<<endl;
  }
  else if(n-m==0){
    for(int i=n;i>=1;i--)ans=ans*i%MOD;
    for(int i=m;i>=1;i--)ans=ans*i%MOD;
    ans=ans*2%MOD;
    cout<<ans<<endl;
  }
  else cout<<0<<endl;
}


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

int main(){
  ll N,W,a,b,ans=0;
  cin>>N>>W;
  set<ll> se;
  map<datas,ll> mp;
  queue<ll> que;
  se.insert(0);
  for(ll i=1;i<=N;i++){
    cin>>a>>b;
    for(auto j:se){
      if(j+a<=W){
        if(!mp[datas(i-1,j+a)])que.push(j+a);
        mp[datas(i,j+a)]=max(mp[datas(i-1,j+a)],mp[datas(i-1,j)]+b);
      }
      mp[datas(i,j)]=max(mp[datas(i,j)],mp[datas(i-1,j)]);
    }
    while(!que.empty()){
      auto x=que.front();que.pop();
      se.insert(x);
    }
  }
  for(auto i:se){
    ans=max(mp[datas(N,i)],ans);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int h,n; cin >> h >> n;
    int sum = 0;
    rep(i,n){
        int a; cin >> a;
        sum += a;
    }
    if(h <= sum) Yes;
    else No;

    return 0;
}

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

int N;
V<ll> a;
bool can(ll A){
	using P = pair<ll,ll>;
	map<ll,ll> i2val;
	rep(i,N){
		if(i==0){
			continue;
		}
		if(a[i-1] < a[i]){
			continue;
		}
		if(a[i-1] > a[i]){
			while(!i2val.empty()){
				P p = *i2val.rbegin();
				if(a[i]<=p.fs){
					i2val.erase(p.fs);
				}else{
					break;
				}
			}
		}
		V<ll> ds;
		for(ll x = a[i]-1;;x--){
			if(x == -1){
				return false;
			}
			i2val[x]++;
			if(i2val[x] == A){
				i2val.erase(x);
			}else{
				break;
			}
		}
	}
	return true;
}
int main(){
	cin>>N;
	a.resize(N);
	rep(i,N) cin>>a[i];
	if(false){
		cin>>N;
		a = V<ll>(N,1);
		rep(i,N) a[i] = rand()%1000000000+1;
	}
	{
		bool ok = 1;
		rep(i,N-1) if(a[i]>=a[i+1]) ok = 0;
		if(ok){
			cout<<1<<endl;
			return 0;
		}
	}
	ll ub = N, lb = 1;
	while(ub-lb>1){
		ll m = (ub+lb)/2;
		if(can(m)) ub = m;
		else lb = m;
	}
	cout<<ub<<endl;
}

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

int main() {
   // freopen( "C:\\Users\\ehab\\Desktop\\problems\\in.txt" , "r" , stdin );

    string s , t;
    cin >> s >> t;

    int sz = t.length();
    for ( int i = 0; i < sz; i++ ){
        if ( s == t ){
            cout << "Yes";
            return 0;
        }
        t = t.back() + t;
        t.pop_back();
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	int arr[4][13] = {0};
	char ch[4] = {'S', 'H', 'C', 'D'};
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string a;
	    int b;
		cin >> a >> b;
		if (a == "S") {
			arr[0][b - 1] = 1;
		}
		else if (a == "H") {
			arr[1][b - 1] = 1;
		}
		else if (a == "C") {
			arr[2][b - 1] = 1;
		}
		else if (a == "D") {
			arr[3][b - 1] = 1;
		}
	}

	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 13; ++j) {
			if (arr[i][j] == 0) {
				cout << ch[i] << " " << j + 1 << endl;
			}
		}
	}
	return 0;
}





Measured memory_bytes: 3116
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	Int N;
	cin >> N;

	string S;
	cin >> S;

	Int ans = 0;
	Int temp;
	vector<Int> x;
	vector<Int> y;
	for (Int i = 1; i < N; i++) {
		x.assign(26, 0LL);
		y.assign(26, 0LL);

		//vector<Int> x(26);
		//vector<Int> y(26);

		for (Int j = 0; j < i; j++) {
			x[S[j] - 'a']++;
		}
		for (Int j = i; j < N; j++) {
			y[S[j] - 'a']++;
		}

		DMP(x, y);

		temp = 0;
		for (Int j = 0; j < 26; j++) {
			if (x[j]&&y[j]) {
				temp++;
			}
		}

		ans = max(ans, temp);
	}
	cout << ans << "\n";
}


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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

// Fenwick Tree {{{
template <class T>
class Fenwick {
	private:
		std::vector<T> arr;
		int sz;
		T myQuery(int idx) {
			T rt{};
			for(;idx>0;idx-=idx&-idx) rt += arr[idx];
			return rt;
		}
		void myUpdate(int idx, const T &val) {
			for(;idx<=sz;idx+=idx&-idx) arr[idx] += val;
		}
	public:
		Fenwick(int n) : arr(n + 1), sz(n) {}
		T query(int x) { return myQuery(x + 1); }
		T query(int l, int r) { return query(r) - query(l - 1); }
		void update(int x, const T &v) { myUpdate(x + 1, v); }
};
// }}}

// Range Update Fenwick {{{
template <class T>
class RangeFenwick {
	private:
		Fenwick<T> tr1, tr2;
	public:
		RangeFenwick(int n) : tr1(n), tr2(n) {}
		T query(int x) { return (x + 1) * tr1.query(x) - tr2.query(x); }
		T query(int l, int r) { return query(r) - query(l - 1); }
		void update(int l, int r, const T &v) {
			tr1.update(l, v);
			tr1.update(r + 1, -v);
			tr2.update(l, v * l);
			tr2.update(r + 1, -v * (r + 1));
		}
};
// }}}

int solve() {
	int n, q; cin >> n >> q;
	RangeFenwick<ll> lst(n);
	while (q--) {
		int op; cin >> op;
		if (op == 0) {
			int l, r, v; cin >> l >> r >> v;
			l--, r--;
			lst.update(l, r, v);
		} else {
			int l, r; cin >> l >> r;
			l--, r--;
			cout << lst.query(l, r) << endl;
		}
	}
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker



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

using namespace std;

const int N = (int)1e5 + 7;

string s;
int n;
int cnt[N][26];

main() {
	cin >> s;
	n = s.size();
	for (int i = 0; i < 26; i++) {
		int mn = 1;
		int pos = 0;
		if (i == s[0] - 'a')
			cnt[0][s[0] - 'a']++;
		for (int j = 1; j < n; j++) {
			cnt[j][i] = cnt[j - 1][i];
			if (i == s[j] - 'a') 
				cnt[j][i]++;
			if (2 * cnt[j][i] - j > mn) {
				cout << pos + 1 << ' ' << j + 1;
				return 0;
			}
			if (2 * cnt[j - 1][i] - j + 1 < mn) {
				mn = 2 * cnt[j - 1][i] - j + 1;
				pos = j;
			}
		}
	}
	puts("-1 -1");
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
static const int N = 1000;
stack<int>s;
/*
	s.pop();s.push(..);s.size();s.empty();s.top();
*/
int operation(int x,int y,string op){
	if(op=="+")
		return x+y;
	if(op=="-")
		return x-y;
	if(op=="*")
		return x*y;
}
int getInt(string s){
	int res=0;
	for(int i=0;i<s.size();i++){
		res = res*10 + s[i]-'0';
	}
	return res;
}
int main(){
	string c,a[N];
	int n=0,x,y;
	while(!s.empty()){
		s.pop();
	}
	while(cin>>c){
		a[n++]=c;
	}
	for(int i=0;i<n;i++){
		if(a[i]=="+"||a[i]=="-"||a[i]=="*"){
			y = s.top();
			s.pop();
			x = s.top();
			s.pop();
			s.push(operation(x,y,a[i]));
		}
		else{
			s.push(getInt(a[i]));
		}
	}
	cout<<s.top()<<endl;
	return 0;
}


Measured memory_bytes: 3240
#include <stdio.h>
#include <string.h>
int main()
{
	int N;
	long long int x;
	scanf("%d%lld",&N,&x);
	long long int a[N];
	int i,j,tmp;
	for(i = 0; i<N;i++){
		scanf("%lld",&a[i]);
	}
	for(i = 0; i<N;i++){
		for(j=N-1;j>i;j--){
			if(a[j]<a[j-1]){
				tmp=a[j];
				a[j]=a[j-1];
				a[j-1]=tmp;
			}
		}
	}
	int count=0;
	for(i = 0;i<N;i++){
		if(i!=N-1){
			if(x>=a[i]){
				x-=a[i];
				count++;
			}
			else break;
		}
		else{
			if(x==a[i]){
				count++;
			}else break;
		}
	}

	printf("%d",count);
}

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

using namespace std;

const int64_t INF = INT64_C(1) << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, S;
  cin >> N >> M >> S;
  vector<vector<pair<int, int>>> G(N);
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v >> A[i] >> B[i];
    u--, v--;
    G[u].emplace_back(make_pair(v, i));
    G[v].emplace_back(make_pair(u, i));
  }
  vector<int> C(N), D(N);
  for (int i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
  }
  int mx = 3000;
  vector<vector<int64_t>> T(N, vector<int64_t>(mx + 1, INF));
  priority_queue<pair<int64_t, pair<int, int>>,
                 vector<pair<int64_t, pair<int, int>>>,
                 greater<pair<int64_t, pair<int, int>>>>
      que;
  que.push(make_pair(0, make_pair(0, min(mx, S))));
  while (!que.empty()) {
    auto q = que.top();
    que.pop();
    int64_t t = q.first;
    int u = q.second.first, c = q.second.second;
    if (T[u][c] != INF) continue;
    T[u][c] = t;
    que.push(make_pair(t + D[u], make_pair(u, min(mx, c + C[u]))));
    for (auto g : G[u]) {
      int v = g.first, a = A[g.second], b = B[g.second];
      if (a > c) continue;
      que.push(make_pair(t + b, make_pair(v, c - a)));
    }
  }
  for (int i = 1; i < N; i++) {
    cout << *min_element(T[i].begin(), T[i].end()) << '\n';
  }
  return 0;
}


Measured memory_bytes: 12720
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

  vector<int> a(n);

  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<int> b(n);
  long long int x = 0;
  for(int i = 0; i < n; ++i) {
    if (i%2 == 0) x+=a[i];
    else x -= a[i];
  }

  b[0] = (int)x;
  for(int i = 1; i < n; ++i) {
    b[i] = (a[i-1]-b[i-1]/2)*2;
  }


  string delim = "";
  for (int i = 0; i < n; ++i) {
    cout << delim << b[i];
    delim = " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2048
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
ans = 0
if N >= K:
    ans += (N-K+1)/N
for i in range(1,min(K-1,N)+1):
    a = i
    r = 0
    while a <= K-1:
        a *= 2
        r += 1
    ans += 1/(N*2**r)

print(ans)


Measured memory_bytes: 65260
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> pii;

const int MAX = 3e2 + 10;
int n, cnt[3];
double dp[MAX][MAX][MAX];

main (){
	cin >> n;
	for (int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		cnt[--x]++;
	}
	dp[0][0][0] = 0.0;
	for (int k = 0 ; k <= n ; k++){
		for (int j = 0 ; j <= n ; j++){
			for (int i = 0 ; i <= n ; i++){
				if (i + j + k == 0){
					continue;
				}
				dp[i][j][k] = 1.0;
				if (i > 0){
					dp[i][j][k] += ((i + 0.0) / n) * (dp[i - 1][j][k]);
				}
				if (j > 0){
					dp[i][j][k] += ((j + 0.0) / n) * (dp[i + 1][j - 1][k]);
				}
				if (k > 0){
					dp[i][j][k] += ((k + 0.0) / n) * (dp[i][j + 1][k - 1]);
				}
				dp[i][j][k] *= ((n + 0.0) / (i + j + k));
			}
		}
	}
	cout << setprecision (20) << dp[cnt[0]][cnt[1]][cnt[2]];
}

Measured memory_bytes: 227584
import Control.Applicative
main = do
  [in_a, in_op, in_b] <- words <$> getLine
  let (a, op, b) = (read in_a :: Int, head in_op, read in_b :: Int)
      ans = case op of
              '+' -> a + b
              '-' -> a - b
              '*' -> a * b
              '/' -> a `div` b
              otherwise -> 0
  if op == '?' then return () else print ans >> main

Measured memory_bytes: 4044
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	string s;
	cin >> s;
	int ans;
	if(s == "SUN")ans = 7;
	else if(s == "MON")ans = 6;
	else if(s == "TUE")ans = 5;
	else if(s == "WED")ans = 4;
	else if(s == "THU")ans = 3;
	else if(s == "FRI")ans = 2;
	else if(s == "SAT")ans = 1;
	cout << ans << endl;

}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> a;
    vector<int> b;
    vector<int> c;
    for(int i=0;i<3;i++){
        for(int j=0;j<n;j++){
            int v;
            cin>>v;
            if(i==0)a.push_back(v);
            if(i==1)b.push_back(v);
            if(i==2)c.push_back(v);
        }
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long ans=0;
    for(int j=0;j<n;j++){
        int base=b[j];
        vector<int>::iterator itr_l=lower_bound(a.begin(),a.end(),base);
        vector<int>::iterator itr_u=upper_bound(c.begin(),c.end(),base);
        long l,u;
        l=distance(a.begin(),itr_l);
        u=distance(c.begin(),itr_u);
        ans+=l*(n-u);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool ok = 1;
    if (s[a] != '-') ok = 0;
    rep(i,a+b+1){
        if (i == a) continue;
        if (s[i] == '-') ok = 0;
    }
    if (ok) PRINT("Yes");
    else PRINT("No");
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::Chars;
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
  input! {s:String}
  println!(
    "{}",
    match &*s {
      "RRR" => 3,
      "RRS" | "SRR" => 2,
      "RSR" | "RSS" | "SSR" | "SRS" => 1,
      _ => 0,
    }
  );
}


Measured memory_bytes: 2136
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int n,k,su,mx;
	scanf("%d%d",&n,&k);
	scanf("%d",&su);
	mx = su;
	for(int i=1;i<n;i++){
		int aa;
		scanf("%d",&aa);
		mx = max(mx, aa);
		su = __gcd(su, aa);
	}
	if(k>mx || k%su){
		printf("IMPOSSIBLE\n");
	}else{
		printf("POSSIBLE\n");
	}
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int x,i;

    x=0;
    i=0;

    while(1){
      {

      scanf("%d",&x);

      if( x==0 ){
        break;
      }

      i++;
      }


    printf("Case %d: %d\n",i,x);
    }

  return 0;

}

Measured memory_bytes: 600
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b&&b<c){
	printf("%d %d %d\n",a,b,c);
	}else if(a<=c&&c<=b){
	printf("%d %d %d\n",a,c,b);
	}else if(b<=a&&a<=c){
	printf("%d %d %d\n",b,a,c);
	}else if(b<=c&&c<=a){
	printf("%d %d %d\n",b,c,a);
	}else if(c<=a&&a<=b){
	printf("%d %d %d\n",c,a,b);
	}else if(c<=b&&b<=a){
	printf("%d %d %d\n",c,b,a);
	}	return 0;
}


Measured memory_bytes: 2044
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
S = list(input().strip())

ans = 0
split = 0
pre = S[0]
for i in range(1, N):
    if pre == S[i]:
        ans += 1
    else:
        split += 1
    pre = S[i]

# print(ans, split)
print(ans + min(2*K, split))

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> a(n);
    map<string, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vector< pair<string, int> > ans;
    for(auto P : mp) {
        ans.push_back({P.first, P.second});
    }
    sort(ans.rbegin(), ans.rend(), [&](auto &a, auto &b) {
        if(a.second == b.second) {
            return a.first > b.first;
        }
        return a.second < b.second;
    });
    cout << ans[0].first << endl;
    for(int i = 1; i < (int)ans.size(); i++) {
        if(ans[i].second == ans[0].second) {
           cout << ans[i].first << endl;
        } else {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 30704
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long N = lread();
    long D, X;
    scan(D, X);
    long sum;
    foreach (_; 0 .. N)
    {
        long A = lread();
        sum += (D + (A - 1)) / A;
    }
    writeln(X + sum);
}


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

a, b = map(int, input().split())

for _ in range(n-1):
    x, y = map(int, input().split())
    p = max(a // x, b // y)
    while x * p < a or y * p < b:
        p += 1
    a, b = x * p, y * p
    
print(a + b)
    

Measured memory_bytes: 3064
n = int(input())
height = list(map(int,input().split()))
cost = []

for i in range(n):
  if i == 0:
    cost.append(0)
  elif i == 1:
    cost.append(abs(height[i]-height[0]))
  else:
    a = cost[-1] + abs(height[i]-height[i-1])
    b = cost[-2] + abs(height[i]-height[i-2])
    cost.append(min([a,b]))
print(cost[-1])    



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

int main(){
	ios::sync_with_stdio(0); 
	cin.tie(0);
	
	string s,t;
	
	cin>>s>>t;
	
	int flag = 0;
;	for(int i=0;i<int(s.length());i++){
		if(s[i]!=t[i]){
			flag = 1;
			break;
		}
	}
	
	if(flag == 1) cout<<"No";
	else cout <<"Yes";
	
	
	
   
}



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

int main() {
    int n;
    char D;

    while (cin >> n, n) {
        int h, v[2][257] = {0}, rd[2][257] = {0}, ld[2][257] = {0};
        int longest = 0;
        for (int i = 1; i <= n; i++) {
            int p = (i-1)&1, c = i&1;
            h = 0;
            for (int j = 1; j <= n; j++) {
                cin >> D;
                if (D == '1') {
                    h++;
                    if (longest < h) longest = h;
                    v[c][j] = v[p][j] + 1;
                    if (longest < v[c][j]) longest = v[c][j];
                    rd[c][j] = rd[p][j-1] + 1;
                    if (longest < rd[c][j]) longest = rd[c][j];
                    ld[c][j] = ld[p][j+1] + 1;
                    if (longest < ld[c][j]) longest = ld[c][j];
                }
                else {
                    h = 0;
                    v[c][j] = 0;
                    rd[c][j] = 0;
                    ld[c][j] = 0;
                }
            }
        }
        cout << longest << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

using path=pair<ll, ll>;
using graph=vector<vector<path>>;

vl dijkstra(graph &g, ll s) {
  vl d(g.size(), LINF);
  priority_queue<path, vector<path>, greater<>> que;
  d[s] = 0;
  que.push(path(0, s)); // cost, index
  while (!que.empty()) {
    path p = que.top(); que.pop();
    int i = p.second;
    if (d[i] < p.first) continue;
    each(x, g[i]) {
      if (d[x.second] > d[i] + x.first) {
        d[x.second] = d[i] + x.first;
        que.push(path(d[x.second], x.second));
      }
    }
  }

  return d;
}

void solve() {
  VAR(int, N);
  graph g(N, vector<path>());
  rep(i, 0, N - 1) {
    VAR(ll, ai, bi, ci);
    g[ai - 1].push_back(path(ci, bi - 1));
    g[bi - 1].push_back(path(ci, ai - 1));
  }

  VAR(int, Q, K);
  vi x(Q), y(Q);
  rep(i, 0, Q) {
    in(x[i], y[i]);
  }
  auto d = dijkstra(g, K - 1);

  rep(i, 0, Q) {
    print(d[x[i] - 1] + d[y[i] - 1]);
  }
}


Measured memory_bytes: 11888
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Packet
{
	int time;
	int source;
	int dest;

	Packet(int t, int s, int d): time(t),source(s),dest(d){}
	
	bool operator<( const Packet &right ) const {
		return time < right.time;
	}
};

int main()
{
	int M,N;

	while(cin >> N >> M && N)
	{
		vector< Packet > packets;
		vector<int> PC( N, 0 ); 
		
		int T,S,D;
		rep(nth,M)
		{
			cin >> T >> S >> D;
			packets.push_back( Packet(T,S-1,D-1) );
		}

		sort(ALL(packets));

		
		PC[0] = 1;
		rep(i,M)
		{
			Packet p =  packets[i];
			if(PC[p.source]){ PC[p.dest] = PC[p.source]; }
		}

		int ans = accumulate(ALL(PC),0);
		cout << ans << endl;
	}
	return 0;
}

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

long long memo[2][1005][1005] = {0};
char c;
long long x, y, bw, n, k;

long long solve();

int main() {
  long long i, j, l;
  cin >> n >> k;
  for(i = 0; i < n; ++i) {
    cin >> x >> y >> c;
    bw = (c == 'B');
    ++memo[(x / k + y / k + bw) % 2][x % k][y % k];
  }
  for(l = 0; l < 2; ++l)
    for(i = 0; i < k; ++i)
      for(j = 0; j < k; ++j) {
        if(j != 0) memo[l][i][j] += memo[l][i][j - 1];
        if(i != 0) memo[l][i][j] += memo[l][i - 1][j];
        if(i != 0 && j != 0)
          memo[l][i][j] -= memo[l][i - 1][j - 1];
      }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 1, now[2];
  for(int i = 0; i < k; ++i)
    for(int j = 0; j < k; ++j)
      for(int l = 0; l < 2; ++l) {
        now[l] = memo[l][i][j];
        if(i != k - 1 && j != k - 1) {
          now[l] += memo[l][k - 1][k - 1];
          now[l] -= memo[l][i][k - 1];
          now[l] -= memo[l][k - 1][j];
          now[l] += memo[l][i][j];
        }
        now[l] +=
            (memo[1 - l][k - 1][j] - memo[1 - l][i][j]);
        now[l] +=
            (memo[1 - l][i][k - 1] - memo[1 - l][i][j]);
        ans = max(ans, now[l]);
      }
  return ans;
}

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

int sum[15][1005];

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  string st[15];
  int s[15][1005];
  rep(i,h) cin>>st[i];
  rep(i,h) rep(j,w) s[i][j]=st[i][j]-'0';

  rep(i,h){
    sum[i][0]=0;
    rep(j,w) sum[i][j+1]=sum[i][j]+s[i][j];
  }
  int ans=1e9;
  for(int bits=0; bits<1<<h-1; bits++){
    int d=__builtin_popcount(bits);
    int l=0;
    for(int r=1;r<=w;r++){
      int add=0;
      bool can2=true;
      rep(i,h){
	add+=sum[i][r]-sum[i][l];
	if(i==h-1||bits&(1<<i)){
	  if(add>k){
	    can2=false;
	  }
	  add=0;
	}
      }
      if(!can2){
	if(r-l==1)
	  goto pass;
	l=r-1;
	r--;
	d++;
      }
    }
    ans=min(ans,d);
  pass:;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector <bool> in(26,false);
    for(int i=0;i<s.size();i++){
        in[s[i]-'a'] = true;
    }
    for(int i=0;i<in.size();i++){
        if(!in[i]){
            printf("%c\n",'a'+i);
            return 0;
        }
        if(i==in.size()-1){
            cout << "None"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


public class Main {
    FastIO io = new FastIO("in.txt");
    long[] A;
    long N, K;

    long solve(){
        long l = 0, r = (long)1e9;
        while(l <= r){
            long m = l + (r - l)/2;
            long c = 0;
            for(int i=0; i<N; i++){
                long a = A[i];
                if(m == 0){
                    return 1;
                }else {
                    c += Math.max((a + m - 1) / m - 1, 0);
                }
            }
            if(c <= K){
                r = m - 1;
            }else{
                l = m + 1;
            }
        }
        return l;
    }

    public void main() throws Exception {
        N = io.nextLong(); K = io.nextLong();
        A = new long[(int)N];
        for(int i=0; i<N; i++){
            A[i] = io.nextLong();
        }

        io.out(solve() + "\n");
    }

    public static void main(String[] args) throws Exception {
        Main task = new Main();
        task.main();
    }

    class FastIO {
        BufferedReader br;
        StringTokenizer sk;

        public FastIO(String fname){
            try{
                File f = new File(fname);
                if(f.exists()) {
                    System.setIn(new FileInputStream(fname));
                }

            }catch (Exception e){
                throw new IllegalArgumentException(e);
            }

            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastIO(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while(sk==null || !sk.hasMoreElements()){
                try {
                    sk = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new IllegalArgumentException(e);
                }
            }
            return sk.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public char nextChar(){
            return next().charAt(0);
        }

        public long nextLong(){
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }

        public String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            }catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }

        public void out(String v){
            System.out.print(v);
        }

        public void out(int v) {
            System.out.print(v);
        }

        public void out(long v){
            System.out.print(v);
        }

        public void out(double v) {
            System.out.print(v);
        }
    }
}



Measured memory_bytes: 57064
#include<bits/stdc++.h>
#include <cmath>
const double PI = 3.141592653589793;

using namespace std;
int main()
{
    int n;
    cin>>n;
    double ans;
    ans=2*n*PI;
    cout << fixed << setprecision(20) <<ans<<endl; 


    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
using namespace std;


typedef long long       ll;
struct edge { ll to; ll cost; };
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

// マクロ
#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX 9223372036854775807
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}

// ***<ここから>****************************************************************



int main(void) {

	int H, W;
	cin >> H >> W;
	vvc a(H, vc(W));
	rep(i, H) rep(j, W) cin >> a[i][j];

	rep(i, H) {
		bool ok = false;
		rep(j, W) {
			if (a[i][j] == '#') {
				ok = true;
				break;
			}
		}
		if (ok) continue;

		rep(j, W) a[i][j] = 'o';
	}

	rep(j, W) {
		bool ok = false;
		rep(i, H) {
			if (a[i][j] == '#') {
				ok = true;
				break;
			}
		}
		if (ok) continue;

		rep(i, H) a[i][j] = 'o';
	}

	rep(i, H) {
		bool out = false;
		rep(j, W) {
			if (a[i][j] != 'o') {
				cout << a[i][j];
				out = true;
			}
		}
		if (out) cout << endl;
	}





	return 0;
}


Measured memory_bytes: 256
import 'dart:async';
import 'dart:io';
import 'dart:convert';

Stream<String> get lineStream =>
    stdin.transform(utf8.decoder).transform(const LineSplitter());

Future<List<String>> readLines() async {
  final lines = <String>[];
  await for (var line in lineStream) {
    lines.add(line);
  }
  return lines;
}

void main() async {
  final lines = await readLines();
  final nxt = lines[0].split(' ').map((e) => int.parse(e)).toList();
  var count = 0;
  var time = 0;
  while (nxt[0] > count) {
    count += nxt[1];
    time += nxt[2];
  }
  print(time);
}


Measured memory_bytes: 13112
#include <stdio.h> using namespace;
int std;
int main(){ 
    int a,b,c,count = 0; 
    scanf("%d %d %d",&a,&b,&c); 
    for(int i = a; i <= b; i++){
        if(c%i == 0) 
        count++; 
        } 
        printf("%d\n",count); 
    return 0;
} 



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

using namespace std;
 
int main() {
    list<char> ans;
    string S;
    long long Q;
    bool aux = false;
    cin >> S >> Q;
    for(long long i = 0; i < S.length(); i++){ 
        ans.push_back(S[i]); 
    }
    for(long long i = 0; i < Q; i++){
        long long T;
        cin >> T;
        if (T == 1){
            aux = !aux;
        } else{
            long long F;
            char C;
            cin >> F >> C;
            if (F == 1){
                if (!aux) 
                    ans.push_front(C);
                else 
                    ans.push_back(C);
            } else{
                if (!aux)
                    ans.push_back(C);
                else 
                    ans.push_front(C);
            }
        }
    }
    if (aux){
        ans.reverse();
    }
    for (auto i = ans.begin(); i != ans.end(); i++){
        cout << *i;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 13060
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf=400000000000020ll;

int n,k;
int a[210000];
ll pre[210000],suf[210000],ans,S;

struct T{
    int l,r,s;
}t[200000*80];int cnt=1;

void ins(int v,ll l,ll r,ll pos){
    t[v].s++;
    if(l==r)return;
    ll mid=(l+r)>>1;
    if(mid>=pos){
        if(t[v].l==0)t[v].l=++cnt;
        ins(t[v].l,l,mid,pos);
    }else{
        if(t[v].r==0)t[v].r=++cnt;
        ins(t[v].r,mid+1,r,pos);
    }
}

void del(int v,ll l,ll r,ll pos){
    t[v].s--;
    if(l==r)return;
    ll mid=(l+r)>>1;
    if(mid>=pos)del(t[v].l,l,mid,pos);
    else del(t[v].r,mid+1,r,pos);
}

int query(int v,ll l,ll r,ll ql,ll qr){
    if(l>=ql&&r<=qr)return t[v].s;
    ll mid=(l+r)>>1;
    int res=0;
    if(mid>=ql)res+=query(t[v].l,l,mid,ql,qr);
    if(mid<qr)res+=query(t[v].r,mid+1,r,ql,qr);
    return res;
}

int main(){
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        a[i]-=k;
    }for(int i=1;i<=n;i++){
        pre[i]=pre[i-1]+a[i];
    }for(int i=n;i>=1;i--){
        suf[i]=suf[i+1]+a[i];
    }S=pre[n];
    for(int i=1;i<=n+1;i++){
        ins(1,-inf,inf,suf[i]);
    }for(int i=0;i<=n-1;i++){
        del(1,-inf,inf,suf[i+1]);
        ans+=query(1,-inf,inf,-inf,S-pre[i]);
    }printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 77056
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dp[5*1000+100][5*1000+100];
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>s;
    rrrep(i,n-1,0){
        rrrep(j,n-1,0){
            if(i>=j)continue;
            if(s[i]==s[j])dp[i][j]=dp[i+1][j+1]+1;
        }
    }
    rep(i,n){
        rep(j,n){
            ans=max(ans,min(dp[i][j],(ll)j-(ll)i));
        }
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 200960