akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> d[100005] = {};
  rep(i, N) {
    int A, B;
    cin >> A >> B;
    d[A].push_back(B);
  }

  priority_queue<int> q;
  int ans = 0;

  for (int i = 1; i <= M ; i++) {
    for (auto x : d[i]) {
      q.push(x);
    }
    if (q.empty()) continue;
    else {
      int y = q.top(); q.pop();
      ans += y;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 5632
#include <iostream>
using namespace std;
     
    int main() {
     	int D, T, S;

	double time;

	cin >> D >> T >> S;

	time = (double)D / S;

	if (time <= T) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}
      return 0;
    }

Measured memory_bytes: 3616
<?php
$inputs = str_split(file_get_contents("php://stdin"));
echo array_reduce($inputs, function($prev, $cur) {
  if ($cur === "B") {
    return strlen($prev) == 0 ? $prev : substr($prev, 0, -1);
  } else {
    return $prev.$cur;
  }
}, "");


Measured memory_bytes: 3576
#include<iostream>
#include <string>
#define ch(x) char(x -32)
using namespace std;

int main(void){
	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
	cout << ch(s1[0])<< ch(s2[0]) << ch(s3[0]) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
unsigned long N, K, ans; cin >> N >> K;
ans=(K)?(N-K+1)*(N-K)/2:N*(N-1)/2;
for(unsigned long i, b=K+1; b<=N; b++){
 for(i=2; (i-1)*b+K<=N && i*b-1<=N; i++){ ans+=(b-K); }
 if((i-1)*b+K<=N && i*b-1>N){ ans+=(N-((i-1)*b+K)+1); }
}
cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String S = in.readLine();
		if (S.charAt(S.length() - 1) != 's') {
			S = S + "s";
		} else {
			S = S + "es";
		}
		System.out.println(S);
	}

	void calc() {
	}

	void showResult() {
	}
}


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

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

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    ll k = sqrt(n);
    ll m = (n-1)/k + 1;
    ll INF = (1ll << 31) - 1;
    vector<ll> a(m*k, INF);
    vector<ll> hei(m, INF);

    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 0){
            ll x,y;
            cin >> x >> y;
            a.at(x) = y;
            ll ind = x/k;
            hei.at(ind) = INF;
            for(j = ind*k;j < k*(ind + 1);++j) hei.at(ind) = min(hei.at(ind), a.at(j));
        }else{
            ll x,y;
            cin >> x >> y;
            ll ans = INF;
            if(x/k == y/k){
                for(j = x;j <= y;++j) ans = min(ans, a.at(j));
            }else{
                while(x%k != 0){
                    ans = min(ans, a.at(x));
                    ++x;
                }
                while(y%k != 0){
                    ans = min(ans, a.at(y));
                    --y;
                }
                ans = min(ans, a.at(y--));
                while(x/k <= y/k){
                    ans = min(ans, hei.at(x/k));
                    x += k;
                }
            }
            cout << ans << endl;
        }
    }

    return 0;
}


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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pll pair<lli,lli>
//#define vector<lli> vl

int main(){
  string S;
  string ans;

  cin>>S;

  rep(i,S.length()){
    if(S[i]=='0')
      ans.push_back('0');
    else if(S[i]=='1')
      ans.push_back('1');
    else if(S[i]=='B')
      if(!ans.empty())
	ans.erase(ans.end()-1);
  }


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

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

#pragma gcc target ("avx2")
#pragma gcc optimization ("o3")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define nopf(T) [](T a){return a;}
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	string s;
	scans(s);
	int cnt = 0;
	for(const auto &aa: s)if(aa == 'o')++cnt;
	printYN(cnt + (15 - s.length()) > 7);

	Please AC;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
using namespace std;
using Int = int64_t;
constexpr long long int mod = 1e9 + 7;

int main() {

	string S, T; cin >> S >> T;

	cout << T << S << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def assignColor():
    C = [-1 for i in range(n)]
    for i in range(n):
        if C[i] == -1:
            C = BFS(G, i, C)
    return C

#@profile
def BFS(G, start, C):
    n = len(G)
    Q = [start]
    C[start] = start

    while len(Q) != 0:
        u = Q.pop(0)
        v = [i for i in G[u] if C[i] == -1] # v := ??£??\???????????????????????¢?´¢??????????????????
        
        for i in v:
            Q.append(i)
            C[i] = C[start]
    
    return C

def main():
    
    for i in range(m):
        s, t = list(map(int, input().split()))
        G[s].append(t)
        G[t].append(s)

    C = assignColor()
        
    q = int(input())
    
    for i in range(q):
        s, t = list(map(int, input().split()))
        if C[s] == C[t]:
            print("yes")
        else:
            print("no")
            
if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    G = [[] for i in range(n)]

    main()    

Measured memory_bytes: 32804
H, N = map(int, input().split())
Attack = []
Magic = []
for _ in range(N):
    a, b = map(int, input().split())
    Attack.append(a)
    Magic.append(b)

DP = [float('inf')] * (H + 1)
DP[0] = 0
for i in range(H):
    for j in range(N):
        d = min(H, i + Attack[j])
        DP[d] = min(DP[d], DP[i] + Magic[j])

print(DP[H])

Measured memory_bytes: 43100
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=5e5+3,mo=998244353;
int n,m,ft[mn*2],ni[mn*2];
int Pow(LL x,int y){
	LL z=1;
	for(;y;y>>=1,(x*=x)%=mo)if(y&1)(z*=x)%=mo;
	return z;
}
int C(int x,int y){
	return 1ll*ft[x]*ni[y]%mo*ni[x-y]%mo;
}
int main(){
	scanf("%d%d",&n,&m);
	if(n<m)swap(n,m);
	ft[0]=1;
	fo(i,1,n+m)ft[i]=1ll*ft[i-1]*i%mo;
	ni[n+m]=Pow(ft[n+m],mo-2);
	fd(i,n+m-1,0)ni[i]=1ll*ni[i+1]*(i+1)%mo;
	int ans=0;
	fo(i,1,m)ans=(ans+1ll*C(i*2,i)*C(n+m-i*2,n-i))%mo;
	printf("%lld",(n+1ll*ans*ni[2]%mo*Pow(C(n+m,n),mo-2))%mo);
	return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

vector <ll> p;

void factor(ll x) {
	for (int i = 2; 1LL * i * i <= x; ++ i) {
		if (x % i == 0) {
			ll c = 1;
			while (x % i == 0) {
				c *= i;
				x /= i;
			}
			p.pb(c);
		}
	}
	if (x > 1) {
		p.pb(x);
	}
}

ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (!b) {
		x = 1; y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

int main() {
	ll n;
	scanf("%lld", &n);
	n *= 2;
	factor(n);
	ll ans = n;
	rep(S, 1 << p.size()) {
		ll a = 1, b = 1;
		rep(i, p.size()) (S >> i & 1 ? a : b) *= p[i];
		ll x, y;
		exgcd(a, b, x, y);
		a *= -1;
		a *= x; b *= y;
		ll delt = max(0LL, -min(a, b));
		delt = (delt + n - 1) / n;
		a += delt * n;
		b += delt * n;
		if (a > 0) ans = min(ans, a);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3832
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    double a,b,c,C,S,h,L;
    cin >> a >> b >> C;
    h = b*sin(C * M_PI / 180);
    S = 0.5 * a * h;
    L = a+b+sqrt(a*a+b*b-2*a*b*cos(M_PI /180 * C));

    cout << setprecision(10) << S << endl;
    cout << setprecision(10) << L << endl;
    cout << setprecision(10) << h << endl;
    return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                               \
  ifstream in("atcoder-problems/codefestival_2016_qualC_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int K, T;
  cin >> K >> T;

  vector<int> c(T, 0);
  rep(i, T) { cin >> c[i]; }
  sort(c.begin(), c.end(), greater<int>());

  ll ans = 0;
  if (T == 1) {
    cout << c[0] - 1 << endl;
    return 0;
  } else {
    ans = max(2 * c[0] - K - 1, 0);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#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<int,int>;
const int MAX = 100100100;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ks(M);
  vector<vector<int>> ss(M, vector<int>(N));
  rep(i, M) {
    cin >> ks[i];
    rep(j, ks[i]) {
      cin >> ss[i][j];
    }
  }
  vector<int> ps(M);
  rep(i, M) {
    cin >> ps[i];
  }

  int ans = 0;
  for(int i = 0; i < (1 << N); i++) {
    bitset<10> s(i);
    bool isOk = true;
    rep(j, M) {
      int cnt = 0;
      rep(k, ks[j]) {
        int num = ss[j][k];
        if (s.test(num-1)) cnt++;
      }
      if (cnt%2 != ps[j]) {
        isOk = false;
        break;
      }
    }
    if (isOk) ans++;
  }

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


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

nextNo = 1
cnt = 0
for i in range(len(a)):
  if a[i] == nextNo:
    cnt += 1
    nextNo += 1

if cnt == 0:
  print(-1)
else:
  print(n-cnt)

  

      


Measured memory_bytes: 24744
char_list = input()
odd = char_list[0::2]
even = char_list[1::2]
odd_easy = ['R','U','D']
even_easy = ['L','U','D']
odd_result = []
even_result = []
true_false = []

for char in odd:
 if char in odd_easy:
  odd_result.append('True')
 else:
  odd_result.append('False')

for char in even:
 if char in even_easy:
  even_result.append('True')
 else:
  even_result.append('False')

true_false = odd_result + even_result

if 'False' in true_false:
 print('No')
else:
 print('Yes')


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  n = readInts()[0]
  p = readInts()

  ans = 0
  for i in range(0, n - 2):
    if sorted([p[i], p[i+1], p[i+2]])[1] == p[i+1]:
      ans += 1
  print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 3060
/*
 * atcoder/dp_2nd/s.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long
#define MOD 1000000007

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX_K = 10100;
const int MAX_D = 120;
int D, N;
string K;

ll dp[2][MAX_K][MAX_D];

void input() {
  cin >> K >> D;
  N = K.size();
}

/*
 * n: 今何桁目
 * d: 今までの合計 (MOD D)
 * l: 次の桁の数字を制限するか
 */
ll rec(int n = 0, int d = 0, bool l = true) {
  ll &cache = dp[l][n][d];
  if (~cache) return cache;
  if (n == N) return cache = d == 0;
  int u = l ? K[n] - '0' : 9;
  ll ways = 0;
  for (int i=0; i<=u; i++) {
    ways += rec(n + 1, (d + i) % D, l && i == u);  // 一度でも制限解除されると最後の桁まで制限なし.
    ways %= MOD;
  }
  return cache = ways;
}

void memoRec() {
  memset(dp, -1, sizeof(dp));
  ll ways = (rec() - 1 + MOD) % MOD; // 1<= なので0の分を引く
  cout << ways << endl;
}

void give() {
  memset(dp, 0, sizeof(dp));
  dp[1][0][0] = 1;
  for (int n=0; n<N; n++) {
    for (int d=0; d<D; d++) {
      for (int l=0; l<=1; l++) {
        for (int i=0; i<=9; i++) {
          if (l && i > K[n] - '0') continue;
          int nl = (l && i == K[n] - '0') ? 1 : 0;
          dp[nl][n+1][(d+i)%D] += dp[l][n][d];
          dp[nl][n+1][(d+i)%D] %= MOD;
        }
      }
    }
  }

  ll ans = dp[0][N][0];
  ans += dp[1][N][0];
  ans--;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

void solve() {
  give();
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 19200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var minSum = long.MaxValue;
            var aSum = (long)0;
            var bSum = inputLongArray.Sum();

            for(int i = 0; i < inputLongArray.Length - 1; i++) { 
                aSum += inputLongArray[i];
                bSum -= inputLongArray[i];
                var sumDif = Math.Abs(aSum - bSum);
                if(sumDif < minSum) {
                    minSum = sumDif;
                }
            }

            Console.WriteLine(minSum);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 34500
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int main(){
    int N; cin >> N;
    vector<ll> B(N);
    for(int i=0;i<N;i++){
        ll a; cin >> a;
        B[i] = a-i-1;
    }
    sort(B.begin(),B.end());
    ll b=B[N/2];
    cerr << N/2 << endl;
    ll ans=0;
    for(int i=0;i<N;i++){
        ans += abs(B[i]-b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcd = GetInput_long();
            List<long> _resultList = new List<long>();
            _resultList.Add(abcd[0] * abcd[2]);
            _resultList.Add(abcd[0] * abcd[3]);
            _resultList.Add(abcd[1] * abcd[2]);
            _resultList.Add(abcd[1] * abcd[3]);

            _resultList.Sort();
            var max = _resultList[_resultList.Count - 1];
            Console.WriteLine(max);
        }
        #region input


        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }
        public static long GCD(long a, long b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                long tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            long r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion
        
    }
}

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

int main() {
  string S;
  cin >> S;
  int i = 0;
  bool f =true;
  
  while(S[i] != NULL) {
    char a = S[i];
    
    if(i % 2 == 0) {
      if(a != 'R' && a != 'U' && a != 'D')
        f = false;
    }      
    else {
      if(a != 'L' && a != 'U' && a != 'D')
        f = false;
    }
    i++;
  }
  
  if(f == true)
  	cout << "Yes" <<endl;
  else
    cout <<"No" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  string s;
  cin >> s;
  int N = s.size();
  rep(i,(N-1)/2){
    if(s.at(i) != s.at(N-1-i)){
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i,(N-1)/4){
    if(s.at(i) != s.at((N-1)/2-1-i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" <<endl;
  return 0;
}

Measured memory_bytes: 256
import math
n,m = map(int,input().split())
a = math.factorial(n)
b = math.factorial(m)
if abs(n-m)>1:
    print(0)
elif abs(n-m)==1:
    print((a*b)%(10**9+7))
else:
    print((a*b*2)%(10**9+7))

Measured memory_bytes: 5180
#include <iostream>
#include <cmath>

#include <vector>
#include <algorithm>
#include <limits>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <queue>

using namespace std;


class UnionFind {

    vector<int> par;

public:
    UnionFind(int n) {
        par = vector<int>(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
        }
    }
    bool unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) {
            return false;
        } else {
            par[ry] = rx;
            return true;
        }
    }
    int root(int x) {
        if (par[x] != x) {
            par[x] = root(par[x]);
        }
        return par[x];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    UnionFind uf(n);
    for(int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        uf.unite(a[i], b[i]);
    }
    unordered_map<int, int> map;
    for (int i = 0; i < n; ++i) {
        map[uf.root(i)] += 1;
    }
    int max_len = 0;
    for (auto it = map.begin(); it != map.end(); ++it) {
        if (it->second > max_len) {
            max_len = it->second;
        }
    }
    cout << max_len << endl;
}


Measured memory_bytes: 11996
_ = int(input())
s = list(input())

count = 0

r_idx = set([n for n, v in enumerate(s) if v == 'R'])
g_idx = set([n for n, v in enumerate(s) if v == 'G'])
b_idx = set([n for n, v in enumerate(s) if v == 'B'])


# ループ2重に減らして，3個目をinで探索
for r in r_idx:
	for g in g_idx:
		out = 0
		if max([r,g]) + abs(g-r) in b_idx:
			out += 1
		if min([r,g]) - abs(g-r) in b_idx:
			out += 1
		if (r+g) / 2 in b_idx:
			out += 1
		count += (len(b_idx) - out)



print(count)

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

#define int long long
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);


main(){
	FIO
	int n,k;
	cin>>n>>k;
	int i,j;
	int arr[n];
	for(i=0;i<n;i++){
		cin>>arr[i];
	}
	int low=1,high=1000000000;
	while(low<high){
		int mid = (low+high)/2;
		int x=0;
		for(i=0;i<n;i++){
			x+=((arr[i]-1)/mid);
		}
		if(x>k){
			low = mid+1;
		}
		else{
			high = mid;
		}
		//cout<<low<<" "<<high<<endl;
	}
	cout<<low<<endl;
	
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
int const INF = 1001001001;

string res(int sx, int sy, int gx, int gy) {
    string s = "";
    if(sx < gx && sy < gy) {
        rep(i,gy-sy) s.push_back('U');
        rep(i,gx-sx) s.push_back('R');
        return s;
    }
    if(sx > gx && sy > gy) {
        rep(i,sy-gy) s.push_back('D');
        rep(i,sx-gx) s.push_back('L');
        return s;
    }
}

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

int sx,sy,gx,gy;
cin >> sx >> sy;
cin >> gx >> gy;

string ans = "";
ans += res(sx, sy, gx, gy);
ans += res(gx, gy, sx, sy);
ans += 'L';
ans += res(sx-1, sy, gx, gy+1);
ans += "DR";
ans += res(gx+1, gy, sx, sy-1);
ans += 'U';

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

Measured memory_bytes: 256
n,m=gets.split.map &:to_i
a=[]
b=[]
n.times do
    a << gets
end
m.times do
    b << gets
end
flag = true
jud = false
(n-m+1).times do |x|
    (n-m+1).times do |y|#始点
        flag = true
        m.times do |i|
            m.times do |j|
                if a[x+i][y+j] != b[i][j]
                    flag = false
                    break
                end
            end
            if !flag
                break
            end
        end
        if flag
            puts "Yes"
            jud = true
            break
        end
    end
    if jud
        break
    end
end

if !jud
    puts "No"
end


Measured memory_bytes: 1788
<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<$m){
  list($a,$b)=explode(" ",trim(fgets(STDIN)));
  $map[$a][$b]=1;
  $map[$b][$a]=1;
  ++$i;
}
$r=array(1);
$f=array_fill(1,$n,0);
$f[1]=1;
$c=$n-1;
while($c>0){
  $b=array();
  $i=0;
  $j=count($r);
  while($i<$j){
    foreach($map[$r[$i]] as $k => $v){
      if($f[$k]==0){
        $f[$k]=$r[$i];
        --$c;
        $b[]=$k;
      }
    }
    ++$i;
  }
  $r=$b;
}
$f[1]="Yes";
echo join("\n",$f);

Measured memory_bytes: 69840
#include <iostream>
#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/tree_policy.hpp>   // Contains class "tree_order_statistics_node_update".
using namespace std;
using namespace __gnu_pbds;   // Appropriate namespace (called "pb_ds" earlier).

typedef tree<
             pair<int,int>,         // type of data (value) inside ordered set
             null_type,
             less<pair<int,int> >,   // should be the same type as value (!), also you can use "greater<int>" here for descending order of sort
             rb_tree_tag,
             tree_order_statistics_node_update
            > ordered_set;

int const MAX_N = 256*1024;
int s[MAX_N];

int main() {
	int n;
	scanf("%d",&n);
	for (int i=0; i<n; i++) scanf("%d",&s[i]);
    ordered_set X;
	for (int i=0; i<n; i++) X.insert(make_pair(s[i],i));
	int l = n-1;
	for (int i=0; i<n; i++) {
		X.erase(make_pair(s[i],i));
		printf("%d\n",X.find_by_order((l+1)/2-1)->first);
		X.insert(make_pair(s[i],i));
	}
    return 0;
}

Measured memory_bytes: 15488
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if (b <= a) {
    cout << "delicious" << endl;
    return 0;
  }
  if (b - a <= x) {
    cout << "safe" << endl;
    return 0;
  }
  cout << "dangerous" << endl;
}


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

int main(){
	int N, X;
	cin >> N >> X;
	
	int i, L[N+1], D[N+1];
	for(i=1; i<=N; i++){
		cin >> L[i];
	}
	
	D[1]=0;
	i=1;
	do{
		i++;
		D[i] = D[i-1] + L[i-1];
	}while(D[i]<=X);
	
	cout << i-1 << endl;
	
	return 0;
}


Measured memory_bytes: 256
def read():
    N = int(input())
    return N,

def solve(N):
    ans = 0
    for i in range(1, N+1):
        if i % 3 != 0 and i % 5 != 0:
            ans += i
    return ans
    

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 9144
#include<stdio.h>

int main()
{
	int x,y,i;
	for(i=0;i<10000;i++)
	{
		scanf("%d %d",&x,&y);
		
		if((x==0)&&(y==0))break;
		
		if(x<=y)
		printf("%d %d\n",x,y);
		
		else
		printf("%d %d\n",y,x);
	}
	return 0;
}

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


//初項ini, 項差diff, 項数numの等差数列の和
long sumUp(long ini, long diff, long num){
  	return num  * (2*ini + (num-1)*diff)/ 2;
}

int main(){
  long N, K;
  cin >> N >> K;
  cout<<fixed<<setprecision(9);

  long p[N];
  for (long i = 0L; i < N; i++) {
    cin >> p[i];
  }
  
  double sum = 0L;
  double ans = 0L;
  for (long i = 0L; i < N; i++) {
    sum += (double)sumUp(1L, 1L, p[i])/(double)p[i];
    if (i-K>=0L) sum -= (double)sumUp(1L, 1L, p[i-K])/(double)p[i-K];
    if (i>=K-1L) {
      ans = max(ans, sum);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

int main() {
	int a, b;
	string s;
	char c;
	bool flag =false;

	cin >> s;
	
	for (int i = 0; i < s.size(); i++) {
		if ((s[i] == 'U' || s[i] == 'D' || s[i] == 'R') && ((i+1) % 2 == 1)) {

		}
		else if ((s[i] == 'U' || s[i] == 'D' || s[i] == 'L') && ((i + 1) % 2 == 0)) {

		}
		else {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  int A,B; read(A,B);
  if(A==B) return puts("0"),0;
  if(A>0) {
    if(B>A) printf("%d\n",B-A);
    else {
      if(B<-A) printf("%d\n",-A-B+1);
      else {
        if(B>0) printf("%d\n",A-B+2);
        else printf("%d\n",B+A+1);
      }
    }
  }
  else if(A<0) {
    if(B<A) printf("%d\n",A-B+2);
    else {
      if(B>-A) printf("%d\n",B+A+1);
      else {
        if(B>0) printf("%d\n",-A-B+1);
        else printf("%d\n",B-A);
      }
    }
  }
  else {
    if(B<0) printf("%d\n",-B+1);
    else printf("%d\n",B);
  }
  return 0;
}


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

int main()
{
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    cout << (60 * H2 + M2) - (60 * H1 + M1) - K << endl;
    return 0;
}


Measured memory_bytes: 3628
n, y = map(int, input().split())

flag = 0
for i in range(n + 1):
    for j in range(n + 1 - i):
        if i * 1000 + j * 5000 + (n - (i + j)) * 10000 == y:
            flag = 1
            ans = [n - i - j, j, i]
            break

print(*ans) if flag == 1 else print(-1, -1, -1)

Measured memory_bytes: 3064
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()


ans = 0
#Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索
for i in B:
    ans += bisect_right(A, i-0.1) * (N-bisect_left(C, i+0.1))
print (ans)


Measured memory_bytes: 105444
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int n,a,v,v2;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a;
		if (a%4==0) v++;
		if (a%2==0 && a%4!=0) v2++;
	}
	v*=2;
	if (v2>=2){
		n-=v2;
		n++;	
	}
	if (n%2==0){
		if (v<n){
			cout<<"No";
		}else{
			cout<<"Yes";
		}
	}else{
		if (v<n-1){
			cout<<"No";
		}else{
			cout<<"Yes";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) (v.begin(), v.end())
#define ff(i, x, n, k) for(int i=x;i<n;i+=k)
#define rf(i, x, n, k) for(int i=n-1;i>=x;i+=k)
#define ef(i, x, n, k) for(int i=x;i<=n;i+=k)
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define input(n) scanf("%lld", &n)
#define output(n) printf("%lld", n);

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MOD = 1e9+7;
const ll INF = pow(10, 18)+5;

int main()
{
  fast_cin();
  ll n;
  cin>>n;
  ll maxVal = 1;
  for(ll i=1;i<=sqrt(n);i++){
    if(n%i == 0){
      maxVal = i;
    }
  }
  //cout<<maxVal<<endl;
  ll finalAns = maxVal + (n/maxVal) - 2;
  cout<<finalAns<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = calloc(n,sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct node{
	struct node *parent;
	struct node **child;
	int id;
	int depth;
	int nchild;
}node;

node *createNode(){
	node *v;
	mymalloc(v,1);
	v->parent=NULL;
	v->nchild=0;
	return v;
}

node **readTree(int n){
	int i,j,id,nchild,k;
	node *child;
	node **T;
	mymalloc(T,n);
	for(i=0;i<n;i++){
		T[i]=createNode();
	}
	for(i=0;i<n;i++){
		scanf(" %d %d",&id,&nchild);
		T[id]->id=id;
		T[id]->nchild=nchild;
		if(nchild==0){continue;}
		mymalloc(T[id]->child,nchild);
		for(j=0;j<nchild;j++){
			scanf(" %d",&k);
			T[id]->child[j]=T[k];
			T[k]->parent=T[id];
		}
	}
	return T;
}

node *findRoot(node **T,int n){
	int i;
	for(i=0;i<n;i++){
		if(T[i]->parent==NULL){
			return T[i];
		}
	}
	return NULL;
}

void calcDepth(node *root,int depth){
	int i;
	if(root!=NULL){
		root->depth=depth;
		for(i=0;i<root->nchild;i++){
			calcDepth(root->child[i],depth+1);
		}
	}
}

void printNode(node *T){
	int i;
	node *child;
	printf("node %d: ",T->id);
	if(T->parent==NULL){
		printf("parent = -1, ");
	}else{
		printf("parent = %d, ",T->parent->id);
	}
	printf("depth = %d, ",T->depth);
	if(T->nchild==0&&T->parent!=NULL){
		printf("leaf, []\n");
	}else{
		if(T->parent==NULL){
			printf("root, ");
		}else{
			printf("internal node, ");
		}
		printf("[");
		for(i=0;i<T->nchild;i++){
			printf("%d",T->child[i]->id);
			if(i!=T->nchild-1){
				printf(", ");
			}
		}
		printf("]\n");
	}
}

void printAll(node *root){
	int i;
	printNode(root);
	for(i=0;i<root->nchild;i++){
		printNode(root->child[i]);
	}
}

void freeNode(node **T,int n){
	int i;
	for(i=0;i<n;i++){
		free(T[i]->child);
		free(T[i]);
	}
	free(T);
}

main(){
	node **T;
	node *root;
	int n,i;
	scanf("%d",&n);
	T=readTree(n);
	root=findRoot(T,n);
	calcDepth(root,0);
	for(i=0;i<n;i++){
		printNode(T[i]);
	}
	freeNode(T,n);
	return 0;
}

Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

struct WF{
  void solve(vector<vector<pair<int, ll> > >&G, vvl&v){
    int n = sz(G);
    v.resize(n);
    FOR(i, 0, n){
      v[i] = vl(n);
      fill(v[i].begin(), v[i].end(), linf);
    }
    FOR(i, 0, n){
      each(itr, G[i]){
        v[i][itr->fi] = itr->se;
      }
      v[i][i] = 0;
    }
    FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n) mins(v[i][j], v[i][k] + v[k][j]);
  }
};

typedef pair<int, ll> T;
typedef vector<T> vt;
vector<vt> G;
int h, w;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  G.resize(10);
  FOR(i, 0, 10)FOR(j, 0, 10){
    ll c;
    cin >> c;
    G[i].pb(mp(j, c));
  }
  WF wf;
  vvl v;
  wf.solve(G, v);
  ll ans = 0;
  FOR(i, 0, h) FOR(j, 0, w){
    int c;
    cin >> c;
    if(c > -1) ans += v[c][1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
class UnionFind:
    def __init__(self, n):
        '木の初期化をする'
        self.p = [-1] * n
        self.rank = [1]*n
        self.b = [0]*n
        self.w = [0]*n
        self.parent = set(range(n))

    def find(self, x):
        'x の親を返す'
        if self.p[x] == -1:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def unite(self, x, y):
        'rankの低い親を高い方のの親にする'
        if not self.same(x,y):
            x = self.find(x)
            y = self.find(y)
            if self.rank[x] > self.rank[y]:
                x,y = y,x
            elif self.rank[x] == self.rank[y]:
                self.rank[y] += 1
            self.b[y] += self.b[x]
            self.w[y] += self.w[x]
            self.p[x] = y
            if x in self.parent:
                self.parent.remove(x)
            return True
        else:
            return False

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

h,w = map(int,input().split())
uf = UnionFind(h*w)
S = []
for i in range(h):
    S.append(input())
    for j,s in enumerate(S[i]):
        if s == '#':
            uf.b[i*w+j] += 1
        else:
            uf.w[i*w+j] += 1

for i in range(h):
    for j in range(w):
        for di,dj in [[1,0],[0,1]]:
            ni = i+di
            nj = j+dj
            if ni < h and nj < w and S[i][j] != S[ni][nj]:
                uf.unite(i*w+j,ni*w+nj)
ans = 0
for p in uf.parent:
    ans += uf.b[p] * uf.w[p]
print(ans)


Measured memory_bytes: 17384
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    int B[110];
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }

    lint res = 0;
    int A[110];
    A[0] = B[0];

    for (int i = 1; i < N; i++) {
        A[i] = B[i-1];
        if (i != N-1 && B[i-1] > B[i]) {
            A[i] = B[i];
        }
    }

    for (int i = 0; i < N; i++) {
        res += A[i];
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctype.h>
#include <string>
using namespace std;
 
int rev(int n){
    int rev=0;
    while(n>0){
        rev=rev*10+n%10;
        n/=10;
    }
    return rev;
}

int main(){
    int A,B,ans=0;
    cin>>A>>B;

    for(int i=A;i<=B;i++){
        if(i==rev(i))ans++;
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb push_back
#define fi first
#define se second



int main(){
    ll i,j;
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    ll sa=0;
    ll sb=0;
    for(i=0;i<n;i++){
        cin>>a[i];
        sa+=a[i];
    }
    for(i=0;i<n;i++){
        cin>>b[i];
        sb+=b[i];
    }

    if(sa<sb){
        cout<<-1<<endl;
        return 0;
    }
    
    ll fus=0;
    ll c2=0;
    ll c3=0;

    vector<ll> ne,po;

    for(i=0;i<n;i++){

        if(a[i]==b[i]) c2++;
        else if(a[i]<b[i]) {
            fus-=b[i]-a[i];
            c3++;
        }
        else {
            po.pb(a[i]-b[i]);
        }
    }
    sort(po.begin(),po.end());
    reverse(po.begin(),po.end());

    ll cnt=0;
    ll bb=0;
    while(fus<0){
        fus+=po[bb];
        cnt++;
        bb++;
    }


    cout<<cnt+c3<<endl;
    return 0;
}

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

using namespace std;

int main() {
  int n, ans = 0;
  cin >> n;
  
  for(int a = 1; a <= n; a++) {
    for(int b = 1; b <= n; b++) {
      if(a * b < n)
        ans++;
      else
        break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
s = input()
t = input()
numlist = []
for i in range(len(s)-len(t)+1):
    a = s[i:i+len(t)]
    count = 0
    for j in range(len(t)):
        if a[j] != t[j]:
            count += 1
    numlist.append(count)
print(min(numlist))

Measured memory_bytes: 9060
s = input()
n = len(s)
s += 'R'
A = [0 for i in range(n)]
r = 0
l = 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    else:
        l += 1
    if s[i] == 'R' and s[i+1] == 'L':
        k = i
    if s[i] == 'L' and s[i+1] == 'R':
        if (r+l)%2 == 0:
            A[k] = (r+l)//2
            A[k+1] = (r+l)//2
        elif r%2 == 0:
            A[k] = (r+l)//2
            A[k+1] = (r+l)//2+1
        else:
            A[k] = (r+l)//2+1
            A[k+1] = (r+l)//2
        r = 0
        l = 0
print(*A)

Measured memory_bytes: 6408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := readint()

	if N&1 != 0 { // Nが奇数の場合、末尾の0はつかない
		fmt.Println(0)
		return
	}

	ans := 0
	for n := 10; n <= N; n *= 5 {
		ans += N / n
	}

	fmt.Println(ans)
}

const (
	iobufsize = 1 * 1024 * 1024 // 1 MB
)

var stdinsc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, iobufsize), iobufsize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func readint() int {
	stdinsc.Scan()
	v, err := strconv.Atoi(stdinsc.Text())
	if err != nil {
		panic(err)
	}
	return v
}

func readstr() string {
	stdinsc.Scan()
	return stdinsc.Text()
}

func pow(x, y int) int {
	if y < 1 {
		return 1
	}
	return x * pow(x, y-1)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 640
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]
 
gh = {i:{} for i in range(h)}
gw = {i:{} for i in range(w)}
 
for _h, _w in hw:
    gh[_h-1][_w-1]=_w-1
    gw[_w-1][_h-1]=_h-1
    
ansh = 0
posh = {}
answ = 0
posw = {}
for k,v in gh.items():
    if len(v) > ansh:
        ansh = len(v)
        
for k,v in gh.items():
    if len(v) == ansh:
        posh[k]=k
        
for k,v in gw.items():
    if len(v) > answ:
        answ = len(v)
        
for k,v in gw.items():
    if len(v) == answ:
        posw[k]=k
        
hoge = True
for i in posh:
    for j in posw:
        if i not in gw[j]:
            hoge = False
            break
            
if hoge:
    print(ansh+answ-1)
else:
    print(ansh+answ)

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

#define B begin()
#define E end()
#define I iterator
using pii = pair < int , int >;
using vi = vector < int >;
using llu = unsigned long long int;
using ll = long long int;
/*

//ofstream cout ("op.txt");
//ifstream fin("inp.in");
int main ()
{
    ll n;
    fin >> n;
    vector <ll> vec(n);
    ll val;
    for ( int i = 0 ; i < n ; i ++ ){
        fin >> val;
        vec[i] = val;
    }
    sort ( vec.B , vec.E , greater<ll>() );
    ll ansa = 0 , ansb = 0 ;
    ansa = vec[0];
    for ( int i = 1; i < n ; i++ ){
        if ( ansb < ansa )
            ansb += vec[i];
        else
            ansa += vec[i];
    }
    cout << max( ansa , ansb ) - min( ansa , ansb );
    return 0;
}
*/
int main()
{
    ll n;
    cin >> n;
    cout << pow( n , 3 );
    return 0;
}




Measured memory_bytes: 384
<?php
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));
$num = strlen($s);
$ans_flg = false;
for($i=0; $i<$num; $i++){
	$s_array = str_split($s);
	$str = $s_array[0];
	array_splice($s_array, 0, 1);
	$s_array[] = $str;
	$s = implode("", $s_array);
	if($s==$t){
		$ans_flg = true;
	}
}
$ans = $ans_flg ? "Yes" : "No";
echo $ans. "\n";
?>

Measured memory_bytes: 4728
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	else if(s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

if n==1 or m==1:
    ans = max(max(n,m)-2,1)
else:
    ans = (n-2)*(m-2)
print(ans)
'''
input_map = [[1 for i in range(m)]for j in range(n)]

def checker(input_map,x,y):
    if 0<=x<=m-1 and 0<=y<=n-1:
        input_map[y][x]*=-1
    return input_map

check_li = [[0,0],[0,1],[1,0],[1,1],[-1,0],[0,-1],[-1,-1],[-1,1],[1,-1]]
for i in range(n):
    for j in range(m):
        for c in check_li:
            input_map = checker(input_map,j+c[0],i+c[1])

ans=0
for i in range(n):
    for j in range(m):
        if input_map[i][j]==-1:
            ans+=1
print(ans)
'''

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){

string s;
cin >>s;
int win=0;
for(int i=0;i<s.size();i++){
    if(s[i]=='o'){
win++;
    }
}
if((15-s.size()+win)>=8){
    cout <<"YES"<<endl;
}
else{
    cout <<"NO"<<endl;
}




 return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S=sc.next();
        char[] s=S.toCharArray();
        long ans=INF;
        int c=0;
        for(int i=0;i<26;i++){
            int count=0;
            c=0;
            for(int j=0;j<S.length();j++){
                if(s[j]==(char)('a'+i)){
                    count=0;
                }else{
                    count++;
                }
                c=Math.max(count,c);
            }
            ans=Math.min(ans,c);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22484