akhauriyash/Code-Regression huggingface dataset:
// @Author :- Gaurav Bharti
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test int t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b) {
	return (a.second < b.second) ;
}

ll binpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b&1) res = res * a;
		a = a*a;
		b = b >> 1;
	}

	return res;
}


/*
BHAI EFFORT DAAL
*/


int main(){
	ItsFUN;

	string s; cin >> s;
	int 	n = s.length();

	if(s[n-1] != 's') {
		cout << s;
		cout <<"s";
	}
	else if(s[n-1]=='s') {
		cout << s;
		cout <<"es";
	}
	return 0;
}




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

const int N = 2e+5 + 5;
long long int a[N], n, s[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    long long int ans = 1e+18;
    for (int i = 2; i < n; i++)
    {
        long long int sl = s[i] - s[0], sr = s[n] - s[i];
        int ir = upper_bound(s + 1, s + n + 1, s[i] + sr / 2) - s;
        int il = upper_bound(s + 1, s + n + 1, sl / 2) - s;
        int ill = il, irr = ir;
        for (int k = -1; k <= 1; k++)
            for (int g = -1; g <= 1; g++)
            {
                il = ill + k, ir = irr + g;
                long long int p = max(max(s[il], s[i] - s[il]), max(s[ir] - s[i], s[n] - s[ir]));
                long long int q = min(min(s[il], s[i] - s[il]), min(s[ir] - s[i], s[n] - s[ir]));
                ans = min(ans, abs(p - q));
            }
    }
    cout << ans;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vi v(7368792, 0);
	while (1) {
		int m, n;
		cin >> m >> n;
		if (!m)break;
		int cnt = 0;
		FOR(i, m, v.size()) {
			if (!v[i]) {
				cnt++;
				for (int j = 1; j*i < v.size(); ++j)v[j*i] = 1;
			}
			if (cnt==n)break;
		}
		FOR(i,m, v.size()) {
			if (!v[i]) {
				cout << i << endl;
				break;
			}
		}
		REP(i, v.size())v[i] = 0;
	}
	return 0;
}

Measured memory_bytes: 31452
import math

while True:
    n = int(input())  # 生徒の数
    if n == 0:
        break
    s = list(map(int, input().split()))  # 生徒の点数リスト

    # 平均値を求める
    sum = 0
    for i in s:
        sum += i
    m = sum / n

    # 分散を求める
    a = 0
    for i in s:
        a += (i - m) ** 2
    a /= n

    print(math.sqrt(a))


Measured memory_bytes: 5700
//
//  main.cpp
//  oct_18 17 Code Festival QualB  C
//
//  Created by Shuangyi Zhang on 10/18/17.
//  Copyright © 2017 Shuangyi Zhang. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
vector<vector<long long>> g(100005);
long long n,m,a,b;
int used[100005];
int main() {
    cin>>n>>m;
    for (int i=1;i<=m;i++){
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i=1;i<=n;i++){
        used[i]=0;
    }
    queue<long long> q;
    q.push(1);
    used[1]=1;
    while (!q.empty()){
        long long x=q.front();
        q.pop();
        for (auto v:g[x]){
            if (used[v]==0){
                q.push(v);
                used[v]=-used[x];
            }else if (used[v]==used[x]){
                long long ans=(n-1)*n/2-m;
                printf("%lld",ans);
                return 0;
            }
        }
        
    }
    long long res1=0,res2=0;
    for (int i=1;i<=n;i++){
        if (used[i]==1){
            res1++;
        }else res2++;
    }
    printf("%lld",res1*res2-m);
    return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <math.h>
#include <iomanip>

typedef long long ll;
using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    int my_sum = l * n + (n*(n-1))/2;
    bool cnd = true;
    for (int i=0; i<n; ++i){
        if (l + i >= 0){
            cnd = false;
            my_sum -= (l+i);
            break;
        }
    }
    if(cnd) my_sum -= l + n - 1;
    cout << my_sum << endl;
    return 0;
}


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

//#define scanf scanf_s

const int kMaxSquare = 64;
const int kMaxMoney = 5100;
const int kMaxGainMoney = 100;

int roulette[4];

typedef struct{
	int type;
	int value;
} BoardState;

BoardState board[kMaxSquare];

int bp(int X, int Y){
	float bp[kMaxSquare][kMaxMoney];
	float prob = 1.0f / static_cast<float>(X);

  for(int n = 0; n <= Y; n++)
    for(int m = 0; m <= Y*kMaxGainMoney; m++)
      bp[n][m] = 0.0f;
  bp[0][0] = 1.0f;
	for (int n = 0; n < Y; n++){
    int mmax = n * kMaxGainMoney;
    for (int m = 0; m <= mmax; m++){
      if(bp[n][m] == 0.0f) continue;
			for (int k = 0; k < X; k++){
        int pos = std::min(n+roulette[k], Y);
				if (board[pos].type == 1)
          bp[std::min(pos + board[pos].value, Y)][m] += bp[n][m] * prob;
				else if (board[pos].type == 2)
					bp[pos][m + board[pos].value] += bp[n][m]* prob;
				else if (board[pos].type == 3)
          bp[pos][std::max(m - board[pos].value, 0)] += bp[n][m] * prob;
				else
					bp[pos][m] += bp[n][m] * prob;
			}
		}
	}

	float res = 0.0f;
  int mmax = Y * kMaxGainMoney;
  for (int m = 0; m <= mmax; m++)
		res += static_cast<float>(m) * bp[Y][m];
	return static_cast<int>(res);
}

int main(){
	while (1){
		int X, Y, Z;
		scanf("%d %d %d", &X, &Y, &Z);
		if (X == 0) return 0;
		for (int i = 0; i < X; i++)
			scanf("%d", &roulette[i]);
		for (int i = 0; i < kMaxSquare; i++)
			board[i] = { 0, 0 };
		for (; Z > 0; Z--){
			int N, E, A;
			scanf("%d %d %d", &N, &E, &A);
			board[N] = { E, A };
		}
		printf("%d\n", bp(X, Y));
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	ll N;
	cin >> N;
	map<ll,ll> input;

	ll ans = 0;

	for (int i = 0; i < N; i++) {
		ll tmp;
		cin >> tmp;
		ans += tmp;

		//要素の検索
		map<ll,ll>::iterator ite;
		ite = input.find(tmp);
		if (ite != input.end()) {
			//値の取得
			ll value = ite->second;
			//要素の削除
			input.erase(tmp);
			//要素の代入
			input.insert(make_pair(tmp, value + 1));
		}
		else {
			//要素の代入
			input[tmp] = 1;
		}

	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		ll B, C;
		cin >> B >> C;

		//要素の検索
		map<ll,ll>::iterator ite;
		ite = input.find(B);
		if (ite != input.end()) {
			// Bが存在するときののみ処理
			//値の取得
			ll valueB = ite->second;
			//要素の削除
			input.erase(B);
			//要素の代入
			input.insert(make_pair(B, 0));
			ans += (C - B) * valueB;

			ite = input.find(C);
			if (ite != input.end()) {
				// Cが存在するときの処理
				//値の取得
				ll valueC = ite->second;
				//要素の削除
				input.erase(C);
				//要素の代入
				input.insert(make_pair(C, valueB + valueC));
			}
			else {
				input.insert(make_pair(C, valueB));
			}
		}
		cout << ans << endl;
	}

	return 0;

}


Measured memory_bytes: 8692
n, d = map(int, input().split())
x = list(list(map(int, input().split())) for _ in range(n))

ans = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        dist = sum((x-y)**2 for x, y in zip(x[i], x[j]))**0.5
        if dist.is_integer(): ans += 1

print(ans)




Measured memory_bytes: 9440
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
#endif

  ll n;
  cin>>n;
  ll sum=0;
  for(ll i=1;i<=n;i++)
  {
    for(ll j=1;j<=n;j++)
    {
      for(ll k=1;k<=n;k++)
      {
        sum+=__gcd(i,__gcd(j,k));
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int n;
	cin >> n;
	vector<int> s(n);
	rep(i, n) cin >> s.at(i);
	sort(s.begin(), s.end());

	int sum = 0;
	rep(i, n) {
		sum += s.at(i);
	}
	int cnt = 0;
	rep(i, n) {
		if (sum % 10 != 0) {
			break;
		}
		if (s.at(i) % 10 != 0) {
			sum -= s.at(i);
			break;
		}
		if (i == (n - 1)) {
			sum = 0;
			break;
		}
	}
	cout << sum << endl;


	return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "vector"
#define ll long long int
using namespace std;
bool prime(int n)
{
    if(n<=1) return false;
    
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0) return false;
    }
    return true;
}
int main() {

    int n;
    cin>>n;
    
   while(!prime(n))
   {
       n++;
   }
    
    cout<<n<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

#define data __Data

const int MAX_M = (int)1e5 + 77;

vector<ll> data[MAX_M];

void solve()
{
	int n, m;
	cin >> n >> m;

	for(int ind = 0; ind < n; ++ind)
	{
		int a, b;
		cin >> a >> b;

		int cost = b;
		int max_pos = m - a;		

		if(max_pos >= 0)
			data[max_pos].push_back(cost);
	}

	for(int i = 0; i < MAX_M; ++i)
		sort(data[i].rbegin(), data[i].rend());

	multiset<ll> answ;

	for(int pos = 0; pos < MAX_M; ++pos)
	{
		if(data[pos].empty())
			continue;

		//cout << pos << " -> " << data[pos] << endl;

		for(auto& x: data[pos])
		{
			if(len(answ) <= pos)
			{
				answ.insert(x);
			}
			else
			{
				auto last = answ.begin();

				if(x > *last)
				{
					answ.erase(last);
					answ.insert(x);
				}
			}
		}
	}

	ll total = 0;

	for(auto& x: answ)
		total += x;

	cout << total << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 10112
s = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(int(input())):
    v = input()
    s[v] += 1
print("AC x", s["AC"])
print("WA x", s["WA"])
print("TLE x", s["TLE"])
print("RE x", s["RE"])


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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, r = 0; cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    vector<ll> s(n), d(n);
    for (int i = 0; i < n; i++) {
        s[i] = x[i] + y[i];
        d[i] = x[i] - y[i];
    }
    sort(s.begin(), s.end());
    sort(d.begin(), d.end());
    cout << max(s[n - 1] - s[0], d[n - 1] - d[0]) << endl;
    return 0;
}


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

int main() {
    int64_t R, C, K;
    cin >> R >> C >> K;

    vector<int64_t> r(K), c(K), v(K);
    for (int64_t i = 0; i < K; i++) {
        cin >> r[i] >> c[i] >> v[i];
        r[i]--;
        c[i]--;
    }

    vector<vector<int64_t>> value(R, vector<int64_t>(C, 0));
    for (int64_t i = 0; i < K; i++) {
        value[r[i]][c[i]] = v[i];
    }

    //dp[i][j][k] := (i, j)で残り拾える個数がkであるときの場合の数
    vector<vector<vector<int64_t>>> dp(R + 1, vector<vector<int64_t>>(C + 1, vector<int64_t>(4, 0)));

    for (int64_t i = 0; i < R; i++) {
        for (int64_t j = 0; j < C; j++) {
            for (int64_t k = 0; k <= 3; k++) {
                if (k > 0) {
                    //拾って右へ
                    dp[i][j + 1][k - 1] = max(dp[i][j + 1][k - 1], dp[i][j][k] + value[i][j]);
                    //拾って下へ
                    dp[i + 1][j][3] = max(dp[i + 1][j][3], dp[i][j][k] + value[i][j]);
                }

                //拾わず右へ
                dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                //拾わず下へ
                dp[i + 1][j][3] = max(dp[i + 1][j][3], dp[i][j][k]);
            }
        }
    }

    int64_t ans = 0;
    for (int64_t i = 0; i <= 3; i++) {
        ans = max(ans, dp[R - 1][C - 1][i]);
        ans = max(ans, dp[R][C - 1][i]);
        ans = max(ans, dp[R - 1][C][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 711284
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, int> p;
int main() {
	int n;
	while (cin >> n, n) {
		p a[30];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i].second >> a[i].first;
			sum += a[i].second;
		}
		sort(a, a + n);
		for (int i = n - 1; i >= 0; i--) {
			if (sum <= a[i].first) {
				sum -= a[i].second;
			}
			else{
				cout << "No\n";
				goto heaven;
			}
		}
		cout << "Yes\n";
		heaven:;
	}
}


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

hlist=[]
for i in range(N):
  hi=int(input())
  hlist.append(hi)
  
hlist.sort()
#print(hlist)

min_diff=10**10
for i in range(K-1,N):
  min_diff=min(min_diff,hlist[i]-hlist[i-K+1])
  
print(min_diff)

Measured memory_bytes: 7384
n=int(input())
p=input().split()
count=0
for i in range(0,n-2):
    if int(p[i])<int(p[i+1]):
        if int(p[i+1])<int(p[i+2]):
            count+=1
    elif int(p[i])>int(p[i+1]):
        if int(p[i+1])>int(p[i+2]):
            count+=1
print(count)


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

int H, W;

char grid[2001][2001];
int C[2001][2001];

int main() {
  cin >> H >> W;

  rep(i, H) scanf("%s", grid[i]);

  rep(i, H) {
    int l = 1, r = 1;
    rep(j, W) {
      if (grid[i][j] == '#') l = 0;
      C[i][j] += l++;
      if (grid[i][W - 1 - j] == '#') r = 0;
      C[i][W - 1 - j] += r++;
    }
  }

  rep(j, W) {
    int u = 1, d = 1;
    rep(i, H) {
      if (grid[i][j] == '#') u = 0;
      C[i][j] += u++;
      if (grid[H - 1 - i][j] == '#') d = 0;
      C[H - 1 - i][j] += d++;
    }
  }

  int ans = 0;
  rep(i, H) rep(j, W) {
    if (grid[i][j] == '#') continue;
    ans = max(ans, C[i][j] - 3);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 19840
#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int MOD = 998244353;

struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((MOD+x)%MOD) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= MOD;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = MOD - 2;
        mint u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

//pow
template<typename T, typename U>
T pow(T k, U n, T unity = 1) {
    while (n > 0) {
        if (n & 1) {
            unity *= k;
        }
        k *= k;
        n >>= 1;
    }
    return unity;
}

// comb (前計算O(NlogMOD) クエリO(1))
struct Combination {
private:
    int N;
    vector< mint > FACT, IFACT;

    // pow
    mint pow(mint k, ll n) {
        mint res = 1;
        while (n > 0) {
            if (n & 1) {
                res *= k;
            }
            k *= k;
            n >>= 1;
        }
        return res;
    }

public:
    // nCk
    Combination(int n) : N(n) {
        FACT.resize(n + 1);
        IFACT.resize(n + 1);
        FACT[0] = 1;
        IFACT[0] = 1;
        for (int i = 1; i <= n; i++) {
            FACT[i] = FACT[i - 1] * i;
            IFACT[i] = pow(FACT[i], MOD - 2);
        }
    }

    mint comb(int n, int r) {
        if (n < 0 || r < 0 || r > n) return 0;
        if (r > n / 2) r = n - r;
        return FACT[n] * IFACT[n - r] * IFACT[r];
    }
};

int main() {
    int n,m,k;cin >> n >> m >> k;
    mint ans = 0;
    Combination cb(n-1);
    for (int i = 0; i <= k; i++) {
        ans += mint(m) * pow(mint(m - 1),n-1-i) * cb.comb(n-1,i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6364
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn gcd(a: u32, b: u32) -> u32 {
    assert!(a != 0 || b != 0);
    if a == 0 {
        b
    } else {
        gcd(b % a, a)
    }
}

fn lcm(a: u32, b: u32) -> u32 {
    a * b / gcd(a, b)
}

fn main() {
    let _n: u8 = read();
    let nums: Vec<u32> = read_vec();
    // &head に注意
    if let Some((&head, tail)) = nums.split_first() {
        // &b に注意
        println!("{}", tail.iter().fold(head, |a, &b| lcm(a, b)));
    }
}



Measured memory_bytes: 5032
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

const int N = 100010;
int a[N];
int n, m;

int gcd_a()
{
	int v = __gcd(a[1], a[2]);
	for (int i = 3; i <= n; i ++)
		v = __gcd(v, a[i]);
	return v;
}

int main()
{
	scanf("%d%d", &n, &m);
	int maxx = 0;
	for (int i = 1; i <= n; i ++)
	{
		scanf("%d", &a[i]);
		maxx = max(a[i], maxx);
	}
	if (m > maxx || m % gcd_a() != 0)
	{
		puts("IMPOSSIBLE");
		return 0;
	}
	else
	{
		puts("POSSIBLE");
		return 0;
	}
}

Measured memory_bytes: 512
#include <stdio.h>

long min(long a,long b);
int main(){
	int i,j,n,w;
	long ans=0;
	scanf("%d %d",&n,&w);
	long dp[n+10][100010];//single,value->wight
	for(i=0;i<n+10;i++){
		for(j=0;j<100010;j++){
			if(i== 0 && j== 0){
				dp[i][j] = 0;
			}else{
				dp[i][j] = 10000000000; 
			}
		}
	}
	int wight[n+10],value[n+10];
	for(i=1;i<=n;i++){
		scanf("%d %d",&wight[i],&value[i]);
		for(j=100001;j>=0;j--){
			dp[i][j] = min(dp[i-1][j], dp[i][j+1]);

			if(j >= value[i]){
				dp[i][j] = min(dp[i][j], dp[i-1][j-value[i]] + wight[i]);
			}
		
		}
	}
	for(i=0;i<=100001;i++){
		if(dp[n][i]  <= w){
		ans=i;
	    }
	}
	
	printf("%ld\n",ans);

	return 0;
}
long min(long a,long b){
	if(a <b){
		return (a);
	}else{
		return (b);
	}
}

Measured memory_bytes: 86144
import java.awt.geom.Line2D.Double;
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	in.useDelimiter("(\\p{javaWhitespace}|,)+");
	Double line1=new Double();
	Double line2=new Double();
	while (in.hasNext()) {
	 line1.x1=in.nextDouble();
	 line1.y1=in.nextDouble();
	 line2.x1=in.nextDouble();
	 line2.y1=in.nextDouble();
	 line1.x2=in.nextDouble();
	 line1.y2=in.nextDouble();
	 line2.x2=in.nextDouble();
	 line2.y2=in.nextDouble();
		System.out.println((line1.intersectsLine(line2))?"YES":"NO");
	}
 }
}

Measured memory_bytes: 12000
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=sorted(set(X));l=len(s);return{s[i]:i for i in r(l)},s,l
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for i in r(L+1)]for _ in r(3)];q=[(h[0],w[0])];z=0
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
while q:
 x,y=q.pop();v[y][x]=1;z+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in(-1,0),(1,0),(0,1),(0,-1),:
  c=x+e;d=y+f
  if 1-v[d][c]and U[(f>0)+y][x]*f+V[y][(e>0)+x]*e==0:q+=(c,d),;v[d][c]=1
print([z,'INF'][z>F])

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

using namespace std;

#define mp make_pair
#define pb push_back
#define llong long long
#define usd unsigned
#define fn fill_n
typedef pair<int, int> P;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int h, w;
char area[50][50];


int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> area[i][j];
		}
	}

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			bool check = false;
			if(area[i][j] == '.') continue;
			for(int k = 0; k < 4; k++){
				int ih = i + nh[k];
				int iw = j + nw[k];
				if(ih < 0 || iw < 0 || ih >= h || iw >= w) continue;
				if(area[ih][iw] == '#') check = true;
			}
			if(check == false){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

alpha_list = "abcdefghijklmnopqrstuvwxyz"

ans = ""
moji_list = []
while(N != 0):
    tmp = N % 26
    
    if(tmp == 0):
        tmp = 26
    
    moji_list.append(alpha_list[tmp-1])

    N = (N - tmp) // 26

#print(moji_list)

for hoge in reversed(moji_list):
    ans += hoge

print(ans)

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

int abs(int x, int y) { return x > y ? x - y : y - x; }

int main(){
	vector<int> ansvec;
	for (;;){
		int n, m;
		cin >> n >> m;
		if (n == 0) break;

		multiset<int> tarocards;
		int tarosum = 0;
		for (int i = 0; i < n; i++){
			int s;
			cin >> s;
			tarocards.insert(s);
			tarosum += s;
		}
		multiset<int> hanakocards;
		int hanakosum = 0;
		for (int i = 0; i < m; i++){
			int s;
			cin >> s;
			hanakocards.insert(s);
			hanakosum += s;
		}

		if (abs(hanakosum - tarosum) % 2 == 1){
			ansvec.push_back(-1);
			continue;
		}

		int taroans = -1, hanakoans = -1;
		int tmpcardsum = 1000;
		for (auto it = tarocards.begin(); it != tarocards.end(); it++){
			int tmptaroans = *it;
			int tmphanakoans = hanakosum - tarosum + 2 * tmptaroans;
			tmphanakoans /= 2;
			if (hanakocards.count(tmphanakoans) > 0 && (tmptaroans + tmphanakoans) < tmpcardsum){
				taroans = tmptaroans;
				hanakoans = tmphanakoans;
				tmpcardsum = tmptaroans + tmphanakoans;
			}
		}

		if (taroans > 0){
			ansvec.push_back(taroans);
			ansvec.push_back(hanakoans);
		}
		else{
			ansvec.push_back(-1);
		}
	}
	
	for (auto it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it;
		if (*it != -1) cout << " " << *(++it);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
using namespace std;
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D)
		cout << "Left" << endl;
	else if (A + B == C + D)
		cout << "Balanced" << endl;
	else
		cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
 
int main(void){
    int N, ans=0;
    double dT=1000, T, A;
    std::cin >> N >> T >> A;
 
    for (int i=0; i<N; ++i){
        double h, tmp;
        std::cin >> h;
        tmp = T - 0.006 * h;
        if (dT > fabs(A - tmp)){
            dT = fabs(A - tmp);
            ans = i + 1;
        }
    }
 
    std::cout << ans << std::endl;
 
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


int main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	t = 1;

	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

ll calc(vi adj[], ll s, vector<ll> &dp)
{
	if (dp[s] != -1)
		return dp[s];

	bool leaf = 1;
	for (auto k : adj[s])
	{
		leaf = 0;
		dp[s] = max(dp[s], 1 + calc(adj, k, dp));
	}

	if (leaf == 1)
		dp[s] = 0;

	return dp[s];
}

void solve()
{
	ll n, m, i, u, v, ans = INT_MIN;
	cin >> n >> m;

	vi adj[n + 1];

	for (i = 0; i < m; i++)
	{
		cin >> u >> v;
		adj[u].pb(v);
	}

	vector<ll> dp(n + 1, -1);

	for (i = 1; i <= n; i++)
		ans = max(ans, calc(adj, i, dp));

	cout << ans << endl;

}


Measured memory_bytes: 11624
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <set>
#include <unordered_map>

using namespace std;
typedef long long ll;

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

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

    int y_m, y_p;
    y_m = y_p = x;

    for (int i = 0; i < 200; i++)
    {
        bool forbidden = false;
        for (size_t j = 0; j < n; j++)
        {
            if (y_m == p[j])
            {
                forbidden = true;
            }
        }
        if (forbidden == false)
        {
            break;
        }
        y_m--;
    }

    for (int i = 0; i < 200; i++)
    {
        bool forbidden = false;
        for (size_t j = 0; j < n; j++)
        {
            if (y_p == p[j])
            {
                forbidden = true;
            }
        }
        if (forbidden == false)
        {
            break;
        }
        y_p++;
    }

    if (abs(y_m - x) < abs(y_p - x))
    {
        cout << y_m;
    }
    else if (abs(y_m - x) > abs(y_p - x))
    {
        cout << y_p;
    }
    else
    {
        cout << min(y_m, y_p);
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define N 100005
using namespace std;

int n;
vector<int> a[N];

int f(int p) {
	int i, mx = 0;
	vector<int> b;
	for (i = 0; i < a[p].size(); i++) b.push_back(f(a[p][i]));
	sort(b.begin(), b.end());
	for (i = 0; i < b.size(); i++) mx = max(mx + 1, b[i]);
	return mx + 1;
}

int main()
{
	int i, t;
	cin >> n;
	for (i = 2; i <= n; i++) scanf("%d", &t), a[t].push_back(i);
    cout << f(1) - 1 << endl;
    return 0;
}

Measured memory_bytes: 13568
import java.util.Scanner; 
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		System.out.print( a*b+" " );
        System.out.println( a*2+b*2 );
		sc.close();

	}

}



Measured memory_bytes: 26072
k,a,b=map(int,input().split())
if b-a<=2:
  print(k+1)
else:
  if k<a+1:
    print(k+1)
  else:
    x=(k-a-1)//(2)
    y=k-a-1-x*(2)
    print((b-a)*(x)+b+y)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int r,g;
    cin>>r>>g;
    cout<<2*g-r<<endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int main(){
      int n; cin >> n ;
      if(n<=81){
      	bool ans = false ;
      	for(int i=1 ; i*i <= n ; i++){
      		  if(n%i==0 && i<=9 && (n/i)<=9)
      		    { 
                    cout << "Yes";
      		  	    ans = true ;
      		  	    break;
				} 
		  }
		  if(!ans) cout << "No" << endl;
	  }
	  else cout << "No" << endl;
}

Measured memory_bytes: 3592
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long[] data = new long[N];
        long[] original = new long[N];
        for (int i = 0; i < N; i++) {
            long x = scan.nextLong();
            data[i] = x;
            original[i] = x;
        }
        Arrays.sort(data);
        for (int i = 0; i < N; i++) {
            long base = original[i];
            long target = data[(N-1)/2];
            if (target < base) {
                System.out.println(target);
            } else {
                System.out.println(data[(N-1)/2 + 1]);
            }
        }
    }
}


Measured memory_bytes: 90724
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FDR(i,a,n) for(int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=105;
//Code begin....

int vis[N];

int main ()
{
    int a, b, c, d, ans=0;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    FOR(i,a,b-1) ++vis[i];
    FOR(i,c,d-1) ++vis[i];
    FOR(i,0,100) if (vis[i]==2) ++ans;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


class UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()),


def main():
    N, M, K = MI()
    uf = UnionFind(N+1)
    friends = {k: set() for k in range(1, N+1)}
    blocks = {k: set() for k in range(1, N+1)}
    # graph = [[] for i in range(N+1)]

    for i in range(M):
        A, B = MI()
        friends[A].add(B)
        friends[B].add(A)
        uf.union(A, B)

    for i in range(K):
        C, D = MI()
        blocks[C].add(D)
        blocks[D].add(C)

    # print(friends)
    # print(blocks)

    # groups = {k: set(g) for k, g in uf.all_group_members().items()}
    people = [0] * (N + 1)

    for i in range(1, N+1):
        people[i] = uf.size(i)

    ans = [0] * N
    for i in range(1, N+1):
        total_count = people[i]
        parent = uf.find(i)
        for block in blocks[i]:
            block_parent = uf.find(block)
            if block_parent == parent:
                total_count -= 1
        ans[i-1] = total_count - len(friends[i]) - 1

    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 124896
h,w=map(int,input().split())
b=[list("."*(w+2))]
for i in range(h):
  b.append(list("."+input()+"."))
b.append(list("."*(w+2)))
ans="Yes"
dx=[0,1,0,-1]
dy=[1,0,-1,0]
for i in range(1,h+1):
  for j in range(1,w+1):
    if b[i][j]==".":continue
    flag=True
    for x,y in zip(dx,dy):
      if b[i][j]==b[i+x][j+y]:flag=False
    if flag:ans="No"
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

int main() {
    int h, a;
    cin >> h >> a;
    int cnt = 0;
    while (h > 0) {
        h -= a;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
//ALL GLORY TO JESUS CHRIST 
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;

#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    ll n; cin >> n;
    ll res = 1e18;
    for(ll i=1; i*i<=n; ++i) {
        if(n%i == 0) {
          res = min(res, n/i + i - 2);
        }
    }
    cout << res << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	double v,y;
	int i;
	while(scanf("%lf",&v)!=EOF){
		y=(98+v*v)/98;
		for(i=0;i<10000;i++){
			if((double)i>=y){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b, c, d;

	cin>>a>>b>>c>>d;

	cout<<yn(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> vec(10,vector<int>(10));
  for(int i=1; i<=N; i++){
    string S = to_string(i);
    int x = S.at(0) - '0';
    int y = S.at(S.size()-1) - '0';
    vec.at(x).at(y)++;
  }
  int64_t ans = 0;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      ans += vec.at(i).at(j) * vec.at(j).at(i);
    }
  }
  cout << ans << endl;
}

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

int main(){
	int N,W;
	int v[100],w[100];
	
	//input
	scanf(" %d %d", &N, &W);
	for(int i=0; i<N; ++i) scanf(" %d %d", &v[i], &w[i]);
	
	//solve
	
	//dp[i][j]:=??????(i-1)?????§??\???????????????????±??????£?????????????????????????????????j???????????????????¨?????????§???
	int dp[101][10001]={0};
	
	for(int i=0; i<N; ++i){
		for(int j=0; j<=W; ++j){
			if(j-w[i]>=0)
				dp[i+1][j] = max( dp[i][j-w[i]]+v[i], dp[i][j] );
			else dp[i+1][j] = dp[i][j];
		}
	}
	
	int ans=0;
	for(int i=0; i<=W; ++i) ans = max(ans,dp[N][i]);
	printf("%d\n", ans);
}

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

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

using namespace std;

using int64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 1) {
    cout << 'a';
  }
  queue<string> q;
  q.push("a");
  while (true) {
    string s = q.front();
    q.pop();
    if ((int)s.length() == n) break;
    char mxS = *max_element(s.begin(), s.end());
    for (char c = 'a'; c <= mxS + 1; c++) {
      string ss = s;
      ss += c;
      if ((int)ss.length() == n) {
        cout << ss << '\n';
      }
      q.push(ss);
    }
  }
  return 0;
}

Measured memory_bytes: 7208
# https://atcoder.jp/contests/abc111/tasks/arc103_a


n = gets.to_i
vs = gets.split.map(&:to_i)

as, bs = vs.each_slice(2).to_a.transpose.map do |ws|
  ws
  .group_by(&:itself)
  .map { |k, vs| [vs.size, k] }
  .group_by { |c, k| c }
  .sort
  .reverse
  .take(2)
  .map { |c, vs| [c, vs.transpose[1].sort] }
  .push([0, []])
end

keep = (
  if as[0][1].size > 1 || bs[0][1].size > 1 || as[0][1] != bs[0][1]
    as[0][0] + bs[0][0]
  else
    [as[0][0] + bs[1][0], as[1][0] + bs[0][0]].max
  end
)

puts n - keep


Measured memory_bytes: 32384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int comps = in.nextInt();
		in.nextLine();
		for(int i = 0; i < comps; i++) {
			String x = in.nextLine();		
			String y = in.nextLine();
			System.out.println(lcs(x, y));
		}
		in.close();
	}
	
	static int lcs(String x, String y){
		int xl = x.length();
		int yl = y.length();
		int[][] lens = new int[xl + 1][yl + 1];
		
		for(int i = 0; i <= xl; i++) {
			for(int j = 0; j <= yl; j++) {
				if(i == 0 || j == 0) {
					lens[i][j] = 0;
				}
				else if(x.charAt(i-1) != y.charAt(j-1)) {
					lens[i][j] = Math.max(lens[i][j - 1], lens[i - 1][j]);
				}
				else {
					lens[i][j] = 1 + lens[i -1][j -1];
				}
			}
		}
		return lens[xl][yl];
	}
}


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

const long long MOD = 1000000007;

long long mod_pow(long long x, long long n, long long mod){
    long long res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    if((x+y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    int num = (x+y)/3;
    vector<long long> f(num+1, 0), fi(num+1, 0);
    f[0] = 1;
    for(int i = 1; i <= num; i++){
        f[i] = f[i-1] * i % MOD;
    }
    fi[num] = mod_pow(f[num], MOD-2, MOD);
    for(int i = num; i > 0; i--){
        fi[i-1] = fi[i] * i % MOD;
    }
    long long ans = 0;
    for(int i = 0; i <= num; i++){
        int j = num - i;
        if(i+2*j != x || i*2+j != y) continue;
        (ans += f[num] * fi[i] % MOD * fi[j] % MOD) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

Measured memory_bytes: 256
s = list(input())
ans = 0
for i in range(len(s)):
    for j in range(i, len(s)):
        # print(s[i:j+1])
        if all(x == 'A' or x == 'C' or x == 'G' or x == 'T' for x in s[i:j+1]):
            # print('Yes')
            if ans < len(s[i:j+1]):
                ans = len(s[i:j+1])
        # if expression:
        #     pass
    # print(s[:i], len(s[:i]))

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    if (s.back() == 's') s = s + "es";
    else s = s + 's';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int n;
int maxWeight;
long long int weights[105];
long long int values[105];
long long int dp[105][100005];

long long int calc(long long int currentWeight, int i)
{
	if(i<0)
		return 0;
	if(dp[i][currentWeight] != -1)
	{
		return dp[i][currentWeight];
	}
	if(currentWeight + weights[i] > maxWeight)
		dp[i][currentWeight] = calc(currentWeight,i-1);
	else
		dp[i][currentWeight] = (long long int)fmax(calc(currentWeight+weights[i],i-1) + values[i], calc(currentWeight,i-1));

	return dp[i][currentWeight];
}

int main() 
{
	scanf("%d %d",&n,&maxWeight);
	for(int i=0;i<105;i++)
	{
		for(int j=0;j<100005;j++)
		{
			dp[i][j] = -1;
		}
	}
	for(int i=0;i<n;i++)
	{
		scanf("%lld %lld",&weights[i],&values[i]);
	}
	long long int ans = calc(0,n-1);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  // アルファベット大文字
  vector<char> Alphabet;
  for (char c='A'; c<='Z'; c++) Alphabet.push_back(c);
  int H, W, ans1 = -1, ans2 = -1;
  cin >> H >> W;
  vector<vector<string>> S(H, vector<string>(W));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) cin >> S[i][j];
  }
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (S[i][j]=="snuke") {
        ans1 = i;
        ans2 = j;
        break;
      }
    }
    if (ans1!=-1&&ans2!=-1) break;
  }
  cout << Alphabet[ans2] << ans1+1 << endl;
}

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

int main(){
    std::string str;
    std::vector<int> count(26, 0);
    
    while(std::getline(std::cin, str)){
        std::transform(str.begin(), str.end(), str.begin(), ::tolower);

        for(int i = 0; i < 26; ++i){
            count.at(i) += std::count(str.begin(), str.end(), (char)(97 + i));
        }

//        std::cout << str << std::endl;
    }

    for(int i = 0; i < 26; ++i){
        std::cout << (char)(97 + i) << " : " << count.at(i) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3160