akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ACLBeginnerContest
{
    class Program
    {
        static void Main(string[] args)
        {
            // 課題C - Connect Cities(2020/9/26)

            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);

            UnionFind uf = new UnionFind(N);
            int c1, c2;

            for (int i = 0; i < M; i++)
            {
                str = Console.ReadLine().Split(' ');
                c1 = int.Parse(str[0]) - 1;
                c2 = int.Parse(str[1]) - 1;

                uf.Union(c1, c2);
            }

            int cnt = -1;

            for (int i = 0; i < N; i++)
            {
                if (uf.Parents[i] < 0) cnt++;
            }

            Console.Write(cnt);
        }
    }


    /// <summary>
    /// Union-Findアルゴリズムの実装クラス
    /// </summary>
    class UnionFind
    {
        // 親要素のインデックスを保持する
        // 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
        public List<int> Parents { get; set; }

        // 初期化
        public UnionFind(int n)
        {
            this.Parents = new List<int>();
            for (int i = 0; i < n; i++)
            {
                // 全要素マイナスで要素数(1個)を保持する
                this.Parents.Add(-1);
            }
        }

        // 要素xのルート要素はどれか
        public int Root(int x)
        {
            // 親がマイナスのものはルート
            if (this.Parents[x] < 0) return x;
            // ルートが見つかるまで再帰的に探す
            this.Parents[x] = Root(this.Parents[x]);
            return this.Parents[x];
        }

        // 要素xの属するグループの要素数を取得する
        public int Size(int x)
        {
            return -this.Parents[this.Root(x)];
        }

        // 要素x, yが同じグループかどうか判定する
        public bool Same(int x, int y)
        {
            return this.Root(x) == this.Root(y);
        }

        // 要素x, yが属するグループを同じグループにまとめる
        public bool Union(int x, int y)
        {
            x = this.Root(x);
            y = this.Root(y);
            // すでに同じグループの場合処理しない
            if (x == y) return false;

            // 要素数が少ないグループを多いほうに書き換えたい
            if (this.Size(x) < this.Size(y))
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            // まとめる先のグループの要素数を更新
            this.Parents[x] += this.Parents[y];
            // まとめられるグループのルートの親を書き換え
            this.Parents[y] = x;
            return true;
        }
    }

}

Measured memory_bytes: 41576
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define mod 1000000007
#define mx 100003
#define ss second
#define ff first
#define ld long double
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;
    int n;
    cin >> n;
    int a[n + 2][5], dp[n + 2][5];
    memset(dp, 0, sizeof(dp));
    rep(i,1,n) cin >> a[i][1] >> a[i][2] >> a[i][3];
    dp[1][1] = a[1][1], dp[1][2] = a[1][2], dp[1][3] = a[1][3];
    for(int i = 2; i <= n; i++)
    {
        dp[i][1] = a[i][1] + max(dp[i - 1][2], dp[i - 1][3]);
        dp[i][2] = a[i][2] + max(dp[i - 1][1], dp[i - 1][3]);
        dp[i][3] = a[i][3] + max(dp[i - 1][2], dp[i - 1][1]);
    }
    cout << max({dp[n][1], dp[n][2], dp[n][3]});
}


Measured memory_bytes: 4224
from heapq import heappop, heappush, heapify


def main():
    n = int(input())
    A = list(map(int, input().split()))

    left_sums = []
    left = A[:n]
    left_sum = sum(left)
    left_sums.append(left_sum)
    heapify(left)

    for a in A[n:2*n]:
        left_sum += a
        heappush(left, a)
        left_sum -= heappop(left)
        left_sums.append(left_sum)

    right_sums = []
    right = []
    for a in A[2*n:]:
        right.append(-a)
    right_sum = sum(right)
    right_sums.append(-right_sum)
    heapify(right)

    for a in A[2*n-1:n-1:-1]:
        right_sum += -a
        heappush(right, -a)
        right_sum -= heappop(right)
        right_sums.append(-right_sum)

    candidates = []
    for sum1, sum2 in zip(left_sums, right_sums[::-1]):
        candidates.append(sum1 - sum2)

    print(max(candidates))


if __name__ == "__main__":
    main()

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


int main(){
  int N;
  cin >> N;
  ll res = 0;
  rep(i,N) {
    int a;cin >> a;
    res += a;
  }
  cout << res - N << endl;
  return 0;
}

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

int main(){
    int64_t A, ans, B_dashdash;
    double B, B_dash;

    cin >> A >> B;

    B_dash = B * 100 + 0.1;

    B_dashdash = B_dash;

    ans = (A * B_dashdash) / 100;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <vector>

using namespace std;

using seika = string;
template <class kizuna>
using akari = vector<kizuna>;

vector<pair<char, int>> RunLengthEncoding(const string &s)
{
    vector<pair<char, int>> res;
    int len = 0, n = s.size();
    char cur = s.front();
    for (int i = 0; i < n; i++)
    {
        if (cur == s[i])
        {
            len++;
        }
        else
        {
            res.push_back(make_pair(cur, len));
            cur = s[i];
            len = 1;
        }
    }
    res.push_back(make_pair(cur, len));
    return res;
}

template <class T>
vector<pair<T, int>> RunLengthEncoding(const vector<T> &v)
{
    vector<pair<T, int>> res;
    int len = 0, n = v.size();
    T cur = v.front();
    for (int i = 0; i < n; i++)
    {
        if (cur == v[i])
        {
            len++;
        }
        else
        {
            res.push_back(make_pair(cur, len));
            cur = v[i];
            len = 1;
        }
    }
    res.push_back(make_pair(cur, len));
    return res;
}

//verified @ https://atcoder.jp/contests/abc143/submissions/8661956

int main(void)
{
    int n;
    cin >> n;
    seika s;
    cin >> s;
    auto v = RunLengthEncoding(s);
    // for (auto &p : v)
    // {
    //     cout << p.first << ' ' << p.second << endl;
    // }
    cout << v.size() << endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int H, A; cin >> H >> A;
    int ans = ceil((H - EPS) / A);
    cout << ans << "\n";
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];
ll tre[3030][3030];
ll dp[3030][3030][4];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s;
	cin >> s;
	ll  n = s.length();
	ll total = 0;
	rep(i, n) {
		ll a = s[i] - '0';
		total += a;
	}
	if (total % 9 == 0) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}


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


int main(){


    int h, w, i, j;

    int a = 0;


    cin >> h >> w;


    vector< vector<char> > s( h, vector<char>(w) );


    vector< vector<int> > l( h, vector<int>(w) );

    vector< vector<int> > r( h, vector<int>(w) );

    vector< vector<int> > u( h, vector<int>(w) );

    vector< vector<int> > d( h, vector<int>(w) );


    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              cin >> s.at(i).at(j);

              }

         }


    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              if( s.at(i).at(j) == '#' ) l.at(i).at(j) = 0;

              else if( j == 0 ) l.at(i).at(j) = 1;

              else l.at(i).at(j) = l.at(i).at(j - 1) + 1;

              }

         }


    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = w - 1 ; j >= 0 ; j = j - 1 ){

              if( s.at(i).at(j) == '#' ) r.at(i).at(j) = 0;

              else if( j == w - 1 ) r.at(i).at(j) = 1;

              else r.at(i).at(j) = r.at(i).at(j + 1) + 1;

              }

         }


    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              if( s.at(i).at(j) == '#' ) u.at(i).at(j) = 0;

              else if( i == 0 ) u.at(i).at(j) = 1;

              else u.at(i).at(j) = u.at(i - 1).at(j) + 1;

              }

         }


    for( i = h - 1 ; i >= 0 ; i = i - 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              if( s.at(i).at(j) == '#' ) d.at(i).at(j) = 0;

              else if( i == h - 1 ) d.at(i).at(j) = 1;

              else d.at(i).at(j) = d.at(i + 1).at(j) + 1;

              }

         }


    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              a = max( a, l.at(i).at(j) + r.at(i).at(j) + u.at(i).at(j) + d.at(i).at(j) - 3 );

              }

         }



    cout << a << endl;

    
    return 0;


    }


Measured memory_bytes: 67072
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ld A;cin>>A;
    ld B;cin>>B;
    prt((ll)(A*B+0.001))
    
    return 0;
}


Measured memory_bytes: 3724
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] A=new int[N];
		for(int i=0; i<N; i++) {A[i]=0;}
		for(int i=0; i<N; i++) {A[i]=sc.nextInt();}
		int max=0,min=-1;
		for(int i=0; i<N; i++) {
			if(A[i]>max)max=A[i];
			if(min==-1||A[i]<min)min=A[i];
		}
		System.out.println((max-min));
	}
}

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

using namespace std;

typedef long long int ll;

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max ({a * c, a * d, b * c, b * d});
  cout << ans << '\n';
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define int long long
#define rep(i, n) for (signed i=0; i<signed(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 110

signed N;
int seq[MAX_N];
int dp[MAX_N][21];

signed main() {
  cin >> N;
  rep(i, N) cin >> seq[i];

  dp[1][seq[0]] = 1;
  rep(i, N) {
    rep(k, 21) {
      int x = seq[i];
      if (k + x <= 20) dp[i+1][k + x] += dp[i][k];
      if (k - x >= 0)  dp[i+1][k - x] += dp[i][k];
    }
  }
  int ans = dp[N-2+1][seq[N-1]];
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,K;
    cin>>N>>K;
    int a[N+100];
    for (int i=0;i<N;i++){
        cin>>a[i];
    }
    for (int i=0;i<N-K;i++){
        if (a[i]<a[i+K]){
            cout<<"Yes"<<endl;
            }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4428
def ev(arr)
  max = arr.max
  return 0 if !max || max==0
  score=(max-arr[0])+(max-arr[1])+(max-arr[2])
end


def process(arr)
  return if ev(arr)==0

  m1=arr.dup;m2=arr.dup
  m1[m1.index(m1.min)]+=2

  dummy=m2.max||m2[0]
  m2.delete_at(m2.index(dummy))
  m2.map!{|n| n+=1}
  m2 << dummy

  @counter+=1
  ans=ev(m1)<ev(m2) ? m1 : m2
  process(ans)
  return
end

s=gets.chomp
nums=s.split(" ").map{|n| n.to_i}

@counter = 0
process(nums)
puts @counter


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

vector<bool> eratosthenes(ll n) {
    vector<bool> sieve(n+1, true);
    vector<ll> table;
    sieve[0] = sieve[1] = false;
    for (ll i = 2; i <= n; i++) {
        if (sieve[i]) {
            table.push_back(i);
            for (ll j = 2; i * j <= n; j++) {
                sieve[i * j] = false;
            }
        }
    }

    return sieve;
}

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

    vector<bool> a = eratosthenes(1e6);
    ll X;
    cin >> X;
    while (true) {
        if (a[X]) {
            cout << X << endl;
            return 0;
        }
        X++;
    }
}

Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

class Z_algorithm {
public:
	void process(const char* str, int n) {
		v.resize(n);
		v[0] = n;
		int i = 1, j = 0;
		while (i < n) {
			while (i + j < n && str[j] == str[i + j]) ++j;
			v[i] = j;
			if (j == 0) { ++i; continue; }
			int k = 1;
			while (i + k < n && k + v[k] < j) v[i + k] = v[k], ++k;
			i += k; j -= k;
		}
	}
	void process(string S) {
		process(S.c_str(), S.length());
	}
	vector<int> v;
};

class Rolling_Hash {
public:
	Rolling_Hash() {
		v.clear();
	}
	void process(const char* str, int n, int width) {
		if (width > n) { return; }
		v.resize(n - width + 1);
		ll p1 = 0, p2 = 0;
		ll t1 = 1, t2 = 1;
		{
			ll k = width;
			ll d1 = digit1;
			ll d2 = digit2;
			while (k > 0) {
				if (k & 1) {
					t1 *= d1;
					t1 %= mod1;
					t2 *= d2;
					t2 %= mod2;
				}
				k /= 2;
				d1 = (d1 * d1) % mod1;
				d2 = (d2 * d2) % mod2;
			}
		}
		for (int i = 0; i < width; i++) {
			p1 *= digit1; p1 += str[i]; p1 %= mod1;
			p2 *= digit2; p2 += str[i]; p2 %= mod2;
		}
		int j = 0;
		v[j] = (p1 << 30) + p2; j++;
		for (int i = width; i < n; i++, j++) {
			p1 *= digit1; p1 += str[i] - str[i - width] * t1; p1 %= mod1;
			p2 *= digit2; p2 += str[i] - str[i - width] * t2; p2 %= mod2;
			if (p1 < 0) { p1 += mod1; }
			if (p2 < 0) { p2 += mod2; }
			v[j] = (p1 << 30) + p2;
		}
	}
	void process(string S, int width) {
		process(S.c_str(), S.length(), width);
	}

private:
	const ll digit1 = 10007LL;
	const ll digit2 = 10009LL;
	const ll mod1 = 1000000007LL;
	const ll mod2 = 1000000009LL;

public:
	vector<ll> v;
};

int main() {
	string S0, T; cin >> S0 >> T;
	int N = S0.size();
	int M = T.size();
	string S = S0;
	while (S.size() < N + M) {
		S += S0;
	}
	Rolling_Hash R; R.process(S, M);
	Rolling_Hash R0; R0.process(T, M);

	vector<bool> f1, f2;
	for (int i = 0; i < N; i++) {
		f1.push_back(R.v[i] == R0.v[0]);
		f2.push_back(false);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (f2[i] == true) { continue; }
		if (f1[i] == true) {
			int c = 0;
			int j = i;
			while (f1[j] == true && c <= N) {
				j = (j - M) % N;
				if (j < 0) { j += N; }
				c++;
			}
			if(c == N + 1){
				ans = -1;
				break;
			}
			j = (j + M) % N;
			c = 0;
			for (; f1[j] == true; j = (j + M) % N) {
				c++;
				f2[j] = true;
			}
			ans = max(ans, c);
		}
		f2[i] = true;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10676
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main (){
    int N;
    cin >> N;
    vector<int> X;
    int X_i;
    for (int i=0; i<N; i++){
        cin >> X_i;
        X.push_back(X_i);
    };

    int min = *std::min_element(X.begin(), X.end());
    int max = *std::max_element(X.begin(), X.end());
    int sum = 0;
    int max_sum, k = 0;

    for(int l = 0; l < N; l++){
        max_sum += pow(X[l]-1,2);
    }

    for (int j = min; j <= max; j++){
        sum = 0;
        k = 0;
        while( sum <= max_sum && k < N){
            sum += pow(X[k]-j,2);
            k++;
        }
        
        if( k == N ) max_sum = std::min(sum, max_sum);
    }

    cout << max_sum << endl;

}

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

long long md = 1000000007ll;
long long n;
long long a[300003];
long long b[300003][62];
long long ans = 0ll;

int main(){

	for(long long i=0ll;i<61ll;i++)b[0][i] = 0ll;
	cin>>n;
	for(long long i=1ll;i<=n;i++){
		cin>>a[i];
		for(long long j=0ll;j<61ll;j++){
			if((a[i] & (1ll<<j)) != 0ll)b[i][j] = b[i-1][j]+1ll;
			else b[i][j] = b[i-1][j];
		}
	}
	for(long long i=1ll;i<n;i++){
		for(long long j=0ll;j<61ll;j++){
			// 0
			if((a[i] & (1ll<<j)) == 0ll){
				ans = (ans + (b[n][j]-b[i][j])*((1ll<<j)%md))%md;
			}
			// 1
			else{
				ans = (ans + ((n-i)-(b[n][j]-b[i][j]))*((1ll<<j)%md))%md;
			}
			//cout<<i<<" "<<j<<" "<<b[n][j]-b[i][j]<<endl;
			//cout<<ans<<endl;
		}
	}

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

Measured memory_bytes: 147840
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int s, w; cin >> s >> w;
    if (s <= w) {
        cout << "unsafe\n";
    } else {
        cout << "safe\n";
    }
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],cal[n];
    for(int i=0;i<n;i++){cal[i]=0;cin>>a[i];}
    for(int i=1;i<n;i++)
    {
        if(i-2>=0)cal[i]=min(abs(a[i]-a[i-1])+cal[i-1],abs(a[i]-a[i-2])+cal[i-2]);
        else cal[i]=abs(a[i]-a[i-1]+cal[i]);
    }
    cout<<cal[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	for(int m,n;scanf("%d%d",&m,&n),m||n;){
		int a[20001];
		rep(i,m+n)	scanf("%d",a+i);
		a[m+n]=0;

		sort(a,a+m+n+1);

		int dmax=0;
		rep(i,m+n)	dmax=max(dmax,a[i+1]-a[i]);
		printf("%d\n",dmax);
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll sm=0;
	int n,m; cin>>n>>m;
	int x;
	for(int i=0;i<m;i++)
	{
		cin>>x; sm+=x;
	}
	if(n-sm<0)
	{
		cout<<-1;
	}
	else
	
	{
		cout<<n-sm<<endl;
	}
	
}

Measured memory_bytes: 3624
#include<stdio.h>

int abs(int x) {
 if (x > 0) return x;
 else return (-1)*x;
}

int main(void) {
long int N;
scanf("%ld", &N);
int A[N];
for (int i = 0; i < N; i++) {
 scanf("%d", &A[i]);
}


//全て訪れた場合の総和
int fare = abs(A[0]);
for (int i = 0; i < N-1; i++) {
 fare += abs(A[i+1]-A[i]);
}
fare += abs(A[N-1]);

//i = 0 のとき
printf("%d\n", fare - abs(A[0]) - abs(A[1]-A[0]) + abs(A[1]));

//1 <= i <= N-2のとき
for (int i = 1; i < N-1; i++) {
 printf("%d\n", fare - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1] - A[i-1]));
}

//i = N-1 のとき
printf("%d\n", fare - abs(A[N-1]-A[N-2]) - abs(A[N-1]) + abs(A[N-2]));

 return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
    fast();
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<" "<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/big"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	line := strings.Split(sc.Text(), " ")
	a := []int{}
	for i := 0; i < n; i++ {
		ai, _ := strconv.Atoi(line[i])
		a = append(a, ai)
	}
	ans := solve(a)
	fmt.Printf(ans)
}

var max = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)

func solve(a []int) (ans string) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	sum := big.NewInt(1)
	for i := range a {
		ai := big.NewInt(int64(a[i]))
		sum.Mul(sum, ai)
		if sum.Cmp(max) == 1 {
			return "-1"
		}
	}
	return sum.String()
}


Measured memory_bytes: 13488
#include <cstdio>
#include <queue>
#include <vector>

typedef struct{
	std::vector<int> neighbors;
	int cluster;
} node;

void dfs(node* nodes, int id, int cluster){
	for (int i=0; i<nodes[id].neighbors.size(); i++){
		if (nodes[nodes[id].neighbors[i]].cluster == -1){
			nodes[nodes[id].neighbors[i]].cluster = cluster;
			dfs(nodes, nodes[id].neighbors[i], cluster);
		}
	}
}

int main(){
	int n, d, num_relation, n_query, s, t, cluster;
	node *nodes;

	scanf("%d %d", &n, &num_relation);
	nodes = new node[n];
	for (int i=0; i<n;i++){
		nodes[i].cluster = -1;
	}
	for(int i=0;i<num_relation;i++){
		scanf("%d %d", &s, &t);
		nodes[s].neighbors.push_back(t);
		nodes[t].neighbors.push_back(s);
	}
	cluster = -1;
	for (int i=0;i<n;i++){
		cluster ++;
		if (nodes[i].cluster == -1) dfs(nodes, i, cluster);
	}
	scanf("%d", &n_query);
	for(int i=0;i<n_query;i++){
		scanf("%d %d", &s, &t);
		if (nodes[s].cluster != -1 && nodes[s].cluster != -1 && nodes[s].cluster == nodes[t].cluster) printf("yes\n");
		else printf("no\n");

	}

	delete []nodes;
	return 0;
}

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

void solve(long long N, std::string S){
    ll cnt_e = 0;
    for(ll i = 0; i < N; ++i) if(S[i] == 'E') cnt_e++;
    //cout << cnt_e << endl;
    vector<ll> cnt(N, cnt_e);
    for(ll i = 0; i < N; ++i){
        if(i > 0) cnt[i] = cnt[i-1];
        if(S[i] == 'E') cnt[i]--;
        if(i > 0 && S[i-1] == 'W') cnt[i]++;
    }
    //for(auto i : cnt) cout << i << " ";
    //cout << endl;
    ll ans = 1e18;
    for(ll i = 0; i < N; ++i) ans = min(ans, cnt[i]);
    cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 6488
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n, m = readInts()
    # mが成功する確率は(1/2)^mであるから、期待値は
    # ACするまでに施行する回数の期待値は、2^m
    # 普通のプログラムは、
    # 1900M + 100(N - M)ms かかることから、
    # 2^m * (1900M + 100(N-M))
    AC = (1 << m) # 2^m
    Expect = 1900 * m + 100 * (n-m)
    print(AC * Expect)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5276
#include<cstdio>

int main()
{
	int n,cnt1=0,cnt2=0;
	long long a;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		if(a%4==0) cnt1++;
		if(a%4==2) cnt2++;
	}
	n-=(cnt2/2)*2;
	if(n/2<=cnt1) printf("Yes");
	else printf("No");
	return 0;
}

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

int main() 
{
    int ans=0;
    int N; cin >> N;
    string S; cin >> S;
    
    for (int i = 1; i < S.length()-1; i++) 
    {
        int cur_ans = 0;
        map<char, int> m1, m2;
        for (int j = 0; j < i; j++) 
        {
            m1[S[j]]++;
        }
        for (int j = i; j < S.length(); j++) 
        {
            m2[S[j]]++;
        }
        
        for (auto i = m1.begin(); i != m1.end(); i++) 
        {
            if (m2.find(i->first) != m2.end()) cur_ans++;
        }
        ans = max(ans, cur_ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int N,M,i;
  char arr[52];
  scanf("%d %d",&N,&M);
  for(i=1;i<=N;i++)
    scanf(" %c",&arr[i]);
  arr[i] = 0;
  arr[M] = arr[M] - 'A' + 'a';
  printf("%s\n",arr+1);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int r = fs.nextInt();
		
		System.out.println((double)(2*r) * Math.PI);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 33184
n, x = gets.split.map(&:to_i)
l = gets.split.map(&:to_i)

count = l.each_with_index.inject(0) do |c, (l_i, i)|
  break i + 1 if c + l_i > x
  c + l_i
end

puts count > n + 1 ? n + 1 : count

Measured memory_bytes: 1916
from sys import stdin
input = stdin.readline

n = int(input())
dic = {}
A = list(map(int, input().split()))
for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1
nums = list(dic.items())
nums.sort(reverse = True)
l = len(nums)
l1 = 0
for i in range(l):
    if l1 == 0 and nums[i][1] >= 4:
        ans = nums[i][0]**2
        break
    elif l1 == 0 and nums[i][1] >= 2:
        l1 = nums[i][0]
    elif l1 > 0 and nums[i][1] >= 2:
        ans = l1*nums[i][0]
        break
else:
    ans = 0
print(ans)
        

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

class TopologicalSort {
    int V;
    vector <vector<int>> G;
    vector <bool> used;
    vector <int> indeg; // 入次数
    vector <int> ret;

    void bfs(int s) {
        queue<int> q;
        q.push(s);
        used[s] = 1;
        while (!q.empty()) {
            int cur = q.front(); q.pop();
            ret.push_back(cur);
            for (int to : G[cur]) {
                indeg[to]--;
                if (indeg[to] == 0 && !used[to]) {
                    used[to] = 1;
                    q.push(to);
                }
            }
        }
    }

public:
    TopologicalSort(vector<vector<int>> &edge) {
        V = edge.size();
        G = edge;
        used.assign(V, false);
        indeg.assign(V, 0);
    }

    vector<int> build() {
        for (int i = 0; i < V; i++) for (int v : G[i]) indeg[v]++;
        for (int i = 0; i < V; i++) if (indeg[i] == 0 && !used[i]) bfs(i);
        return ret;
    }

    bool isDAG() {
        return ret.size() == V;
    }
};


// verified
//   https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/4/GRL_4_A
void AOJ_GRL_4_A() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> edge(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        edge[s].push_back(t);
    }
    TopologicalSort ts(edge);
    ts.build();
    cout << (ts.isDAG() ? 0 : 1) << '\n';
}


// verified
//   https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/4/GRL_4_B
void AOJ_GRL_4_B() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> edge(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        edge[s].push_back(t);
    }
    TopologicalSort ts(edge);
    vector <int> dag = ts.build();
    for (int i : dag) cout << i << '\n';
}

int main() {
    AOJ_GRL_4_A();
    // AOJ_GRL_4_B();
    return 0;
}


Measured memory_bytes: 3168
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var A = ReadLong();
            var B = ReadLong();
            var C = ReadLong();
            var X = ReadLong();

            var count = 0L;
            for (int a = 0; a <= A; a++)
            {
                for (int b = 0; b <= B; b++)
                {
                    for (int c = 0; c <= C; c++)
                    {
                        if (X == 500 * a + 100 * b + 50 * c)
                        {
                            count++;
                        }
                    }
                }
            }


            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27536
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  int n, m;
  cin >> n >> m;
  priority_queue<ll> a;
  REP(i, n){
    ll x;
    cin >> x;
    a.push(x);
  }
  REP(i, m) {
    ll x = a.top();
    a.pop();
    a.push(x / 2);
  }
  ll ans = 0;
  while (!a.empty())
  {
    ans += a.top();
    a.pop();
  }
  cout << ans << endl;
  return 0;
}


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

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

    ll x, y; cin >> x >> y;

    ll ans = 0;
    if (x % y == 0) ans = -1;
    else {
        for (ll i = x; i <= (ll)1e18; i += x)
            if (i % y) {
                ans = i;
                break ;
            }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll dp[100001][2];

signed main(){
	string l; cin>>l; int n=l.size();
	dp[0][0]=1;
	rep(i,n){
		dp[i+1][1]+=dp[i][1]*3%MOD;
		if(l[i]=='0'){
			dp[i+1][0]+=dp[i][0]%MOD;
		}else{
			dp[i+1][0]+=dp[i][0]*2%MOD;
			dp[i+1][1]+=dp[i][0]%MOD;
		}
	}
	cout<<(dp[n][0]+dp[n][1])%MOD<<endl;
	return 0;
}


Measured memory_bytes: 2000
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
//namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)

#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N),b(N);
    FORi(N) { cin >> a[i]; }
    FORi(N) { 
        ll ii = N - i;//N->1
        ll sum = 0;//ここを0ととりあえず仮定
        for(int j = ii * 2; j <= N;j += ii){
            sum += b[j-1];
        }
        if(sum%2==a[ii-1]){
            b[ii-1] = 0;
        }else{
            b[ii - 1] = 1;
        }
    }
    ll M = 0;
    FORi(N) { M += b[i]; }
    cout << M << endl;
    FORi(N){
        if(b[i]!=0){
            cout << i + 1<<" ";
        }
    }
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a % 2 == 0) a = (a / 2) * (a / 2);
  else a = (a / 2) * ((a / 2) + 1);
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] card = new int[N];
	for(int i = 0; i < N; i++){
	    card[i] = sc.nextInt();
	}
	Arrays.sort(card);

	int Alice = 0;
	int Bob = 0;
	for(int i = (N - 1); i >= 0; i -= 2){
	    Alice += card[i];
	}
	for(int i = (N - 2); i >= 0; i -= 2){
	    Bob += card[i];
	}
	System.out.print(Alice - Bob);
    }
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  int b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    b[i] = a[i];
  }
  sort(a,a+n,greater<>());
  for(int i=0;i<n;i++){
    if(a[0] == b[i]) cout << a[1] << endl;
    else cout << a[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include<iostream>

using namespace std;

int main(){
  long long int N;
  int A[15];
  cin >> N;
  N--;
  for(int i = 0;i < 15;i++){
    if(N < 0){A[i] = -1;}
    else{
      A[i] = (int)(N%26ll);
      N = N/26ll-1;
    }
  }
  for(int i = 14;i >= 0;i--){
    if(A[i] >= 0){
      cout << char('a'+A[i]);
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3656
import           Control.Monad
import qualified Data.ByteString.Lazy.Char8 as B
import           Data.Char
import           Data.List

main :: IO ()
main = do
    [n, c, k] <- map read . words <$> getLine
    ts <- sort . unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getContents
    print $ solve c k ts

solve :: Int -> Int -> [Int] -> Int
solve c k [] = 0
solve c k ts@(t:ts0) = 1 + solve c k (us2 ++ ts2)
    where
        (ts1, ts2) = span (<= t + k) ts
        (us1, us2) = splitAt c ts1

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

class Item{
   int val, weight;
   public Item(int weight, int val){
      this.weight = weight;
      this.val = val;
   }
   
}
public class Main {
   public static void main(String[]abc) {
      Main ans = new Main();
      long solution = ans.solve();
      System.out.println(solution);
   }
   private long solve() {
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int maxWeight = sc.nextInt();
      // max value of an item is 10000
      int maxValue = N*1000;
      Item [] array = new Item[N+1];
      for(int i=1;i<=N;i++){
         array[i] = new Item(sc.nextInt(),sc.nextInt());
      }
      long [][] dp = new long[(N+1)][maxValue+1];
      long INF = (long) 1e9+1;
	  for(int val=0;val<=maxValue;val++){
         dp[1][val] = INF;
      }
      dp[1][array[1].val]= array[1].weight;
      dp[1][0] = 0;
      for(int i=2;i<=N;i++){
         for(int val=0;val<=maxValue;val++){
            dp[i][val] = dp[i-1][val];
            if (array[i].val>val) continue;
            dp[i][val] = Math.min(dp[i][val], array[i].weight + dp[i-1][val-array[i].val]);
         }
      }
      long bestVal=0;
      for(int val=0;val<=maxValue;val++){
         if (dp[N][val]<=maxWeight) bestVal = Math.max(bestVal, val);
      }
      return bestVal;
	       
   }
}


Measured memory_bytes: 140220
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
H,W = map(int,input().split())
S = [input().rstrip() for _ in range(H)]

for h in range(H):
    for w in range(W):
        # 白マスなら次へ
        if S[h][w]==".":
            continue
        # 黒マスなら上下左右に黒マスが1つでもあれば ok, なければ ng
        flg = False
        for dh,dw in [(1,0), (-1,0), (0,1), (0,-1)]:
            nh = h+dh
            nw = w+dw
            if 0 <= nh < H and 0 <= nw < W:
                if S[nh][nw] == "#":
                    flg = True
                    break
        if not flg:
            print("No")
            sys.exit()

print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

void failure () {
  cout << "No" << endl;
  exit(0);
}

const int MAX_N = 1e5 + 5;

int grid [3][MAX_N];

int arr [MAX_N];
int flip [MAX_N];

int parity (vector<int> perm) {
  int n = perm.size();
  vector<int> vis (n, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      int u = i;
      int len = 0;
      do {
        vis[u] = 1;
        len++;
        u = perm[u];
      } while (u != i);
      if (len % 2 == 0) ans ^= 1;
    }
  }
  return ans;
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      cin >> grid[i][j];
      grid[i][j]--;
    }
  }

  for (int i = 0; i < n; i++) {
    int mn = min(grid[0][i], min(grid[1][i], grid[2][i]));
    if (mn % 3 != 0) {
      failure();
    }

    arr[i] = mn / 3;
    if (grid[0][i] < grid[1][i] && grid[1][i] < grid[2][i]) {
      if (grid[1][i] != mn + 1 || grid[2][i] != mn + 2) failure();
      flip[i] = 0;
    } else if (grid[2][i] < grid[1][i] && grid[1][i] < grid[0][i]) {
      if (grid[1][i] != mn + 1 || grid[0][i] != mn + 2) failure();
      flip[i] = 1;
    } else {
      failure();
    }
  }

  vector<int> evs;
  int evc = 0;
  for (int i = 0; i < n; i += 2) {
    if (arr[i] % 2 != 0) {
      failure();
    }
    evs.push_back(arr[i] / 2);
    evc ^= flip[i];
  }

  vector<int> ods;
  int odc = 0;
  for (int i = 1; i < n; i += 2) {
    if (arr[i] % 2 != 1) {
      failure();
    }
    ods.push_back(arr[i] / 2);
    odc ^= flip[i];
  }

  int evp = parity(evs);
  int odp = parity(ods);

  if (evp == odc && odp == evc) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int n,s[200009];
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",s+i);
	map<int,int>mp;
	for(int i=0;i<n;i++)
		if(mp[s[i]]!=0) {
			printf("NO\n");
			return 0;
		}
		else mp[s[i]]=1;
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

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

template <typename T>
struct SegmentTree {
 private:
  ll n;            //最下段のサイズ
  T e;             //単位元
  vector<T> node;  //セグメント木を表現する配列
  typedef function<T(T, T)> Func;
  Func f;  //区間クエリで使う処理

 public:
  SegmentTree(vector<T> v, Func f_input, T e_input) {
    f = f_input;
    e = e_input;
    ll sz = SZ(v);
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, e);
    REP(i, sz) node[i + n - 1] = v[i];
    IREP(i, n - 1) node[i] = f(node[2 * i + 1], node[2 * i + 2]);
  }

  // x番目(0-indexed)の要素をvalに更新する
  void update(ll x, T val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = f(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // [a, b) に対する区間クエリに答える
  // k := 自分がいるノードのインデックス
  // [l, r) : ノードkの対象区間
  T query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }

  // 添字でアクセス
  T operator[](ll i) { return node[i + n - 1]; }
};

int main() {
  ll n;
  cin >> n;
  vector<ll> h(n), a(n);
  REP(i, n) {
    cin >> h[i];
    h[i]--;
  }
  REP(i, n) { cin >> a[i]; }
  vector<ll> dp(n, 0);

  SegmentTree<ll> sg(
      dp, [](ll i, ll j) { return max(i, j); }, 0LL);

  REP(i, n) { sg.update(h[i], max(sg[h[i]], sg.query(0, h[i]) + a[i])); }

  ll ans = 0;
  REP(i, n) { chmax(ans, sg[i]); }
  cout << ans << endl;
}

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

#define      ll     long long int

const int N = 100005;
int A[N];
int B[N];
int C[N];

int main()
{
    ll n, i, j, k, l;
    ll s = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> A[i];
    }
    sort(A, A + n);
    for (i = 0; i < n; i++) {
        cin >> B[i];
    }
    sort(B, B + n);
    for (i = 0; i < n; i++) {
        cin >> C[i];
    }
    sort(C, C + n);
    for (i = 0; i < n; i++) {
        j = B[i];
        k = (int) (lower_bound(A, A + n, j) - A);
        l = (int) (upper_bound(C, C + n, j) - C);
        l = n - l;
        //cout << j << ' ' << k << ' ' << l << '\n';
        s += (k * l);
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 998244353
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;

#define endl '\n'
#define int ll

int dp[3001][3001];
int dp1[3001][3001];

signed main() {
    fast;

    int n,s;
    cin>>n>>s;

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

    dp[0][0] = 1;

    for(int i=1;i<=n;i++) {
        for(int j=0;j<=s;j++) dp[i][j] = dp[i-1][j];
        for(int j=0;j<=s;j++) {
            if(j-a[i-1]>=0) {
                dp[i][j] += dp[i-1][j-a[i-1]];
                dp[i][j] %= MOD;
            }
        }
    }

    int ans = 0;

    for(int i=n;i>0;i--) {
        if(s-a[i-1]>0) {
            dp1[i-1][s-a[i-1]] += (n+1-i);
            dp1[i-1][s-a[i-1]] %= MOD;
        }
        else if(s-a[i-1]==0) {
            ans += (n+1-i)*(i);
            ans %= MOD;
        }

        for(int j=s-1;j>0;j--) {
            if(dp1[i][j]==0) continue;

            if(j-a[i-1]>0) {
                dp1[i-1][j-a[i-1]] += dp1[i][j];
                dp1[i-1][j-a[i-1]] %= MOD;
            }
            else if(j-a[i-1]==0) {
                ans += dp1[i][j]*(i);
                ans %= MOD;
            }

            dp1[i-1][j] += dp1[i][j];
            dp1[i-1][j] %= MOD;
        }
    }

    cout<<ans;

}

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

int main(){
  int i;
  char s[3];
  for(i=0;i<3;i++){
    cin>>s[i];
  }
  sort(s,s+3);
  cout<<(s[0]=='a'&&s[1]=='b'&&s[2]=='c'?"Yes":"No");
  
}

Measured memory_bytes: 256