akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
vector<int> primeFactors(int n) {
    vector<int> v;
    int i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            v.push_back(i);
            n /= i;
        } else {
            i++;
        }
    }
    if(n != 1)v.push_back(n);
    return v;
}
signed main(){
    auto dp = vector<vector<int>>(101);
    rep(i,101)dp[i] = primeFactors(i);
    int n; cin >> n;
    map<int,int>mp;
    for(int i = 1; i <= n;i++){ for(auto val : dp[i]){mp[val]++;}}
    int res = 0, ta = 0, tb = 0;
    for(auto i : mp){
        for(auto j : mp){
            for (auto k :mp){
                if(i == j or j == k or k == i)continue;
                if(i.second >= 4 and j.second>=4 and k.second>=2)++res;
            }
        }
    }
    for(auto i : mp){
        for(auto j : mp){
            if(i.first == j.first)continue;
            if(i.second >= 14 and j.second >= 4)ta++;
        }
    }
    int subans = 0;
    for(auto i : mp){
        for(auto j : mp){
            if(i.first == j.first)continue;
            if(i.second >= 24 and j.second >= 2)tb++;
        }
        if(i.second >= 74)subans++;
    }
    cout << res/2 + ta + tb + subans << endl;
    
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >> a >> b;
    
    if(a == 1){
        a = 14;
    }
    if(b == 1){
        b = 14;
    }
    
    
    if(a>b){
        cout << "Alice" <<endl ;
    }    
    
    else if(a<b){
        cout <<"Bob" <<endl ;
    }
    
    else if(a==b){ 
        cout <<"Draw" <<endl ;
    
    }
}

Measured memory_bytes: 256
import Control.Monad

solve t ct
  | null candy = "TLE"
  | otherwise = show $ minimum candy
  where candy = map head $ filter ((<=t) . last) ct

main = do
  [n, t] <- map read . words <$> getLine
  ct <- replicateM n $ map read . words <$> getLine
  putStrLn $ solve t ct

Measured memory_bytes: 1020
n, x = map(int, input().split())
al = list(map(int, input().split()))

cnt = 0
for i in range(n-1):
    if al[i] + al[i+1] > x:
        if al[i+1] > (al[i] + al[i+1]) - x:
            cnt += al[i] + al[i+1] - x
            al[i+1] -= (al[i] + al[i+1] - x)
        else:
            cnt += al[i+1] + al[i] - x
            al[i+1] = 0
            al[i] = x

print(cnt)
# print(al)

Measured memory_bytes: 19940
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Pip; 
const int INF = (1<<30);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n;
  int k;
  cin >> n >> k;

  while ( k-- ) {
    int x, y;
    cin >> x >> y;
    if( n / 2 < x ) {
      x = n - x + 1;
    }
    if( n / 2 < y ) {
      y = n - y + 1;
    }
    int a = min(x, y);
    a = a - (a / 3) * 3;
    if( a == 0 ) cout << '3' << endl;
    else cout << a << endl;
  }
}

Measured memory_bytes: 1160
a,u=map(int,input().split())
b,v=map(int,input().split())
t=int(input())
if(a==b):
  print('YES')
else:
  dif=abs(b-a)
  d=v*t
  dif+=d
  d1=u*t
  if(d1>=dif):
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 61608
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};



int main(){
  ll N, A, B; cin >> N >> A >> B;
  ll sa = B - A;
  cout << max(0, sa * (N-2) + 1) << endl;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// =================グラフテンプレート==================

// costの部分の型は指定できます
template <typename T>
struct edge {
  int from, to;
  T cost;

  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

  // 行き先を代入できる
  edge& operator=(const int& x) {
    to = x;
    return *this;
  }

  // その他便利機能、って感じ
  operator int() const { return to; }
  bool operator<(edge x) { return this->cost < x.cost; }
};

template <typename T>
using Edges = vector<edge<T>>;

template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
using Matrix = vector<vector<T>>;

using UnWeightedGraph = vector<vector<int>>;

// ===============ワーシャルフロイド法==============
// warshall_floyd(隣接行列,INF(intでもllでも))
// i-jと,i-k-jルートを比較して短い方を採用していく
// 隣接行列が穴埋めされます
template <typename T>
void warshall_floyd(Matrix<T>& g, T INF) {
  for (int k = 0; k < g.size(); k++) {
    for (int i = 0; i < g.size(); i++) {
      for (int j = 0; j < g.size(); j++) {
        if (g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  int n;
  cin >> n;
  Matrix<int> g(n, vector<int>(n, INF));
  vector<string> g2(n);
  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
    cin >> g2[i];
    for (int j = 0; j < g2[i].size(); j++) {
      if (g2[i][j] == '1') {
        g[i][j] = 1;
        g[j][i] = 1;
      }
    }
  }

  warshall_floyd<int>(g, INF);

  int m = 0, s = 0;
  for (int i = 0; i < g.size(); i++) {
    for (auto x : g[i]) {
      if (m < x) {
        m = x, s = i;
      }
    }
  }

  // for (int i = 0; i < n; i++) { cout << g[i] << endl; }
  // cout << m << " " << s << endl;

  vector<int> color(n, -1);  // -1はまだ決まっていない
  color[0] = 1;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int i = 0; i < n; i++) {
      if (g2[now][i] == '1') {  // つながってる
        if (color[i] == -1) {
          color[i] = !color[now];
          que.push(i);
        } else {  // 何かしら色が塗られている
          if (color[now] == color[i]) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
  }

  // for (int i = 0; i < n; i++) {
  //   cout << g2[i] << endl;
  // }
  //cout << color << endl;

  cout << m + 1 << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<ll> enumdiv(ll n) {
	vector<ll> S;
	for (ll i = 1; i*i <= n; i++) if (n%i == 0) { S.push_back(i); if (i*i != n) S.push_back(n / i); }
	sort(S.begin(), S.end());
	return S;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	set<ll> ans;

	auto ed1 = enumdiv(N);
	fore(d, ed1) if (2 <= d) {
		ll K = d;
		ll n = N;
		while (n % K == 0) n /= K;
		if ((n - 1) % K == 0) ans.insert(K);
	}

	auto ed2 = enumdiv(N - 1);
	fore(d, ed2) if (2 <= d) ans.insert(d);

	cout << ans.size() << endl;
}







Measured memory_bytes: 384
#include "iostream"
#include "cstring"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "stack"
#include "functional"

using namespace std;
using ll = long long int;
using PII = pair<ll, ll>;

int dp[6][6][6][6][2];

int check(int A, int B, int C, int D, int turn) {
	if (dp[A][B][C][D][turn] != -1) {
		return dp[A][B][C][D][turn];
	}
	if (A == 5 && B == 5) {
		return dp[A][B][C][D][turn] = turn ^ 1;
	}
	else if (C == 5 && D == 5) {
		return dp[A][B][C][D][turn] = turn;
	}

	int ret = 0;
	if (turn) { //Isono
		if (A < 5 && C < 5) {
			ret |= check(A, B, min(A + C, 5), D, turn ^ 1) ^ 1;
		}
		if (A < 5 && D < 5) {
			ret |= check(A, B, C, min(A + D, 5), turn ^ 1) ^ 1;
		}
		if (B < 5 && C < 5) {
			ret |= check(A, B, min(B + C, 5), D, turn ^ 1) ^ 1;
		}
		if (B < 5 && D < 5) {
			ret |= check(A, B, C, min(B + D, 5), turn ^ 1) ^ 1;
		}
	}
	else {
		if (C < 5 && A < 5) {
			ret |= check(min(A + C, 5), B, C, D, turn ^ 1) ^ 1;
		}
		if (C < 5 && B < 5) {
			ret |= check(A, min(B + C, 5), C, D, turn ^ 1) ^ 1;
		}
		if (D < 5 && A < 5) {
			ret |= check(min(A + D, 5), B, C, D, turn ^ 1) ^ 1;
		}
		if (D < 5 && B < 5) {
			ret |= check(A, min(B + D, 5), C, D, turn ^ 1) ^ 1;
		}
	}
	return dp[A][B][C][D][turn] = ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	int C, D;
	cin >> A >> B;
	cin >> C >> D;
	memset(dp, -1, sizeof(dp));
	if (check(A, B, C, D, 1)) {
		cout << "ISONO" << endl;
	}
	else {
		cout << "NAKAJIMA" << endl;
	}
}


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

string s;
int cnt[123];

int main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		cnt[(int)s[i]]++;
	}
	for (int i = 97; i < 124; i++) {
		if (i == 123) {
			cout << "None" << endl;
			return 0;
		}
		if (cnt[i] == 0) {
			cout << (char)i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 512
N,K = map(int,input().split())
d=[None for _ in range(K)]
A=[None for _ in range(K)]
for i in range (K):
    d[i]=input()
    A[i]=list(map(int,input().split()))


c=sum(A, [])
c=set(c)
NN=len(c)
ans=N-NN
print(ans)

Measured memory_bytes: 9416
#include<stdio.h>
#include<string.h>
int main()
{
    char S[3],T[3];
    gets(S);
    gets(T);
    int i;
    int cnt = 0;
    for(i=0; i<3; i++)
       {if(S[i]==T[i])cnt++;}
    printf("%d\n",cnt);
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


map<ll,ll> memo;
vl mult = {2,3,5};
vl cst = {-1,-1,-1};
ll d;
const double inf = 1e18;

ll f(ll n){
    auto it = memo.find(n);
    if(it != memo.end()) return it->second;
    ll ans = inf;
    if(double(n) * d < inf){
        ans = n*d;
    }
    for(int i=0;i<3;i++){
        auto k = mult[i];
        ll cr = ((n%k)*d) + f(n/k) + cst[i];
        ans = min(ans, cr);
        if(n%k != 0){
            cr = ((k - (n%k))*d) + f((n+k-1)/k) + cst[i];
            ans = min(ans, cr);
        }
    }
    memo[n] = ans;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int nt;
    cin >> nt;
    for(int tt=1;tt<=nt;tt++){
        memo.clear();
        ll  n;
        cin >> n >> cst[0] >> cst[1] >> cst[2] >> d;
        memo[0] = 0;
        memo[1] = d;
        cout << f(n) << "\n";
    }
    return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	vector<int> value_list(N, 0);

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

	int result = 0;

	for (int i = 0; i < N; i++)
	{
		if (value_list[i] >= K)
		{
			result++;
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 3704
#include <iostream>
using namespace std;
typedef unsigned long long ll;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define lp(i,a,n) for(ll i = (a);i <= (n);i++)
#define MAX 500000000

int main(){
  ll a,b,c;
  ll x = 0;
  cin >> a >> b >> c;
  if(a == b && c != 0){
    goto end;
  }else if(a == 1){
    x = 1;
    goto end;
  }
  rep(i,1,b){
    if(a * i % b == c){
      x = 1;
      break;
    }
  }
  end:;
  if(x == 0)cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
int n,m,k;
int pref1[500000+5],pref2[500000+5];
bool chk(int x)
{
   // test3(n,m,k);
    if(x>n+m)
    return false;

    if(x==0)
    return true;

   // test1(x);
    if(pref1[x-1]<=k&&x<=n)
    return true;
    if(pref2[x-1]<=k&&x<=m)
    return true;
    for(int i=1;i<x;i++)
    {
        if(i>n||x-i>m)
        continue;

        int val = pref1[i-1] + pref2[x-i-1];
      //  test2(val,x);
        if(val<=k)
        return true;
    }
    return false;
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	
    
    
    cin>>n>>m>>k;

    int A[n],B[m];
    for(int i=0;i<n;i++)
    cin>>A[i];

    for(int i=0;i<n;i++)
    {
        if(!i)
        pref1[i]=A[i];
        else
        {
            pref1[i] = pref1[i-1] + A[i];
        }
        
    }

    for(int i=0;i<m;i++)cin>>B[i];

     for(int i=0;i<m;i++)
    {
        if(!i)
        pref2[i]=B[i];
        else
        {
            pref2[i] = pref2[i-1] + B[i];
        }
        
    }
    
    int s = 0;
    for(int z = n+m;z>0;z=z/2)
    {
        while(chk(s+z))
        s+=z;
    }
    cout<<s;

return 0;
}

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

vector<int> to[100005];
int n;

vector<int> dist;
void dfs(int v, int d=0, int p=-1){
    dist[v] = d;
    for(int u : to[v]){
        if(u == p) continue;
        dfs(u, d+1, v);
    }
}

vector<int> calcDist(int s){
    dist = vector<int>(n);
    dfs(s);
    return dist;
}

int main() {
    cin >> n;
    int s, t;
    cin >> s >> t;
    --s; --t;
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    vector<int> dists = calcDist(s);
    vector<int> distt = calcDist(t);

    int mx = 0;
    rep(i,n){
        if(dists[i] < distt[i]){
            mx = max(mx, distt[i]);
        }
    }
    int ans = mx-1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10744
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;

int n;
char seq[100111];

int verCtr = 1;
int activeVer = 1;

vector< pair<int,int> > edges;

int nextOne(int ind)
{
    int i;

    for (i=ind;i<=n;i++)
    {
        if (seq[i] == '1')
            return i;
    }

    return n+1;
}

int main()
{
    int i;
    int cur;

    scanf("%s",seq+1);
    n = strlen(seq+1);

    for (i=1;i<n;i++)
    {
        if (seq[i] != seq[n-i])
        {
            printf("-1\n");
            return 0;
        }
    }

    if (seq[1] == '0' || seq[n] == '1')
    {
        printf("-1\n");
        return 0;
    }

    activeVer = 2;
    verCtr = 2;
    cur = 2;
    edges.push_back(make_pair(1,2));

    while(nextOne(cur) <= n/2)
    {
        int nxt = nextOne(cur);

        for (i=1;i<=nxt-cur;i++)
        {
            verCtr++;
            edges.push_back(make_pair(activeVer, verCtr)); ///Leaves
        }

        cur = nxt + 1;

        verCtr++;
        edges.push_back(make_pair(verCtr, activeVer));
        activeVer = verCtr;
    }

    while(verCtr < n) ///Put all leaves
    {
        verCtr++;
        edges.push_back(make_pair(activeVer, verCtr));
    }

    sort(edges.begin(), edges.end());

    for (i=0;i<edges.size();i++)
    {
        printf("%d %d\n",edges[i].first,edges[i].second);
    }
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main() {
	string s;
	cin>>s;
	if (SZ(s)%2!=0) {
		puts("No");
		return 0;
	}
	for (int i=0;i<SZ(s);i++) if (s[i]!="hi"[i%2]) {
		puts("No");
		return 0;
	}
	puts("Yes");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 3000


enum Type{
	TATE,
	YOKO,
	NONE,
};


int H,W;
int dp[3][NUM+1];
char base_map[NUM][NUM+1];


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

int calc(int start_row,int start_col){

	int ret = 0;

	for(int col = start_col; col <= W-1; col++){
		dp[TATE][col] = 0;
		dp[YOKO][col] = 0;
		dp[NONE][col] = 0;
	}

	int row = start_row;
	for(int col = start_col; col <= W-1 && row >= 0; col++){
		if(base_map[row][col] != 'G'){
			if(col == start_col){
				//Do nothing
			}else{
				dp[NONE][col] = max(dp[NONE][col-1],max(dp[TATE][col-1],dp[YOKO][col-1]));
			}
		}else{ //base_map[row][col] == 'G'
			if(rangeCheck(row-1,col) == true && base_map[row-1][col] == 'R' && rangeCheck(row+1,col) == true && base_map[row+1][col] == 'W'){ //縦に作れる

				if(col == start_col){
					dp[TATE][col] = 1;
				}else{
					dp[TATE][col] = max(dp[TATE][col-1],dp[NONE][col-1])+1;
				}
				ret = max(ret,dp[TATE][col]);
			}
			if(rangeCheck(row,col-1) == true && base_map[row][col-1] == 'R' && rangeCheck(row,col+1) == true && base_map[row][col+1] == 'W'){ //横に作れる

				if(col == start_col){
					dp[YOKO][col] = 1;
				}else{
					dp[YOKO][col] = max(dp[YOKO][col-1],dp[NONE][col-1])+1;
				}
				ret = max(ret,dp[YOKO][col]);
			}
			//どちらも作らない
			if(col == start_col){
				//Do nothing
			}else{
				dp[NONE][col] = max(dp[NONE][col-1],max(dp[TATE][col-1],dp[YOKO][col-1]));
			}
		}
		row--;
	}
	return ret;
}

int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		scanf("%s",base_map[row]);
	}

	int ans = 0;
	for(int row = 1; row <= H-1; row++){
		ans += calc(row,0);
	}
	for(int col = 1; col <= W-1; col++){
		ans += calc(H-1,col);
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 12028
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

class Connection
{
public:
    Connection(int from, int to)
    {
        From = from;
        To = to;
    }

    int From;
    int To;
};

int main()
{
    int N, M;
    std::cin >> N >> M;
    std::vector<int> lapDuplicationTable(N-1, 0);
    std::vector<Connection*> connections;
    std::vector<int> cutTable;

    for (int i=0; i<M; ++i)
    {
        int ai, bi;
        std::cin >> ai >> bi;
        connections.emplace_back(new Connection(ai, bi));
    }

    std::sort(connections.begin(), connections.end(),
        [&](Connection* c1, Connection* c2)
        {
            return c1->To < c2->To;
        });

    for (int i=0; i<connections.size(); ++i)
    {
        bool isSatisfied = false;
        for (int k=0; k<cutTable.size(); ++k)
        {
            int cut = cutTable[k];
            if (connections[i]->From <= cut && cut < connections[i]->To)
                isSatisfied = true;
        }

        if (isSatisfied)
            continue;

        cutTable.emplace_back(connections[i]->To-1);
    }

    std::cout << cutTable.size();
}

Measured memory_bytes: 4596
#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 W, H, x, y;

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

  double d = double(W) * H * 0.5;
  cout << setprecision(10) << d;
  cout << " " << (2 * x == W && 2 * y == H) << endl;
  return 0;
}


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

#define mp make_pair
#define all(x) x.begin(), x.end()

int main() {
        long long n;
        scanf("%lld", &n);
        vector<long long> sq;
        long long res = 1;
        while (res * res <= n) res ++;
        res --;
        printf("%lld\n", res * res);
        return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static char[] s;
	static int[] PQR;
	static int[] tuf = {0, 1, 2};// true, unknown, false
	static int idx;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			idx=0;
			String str = cin.next();
			if(str.equals(".")){
				break;
			}
			s = new char[81];
			PQR=new int[3];
			for(int i = 0; i < str.length(); i++){
				s[i] = str.charAt(i);
			}

			int count=0;
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < 3; j++){
					for(int k = 0; k < 3; k++){
						idx=0;
						PQR[0]=tuf[i];
						PQR[1]=tuf[j];
						PQR[2]=tuf[k];
						if(expression()==2){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
	static int expression(){
		int res = term();
		if(s[idx]=='+'){
			idx++;
			res = or(res, expression());
		}
		return res;
	}
	static int term(){
		int res = fact();
		if(s[idx]=='*'){
			idx++;
			res = and(res, term());
		}
		return res;
	}
	static int fact(){
		int res;
		if(s[idx]=='('){
			idx++;
			res=expression();
			idx++;
		}
		else if(s[idx]=='-'){
			idx++;
			res = not(fact());
		}
		else{
			res = variable();
		}
		return res;
	}
	static int variable(){
		if(s[idx]=='P'){
			idx++;
			return PQR[0];
		}
		else if(s[idx]=='Q'){
			idx++;
			return PQR[1];
		}
		else if(s[idx]=='R'){
			idx++;
			return PQR[2];
		}
		else{
			return s[idx++] - '0';
		}
	}
	static int or(int x, int y){
		if(x <= 1 && y <= 1){
			if(x == 0 && y == 0){
				return 0;
			}
			else{
				return 1;
			}
		}
		else{
			return 2;
		}
		
	}
	static int and(int x, int y){
		if(x >= 1 && y >= 1){
			if(x == 2 && y == 2){
				return 2;
			}
			else{
				return 1;
			}
		}
		else{
			return 0;
		}
	}
	static int not(int x){
		if(x ==0){
			return 2;
		}
		else if(x==1){
			return 1;
		}
		else{
			return 0;
		}
	}
}

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

int main (){
  int N,a[100],Alice = 0,Bob = 0,memo = 0;
  cin >> N;
  for (int j = 0; j<= N - 1;j++){
    cin >> a[j];
  }
  for (int i = 0; i<= N - 1;i++){
    for(int j = 0; j<= N - 2;j++){
      if (a[j] <= a[j+1]){
        memo = a[j];
        a[j] = a[j+1];
        a[j+1] = memo;
      }
    }
  }
  for (int j = 0; j<= N - 1;j++){
    if (j%2 == 0){
      Alice += a[j];
    }else{
      Bob += a[j];
    }
  }
  cout << Alice - Bob <<endl;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int n;
    cin >> n;

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;

        ans += (i % 2 == 1 && a % 2 == 1);
    }
    cout << ans << newl;

    return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<map>
using namespace std;
int main()
{

    int N,x;
    scanf("%d",&N);
    map<int,int> mp;
    for(int i=0; i<N; i++)
    {
        scanf("%d",&x);
        mp[x]++;
    }
    int k=0;
    for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
        if(it->second%2!=0)
            k++;
    }
    printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 4864
const main = input => {
    input = input[0].split(' ');
    n = parseInt(input[0],10);
    l = parseInt(input[1],10);
    var sum=0,i;
    for(i=l;i<n+l;i++) {
        sum+=i;
    }
    // console.log(sum);
    // console.log(n, l);
    if (l>0) {
        sum-=l;
    } else if (l+n<=0) {
        sum-=l+n-1;
    }
    console.log(sum);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N ,x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i,N){
        cin >> a.at(i);
    }
    long ans=0;
    rep(i,N-1){
        if(x<a.at(i)+a.at(i+1)&&a.at(i)>x){
            ans+=a.at(i+1);
            a.at(i+1)=0;
            ans+=a.at(i)-x;
            a.at(i)=x;
        }else if(x<a.at(i)+a.at(i+1)&&a.at(i)<=x){
            ans+=a.at(i+1)-(x-a.at(i));
            a.at(i+1)=x-a.at(i);
        }else if(x>=a.at(i)+a.at(i+1)){
            continue;
        }else{

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


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    ll x[m];
    vector<ll> d;
    for(int i=0;i<m;i++) cin >> x[i];
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    sort(x, x+m);
    ll ans = 0;
    for(int i=1;i<m;i++){
        d.push_back(x[i] - x[i-1]);
        ans += (x[i] - x[i-1]);
    }
    sort(d.rbegin(), d.rend());
    for(int i=0;i<n-1;i++){
        ans -= d[i];
    }
    cout << ans << endl;
}

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

int main(void)
{
	int a, b;
	int l, s;
	
	cin >> a >> b;
	
	l = a * 2 + b * 2;
	s = a * b;
	
	cout << s << " " << l << endl;
	
	return (0);
}

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

int main(){
  int n;
  int r;
  while(cin>>n>>r && n+r){
    vector<int> vec;
    vec.resize(n);
    for(int i=0;i<n;i++){
      vec[i]=n-i;
    }

    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      p--;
      vector<int> v;
      v.resize(c);
      for(int j=0;j<c;j++){
	v[j]=vec[p+j];
      }
      for(int j=p-1;j>=0;j--){
	vec[j+c]=vec[j];
      }
      for(int j=0;j<c;j++){
	vec[j]=v[j];
      }
    }
    cout<<vec[0]<<endl;

  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	int n;
	cin>>n;
	double p[n+1];
	double dp[n+1][n+1];
	FOR1(i,n) cin>>p[i];
	dp[0][0] = 1;
	FOR1(i,n){
		dp[i][0] = dp[i-1][0]*(1-p[i]);
	}
	dp[1][1] = p[1];
	for(int i = 2; i <= n; i++){
		FOR1(j, n){
			dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i])*dp[i-1][j];
		}
	}
	// FOR1(i,n){
	// 	FOR1(j,i) cout << dp[i][j] << " ";
	// 	cout << endl;
	// }
	double ans = 0;
	for (int i = n; i > n/2; i--){
		ans+=dp[n][i];
	}
	cout << fixed << setprecision(10) << ans << endl;

}

Measured memory_bytes: 70528
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    cout << x << " " << y << " " << z << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define MIN_N 1
#define MAX_N 100
#define MIN_A 0
#define MAX_A 1000

using namespace std;

void print_array(int* a, int n) {
  for(int i=0; i<n; i++) {
    cout << a[i];
    if(i != n-1) {
      cout << " ";
    }
  }
  cout << endl;
}

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

  // insertion sort
  for(int i=1; i<n; i++) {
    print_array(a, n);
    int v = a[i];
    int j = i-1;
    while(j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
  }
  print_array(a, n);

  return 0;
}

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

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef map<string, int> maps;
typedef map<int, int> mapi;

#define int long long
#define db double
#define add push_back
#define rem pop_back
#define mod 1000000007
#define all(a) a.begin(), a.end()
#define sz(a) int((a).size())
#define BS(i, j, k) binary_search(i, j, k)
#define prec(n) fixed<<setprecision(n)

void input(int *a, int size)  { for(int i = 0; i < size; ++i) cin >> a[i]; }
void output(int *a, int size) { for(int i = 0; i < size; ++i) cout << a[i] << " "; cout<<endl; }

#define repi(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define rep(i, a, b)  for(int i = a; i <  b; i++)
#define repn(i, a, b) for(int i = a; i <= b; i++)
#define repv(i, b, a) for(int i = b - 1; i >= a; i--)
#define _1 first
#define _2 second

const double EPS = 1e-9;
const double PI = acos(-1.);
const int MOD = 1e9 + 7;
const int MAXN = 120001;
int INF = __INT64_MAX__;
int MAX = -1e9;
int MIN = 1e9;
string YN[] = {"NO", "YES"};

bool isPrime(int n)
{
          if (n <= 1)  return false;
          if (n <= 3)  return true;

          if (n%2 == 0 || n%3 == 0) return false;

          for (int i=5; i*i<=n; i=i+6)
                    if (n%i == 0 || n%(i+2) == 0)
                              return false;
          return true;
}
int n, m, A[MAXN], B[MAXN], res, cnt;
void solution()
{
		cin >> n >> m;
		cout << max(max(n + m, n * m),  n - m);

}
__INT16_C() main()
{
          ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
          int t = 1;
          //cin >> t;
          while(t--) solution();
}


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

using namespace std;

#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

string ans = "Three";
char c;
ll n;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c;
        if (c == 'Y')
            ans = "Four";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
  int n;
  while(cin >> n){
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    sort(v.begin(), v.end());
    partial_sum(v.begin(), v.end(), v.begin());
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
const int MAX = 210000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){

	COMinit();
	lli h,w,a,b;
	cin>>h>>w>>a>>b;
	h--,w--;

 	lli ans = 0;
 
    for(lli i=0;i<=h-a;i++){
	   	ans += (COM(b+i-1,i) * COM(h-i+w-b,h-i)) % MOD;
    }
 
    cout<<ans%MOD<<endl;
 

	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define loop(i,n) for(ll (i)=0;(i)<n;(i)++)
#define cloop(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define Matrix vector<vector<ll>>
#define Point pair<ll,ll>
#define Coordinates vector<Point>
#define zero(a) memset((a),0,sizeof((a)))
#define reverse_sort(a) sort(a.begin(),a.end(),greater<ll>())
#define reverse_sortA(a) sort(a,a+sizeof(a)/sizeof(ll),greater<ll>())

ll global =0;
using namespace std;
ll gcd(ll a, ll b){
    /*
    return gcd of a,b
    */
    if(b>a)return gcd(b,a);
    if(a%b)return gcd(b,a%b);
    return b;
}
void init_matrix( Matrix& graph, ll num){
    /*
    Initialize Matrix elements with num rows 
    */
    loop(i,num) graph.push_back(vector<ll>());
}
template
<
typename Key =ll,
typename Val = ll
>
auto max_mp(map<Key,Val>&mp){
    /*
    return max element of map in form pair<key,val>
    */
    auto max_e = mp.begin();
    auto it = mp.begin();
    while(it!=mp.end()){
        if(it->second > max_e->second){
            max_e = it;
        }
        it++;
    }
    return *max_e;
}
template
<
typename Key =ll,
typename Val = ll
>
auto min_mp(map<Key,Val>&mp){
    /*
    return min element of map in form pair<key,val>
    */
    auto min_e = mp.begin();
    auto it = mp.begin();
    while(it!=mp.end()){
        if(it->second < min_e->second){
            min_e = it;
        }
        it++;
    }
    return *min_e;
}
vector<ll> generate_prime(ll n) { 
    /*
    generate all primes number less than equal to n
    */
    vector<bool> prime(n+1,true);
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    vector<ll> pr;
    for (ll p=2; p<=n; p++) 
       if (prime[p]) 
          pr.push_back(p);
    return pr;
}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}
bool sortbyfir(const pair<ll,ll> &a,const pair<ll,ll> &b){ 
    return (a.first < b.first); 
}




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll K;
    cin >> K;
    ll res=0;
    cloop(i,1,K+1)cloop(j,1,K+1)cloop(k,1,K+1) res+= gcd(gcd(i,j),k);
    cout << res << endl;
    return 0;
}
	
/*
input:

*/

/*
output:

*/	


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tmp,case_num = 1;

		while((tmp = sc.nextInt()) != 0){
			System.out.printf("Case %d: %d\n",case_num++, tmp);
		}
	}
}




Measured memory_bytes: 65072
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int w,h,n;
  int x,y,a;
  int r,l,u,d;
  cin>>w>>h>>n;
  l=d=0;u=h;r=w;
  rep(i,n){
    cin>>x>>y>>a;
    if(a==1) l=max(x,l);
    if(a==2) r=min(x,r);
    if(a==3) d=max(y,d);
    if(a==4) u=min(y,u);
  }
  int ww=r-l;
  int hh=u-d;
  if(ww<0) ww=0;if(hh<0) hh=0;
  cout<<ww*hh<<endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m= map(int,input().split())
A =[list(map(int,input().split())) for _ in range(n)]
pay = 0
A.sort()
for i in range(n):
    if A[i][1] > m:
        pay += A[i][0]*m
        break
    else :
        m -= A[i][1] 
        pay += A[i][0]*A[i][1]
print(pay)

Measured memory_bytes: 27808
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    }


}


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

struct UnionFind {
  vector<int> r;
  UnionFind(int N) {
    r = vector<int>(N, -1);
  }

  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) {
    return -r[root(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.unite(a, b);
  }

  int ans = 0;
  for (int i=0; i<n; i++)
    ans = max(ans, uf.size(i));
  cout << ans << endl;
}


Measured memory_bytes: 4052
// キョウプロ.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#pragma once


#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long A, B, C, D, M, N, X, Y, Z;
long long a[10000];
char ch;
string S;


int main()
{

	cin >> S;
	M = 0;
	C = 0;
	D = 0;
	for (int i = 0; i < S.size(); i++) {
		
		if (M !=S[i]-'0') {
			C++;
		}


		A /= 10;
		M++;
		M %= 2;
	}

	M = 1;

	for (int i = 0; i < S.size(); i++) {
		if (M != S[i] - '0') {
			D++;
		}
		M++;
		M %= 2;
	}


	cout << min(C,D) << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,k;
	cin >> n >> k;
	vector<ll> sum(n+1, 0);
	REP(i,n){ 
		ll a;
		cin >> a;
		a--;
		sum[i+1] = (sum[i] + a) % k;
	}
	map<ll, int> mp;
	ll ans = 0;
	REP(i,n+1){
		ans += mp[sum[i]];
		mp[sum[i]]++;
		if(i-k+1>=0) mp[sum[i-k+1]]--;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 17148
from itertools import combinations

def main():
    S = input()
    n = len(S)
    a = [i for i in range(1, n)]
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(int(S))
        else:
            k = list(combinations(a, i))
            for ki in k:  # ki: (1, 3)
                r = 0
                t = 0  # 一時記憶
                for j, sj in enumerate(S):
                    if j in ki:
                        r += t
                        t = int(sj)
                    else:
                        t = t * 10 + int(sj)
                r += t
                ans.append(r)

    # print(ans)
    print(sum(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);

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

	for(int i = 1; i <= n; ++i)
	{
		cout << a[i] << endl;
	}
}

int main()
{
	fastio;
	solve();

	return 0;
}


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

using namespace std;

int main(void) {
    int cnt[26] = {};
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        cnt[s[i] - 'a']++;
    
    for (int i = 0; i < 26; i++) {
        if (cnt[i] <= 1) continue;
        cout << "no\n";
        return 0;
    }
    cout << "yes\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

const int MOD = 1e9 + 7;

int mod_pow(int n, int p, int MOD){
  int r = 1;
  for(; p > 0; p >>= 1){
    if(p & 1LL) r = (r * n) % MOD;
    n = (n * n) % MOD;
  }
  return r; // r = n^p % MOD
}

signed main(){

  int n, k; cin >> n >> k;

  int ans = 0;
  vector<int> cnt(k+1);
  for(int i = k; i >= 1; i--){
    cnt[i] = mod_pow(k/i, n, MOD);
    for(int j = i*2; j <= k; j+=i){
      cnt[i] = (cnt[i] - cnt[j] + MOD) % MOD;
    }
    ans = (ans + i * cnt[i]) % MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4024
<?php

$mp = array_fill(0, 10, array_fill(0, 10, 0));
$updateRange = [];
$updateRange[1] = [[1, 0], [0, -1], [0, 0], [0, 1], [-1, 0]];
$updateRange[2] = [[1, -1], [1, 0], [1, 1], [0, -1], [0, 0], [0, 1], [-1, -1], [-1, 0], [-1, 1]];
$updateRange[3] = [[2, 0], [1, -1], [1, 0], [1, 1], [0, -2], [0, -1], [0, 0], [0, 1], [0, 2], [-1, -1], [-1, 0], [-1, 1], [-2, 0]];

function drop($x, $y, $size) {
    global $updateRange;
    foreach ($updateRange[$size] as $point) {
        list($dx, $dy) = $point;
        $nx = $x + $dx;
        $ny = $y + $dy;
        update($nx, $ny);
    }
}

function update($nx, $ny) {
    global $mp;
    if ((0 <= $nx) and ($nx < 10) and (0 <= $ny) and ($ny < 10)) {
        $mp[$ny][$nx]++;
    }
}

while (fscanf(STDIN, "%d,%d,%d", $x, $y, $s)) {
    drop($x, $y, $s, $updateRange, $mp);
}

$cnt = 0;
$score = 0;
for ($y = 0; $y < 10; $y++) {
    for ($x  = 0; $x < 10; $x++) {
        if ($mp[$y][$x] == 0) {
            $cnt++;
        }
        if ($mp[$y][$x] > $score) {
            $score = $mp[$y][$x];
        }
    }
}
echo $cnt . "\n";
echo $score . "\n";



Measured memory_bytes: 9420