akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll n;
    cin>>n;
    ll x[100010];
    rep(i,n){
        cin>>x[i];
    }
    ll m[100100];
    m[1]=1,m[0]=1;
    rep2(i,1,n+10){
        m[i+1]=m[i]*(i+1)%MOD;
    }
    vll v;
    rep(i,n-1){
        v.pb(x[i+1]-x[i]);
    }
    ll a[100100]={};
    a[0]=0;
    rep(i,n+10){
        a[i+1]=(i+1)*a[i]%MOD+m[i]%MOD;
        a[i+1]%=MOD;
        // cout<<a[i]<<endl;
    }
    ll ans=0;
    m[n-2]=1;
    ll now=n-1;
    repr(i,n-2){
        m[i]=m[i+1]*now%MOD;
        now--;
    }
    rep(i,n-1){
        ans+=a[i+1]*m[i]%MOD*v[i]%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3572
using System;

namespace _120c
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int N = S.Length;
            int oneNum = 0;
            int zeroNum = 0;
            int res = 0;
            for(int i = 0; i<N;i++){
                if(S[i]=='0'){
                    oneNum++;
                }else{
                    zeroNum++;
                }
            }
            if(oneNum == 0 || zeroNum == 0){
                res = 0;
            }else{
                if(oneNum > zeroNum){
                    res = zeroNum * 2;
                }else{
                    res = oneNum * 2;
                }
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 13140
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

const string ans[10] = {"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    N %= 10;
    cout << ans[N] << ln;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>
#include <regex>
#include <functional>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int MAX_N = 100000;

typedef long long ll;



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

    string S;
    cin >> S;
    if (S == "ABC") {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }
    
    return 0;
}

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

long power(long a, long b, long mod) {
	if (b == 0) return 1;
	long res = power(a, b / 2, mod);
	if (b % 2) res = res * res % mod * a % mod;
	else res = res * res % mod;
	return res;
}

int main() {
	long m, n;
	cin >> m >> n;
	cout << power(m, n, 1000000007) << endl;
}


Measured memory_bytes: 3112
#include "stdio.h"

int main()
{
	//目標地点を標準入力で与える
	long X = 0;
	scanf("%ld",&X);

	/*たどり着くのにかかる時間を計算する*/
	//順番に、時間、それまで飛び続けたときのカンガルーの位置
	int i = 0,pos = 0;
	while (1) {
		//１tickずつ時間をすすめていって、飛び越せたらループ抜けてみる
		//本来ぴったりたどり着けないといけないんだけど、
		//1~iで任意のジャンプを回避できるので値の調整はまず可能だと思う
		i++;
		pos = pos + i;
		if (pos >= X)
			break;
	}

	//答えを標準出力
	printf("%ld",i);

    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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 argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int minus_cnt = 0, x;
  int abs_min = INF;
  fi(0, n) {
    cin >> x;
    if(x < 0) minus_cnt++;
    ans += abs(x);
    chmin(abs_min, abs(x));
  }
  if(minus_cnt % 2) {
    ans -= 2 * abs_min;
  }
  cout << ans << endl;
  return 0;
}



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

int H, W;
int h, w;

int main() {
  // 入力
  cin >> H >> W;
  cin >> h >> w;

  // 解は (H - h)(W - w)
  auto ans = (H - h) * (W - w);

  // 出力
  cout << ans << endl;

  return 0;
}

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

int main() {
  string s;

  cin >> s;

  char a = s[0];

  for (int i = 1; i < (int)s.size(); i++) {
    if (s[i] == a) {
      cout << "Bad";
      return 0;
    }
    a = s[i];
  }

  cout << "Good";

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int maxn = 100005;
int n, A[maxn];
long long ans;

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", &A[i]);
    ans = 0;
    int p = 1;
    for(int i = 1; i <= n; ++i) {
        int v = A[i] / p;
        if(A[i] % p == 0) v--;
        if(A[i] >= p) {
            ans += v;
            if(A[i] == p || i == 1) p++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    W,H,N=MI()
    L=[0,W,0,H]
    for _ in range(N):
        x,y,a=MI()
        a-=1
        if a==0:
            L[a]=max(L[a],x)
        elif a==1:
            L[a]=min(L[a],x)
        elif a==2:
            L[a]=max(L[a],y)
        else:
            L[a]=min(L[a],y)
            
            
    dx=L[1]-L[0]
    dy=L[3]-L[2]
    
    if dx>0 and dy>0:
        print(dx*dy)
    else:
        print(0)
            

main()


Measured memory_bytes: 38256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
int main(){
    int a,b;

    cin>>a>>b;


    cout<<max({a+b,a-b,a*b})<<endl;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        String a = scanner.nextLine();
        boolean t = true;

        for(int i = 0;i < a.length()-1;i++){
            if (a.charAt(i) == a.charAt(i + 1)) {
                t = false;
                break;
            }
        }
        
        if (t) {
            System.out.println("Good");
        }else{
            System.out.println("Bad");
        }
    }
}

Measured memory_bytes: 23764
using System;
using System.Linq;

namespace _0500
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int maisuu = int.Parse(Console.ReadLine());
                int A = 0;
                int B = 0;
                if(maisuu==0)
                {
                    break;
                }
                for(int i=0;i<maisuu;i++)
                {
                    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    if(x[0]>x[1])
                    {
                        A += (x[0] + x[1]);
                    }
                    else if(x[0] == x[1])
                    {
                        A += x[0];
                        B += x[1];
                    }
                    else
                    {
                        B += (x[0] + x[1]);
                    }
                }
                Console.WriteLine(A + " " + B);
            }
        }
    }
}

Measured memory_bytes: 9672
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
using ll = unsigned long long;
ll u18 = 1000000000000000000;
int main()
{
    
    long double a, b;
    cin >> a >> b ;

    cout << (ll)(a*b) << endl;
   
    return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    string s;
    cin >> s;
    if( s[0] == '7' || s[1] == '7' || s[2] == '7' ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
import math
q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r) + 10
is_prime = [True] * (r_max+1)
is_prime[0] = is_prime[1] = False
for i in range(2, r_max):
    if is_prime[i]:
        for j in range(2, r_max // i + 1):
            is_prime[i*j] = False

# print(is_prime)
a = [0] * r_max
for i in range(3, r_max):
    a[i] = a[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i]-1])


Measured memory_bytes: 13368
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a2 = list(reversed(a2))

ans = 0
suma2 = [a2[0]]
for i in range(1,N):
    suma2.append( suma2[i-1] + a2[i])
suma2 = list(reversed(suma2))

toprow = 0
for i in range(N):
    toprow += a1[i]
    ans = max(ans, toprow + suma2[i])
print(ans)


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b;
ll k, s;
pii c[100000];

int main() {
	cin >> n >> k;
	rep(i,n) {
		cin >> a >> b;
		c[i] = mp(a,b);
	}
	
	sort(c, c+n);
	rep(i,n) {
		s += c[i].se;
		if (k<=s) {
			cout << c[i].fi << ln;
			return 0;
		}
	}
}

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

int main() {
	// your code goes here
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H'){
		cout<<'H';
	}
		if(a=='H'&&b=='D'){
		cout<<'D';
	}
		if(a=='D'&&b=='H'){
		cout<<'D';
	}
		if(a=='D'&&b=='D'){
		cout<<'H';
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  int red=0;
  int white=0;
  rep(i,n){
    if(s[i]=='R') red++;
    else white++;
  }
  ans=min(red,white);
  int w=0;
  for(int i=0;i<red;i++){
    if(s[i]=='W'){
      w++;
    }
  }
  ans=min(ans,w);
  cout<<ans<<endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std ;
#define ll         long long
#define IOS         ios_base::sync_with_stdio(false);   cin.tie(NULL);
#define FOR(i,n)     for(ll i=0;i<n;i++)
#define REP(i,k,n)  for(ll i=k;i<n;i++)
#define nl         "\n"
#define BUFFER         cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define SORT        sort(a,a+n);
#define mod         1000000007
#define pb          push_back

int main()
{
    ll n,sum=0;
    cin>>n;
    string s;
    cin>>s;
    stack <char> st;
    st.push(s[0]);
    for(ll i=1;i<n;i++)
    {
        if(s[i]!=st.top())
        st.push(s[i]);
        
    }
    cout<<st.size();
return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python
# coding: utf-8

# In[3]:


N = int(input())
a = list(map(int, input().split()))


# In[6]:


mylist = [0]*(N+1)
i = N
while i > 0:
    idx = i
    x = 0
    while idx <= N:
        x += mylist[idx]
        idx += i
    if x%2 != a[i-1]:
        mylist[i] = 1
    i -= 1
ans = []
for i in range(1,N+1):
    if mylist[i] == 1:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)


# In[ ]:






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

#pragma GCC optimize("02")
#pragma GCC target("tune=native")

using namespace std;

#define ll long long int
#define lu unsigned long long int
#define fi first
#define se second
#define edge pair<long long int,long long int>
#define weighted_edge pair<long long int,pair<long long int,long long int>>

//test

ll dp[(int)1e5 + 1];
ll values[100];
ll weight[100];

ll min(ll a, ll b) {

	return a < b ? a : b;
}

ll knapsack(ll n, ll w) {

	dp[0] = 0;
	
	ll limit = 0;

	for(int i = 0; i < n; i++) limit += values[i];
	for(int i = 1; i <= limit; i++) dp[i] = 10000000000;

	for(int i = 0; i < n; i++) {
		for(int j = limit; j >= values[i]; j--) {
			dp[j] = min(dp[j], dp[j-values[i]] + weight[i]);

		}
	}

	for(int i = limit; i >= 0; i--) {
		if(dp[i] <= w) return i;
	}
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n,w; cin >> n >> w;
	
	for(int i = 0; i < n; i++) {
		cin >> weight[i] >> values[i];
	}

	cout << knapsack(n,w) << '\n';

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
ll arr[26];
ll ans;
ll dp[26];
ll marked[26];
ll recurse(ll idx)
{
	if(marked[idx]!=1)
	{
		marked[idx] = 1;
	}
	ll i;
	ll temp = 0;
	F(i,idx+1,26)
	{
		if(marked[i]==1)
		{
			temp = (temp+(dp[i]*(arr[idx]))%MOD)%MOD;
			
		}
		else
		{
			recurse(i);
			temp = (temp+(dp[i]*arr[idx])%MOD)%MOD;
			
		}
	}
	temp = (temp+ arr[idx])%MOD;
	dp[idx] = temp;
	ans =(ans+ dp[idx])%MOD;
}
int main()
{
	nfs;
	int t;
	t=1;
	//cin >> t;
	
	while(t--)
	{
		ll n;
		
		string s;
		cin >> n;
		
		cin >> s;
		//ll arr[26];
		ll i;
		F(i,0,26)
		{
			arr[i] = 0;
		}
		F(i,0,n)
		{
			arr[(int)(s[i]-'a')]++;
		}
		
		ans = 0;
		recurse(0);
		cout << ans << endl;
		
		
	}
	return 0;

}



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

int main(){
  char cha;
  cin>>cha;
  
  if('A'<=cha&&cha<='Z'){
    cha='A';
  }
  else if('a'<=cha&&cha<='z'){
    cha='a';
  }
  
  cout<<cha<<'\n';
  
  return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	qsort(a, n, sizeof(int), asc);
	int k = 1;
	int b[3];
	b[0] = a[0];
	for (i = 1; i < n; i++)
	{
		if (a[i] != a[i - 1])
		{
			if (k < 3)
			{
				b[k] = a[i];
				k++;
			}
			else
			{
				printf("No\n");
				return 0;
			}
		}
	}
	int count[3];
	if (k == 1)
	{
		if (a[0] == 0)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else if (k == 2)
	{
		count[0] = count[1] = 0;
		for (i = 0; i < n; i++)
		{
			if (a[i] == b[0])
				count[0]++;
			else
				count[1]++;
		}
		if (a[0] == 0)
		{
			if (count[0] * 2 == count[1])
				printf("Yes\n");
			else
				printf("No\n");
		}
		else
			printf("No\n");
	}
	else
	{
		count[0] = count[1] = count[2] = 0;
		for (i = 0; i < n; i++)
		{
			if (a[i] == b[0])
				count[0]++;
			else if (a[i] == b[1])
				count[1]++;
			else
				count[2]++;
		}
		if (count[0] == count[1] && count[1] == count[2])
		{
			if ((b[0] ^ b[1] ^ b[2]) == 0)
				printf("Yes\n");
			else
				printf("No\n");
		}
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 892
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
  int64_t x;
  mint(int64_t x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(int64_t t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  //for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int K = 1e5+10;

//head

int n, k;
mint dp[K], sum[K];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  dp[0] = 1;
  fill(sum+1, sum+k+2, mint(1));
  rep(i, n) {
    int a;
    cin >> a;
    for(int j = 1; j <= k; j++) {
      if(j >= a) {
        dp[j] = sum[j+1] - sum[j-a];
      }
      else dp[j] = sum[j+1];
    }
    rep(j, k+1) sum[j+1] = sum[j] + dp[j];
  }

  cout << dp[k] << endl;
}

Measured memory_bytes: 5112
#include <stdio.h>

int main()
{
  int n;
  int ans=0;
  scanf("%d", &n);
  if(n<10){
    ans=n;
  }else{
    ans+=9;
    if(n>=100 && n<1000){
      ans+=n-99;
    }else if(n>=1000 && n<10000){
      ans+=900;
    }else if(n>=10000 && n<100000){
      ans+=900;
      ans+=n-9999;
    }else if(n==100000){
      ans=90909;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

## DFS

def main():

    #入力受け取り
    N, Q = mi()
    x = li2(N-1)

    cnt = [0]*N
    for i in range(Q):
        p0, p1 = mi()
        cnt[p0-1] += p1

    #隣接リスト作成
    adj = [[] for i in range(N)]
    for i in range(N-1):
        #x[i][0] -= 1
        #x[i][1] -= 1
        adj[x[i][0]-1].append(x[i][1]-1)
        adj[x[i][1]-1].append(x[i][0]-1)

    #DFS
    global ans
    ans = [0]*N

    def dfs(fr, nx):
        ans[nx] += ans[fr] + cnt[nx]
        for v in adj[nx]:
            if v != fr:
                dfs(nx, v)

    dfs(0, 0)
    '''
    for i in range(N):
        print(ans[i], '', end='')
    '''
    print(*ans)

if __name__ == "__main__":
    main()

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

int main() {
  int n, count = 0;
  cin >> n;
  int arr[n];
  
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  sort(arr, arr+n);

  for (int i = n-1; i >= 1; i--) {
    int l = 0, r = i-1;
    while (l < r) {
      if (arr[l] + arr[r] > arr[i]) {
        count += (r-l);
        r--;
      } else {
        l++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d%d',$N,$K);
$count=1;
for ($i=1; $i <=$N ; $i++) {
  // code...
  if($i==1){
    $count*=$K;
  }else{
    $count*=($K-1);
  }
}
echo $count;
?>


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<signed MOD = 1000000007>
struct Mint{
  signed v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(int k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a){return Mint(v)+=a;};
  Mint operator-(Mint a){return Mint(v)-=a;};
  Mint operator*(Mint a){return Mint(v)*=a;};
  Mint operator/(Mint a){return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}

  static vector<Mint> fact,finv,invs;
  
  void init(int n){
    if(n+1<=(signed)fact.size()) return;
    fact.assign(n+1,1);
    finv.assign(n+1,1);
    invs.assign(n+1,1);
    
    for(int i=1;i<=n;i++) fact[i]=fact[i-1]*Mint(i);
    finv[n]=Mint(1)/fact[n];
    for(int i=n;i>=1;i--) finv[i-1]=finv[i]*Mint(i);
    for(int i=1;i<=n;i++) invs[i]=finv[i]*fact[i-1];
  }

  Mint C(int n,int k){
    if(n<k||k<0) return Mint(0);
    return fact[n]*finv[n-k]*finv[k];
  }

  Mint P(int n,int k){
    if(n<k||k<0) return 0;
    return fact[n]*finv[n-k];
  }
  
  Mint H(int n,int k){
    if(n<0||k<0) return 0;
    if(!n&&!k) return 1;
    return C(n+k-1,n);
  }

  
};
template<signed MOD> vector<Mint<MOD> > Mint<MOD>::fact = vector<Mint<MOD> >();
template<signed MOD> vector<Mint<MOD> > Mint<MOD>::finv = vector<Mint<MOD> >();
template<signed MOD> vector<Mint<MOD> > Mint<MOD>::invs = vector<Mint<MOD> >();
//END CUT HERE

template<typename T> 
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  Mint<> m;
  scanf("%d %d",&n,&m.v);

  m.init(n+100);
  
  Mint<> ans(1);
  auto x=factorize(m.v);
  for(auto p:x) ans*=m.H(p.second,n);

  printf("%d\n",ans.v);
  return 0;
}


Measured memory_bytes: 1408
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1 )) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))
    if temp != 1:
        arr.append((temp, 1))
    if arr == []:
        arr.append((n, 1))
    return arr

def solve():
    X = int(input())
    for i in range(X, 0, -1):
        F = factorization(i)
        mi = min(f[1] for f in F)
        if mi > 1 and all([f[1] % mi == 0 for f in F]):
            print(i)
            exit()
    print(1)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 63416
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>

using namespace std;

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

struct Rule {
	int num;
	int l;
	int r;
};
int memo[10][100][100] ;
vector<Rule> Rules;
int start;
vector<int> Retu;

bool dp(int kisoku,int l,int r) {
	if (memo[kisoku][l][r] != -1) {
		return memo[kisoku][l][r];
	}
	if (l == r) {
		memo[kisoku][l][r] = (Rules[kisoku].num == Retu[l]);
		return memo[kisoku][l][r];
	}
	else {
		for (int i = l; i < r; ++i) {
			if (dp(Rules[kisoku].l-1, l, i) && dp(Rules[kisoku].r-1, i + 1, r)) {
				memo[kisoku][l][r] = true;
				return true;
			}
			else {

			}
		}
	}
	memo[kisoku][l][r] = false;
	return false;
}
int main() {
	for (int i = 0; i < 10; ++i) {
		for (int j = 0; j < 100; ++j) {
			for (int k = 0; k < 100; ++k) {
				memo[i][j][k] = -1;
			}
		}
	}
	int N;
	cin >> N;
	rep(i, N) {
		int x;
		cin >> x;
		Retu.push_back(x);
	}
	int M;
	cin >> M;

	rep(i, M) {
		int kisoku,l,r;
		cin >> kisoku >> l >> r;
		Rules.push_back({ kisoku,l,r });
	}
	start = Rules[0].num;
	if (dp(0, 0, N - 1)) {
		cout << "Yes"<< endl;
	}
	else {
		cout << "No" << endl;
	}
	

	return  0;
}

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

#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define per(i,n) for (int i=(int)(n)-1;i>=0;i--)
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define Rep(i,n) for (int i=0;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define cmax(x,y) x=max(x,y)
#define cmin(x,y) x=min(x,y)
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=(1<<21)+3;
const int MOD=1e9+7;

int n,f[23][MAXN];
bool a[23][23];

void next_p(int &x){
	int p,a;
	p=x & (-x);
	a=x + p;
	x=(((a ^ x)>>2)/p)|a; 
}

int main(){
	fio;
	cin>>n;
	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
		}
	}
	rep(i,n){
		if (a[0][i]) f[0][1<<i]=1;
	}
	for (int i=1;i<n;i++){
		int j=(1<<i)-1;
		while (j<(1<<n)){
			rep(k,n){
				if (!a[i][k] || j&(1<<k)) continue;
				f[i][j|(1<<k)]+=f[i-1][j];
				if (f[i][j|(1<<k)]>=MOD) f[i][j|(1<<k)]-=MOD;
			}
			next_p(j);
		}
	}
	cout<<f[n-1][(1<<n)-1]<<endl;
	re 0;
}

Measured memory_bytes: 162048
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        S.append(s)

    a = []
    st = set(S[0])

    for c in list(st):
        cnt = 10 ** 9
        for s in S:
            cnt = min(cnt, s.count(c))
        for i in range(cnt):
            a.append(c)
            
    ans = sorted(a)
    print("".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int N = sc.nextInt();
		int nowx = 0;
		int nowy = 0;
		int nowt = 0;
		for(int i=0; i<N; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			int d = Math.abs(x - nowx) + Math.abs(y - nowy);
			if((t - nowt) - d < 0 || ((t - nowt) - d) % 2 == 1) {
				System.out.println("No");
				return;
			}
			nowx = x;
			nowy = y;
			nowt = t;
		}
		System.out.println("Yes");
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 43260
#include <stdio.h>

int main(void) {
	int L, R, d;
	int i;
	int cnt = 0;

	scanf("%d %d %d", &L, &R, &d);
	
	for ( i = L; i <= R; i++ ) {
		if ( (i % d) == 0 ) {
			cnt++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)cin>>s[i];
    bool tate[h],yoko[w];
    for(int i=0;i<h;i++)tate[i]=true;
    for(int i=0;i<w;i++)yoko[i]=true;
    for(int i=0;i<10;i++)
    for(int i=0;i<h;i++){
        bool ok=false;
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')ok=true;
        }
        tate[i]=ok;
    }
    for(int j=0;j<w;j++){
        bool ok=false;
        for(int i=0;i<h;i++){
            if(s[i][j]=='#')ok=true;
        }
        yoko[j]=ok;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(tate[i]&&yoko[j])cout<<s[i][j];
        }cout<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    cout << (n % 2 ? n / 2 : n / 2 - 1) << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
const long long inf = 9000000000;
struct P {
	long long cost, pos;
};
bool operator<(P a, P b) {
	return a.cost < b.cost;
}
bool operator>(P a, P b) {
	return a.cost > b.cost;
}
struct A {
	long long cost, to;
};
vector<A>a[100001];
long long b[100001];
int main() {
	long long v, e, r, s, t, d;
	cin >> v >> e >> r;
	for (int i = 0; i < e; i++) {
		cin >> s >> t >> d;
		a[s].push_back(A{ d,t });
	}
	priority_queue<P, vector<P>, greater<P>>p;
	fill(b, b + v, inf);
	p.push(P{ 0, r });
	b[r] = 0;
	while (!p.empty()) {
		P y = p.top(); p.pop();
		long long o = y.pos;
		for (int i = 0; i < (int)a[o].size(); i++) {
			if (b[a[o][i].to] > b[o] + a[o][i].cost) {
				b[a[o][i].to] = b[o] + a[o][i].cost;
				p.push(P{ b[a[o][i].to],a[o][i].to });
			}
		}
	}
	for (int i = 0; i < v; i++) {
		if (b[i] == inf) cout << "INF" << endl;
		else cout << b[i] << endl;
	}
}

Measured memory_bytes: 19468
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9){
    printf("hon\n");
  } else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
    printf("pon\n");
  } else {
    printf("bon\n");
  }
  return 0;
}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

template <typename T>
struct Graph {
  int n;
  vector<vector<pair<int, T>>> to;
  Graph(int n) : n(n), to(n) {}
  void add_edge(int s, int t, T cost=1) {
    to[s].push_back(pair<int, T>(t, cost));
  }
  vector<T> dijkstra(int s, T init) {
    vector<T> d(n, init);
    d[s] = 0;
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>> > pq;
    pq.push(pair<T, int>(0, s));
    while (!pq.empty()) {
      int v = pq.top().second; pq.pop();
      for (auto u : to[v]) {
        if (d[v] + u.second < d[u.first]) {
          d[u.first] = d[v] + u.second;
          pq.push(pair<T, int>(d[u.first], u.first));
        }
      }
    }
    return d;
  }
};

int a[309][309];
using P=pair<ll,ll>;
using Q=pair<P,P>;

int main() {
  int n;
  cin>>n;
  rep(i,n)rep(j,n){
    cin>>a[i][j];
  }
  vector<Q>to;
  rep(i,n)rep(j,i){
    to.push_back(Q(P(a[i][j],i),P(j,0)));
  }
  sort(to.begin(),to.end());
  Graph<ll>g(n);
  ll ans=0;
  for(auto x:to){
    ll dist=x.fi.fi;
    ll i=x.fi.se;
    ll j=x.se.fi;
    auto d=g.dijkstra(i,LLINF);
    if(d[j]<dist){
      cout<<-1<<endl;
      return(0);
    }
    if(d[j]==dist)continue;
    g.add_edge(i,j,dist);
    g.add_edge(j,i,dist);
    ans+=dist;
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 5704
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

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;
}

int main(void){

    ll n;
    cin>>n;

    if(n%105== 0 || n%100==0){
        cout<<"1"<<endl;
        return 0;
    }
    for(int i = n/105 +1;i<n/100 + 1;i++){
        //cout<<i<<endl;
        ll num = n- (i*100);
       // cout<<num<<endl;
        if(num/i <=5 ){
            if(num%i==0){
                cout<<"1"<<endl;
                return 0;
            }else if(num%i==5){
                if(num%i==0){
                    cout<<"1"<<endl;
                    return 0;
                }else{
                    cout<<"0"<<endl;
                }
            }else{
                cout<<"1"<<endl;
                return 0;
            }
        }
    }

    cout<<"0"<<endl;

    
        return 0;

}

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

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

	string S;
	cin >> S;

	int result = 0;
	for( int i = 1; i < S.size(); ++i ) {
		if( S[i] == S[i-1] ) {
			S[i] += S[i] == '0' ? 1 : -1;
			result += 1;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~









int main(void){
    int r; scanf("%d", &r);
    printf("%d\n", r * r);

    


    return 0;
}


Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def find(s:Double,i:Int,l:IndexedSeq[Double],d:Double):Int =
    if( s >= d ) i else find(s+l(i),i+1,l,d)

  def main(args:Array[String]) = {
    val b = new StringBuilder

    for(l<-stdin.getLines.map(s=>s.split(",").map(_.toDouble))) {
      val d = l.take(10).sum * l(10)/(l(10)+l(11))
      b.append(find(0D,0,l,d) + "\n")
    }
    print(b.result)
  }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  vector<ll> k;
  rep(i, n) {
    ll a;
    cin >> a;
    if (mp.count(a) == 0) k.push_back(a);
    mp[a]++;
  }
  rep(i, m) {
    ll b, c;
    cin >> b >> c;
    if (mp.count(c) == 0) k.push_back(c);
    mp[c] += b;
  }
  sort(k.begin(), k.end());
  reverse(k.begin(), k.end());
  int i = 0;
  ll total = 0;
  while (n > 0) {
    int t = mp[k[i]];
    total += min(t, n) * k[i];
    n -= t;
    i++;
  }
  cout << total << endl;
}


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

int main()
{
	int s,w;
    cin>> s >> w;
    
    if(s>w)
    {
        cout <<"safe"<<endl;
    }
    else
    {
        cout <<"unsafe" <<endl;
    }
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#define MAX 100000
#define NIL -1
 
struct node {
  int p, l, r, t;
};

struct node T[MAX];

void depth(int);
int height(int);
void print(int);

int n, H, D[MAX], h[MAX];
 
int main(){
  
  int i, d, v, c, l, r;
   
  scanf("%d", &n);
   
  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }
   
  for(i = 0; i < n; i++) {
    scanf("%d %d %d", &v, &l, &r);
    if(l != NIL) {
      T[l].p = v;
    }
    if(r != NIL) {
      T[r].p = v;
    }
    T[v].l = l;
    T[v].r = r;
  }
  for ( i = 0; i < n; i++ ){
    if(T[i].l != NIL) {
      T[i].t++;
    }
    if(T[i].r != NIL){
      T[i].t++;
    }
  }
   
  for(i = 0; i < n; i++){
    if(T[i].p==NIL) {
      D[i] = 0; 
      depth(i); 
      break;
    }
  }
  for(i = 0; i < n; i++){
    h[i] = height(i); 
  }
 
  for ( i = 0; i < n; i++ ) {
    print(i);
  }

  return 0;
}

void depth(int u){
  
  int d = 0;

  if(T[u].r != NIL){
    D[T[u].r] = D[u]+1;
    depth(T[u].r);
  }
  if(T[u].l != NIL){ 
    D[T[u].l] = D[u]+1;
    depth(T[u].l);
  }
}
 
int height(int u){
  
  int a = 0, s = 0;

  if(T[u].r == NIL && T[u].l == NIL) 
    return 0;
  if(T[u].l != NIL) {
    a = height(T[u].l)+1;
  }
  if(T[u].r != NIL) {
    s = height(T[u].r)+1;
  }
  if(a > s) 
    return a;
  else 
    return s;
}
 
void print(int u){
  printf("node %d: parent = %d,", u, T[u].p);
  if(T[u].p == NIL)
    printf(" sibling = -1, ");
  else if(T[T[u].p].r == u)
    printf(" sibling = %d, ", T[T[u].p].l);
  else if(T[T[u].p].l == u)
    printf(" sibling = %d, ", T[T[u].p].r);
  printf("degree = %d, ", T[u].t);
  printf("depth = %d, height = %d, ", D[u], h[u]);

  if(T[u].p == NIL)
    printf("root\n");
  else if(T[u].t == 0)
    printf("leaf\n");
  else
    printf("internal node\n");
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, a, b, ans;
    cin >> n >> a >> b;
    if(b == 0)
    {
        cout << n << endl;
        return 0;
    }
    cout << (n / (a + b)) * a + min(a, n % (a + b)) << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	string s;
	cin >> s;
	if('a' <= s[0] && s[0] <= 'z'){
		cout << 'a' << endl;
	} else {
		cout << 'A' << endl;
	}

}


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

int p[20];

int main(){
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  int count = 0;
  for(int i=1; i<n-1; i++){
    if((p[i-1] < p[i] && p[i] < p[i+1])||(p[i-1] >p[i] && p[i] > p[i+1])) count++;
  }
  cout << count << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  for (int i=0; i < N; i++){
    string S;
    cin >> S;
    
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if(i == N-1)
      cout << "Three" << endl;
  }
}


Measured memory_bytes: 256