akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

long long n, a, b, diff;
vector<long long> h;

long long calc_n_center(long long hp, long long magics) {
	hp -= b * magics;
	return (hp + diff - 1) / diff;
}


bool isok(long long magics) {
	long long n_center = 0;
	for (auto hp : h) {
// printf("magics %lld: %lld %lld\n", magics, hp, (hp + diff - 1) / diff);
		hp -= b * magics;
		if (hp > 0) {
			n_center += (hp + diff - 1) / diff;
		}
	}

// printf("n_center %lld, magics %lld\n", n_center, magics);
	if (n_center <= magics) {
		return true;
	}
	return false;
}

int main() {
	cin >> n >> a >> b;
	diff = a - b;

	h.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	int n_bit = 30;
	long long ans = (1LL << n_bit) - 1;
	for (int bit = n_bit - 1; bit >= 0; bit--) {
		auto tmp = ans - (1LL << bit);
		if (isok(tmp)) {
			ans = tmp;
		}
	}

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


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

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

    vector<bool> y(h,false),x(w,false);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                y[i]=true;
                x[j]=true;
            }
        }
    }
    for(int i=0;i<h;i++){
        if(y[i]){
            for(int j=0;j<w;j++){
                if(x[j]) cout<<a[i][j];
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 256
MOD = 10**9 + 7
K = int(input())
S = input()
N = len(S)


class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * \
                modinv[self.mod % i] % self.mod
        return modinv


comb = Combination(2100000)
ans = 0
for i in range(K + 1):

    temp = comb(N + K - i - 1, N - 1)
    temp %= MOD
    temp *= pow(26, i, MOD)
    temp %= MOD
    temp *= pow(25, K - i, MOD)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)


Measured memory_bytes: 218572
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 30

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define DIVISOR 1000000007

int main(void) {
    int n, llimit;
    get_int2(&n, &llimit);
    uint64_t k;
    uint64_t sum = 0;
    for(k = llimit; k <= n+1; k++) {
        sum = (sum + k*(n-k+1)+1)%DIVISOR;
    }
    printf("%d\n", (int)sum);
    return 0;
}

Measured memory_bytes: 1732
import math
A,B = map(int,input().split())
x = math.gcd(A,B)

def prime_decomposition(x):
  i = 2
  ls = []
  while i * i <= x:
    while x % i == 0:
      x /= i
      ls.append(i)
    i += 1
  if x > 1:
    ls.append(x)
  return ls

cnt = len(set(prime_decomposition(x)))

print(cnt+1)

Measured memory_bytes: 9204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int b = int.Parse(Console.ReadLine());
            double d = 0, c = 100000, f = 0,a=0;
            for (int e = 0; e < b; e++)
            {
                a += c * 1.05d;
                d += a / 1000d;
                f = Math.Ceiling(d);
                c -= c;
                c += f * 1000;
                d -= d;
                f -= f;
                a -= a;
            }
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N; cin >> N;
  vector<string> w(N);
  for(auto& s : w) cin >> s;
  std::unordered_set<string> s(w.begin(), w.end());
  if(s.size() != w.size())
  {
    cout << "No" << CRLF;
    return;
  }  

  ui res{1};
  for(ui i = 1; i < N; ++i)
  {
    if(w[i][0] != w[i - 1].back())
    {
      res = 0;
      break;
    }
  }

  cout << (res ? "Yes" : "No") << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, c;
        cin >> n >> c;

        vector<bitset<16> > x(n);
        for(int i=0; i<n; ++i){
            for(int j=0; j<16; ++j){
                int a;
                cin >> a;
                x[i][j] = (a == 1);
            }
        }
        if(n == 0)
            return 0;

        vector<bitset<16> > y(c);
        for(int i=0; i<c; ++i){
            for(int j=0; j<16; ++j){
                int a;
                cin >> a;
                y[i][j] = (a == 1);
            }
        }

        vector<int> dp(1<<16, -1);
        dp[0] = 0;
        for(int i=0; i<n; ++i){
            vector<int> next(1<<16, -1);
            for(int j=0; j<(1<<16); ++j){
                if(dp[j] == -1)
                    continue;
                for(int k=0; k<c; ++k){
                    bitset<16> bs(j);
                    bs |= x[i];
                    int p = (bs & y[k]).count();
                    bs &= ~y[k];
                    next[bs.to_ulong()] = max(next[bs.to_ulong()], dp[j] + p);
                }
            }
            dp.swap(next);
        }

        cout << *max_element(dp.begin(), dp.end()) << endl;
    }
}

Measured memory_bytes: 1652
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll strr[200005];
    double a[9];
    double b[9];
    double sum=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        cin>>b[i];
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            sum=sum+sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
            //cout<<sum<<endl;
        }
    }
    ll kai=0;
    for(i=1;i<n;i++){
        kai=kai+i;
    }
    //cout<<kai;
    sum=sum*(n-1)/kai;

    printf("%f\n",sum);

    return 0;
}

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

using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;

	vector<string> s(n);

	for(auto&& si : s) {
		cin >> si;
	}

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

	for(auto&& si : s) {
		cout << si;
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	
		int x;
		scanf("%d", &x);
		int p = x;
		if (p % 2 == 1) {
			p = p / 2 + 1;
		}
		else {
			p = p / 2;
		}
		printf("%lf", (double)p / x);
}

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


//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these differences you’ll be able to get past them and grow even closer.
//You can die anytime, but living takes true courage.
//Every journey begins with a single step. We just have to have patience.
//Life is not a game of luck. If you wanna win, work hard.
//It’s more important to master the cards you’re holding 
//than to complain about the ones your opponent was dealt.
//If you just submit yourself to fate, then that’s the end of it.
//Whatever you do, enjoy it to the fullest. That is the secret of life.
//I too will obtain everything that I desire. Not because someone asked me to do it, 
//but because I know in my heart that I have something worth fighting for.


#define ps push_back
#define le length
#define in insert
#define vint vector<int>
#define vlld vector<long long int>
#define pii pair<int,int>
#define mk make_pair
#define vst vector<string>
#define lld long long int 
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)

int main()
{
	bool f1 = true , f2 = true;
	string st; 
	cin>>st;
	int n = st.le();
	int s1 , e1 , s2 , e2;
	s1 = 0 ; 
	e1 = ((n-1)/2) - 1 ; 
	s2 = ((n+3)/2) - 1;
	e2 = n-1;
	for(int i = s1 ; i <= e1 ; i++){
		if(st[i] != st[e1 - i]){
			f1 = false;
			break;
		}
	}
	for(int  i = s1 ; i <= e2 ; i++){
		if(st[i] !=  st[e2 - i]){
			f2 = false;
			break;
		}
	}
	if(f1 && f2){
		cout<<"Yes\n";
	}else 
		cout<<"No\n";
	return 0;
}

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


int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	if (s.size() != a + b + 1) {
		cout << "No" << endl;
		return 0;
	}

	if (s.at(a) != '-') {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < s.size(); i++) {
		if (i == a) continue;
		if (s.at(i) >= '0' && s.at(i) <= '9') continue;
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = null;
		int[] days = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextInt()) {
				int month = sc.nextInt();
				int day = sc.nextInt();
				if (month == 0 && day == 0)
					break;
				int daySum = 0;
				for (int i = 0; i < month - 1; i++)
					daySum += days[i];
				daySum += day;

				switch (daySum % 7) {
				case 0:
					System.out.println("Wednesday");
					break;
				case 1:
					System.out.println("Thursday");
					break;
				case 2:
					System.out.println("Friday");
					break;
				case 3:
					System.out.println("Saturday");
					break;
				case 4:
					System.out.println("Sunday");
					break;
				case 5:
					System.out.println("Monday");
					break;
				case 6:
					System.out.println("Tuesday");
					break;
				default:
					break;
				}
			}
		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 17216
from fractions import gcd

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

if N == 2:
    ans = max(A)

else:
    memo = {(0,0):1, (N,N):1}

    for i in range(1,N+1):

        if i == 1:
            memo[(0,1)] = A[0]
            memo[(N-1,N)] = A[-1]

        else:

            # gcd first i
            memo[(0,i)] = gcd(memo[(0,i-1)], A[i-1])

            # gcd last i
            memo[(N-i,N)] = gcd(memo[(N-i+1,N)], A[-i])

    ans = memo[(0,N)]

    for i in range(1,N+1):

        if i == 1:
            curgcd = memo[(1,N)]
        elif i == N:
            curgcd = memo[(0,N-1)]
        else:
            curgcd = gcd(memo[(0,i-1)], memo[(i,N)])

        ans = max(ans, curgcd)

print(ans)

Measured memory_bytes: 45644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9+7;
const int N = 200050;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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(ll 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) const { 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;}

struct Combination {
    vector<mint> fact, ifact;
    Combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        repran(i, 1, n+1){
            fact[i] = fact[i-1]*i;
        }
        ifact[n] = fact[n].inv();
        repd(i, n){
            ifact[i] = ifact[i+1]*(i+1);
        }
    };
    mint combination(int n, int i){
        return fact[n]*ifact[i]*ifact[n-i];
    }
    mint permutation(int n, int i){
        return fact[n]*ifact[i];
    }


};

int main()
{
    int n, k;
    cin >> n >> k;
    Combination c(n);
    k = min(k, n-1);
    mint ans;
    rep(i, k+1){
        ans += c.combination(n, i)*c.combination(n-1, i);
    }
    cout << ans.x << endl;

}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x=0;
	cin>>n>>m;
	int a[n][m];
	for(int i=0; i<n; i++)
	{
		for(int i2=0; i2<m; i2++)
		{
			cin>>a[i][i2];
		}
	}

	int b[m];
	for(int i=0; i<m;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int i2=0;i2<m;i2++)
		{
			x+=a[i][i2]*b[i2];
		}
	
		cout<<x<<endl;
		x=0;
	}

	return 0;
}


Measured memory_bytes: 3124
N,K = map(int,input().split())
h = list(map(int,input().split()))
 
dp = [100000000000]*N
 
dp[0] = 0
dp[1] = abs(h[1]-h[0])
 
for i in range(2,N):
  for num in range(K):
    if num+1<=i:
      A = dp[i-num-1]+abs(h[i]-h[i-num-1])
      if dp[i] >= A:
        dp[i] = A
 
print(dp[N-1])

Measured memory_bytes: 52448
"use strict";
main(
  require("fs")
    .readFileSync("/dev/stdin", "UTF-8")
    .trim()
    .split("\n")
);

function main(input) {
  const digit = Number(input[0].split(" ")[0]);
  let M = Number(input[0].split(" ")[1]);
  input.shift();
  let base = digit === 1 ? 0 : Math.pow(10, digit - 1);
  let result = -1;

  if (M > 0) {
    for (let i = base; i < Math.pow(10, digit); i++) {
      for (let f = 0; f < M; f++) {
        let condi = input[f].split(" ");
        let left = Number(condi[0] - 1);
        let num = Number(condi[1]);

        if (Number(i.toString(10).split("")[left]) !== num) {
          result = -1;
          break;
        } else result = i;
      }
      if (result !== -1) break;
    }
  } else {
    result = base;
  }

  console.log(result);
}


Measured memory_bytes: 7740
//Guruguruよりも実装は簡単。考察は難しめ。総合的に見て自分にとっての解きやすさは同じくらい。
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, string> P;

int n;
P drink[100000];
int m;
string color[100000];

int main() {
	int i;
	
	cin >> n;
	rep(i, n) { cin >> drink[i].second >> drink[i].first; }
	sort(drink, drink + n);
	
	cin >> m;
	rep(i, m) { cin >> color[i]; }
	
	int w = -114514, id = 0;
	rep(i, n) {
		if (drink[i].first <= w) continue;
		if (id < m && drink[i].second == color[id]) {
			w = drink[i].first;
			id++;
		}
	}
	
	if (id == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
    string S;
    cin >> S;
    int S_length = S.length();

    int count = 0;
    int j = S_length - 1;
    for(int i = 0; i < S_length / 2; i++){
        char mae = S[i];
        char ushiro = S[j];
        if(mae != ushiro) count++;
        j--;
    }
    cout << count << endl;
}

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

int main() {

  ll N;
  string x;
  cin >> N;
  map<string,int> S;

  for(ll i=0;i<N;i++){
    cin >> x;
    S[x]++;
  }

  cout << S.size() << endl;

}


Measured memory_bytes: 19224
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<queue>

typedef long long ll;
using namespace std;
const int max_n =1e5 + 1;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

 
int H,W,N;
int ans[101][101];
int a[10001];
 int main() 
{
	IOS;
	cin >> H >> W>>N;
	for (int i = 0; i <N; i++)
		cin >> a[i];

	int cur = 0;
	for (int i = 0; i < H; i++)
	{
		if (i % 2 != 0)
		{
			for (int j = 0; j < W; j++)
			{
				if (a[cur]==0)
					cur++;
				a[cur]--;
				ans[i][j] = cur+1;
			}
		}
		else {
			for (int j = W - 1; j >= 0; j--)
			{
				if (a[cur] == 0)
					cur++;
				a[cur]--;
				ans[i][j] = cur + 1;
			}
		}
	}
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
			cout << ans[i][j] << " ";
		cout << "\n";
	}
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = in.nextInt();
		}
		
		Arrays.sort(A);
		
		long ans = 1;
		int count = 0;
		int prev = A[N-1];
		for(int i=N-2;i>=0;i--){
			if(A[i]==prev){
				ans *= prev;
				count ++;
				prev = 0;
			}else{
				prev = A[i];
			}
			if(count==2){
				System.out.println(ans);
				return;
			}
		}
		
		System.out.println(0);
	}

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

Measured memory_bytes: 50160
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair<int,int> , null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
#define fdt fuck donald trump
// mt19937 rnd(time(0));
// const int SMALL = LLONG_MIN >> 2;
// const int BIG = LLONG_MAX >> 2;
const int MAXN = (int)2e5 + 3;
const int MOD = 998244353;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
	// freopen("FDT.txt","r",stdin);
	int x;
	cin >> x;
	int ans = 0;
	ans += (x/500)*1000;
	x%= 500;
	ans += (x/5)*5;
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 500 + 5;
int n, m, a, b;
int read() {
    char c; int x = 0, f = 1;
    c = getchar();
    while (c > '9' || c < '0') { if(c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int main() {
    n = read(), m = read(), a = read(), b = read();
    if(n % a == 0 && m % b == 0) puts("No");
    else {
        puts("Yes");
        rep(i, 1, n / a * a) {
            rep(j, 1, m) {
                if(i % a == 0 && j % b == 0) printf("%d ", -500 * (a * b - 1) - 1);
                else printf("500 ");
            }
            puts("");
        }
        rep(i, n / a * a + 1, n) {
            rep(j, 1, m) printf("500 ");
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>

#define ll long long

using namespace std;

void solve() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a <<endl;
}

int main() {
    
    // int T;
    // cin >> T;
    // while(T--) {
        // solve();
    // }
    solve();
    
    return 0;
};


Measured memory_bytes: 3592
function main(input) {
  const nums = input.split("\n")[1].split(" ").map(x => parseInt(x));
  let currentConsecutive = 0;
  let maxConsecurive = 0;
  let befor = 0;

  nums.forEach(x => {
    if (x === 1) {
      if (befor === 1) {
        currentConsecutive++;
      } else {
        currentConsecutive = 1;
      }
      befor = 1;
    } else {
      currentConsecutive = 0;
      befor = 0;
    }
    if (currentConsecutive >= maxConsecurive) {
      maxConsecurive = currentConsecutive;
    }
  });
  console.log(maxConsecurive + 1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 17188
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if(A == B && A != C){
    	System.out.println("Yes"); 
    }
    else if(A == C && A != B){
    	System.out.println("Yes"); 
    }
    else if(C == B && A != C){
    	System.out.println("Yes"); 
    }
    else{
      System.out.println("No"); 
    }
  }
}
  


Measured memory_bytes: 35724
def dfs(v):  # vを訪問する
    global time
    seen[v] = 1
    start[v] = time
    time += 1

    for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
    end[v] = time
    time += 1


n = int(input())
graph = []
for _ in range(n):
    line = list(map(int, input().split()))
    graph.append([v - 1 for v in line[2:]])

seen = [0] * n  # 0: 未訪問、1: 訪問済
start = [0] * n
end = [0] * n
time = 1

for v in range(n):
    if not seen[v]: dfs(v)

for i in range(n):
    print(i+1, start[i], end[i])



Measured memory_bytes: 5652
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
using pii = pair<int, int>;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int A, B, C;
  cin >> A >> B >> C;
  int mx = max({A, B, C});
  cout << mx*10 + (A+B+C-mx) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>

#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

signed main() {
	
	//fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://codeforces.com/contest/1084/problem/D
	// https://codeforces.com/contest/1155/problem/E
	//https://www.spoj.com/problems/MON2012/
	//https://codeforces.com/blog/entry/52726	
	
	int n,k;
	cin>>n>>k;
	cout<<(n-k+1);
	return 0;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef pair<int, int> P;

P func(int x) {
        P ret;
        ret.first = x %  10;
        ret.second = 0;
        while(x > 0) {
                ret.second = x;
                x /= 10;
        }
        return ret;
}

int main() {
        int n;
        cin >> n;

        map<P, int> mp;
        for(int i = 1; i <= n; i++) {
                P p = func(i);
                mp[p]++;
        }

        int ans = 0;
        for(int i = 1; i <= n; i++) {
                P p = func(i);
                P q;
                q.first = p.second;
                q.second = p.first;
                ans += mp[q];
        }

        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
typedef complex<double> xy_t;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    string s[n];
    int c = 0;
    //vector<pii> v(n);
    int aa = 0, bb = 0, cc = 0;
    rep(i, n) {
        cin >> s[i];
        rrep(j, 1, s[i].size()) {
            if (s[i][j - 1] == 'A' && s[i][j] == 'B') {
                c++;
            }
        }
        if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') {
            //v[i].first = 1;
            aa++;
        } else if (s[i][s[i].size() - 1] == 'A') {
            //v[i].second = 1;
            bb++;
        } else if (s[i][0] == 'B') {
            cc++;
        }
    }
    //cout << c << endl;
    //rep(i, n) cout << v[i].first << " " << v[i].second << endl;
    //cout << aa << " " << bb << " " << cc << endl;
    if (aa) {
        c += aa - 1;
        if (bb) {
            c += 1;
            bb--;
        }
        if (cc) {
            c += 1;
            cc--;
        }
    }
    //cout << c << endl;
    //cout << bb << " " << cc << endl;
    //cout << min(bb, cc) << endl;
    c += min(bb, cc);
    cout << c << endl;
    
}




Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll K;
	cin >> K;
	if (K == 0) {
		cout << 2 << endl << 0 << " " << 0 << endl;
	}
	else if (K == 1) {
		cout << 2 << endl << 0 << " " << 2 << endl;
	}
	else if (K <= 49) {
		cout << K << endl;
		for (int i = 0; i < K; i++) cout << K << " ";
		cout << endl;
	}
	else {
		cout << 50 << endl;
		ll num = K / 50;
		ll R = K % 50;
		ll ans = 49 + num;
		for (int i = 0; i < R; i++) {
			cout << 100 + (num - 1) - R + 1 << " ";
		}
		for (int i = R; i < 50; i++) {
			cout << ans - R << " ";
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
n = gets.to_i
pList = []

n.times do
  pn = gets.to_i
  pList.push(pn)
end

pList.sort!.reverse!

ans = 0
for i in 0..pList.length-1 do
  if i == 0 then
    ans += (pList[i] / 2)
  else
    ans += pList[i]
  end
end

puts ans


Measured memory_bytes: 1788
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i % 2 == 0:
                if W % 2 == 0:
                    print('#.'*(W//2))
                else:
                    print('#.'*(W//2)+'#')
            else:
                if W % 2 == 0:
                    print('.#'*(W//2))
                else:
                    print('.#'*(W//2)+'.')
        print()


Measured memory_bytes: 5612
#include<stdio.h>
int main()
{
	int N; 
	int O; 
	int Z;
	scanf("%d",&N);
	if(N%2!=0){
		printf("%d",N/2+1);
	}
	else if(N%2==0)
		printf("%d",N/2);
	
	return 0;
}

Measured memory_bytes: 1688
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Array.Sort(V);
		double ans = V[0];
		for(int i=1;i<N;i++){
			ans = (ans + (double) V[i]) / 2.0;
		}
		Console.WriteLine(ans);
	}
	int N;
	int[] V;
	public Sol(){
		N = ri();
		V = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<ll> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n;
void solve(){
	string s;
	cin>>s;
	n = sz(s);
	vector<VI> dp(n+1,VI(13,0));
	dp[0][0] = 1;
	for(int i=0;i<n;i++){
		int c = -1;
		if(s[i]!='?')c = s[i]-'0';
		for(int j=0;j<10;j++){
			if(c!=-1&&c!=j)continue;
			for(int ki = 0;ki<13;ki++){
				dp[i+1][(ki*10+j)%13] += dp[i][ki];
			}
		}
		for(int j=0;j<13;j++){
			dp[i+1][j] %= mod;
		} 
	}
	cout<<dp[n][5];
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 13648
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    struct A{int a; int num;};
    vector <A> a(n);
    vector <pair<int, int>> scores(n);
    rep (i, n) cin >> a[i].a, a[i].num = i, scores[i] = make_pair(0, i + 1);
    rep (i, m) {
        int b;
        cin >> b;
        sort(a.begin(), a.end(), [](A a, A b){return a.a < b.a;});
        int koko = 0;
        while(a[koko].a <= b && koko < n) koko++;
        sort(a.begin(), a.begin() + koko, [](A a, A b){return a.num < b.num;});
        scores[a.front().num].first++;
    }

    sort(scores.rbegin(), scores.rend());
    cout << scores.front().second << endl;

    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DB(x) cerr << #x << ": " << x << endl;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long LL;
typedef long double LD;

typedef pair<int, int> pii;

const int MAXN = 100000;
const int MOD = 1000 * 1000 * 1000 + 7;

void solve();

int main()
{
    auto start = clock();
    cout.sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

#ifdef HOME
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    cerr << "\nTime: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n";

    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vector<pii> a(n);
    LL ans = 0;
    REP(i, n) {
        int x;
        cin >> x;
        a[i] = mp(x, i);
    }
    sort(a.begin(), a.end());
    int cnt = 0;
    REP(i, n) {
        cnt += (i % 2 != a[i].second % 2);
    }
    assert(cnt % 2 == 0);
    //DB(cnt);
    cout << cnt / 2 << endl;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc141/tasks/abc141_c
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

template <unsigned mod> struct RollingHash {
    vector<unsigned> hashed, power;

    inline unsigned mul(unsigned a, unsigned b) const {
        unsigned long long x = (unsigned long long)a * b;
        unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
        asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod));
        return m;
    }

    RollingHash(const string &s, unsigned base = 10007) {
        int sz = (int)s.size();
        hashed.assign(sz + 1, 0);
        power.assign(sz + 1, 0);
        power[0] = 1;
        for (int i = 0; i < sz; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if (hashed[i + 1] >= mod)
                hashed[i + 1] -= mod;
        }
    }

    unsigned get(int l, int r) const {
        unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if (ret >= mod)
            ret -= mod;
        return ret;
    }

    unsigned connect(unsigned h1, int h2, int h2len) const {
        unsigned ret = mul(h1, power[h2len]) + h2;
        if (ret >= mod)
            ret -= mod;
        return ret;
    }

    int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) {
        int len = min(r1 - l1, r2 - l2);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
                low = mid;
            else
                high = mid;
        }
        return (low);
    }
};

using RH = RollingHash<1000000007>;

bool check(ll x, RH &rh, int n) {
    for (int i = 0; i < n - x + 1; i++) {
        auto hash1 = rh.get(i, i + x);
        for (int j = i + x; j < n - x + 1; j++) {
            auto hash2 = rh.get(j, j + x);
            if (hash1 == hash2) {
                return true;
            }
        }
    }
    return false;
}

int binsearch(int lo, int hi, RH &rh, int n) {
    while (lo < hi) {
        int mid = (lo + hi + 1) / 2;
        if (check(mid, rh, n))
            lo = mid;
        else
            hi = mid - 1;
    }
    return lo;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    RH rh(s);
    cout << binsearch(0, n / 2, rh, n) << endl;
}


Measured memory_bytes: 384
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#define l(x) (x<<1)
#define r(x) ((x<<1)+1)
#define IL inline
#define reg register
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	int n,i,x,y=0;
	n=read();
	for (i=1;i<=n;i++){
		x=read();
		if ((i%2) && (x%2))	y++;
	}
	cout<<y<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
const int INF= 1001001001;
vector<int> a;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a,b;
    cin >> a >> b;
    if(a >= 10 || b >= 10) cout << -1 << "\n";
    else cout << a* b << "\n";
    return 0;
 
}

Measured memory_bytes: 892
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

H, W = map(int, input().split())

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()

bx = min(H, W) // 2
cx = min(H, W) - bx
ans = 10 ** 18
for i in range(1, max(H, W)):
    a = min(H, W) * i

    b = (max(H, W) - i) * bx
    c = (max(H, W) - i) * cx

    ans = min(ans, max(a, b, c) - min(a, b, c))

bx = max(H, W) // 2
cx = max(H, W) - bx
for i in range(1, min(H, W)):
    a = max(H, W) * i

    b = (min(H, W) - i) * bx
    c = (min(H, W) - i) * cx

    ans = min(ans, max(a, b, c) - min(a, b, c))

aa = H // 3
bb = (H - aa) // 2
cc = H - aa - bb
ans = min(ans, (max(aa, bb, cc) - min(aa, bb, cc)) * W)

aa = W // 3
bb = (W - aa) // 2
cc = W - aa - bb
ans = min(ans, (max(aa, bb, cc) - min(aa, bb, cc)) * H)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
	operator int() const noexcept { return to; }
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
struct TwoEdgeConnectedComponents{
	T G;
	Graph nG;
	vector<int> cmp,depth,s;
	vector<vector<int>> tecc;
	stack<int> vs;
	vector<pair<int,int>> bridge;

	int operator[](int i) const{ return cmp[i]; }

	TwoEdgeConnectedComponents(const T &G) : G(G),cmp(G.size()),depth(G.size(),-1),s(G.size()){}

	void dfs(int v,int par,int d){
		depth[v] = d;
		vs.push(v);
		for(const auto &e : G[v]){
			int to = (int)e;
			if(depth[to] == -1){
				dfs(to,v,d + 1);
				s[v] += s[to];
			}else if(to != par && depth[v] > depth[to]) s[to]--,s[v]++;
		}
		if(!s[v]){
			if(par != -1) bridge.push_back(minmax(v,par));
			tecc.emplace_back();
			while(1){
				int u = vs.top(); vs.pop();
				tecc.back().push_back(u);
				cmp[u] = tecc.size() - 1;
				if(u == v) break;
			}
		}
	}

	void build(){
		for(int i = 0;i < G.size();i++) if(depth[i] == -1) dfs(i,-1,0);
		nG.resize(tecc.size());
		for(const auto &e : bridge){
			int x = cmp[e.first],y = cmp[e.second];
			nG[x].push_back(y);
			nG[y].push_back(x);
		}
	}
};

int n,m,w[100010],s[100010],ma = 0;
bool isMulti[100010];

bool dfs(TwoEdgeConnectedComponents<Graph> &tecc,int v,int par){
	isMulti[v] = (tecc.tecc[v].size() >= 2);
	for(int to : tecc.nG[v]){
		if(to != par){
			isMulti[v] |= dfs(tecc,to,v);
			chmax(s[v],s[to]);
		}
	}
	s[v] += w[tecc.tecc[v][0]];
	if(!isMulti[v]) chmax(ma,s[v]);
	return isMulti[v];
}

signed main(){
	cin >> n >> m;
	for(int i = 0;i < n;i++) cin >> w[i];
	Graph G(n);
	for(int i = 0;i < m;i++){
		int u,v;
		cin >> u >> v; u--;v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	TwoEdgeConnectedComponents<Graph> tecc(G);
	tecc.build();
	dfs(tecc,tecc[0],-1);
	int ans = 0;
	for(int i = 0;i < tecc.tecc.size();i++){
		if(isMulti[i]){
			for(int v : tecc.tecc[i]) ans += w[v];
		}
	}
	cout << ans + ma << endl;
}



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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define M 100001
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define lp(i,a,b) for(i=a;i<b;i++)
#define lpr(i,a,b) for(i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main(){

	/*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/

	fast;  
  int k,n;
  string s;
  cin>>s;
  bool c=false;
  if(s[2]==s[3] && s[4]==s[5]) c=true;
  if(c) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
s_cu = [0] * (n+1)
counter = [0] * 2019
counter[0] += 1
for i in range(n):
    s_cu[i+1] = (int(s[n-i-1]) * pow(10,i,2019) + s_cu[i]) % 2019
    counter[s_cu[i+1]] += 1

ans = 0
for i in counter:
    ans += (i * (i - 1)) // 2

print(ans)


Measured memory_bytes: 16148
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use std::*;

#[allow(dead_code)]
const MOD: i128 = 100_000_007;

#[fastout]
fn main() {
    input!{
        a : usize,
        b : usize
    };
    println!("{}", a*b);
}


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

int main(void){
    string s;
    getline(cin, s);
    for(int i = 0; i < s.size(); i++){
        char c = s[i];
        if ('A' <= c && c <= 'Z'){
            c = c + 32;
        }
        else if ('a' <= c && c <= 'z'){
            c = c - 32;
        }
        cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 3184
#include <iostream>
#include<algorithm>
#include <set>
#include <utility>
#include <cmath>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <ctime>
#include <limits>
#include <istream>
#include <ostream>
#include <complex.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define INF 1e16
#define mod 10000000007
#define mmax(x,y)(x>y?x:y);
#define mmin(x,y)(x<y?x:y);
int main()
{
	int n;
	cin>>n;
	vector<int> p(n);
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(p[i]!=i+1)
			cnt++;
	}
	if(cnt<=2)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
hh = list(map(int, input().split()))
 
prev = -999
for i in range(N):
  if prev > hh[i]:
    print('No')
    exit(0)
  if prev + 1 <= hh[i]:
    prev = hh[i] - 1
  else:
    prev = hh[i]

print('Yes')
exit(0)

Measured memory_bytes: 15020
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;

typedef struct {
    int p;			// parent
    int l;			// left child
    int r;			// right child
    int dep;			// depth
    int hei;			// height
    bool is_l;			// whether this is left child.
    int deg;		// the number of children.
} Node;

#define MAX_N (30)
#define NIL (-1)
int n;
Node N[MAX_N];

void output( int id ) {
    int sib = -1;
    char type[100];

    if ( N[id].p != NIL ) {
	if ( N[id].is_l ) 
	    sib = N[N[id].p].r;
	else 
	    sib = N[N[id].p].l;
    }

    if ( N[id].p == NIL )
	sprintf( type, "root" );
    else if ( N[id].l == NIL && N[id].r == NIL ) 
	sprintf( type, "leaf" );
    else 
	sprintf( type, "internal node" );
	
    printf("node %d: ", id);
    printf("parent = %d, ", N[id].p );
    printf("sibling = %d, ", sib );
    printf("degree = %d, ", N[id].deg );
    printf("depth = %d, ", N[id].dep );
    printf("height = %d, ", N[id].hei );
    printf("%s", type );
    printf("\n");
    return;
}

int set_depth_height( int id, int dep ) {
    N[id].dep = dep;
    int h0 = 0;
    int h1 = 0;
    if ( N[id].l != NIL ) {
	h0 = set_depth_height( N[id].l, dep + 1 ) + 1;
    }

    if ( N[id].r != NIL ) {
	h1 = set_depth_height( N[id].r, dep + 1 ) + 1;
    }

    N[id].hei = max(h0, h1);

    return N[id].hei;
}

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	N[i].p = N[i].l = N[i].r = NIL;
    }

    for ( int i = 0; i < n; i++ ) {
	int id;
	scanf("%d", &id);
	scanf("%d %d", &N[id].l, &N[id].r);
	if (N[id].l != -1 ) {
	    N[id].deg++;
	    N[N[id].l].is_l = true;
	    N[N[id].l].p = id;
	}

	if (N[id].r != -1 ) {
	    N[id].deg++;	
	    N[N[id].r].is_l = false;
	    N[N[id].r].p = id;
	}
    }

    int root = -1;
    for ( int i = 0; i < n; i++ ) {
	if ( N[i].p == NIL ) {
	    root = i;
	    break;
	}
    }

    set_depth_height( root, 0 );

    for ( int i = 0; i < n; i++ ) {
	output( i );
    }

    return 0;
}

Measured memory_bytes: 3196
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
  int N=sc.nextInt();
  int K=sc.nextInt();
  int[] data=new int[200000];
  Arrays.fill(data,0);
  int i,cnt=0,ans=0;
  for(i=0;i<N;i++) {
    data[sc.nextInt()]++;
  }
  for(i=0;i<200000;i++){
    if(data[i]>0)cnt++;
  }
  Arrays.sort(data);
  for(i=200000-cnt;i<200000-K;i++){
    ans+=data[i];
  }
  System.out.println(ans);
}}

Measured memory_bytes: 72000
n=int(input())
h=list(map(int,input().split()))
dp=[0 for i in range(n+1)]

dp[1]=abs(h[1]-h[0])
for i in range(2,n):
	dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])



Measured memory_bytes: 20516