akhauriyash/Code-Regression huggingface dataset:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def retuen_num(n):
    ans = 0
    count = 0
    for i in range(2,100,1):
        count += i
        if n <= count:
            ans = i - 1
            break
        
    return ans

def main():
    n = int(input())
    sosu = prime_factorize(n)
    c = Counter(sosu)
    count = 0

    for i in c.values():
        count += retuen_num(i)

    print(count)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9456
#!/usr/bin/env python3
import sys


def solve(N: int, A: int):
    ret = N * N - A
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
    char c;
    scanf("%c",&c);
    if(c == 'A')printf("T\n");
    else if(c == 'T')printf("A\n");
    else if(c == 'C')printf("G\n");
    else printf("C\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	
	vector<vector<int>> yv(H);
	vector<int> xcnt(W); // [i] := x = i の対象の個数
	
	vector<int> h(M), w(M);
	REP(i, M) {
		scanf("%d %d", &h[i], &w[i]);
		--h[i]; --w[i];
		yv[h[i]].emplace_back(i);
		++xcnt[w[i]];
	}
	
	int ans = 0;
	
	multiset<int> ms; // x 座標ごとの対象の個数の max を求めたい
	REP(i, W) ms.insert(xcnt[i]);
	REP(i, H) {
		for (int idx : yv[i]) {
			ms.erase(ms.find(xcnt[w[idx]]));
			ms.insert(xcnt[w[idx]] - 1);
		}
		
		chmax(ans, yv[i].size() + *(--ms.end()));
		
		for (int idx : yv[i]) {
			ms.erase(ms.find(xcnt[w[idx]] - 1));
			ms.insert(xcnt[w[idx]]);
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 37388
s = gets.chomp
size = s.size
arr = [1, 10, 9, 12, 3, 4]
mod = 10**9 + 7
dp = Array.new(size + 1) { Array.new(13) { 0 } }
dp[0][0] = 1

size.times do |i|
  13.times do |j|
    if s[i] == '?'
      10.times { |k| dp[i + 1][(j + arr[(size - 1 - i) % 6] * k) % 13] += dp[i][j] }
    else
      dp[i + 1][(j + arr[(size - 1 - i) % 6] * s[i].to_i) % 13] += dp[i][j]
    end
  end
  13.times { dp[i + 1][_1] %= mod }
end

puts dp[size][5]


Measured memory_bytes: 37492
import fractions
N, X = map(int, input().split())
x = list(map(int, input().split()))
# 全て回るには距離が共通の倍数でないとダメ
# 最大の正整数は最大公約数
ans = abs(X - x[0])
for i in range(1, N):
    ans = fractions.gcd(ans, abs(X - x[i]))
print(ans)

Measured memory_bytes: 16240
import           Control.Applicative
import           Control.Monad

rpn :: [String] -> [String] -> Int
rpn [x] [] = read x
rpn s@(x1:x2:xs) (y:ys)
    | y == "+" = rpn (show (a + b) : xs) ys
    | y == "-" = rpn (show (a - b) : xs) ys
    | y == "*" = rpn (show (a * b) : xs) ys
  where
    a = read x2
    b = read x1
rpn xs (y:ys) = rpn (y : xs) ys

main :: IO ()
main = do
    xs <- words <$> getLine
    print $ rpn [] xs



Measured memory_bytes: 4108
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int i,n0=0,n1=0;
	string str;
	cin >> str;
	for(i=0;i<str.size();i++){
		if(str.at(i)=='0'){
			n0++;
		}else{
			n1++;
		}
	}
	cout << min(n0,n1)*2;
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()

    if (n % 1000 == 0) {
      println(0)
    } else {
      val i = n / 1000
      val ans = (i + 1) * 1000 - n

      println(ans)
    }
  }
}


Measured memory_bytes: 55320
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int N,i;
  scanf("%d",&N);
  vector<int> A(N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
sort(A.begin(),A.end());
printf("%d",A[N-1]-A[0]);
return 0;
}

Measured memory_bytes: 256
//****************************//
/**********  main *************/
//****************************//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <math.h> 

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (i = 0; i < n; i++)
#define FOR(i, a, b) for (i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

double pi = 3.141592653589793;

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

int main()
{

    std::cin.tie(0);

    // vector<int> v(5);

    int a,b,c,d,e;
    int res;
    cin >> a >> b >> c >> d >> e;

    if(a==0){
        res = 1;
    }
    if(b==0){
        res = 2;
    }
    
    if(c==0){
        res = 3;
    }    
    if(d==0){
        res = 4;
    }
    if(e==0){
        res = 5;
    }
     cout << res << endl;

    return 0;

}



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

#include <vector>

using namespace std;

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

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

    int curr = K;
    int digit = 1;
    while (N >= curr)
    {
        curr *= K;
        digit++;
    }

    cout << digit;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		const char *ans="hoge";
		switch(n%10)
		{
			case 2:
			case 4:
			case 5:
			case 7:
			case 9:
				ans="hon";
				break;
			case 0:
			case 1:
			case 6:
			case 8:
				ans="pon";
				break;
			case 3:
				ans="bon";
				break;
			default:
				ans="error";
				break;
		}
		printf("%s\n", ans);
	}
	return 0;
}


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


int N;

void read() {
    cin >> N;
}


void rec(int nTh, int history[6], int cnt[10][10]) {
    int maxV = 0, minV = 0, lastDigit = -1;
    for (int i = 5; i >= 0; --i) {
        maxV = maxV * 10 + (history[i] == -1 ? 9 : history[i]);
        minV = minV * 10 + (history[i] == -1 ? 0 : history[i]);
        if (lastDigit == -1) {
            if (history[i] == -1) {
                lastDigit = -2;
            } else if (history[i] > 0) {
                lastDigit = history[i];
            }
        }
    }

    if (minV > N) return;
    if (maxV <= N && lastDigit > 0) {
        int toAdd = 1;
        for (int i = 0; i < 6; ++i) {
            if (history[i] == -1) {
                toAdd *= 10;
            }
        }
        cnt[history[0]][lastDigit] += toAdd;
        return;
    }
    
    for (int digit = 0; digit <= 9; ++digit) {
        history[nTh] = digit;
        rec(nTh - 1, history, cnt);
        history[nTh] = -1;
    }
}


void work() {
    int history[6];
    memset(history, -1, sizeof(history));
    
    int cnt[10][10] = {};
    for (int digit = 1; digit <= 9; ++digit) {
        history[0] = digit;
        rec(5, history, cnt);
    }

    int ans = 0;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }

    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


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


int main() {
    int n;
    cin >> n;
    double rev_sum = 0;
    for (int i = 0; i < n; i++) {
        double num;
        cin >> num;
        rev_sum += 1 / num;
    }
    cout << 1 / rev_sum << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			System.out.println("Possible");;
		} else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int N = 100005;
set<int> g[N];
int p[N];
int find(int x){
    return x == p[x] ? x : p[x]=find(p[x]);
}
void merge(int u, int v){
    u = find(u), v = find(v);
    if (u == v) return;
    if (g[u].size() < g[v].size()) swap(u,v);
    //printf("merge %d to %d\n",v,u);
    vector<ii> que;
    for (auto x: g[v]){
        if (x == u) continue;
        //printf("%d connected to %d\n",x,v);
        g[x].erase(v);
        if (g[u].count(x)){
            que.push_back({u,x});
        }
        g[u].insert(x);
        g[x].insert(u);
    }
    p[v] = u;
    for (auto cur : que){
        merge(cur.first,cur.second);
    }
}
int main(){
    int n;
    scanf("%d",&n);
    iota(p,p+N,0);
    for (int i = 0; i < 2*n-2; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a = find(a); b = find(b);
        if (g[a].count(b)) merge(a,b);
        g[a].insert(b);
        g[b].insert(a);
    }
 	int c =find(1);
    for (int i = 2; i <= n; i++){
      	if (c != find(i)){
         	printf("NO");
         	return 0;
        }
    }
  	printf("YES");
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1000000007;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)

ll dp[105][4][4][4]; //A,G,C,T

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

 ll n;
  cin >> n;
  dp[0][3][3][3]=1; 
  
  rep(i,0,n){
   rep(j,0,4){
    rep(k,0,4){
     rep(l,0,4){
      rep(m,0,4){
        if(j==0&&k==1&&m==2) continue; //AGXC
        if(k==0&&l==1&&m==2) continue; //XAGC
        if(j==0&&l==1&&m==2) continue; //AXGC
        if(k==1&&l==0&&m==2) continue; //XGAC
        if(k==0&&l==2&&m==1) continue; //XACG
        (dp[i+1][k][l][m]+=dp[i][j][k][l])%=mod;
      }
      } 
    }
   }
  }
  
  ll res=0;
  rep(j,0,4){
   rep(k,0,4){
    rep(l,0,4){
     (res+=dp[n][j][k][l])%=mod; 
    }
   }
  }
  cout <<res << endl;
}


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

using namespace std;

const int maxn = 15;
const int mod = 1e9+7;

int n, m;
int out[maxn], in[maxn], sz[1<<maxn];
int dp[1<<maxn];

int lowbit(int x) {return x & (-x);}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i < (1<<n); i++) sz[i] = sz[i ^ lowbit(i)] + 1;
	for (int i = 1; i <= m; i++) {
		int x, y; scanf("%d%d", &x, &y);
		-- x, -- y;
		out[x] ^= (1<<y), in[y] ^= (1<<x);
	}
	dp[0] = 1;
	for (int mask = 1; mask < (1<<n); ++ mask) {
		for (int s = mask; s; s = (s - 1) & mask) {
			if ((s & 1) && (s & 2)) continue;
			int t = dp[mask ^ s];
			for (int i = 0; i < n; i++) {
				if (s & (1<<i)) {
					t = 1LL * t * (1<<(sz[out[i] & (~ mask)])) % mod;
				} else if (!(mask & (1<<i))) {
					t = 1LL * t * ((1<<sz[s & out[i]]) - 1) % mod;
				}
			}
			dp[mask] = (dp[mask] + t) % mod;
		}
	}
	printf("%d\n", dp[(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 640
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

# N = I()
X,N = LI()
_p = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
# p = np.array(_p)
#C = np.zeros(N + 1)

p = set(_p)
for i in range(100):
    if X - i not in p:
        print(X - i)
        exit()
    if X + i not in p:
        print(X + i)
        exit()

# 条件を満たす配列
#q = np.where(p - X == 0)



Measured memory_bytes: 27200
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
ll a[22][22];
ll dp [1<<22+2];
ll m=1e9+7;
void solve (ll num, ll k)
{
	if (dp[num]!=-1)
		return;
	if (num==0)
	{
		//cout<<"check"<<endl;
		dp[num]=1;
		return;
	}
	else
	{
		ll ans=0;
		//cout<<"check"<<endl;
		for (ll i=0;i<n;i++)
		{
			if (num&(1<<i))
			{
				if (k>=0)
				{
				if (a[k][i])
				{
					//cout<<num-(1<<i)<<endl;
					solve(num-(1<<i),k-1);
					ans=(ans%m+dp[num-(1<<i)]%m)%m;
				}
				}
			}
		}
		dp[num]=ans%m;
		return;
	}
}
int main()
{
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for (ll i=0;i<n;i++)
	{
		for (ll j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	ll k=1<<n;
	ll temp=n;
	k--;
	solve(k,temp-1);
	// for (ll i=0;i<=k;i++)
	// 	cout<<dp[i]<<" ";
	cout<<dp[k]%m;
}

Measured memory_bytes: 131328
N = int(input())
H = list(map(int, input().split()))

ans = 0
flag = 0
tmp = H[0]
for i in range(N-1):
    if flag==0:
        if H[i] <= H[i+1]:
            tmp = H[i+1]
        else:
            ans += tmp
            tmp = H[i+1]
            flag = 1
    else:
        if H[i] >= H[i+1]:
            tmp = H[i+1]
        else:
            ans -= tmp
            tmp = H[i+1]
            flag = 0
if flag == 0:
    ans += tmp
print(ans)

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

void solve(long long N, long long K, std::vector<long long> P, std::vector<long long> C) {
  V<bool> done(N, false);
  VV<ll> path;
  REP(i, N) {
    if (!done[i]) {
      V<ll> v;
      ll cur = P[i] - 1;
      v.push_back(cur);
      done[cur] = true;
      while (cur != i) {
        cur = P[cur] - 1;
        v.push_back(cur);
        done[cur] = true;
      }
      path.push_back(v);
    }
  }
  dbg(path[0].size());
  ll ans = -1e18;
  REP(i, path.size()) {
    const auto &v = path[i];
    REP(j, v.size()) {
      dbg(v[j]);
    }
    ll n = v.size();
    ll all = 0;
    REP(j, n) {
      all += C[v[j]];
    }
    ll d = K / n;
    ll r = K % n;
    if (all <= 0) {
      r = n;
    } else if (d > 0 && r == 0) {
      r = n;
      d--;
    }
    dbg(d);
    dbg(r);
    dbg(all);
    V<ll> s(2 * n + 1);
    s[0] = 0;
    FOR(j, 1, s.size()) {
      s[j] = s[j - 1] + C[v[(j - 1) % v.size()]];
    }
    REP(j, s.size()) {
      dbg(s[j]);
    }
    ll m = s[1] - s[0];
    REP(j, s.size()) {
      FOR(k, j + 1, s.size()) {
        if (k - j <= r) {
          m = max(m, s[k] - s[j]);
        }
      }
    }
    dbg(m);
    if (all > 0) {
      ans = max(ans, all * d + m);
    } else {
      ans = max(ans, m);
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> P(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &P[i]);
  }
  std::vector<long long> C(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
  }
  solve(N, K, std::move(P), std::move(C));
  return 0;
}


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

using namespace std;

int main() {

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

	for (int i = k + 1; i <= n; i++) {
		if (a[i - k] < a[i]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	ll n, ans = -1e10;
	cin >> n;
	int f[100][10] = {};
	rep(i,n) rep(j,10) cin >> f[i][j];
	ll p[100][11] = {};
	rep(i,n) rep(j,11) cin >> p[i][j];

	for(int i = 1; i < (1 << 10); i++) {
		ll sum = 0, count = 0;
		rep(k,n) {
			count = 0;
			rep(b,10) {
				if ((i >> b & 1)&&f[k][b]) count++;
			}
			sum += p[k][count];
		}
		if (ans < sum) ans = sum;
	}

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


Measured memory_bytes: 3632
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
ans = 0
for i in range(N):
    if i % 2 ==0 and A[i] % 2 ==1:
        ans += 1
print(ans)

Measured memory_bytes: 9228
# ALDS1_1_D - Maximum Profit
def main():
    N, *A = map(int, open(0).read().split())
    ans, cur = -float("inf"), float("inf")
    for i in A:
        ans = max(ans, i - cur)
        if i < cur:
            cur = i
    print(ans)


if __name__ == "__main__":
    main()


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

main(){
	int n; cin>>n;
	
	int a[n], b[n];
	for(auto &it : a) cin>>it;
	for(auto &it : b) cin>>it;
	
	reverse(b, b+n);
	
	int c, l=0, r=-1;
	for(int i=0; i<n; i++){
		if(a[i]==b[i]){
			c = a[i];
			l = i;
			break;
		}
	}
	for(int i=n-1; i>=0; i--){
		if(a[i]==c && b[i]==c){
			r = i;
			break;
		}
	}
	for(int i=0; i<n; i++){
		if(a[i]!=c && b[i]!=c && l<=r){
			swap(b[i],b[l]);
			l++;
		}
	}
	if(l<=r)  cout<<"No";
	else{
		cout<<"Yes"<<endl;
		for(int x : b) cout<<x<<" ";
	}
}

Measured memory_bytes: 5196
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1,len(p)-1):
  if (p[i]>p[i-1] and p[i]<p[i+1]) or (p[i]<p[i-1] and p[i]>p[i+1]):
    cnt += 1
print(cnt)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,x; cin>>n>>x;
  ll dp[100000]={};
  ll count=0;
  REP(i,n){
    cin>>dp[i];
    if(i==0 && dp[0]>x) {
      count+=dp[0]-x;
      dp[0]=x;
    }
    if(i>=1 && dp[i]+dp[i-1]>x) {
      count+=dp[i]+dp[i-1]-x;
      dp[i]=x-dp[i-1];
    }
  }
  P(count);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using ll = long long;
constexpr ll MOD = 1e9 + 7;

int main()
{
  int N, K;
  std::cin >> N >> K;
  
  ll ans = 0ll;
  for (int k = K; k <= N + 1; k++)
  {
    ll mul = ((ll)k * (N-k+1)) % MOD;
    ans = (ans + mul + 1) % MOD;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 3184
x = int(input())
lst = []
for i in range(-118, 120):
    for j in range(-119, 119):
        y = i ** 5 - j ** 5
        if y == x:
            lst_1 =[]
            lst_1.append(i)
            lst_1.append(j)
            lst.append(lst_1)
print(lst[0][0], lst[0][1])

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

static const int MAX = 1000;

void trace(int A[], int N){
    int i;
    for (i=0;i<N;i++){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void bubbleSort(int A[],int N){
    int flag = 1;
    int v0;
    int cnt = 0;
    while (flag == 1){
        flag = 0;
        for (int j=N-1;j>=1;j--){
            if(A[j] < A[j-1]){
                v0 = A[j-1];
                A[j-1] = A[j];
                A[j] = v0;
                flag = 1;
                cnt ++;
            }
        }
    }
    trace(A,N);
    cout << cnt << endl;;
}

int main(){
    int n, A[MAX];
    cin >> n;
    for (int i=0;i<n;i++) cin >> A[i];
    bubbleSort(A,n);
    return 0;
}



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

int main()
{
	string s;

	while (cin >> s) {

		int n = 0, m = 0;
		for (int i = 0; i < s.size() - 2; i++) {
			if (s.substr(i, 3) == "JOI")
				n++;
			if (s.substr(i, 3) == "IOI")
				m++;
		}

		cout << n << endl;
		cout << m << endl;
	}

	return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
ll fastexpo(ll x,ll y,ll m)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
void fff()
{
	ll a, b, c;
	cin >> a >> b >> c;
	cout<<c<<" "<<a<<" "<<b<<ln;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    s_list = list(map(int, list(S)))[::-1]
    MOD = 2019

    sum_v = 0
    cnt = [0] * MOD
    cnt[0] = 1
    for i, s in enumerate(s_list):
        sum_v += s * pow(10, i, MOD)
        sum_v %= MOD
        cnt[sum_v] += 1
    print(sum([c * (c - 1) // 2 for c in cnt if c > 1]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 88900
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
map<string,ll>mp;
int main()
{
    ll a,b,c,i,j,k=0,x=0;
    string s;
    cin>>a;
    getchar();
    for(i=1;i<=a;i++)
    {
        cin>>s;
        sort(s.begin(),s.end());
        if(mp.find(s)==mp.end())
        {
            k++;
            mp[s]=k;
        }
        ar[mp[s]]++;
    }
    for(i=1;i<=100009;i++)
    {
        x=x+((ar[i]*(ar[i]-1))/2);
    }
    cout<<x;
}


Measured memory_bytes: 15232
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int c[3][3];

bool is_check ( int a1, int a2, int a3, int b1, int b2, int b3 ) {
    bool ret = true;

    ret &= c[0][0] == a1+b1;
    ret &= c[0][1] == a1+b2;
    ret &= c[0][2] == a1+b3;

    ret &= c[1][0] == a2+b1;
    ret &= c[1][1] == a2+b2;
    ret &= c[1][2] == a2+b3;
    
    ret &= c[2][0] == a3+b1;
    ret &= c[2][1] == a3+b2;
    ret &= c[2][2] == a3+b3;

    return ret;
}

int main()
{

    rep(i, 3) rep(j, 3) cin >> c[i][j];

    bool is_exist = [&]() {
        reep(a1, -100, 101){
            int b1 = c[0][0] - a1;
            reep(a2, -100, 101){
                int b2 = c[1][1] - a2;
                reep(a3, -100, 101){
                    int b3 = c[2][2] - a3;

                    if( is_check(a1, a2, a3, b1, b2, b3) ) {
                        return true;
                    }
                }
            }
        }

        return false;
    }();

    cout << (is_exist ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    int num=max(a,max(b,c));
    ans+=(num-a)/2;
    a=num-(num-a)%2;
    //cout << ans<<endl;
    ans+=(num-c)/2;
    c=num-(num-c)%2;
    //cout << ans<<endl;
    ans+=(num-b)/2;
    b=num-(num-b)%2;
    //cout << ans<<endl;
    int maki=0;
    if(a==num)maki++;
    if(b==num)maki++;
    if(c==num)maki++;
    //cout << maki<<endl;
    if(maki==1)ans++;
    if(maki==2)ans+=2;
    cout << ans<<endl;
    return 0;
}


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

int main() {
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<int> s(a),t(b),u(c);
  for(int i=0;i<a;i++) cin>>s.at(i);
  for(int i=0;i<b;i++) cin>>t.at(i);
  for(int i=0;i<c;i++) cin>>u.at(i);
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  vector<int> v(0);
  for(int i=0;i<x;i++) v.push_back(s.at(a-1-i));
  for(int i=0;i<y;i++) v.push_back(t.at(b-1-i));
  for(int i=0;i<c;i++) v.push_back(u.at(i));
  sort(v.begin(),v.end());
  long long ans=0;
  for(int i=0;i<x+y;i++) ans+=v.at(x+y+c-1-i);
  cout<<ans<<endl;
}
  

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,x,y;
bool vis[300000];
vector<int>v[300000];
int a1[300000],a2[300000];
int dfs(int x,int d){
  vis[x]=1;
  a1[x]=d;
  int res=1;
  for(int i=0;i<v[x].size();i++){
    if(!vis[v[x][i]]){
      res+=dfs(v[x][i],d+1);
    }
  }
  return res;
}
int dfs2(int x,int d){
  vis[x]=1;
  a2[x]=d;
  int res=1;
  for(int i=0;i<v[x].size();i++){
    if(!vis[v[x][i]]){
      res+=dfs2(v[x][i],d+1);
    }
  }
  return res;
}
main(){
  cin>>n;
  r(i,n-1){
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  memset(vis,0,sizeof(vis));
  int a1a=dfs(1,0);
  memset(vis,0,sizeof(vis));
  int a2a=dfs2(n,0);
  int p1=0,p2=0;
  for(int i=1;i<=n;i++){
    if(a1[i]<=a2[i])p1++;
    else p2++;
  }
  if(p1>p2)cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
}

Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
int n,W;
int w[105];
long long v[105],f[100005];
int main()
{
	scanf("%d%d",&n,&W);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%lld",&w[i],&v[i]);
		for(int j=W;j>=w[i];j--)
			f[j]=max(f[j],f[j-w[i]]+v[i]);
	}
	printf("%lld",f[W]);
}


Measured memory_bytes: 1024
#include<cstdio>

using namespace std;

bool eq_string(char a[], char b[]){
    for(int i = 0; a[i] != 0; i++){
        if (a[i] != b[i]) {
            return false;
        }
    }
    for(int i = 0; b[i] != 0; i++){
        if (a[i] != b[i]) {
            return false;
        }
    }
    
    return true;
}

bool eq(char a[], char b[]){
    int a_size = 0;
    int b_size = 0;
    for(int i = 0; a[i] != 0; i++){
        a_size = i + 1;
    }

    if (a[a_size-1] == b[0]) return true;
    else return false;
    
}

int main(){
    int n;
    scanf("%d", &n);
    char w[n][11];
    for(int i = 0; i < n; i++){
        scanf("%s", w[i]);
    }

    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            if(eq_string(w[i], w[j])){
                puts("No");
                return 0;
            }
        }   
    }

    for(int i = 0; i < n - 1; i++){
        if (!eq(w[i], w[i+1])) {
            puts("No");
            return 0;
        }
        
    }
    
    puts("Yes");
    
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    bool good = true;
    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i+1]) {
            good = false;
        }
    }

    cout << (good ? "Good" : "Bad") << "\n";
    return 0;
}

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

int main(){
    int n,m,l;
    long long A[100][100], B[100][100],C[100][100];
    
    cin>> n>>m>>l;
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++) cin>>A[i][j];
        for(int i=0;i<m;  i++)
        for(int j=0;j<l; j++) cin >> B[i][j];
        
        for(int i=0;i<n; i++){
            for(int j=0; j<l; j++){
                C[i][j]=0;
                for(int k=0; k<m; k++){
                    C[i][j] += A[i][k]*B[k][j];
                }
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<l; j++){
                if(j) cout << " ";
                cout << C[i][j];
            }
            cout << endl;
        }
        
        return 0;
    
}


Measured memory_bytes: 3276
#include<stdio.h>
int main(void)
{
	int n,i;
	double a[101],s;
	scanf("%d",&n);
	s=0.0;
	for(i=0;i<n;i++){
		scanf("%lf",&a[i]);
		s+=1.0/a[i];
	}
	s=1.0/s;
	printf("%lf\n",s);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    final int MOD = 1000000007;

    while(br.ready()){
      String[] s = br.readLine().split(" ");
      int N = Integer.parseInt(s[0]);
      int W = Integer.parseInt(s[1]);
      ArrayList<Integer> wal = new ArrayList<Integer>();
      int[] pre = new int[W + 2];

      for(int i = 0; i < N; i++){
        int x = Integer.parseInt(br.readLine());

        if(x <= W){
          pre[x] += x;
          wal.add(x);
        }
      }

      for(int i = 0; i < W; i++){
        pre[i + 1] += pre[i];
      }

      Collections.sort(wal);
      Integer[] w = (Integer[])wal.toArray(new Integer[0]);
      N = w.length;

      int[] idx = new int[W + 2];
      Arrays.fill(idx, -1);

      int[][] dp = new int[N + 2][W + 2];
      dp[N][0] = 1;

      for(int i = N; i > 0; i--){
        for(int j = 0; j <= W; j++){
          dp[i - 1][j] += dp[i][j];
          dp[i - 1][j] %= MOD;

          if(j + w[i - 1] <= W){
            dp[i - 1][j + w[i - 1]] += dp[i][j];
            dp[i - 1][j + w[i - 1]] %= MOD;
          }
        }

        if(w[i - 1] <= W){
          idx[w[i - 1]] = i - 1;
        }
      }

      idx[W + 1] = N;
      for(int i = W + 1; i > 0; i--){
        if(idx[i - 1] == -1){
          idx[i - 1] = idx[i];
        }
      }

      int ans = 0;

      for(int x = 0; x <= W; x++){
        if(x < pre[W - x]) continue;
        ans += dp[ idx[W - x + 1] ][ x - pre[W - x] ];
        ans %= MOD;
      }

      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 0
from collections import Counter

n,p = map(int,input().split())

def prime_decomposition(n):
    table = []
    for i in range(2, int(n**0.5)+1):
        while n%i==0:
            n /= i
            table.append(i)
    if n>1:
        table.append(int(n))
    table = sorted(table, reverse=False)
    return table

lst = prime_decomposition(p)
c = dict(Counter(lst))

ans = 1
for k,v in c.items():
    if v >= n:
        ans *= k**(v//n)
print(ans)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> memo(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    memo.at(i).at(1) = a;
    memo.at(i).at(0) = b - 1;
  }
  int c = 0;
  sort(memo.begin(), memo.end());
  int G = 0;
  for (int i = 0; i < M; i++) {
    if (memo.at(i).at(1) > G) {
      c++;
      G = memo.at(i).at(0);
    }
  }
  cout << c << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)


signed main(){

	lli n;
	string s;
	cin>>n>>s;

    set<lli> sets[26];
    REP(i,0,n)sets[s.at(i)-'a'].insert(i);

	lli q;
	cin>>q;
    REP(i,0,26)sets[i].insert(INF);

	REP(i,0,q){
		lli k;
		cin>>k;
		if(k==1){
			lli index;
			char a;
			cin>>index>>a;
            index--;
            sets[s.at(index)-'a'].erase(index);
            s[index] = a;
            sets[s.at(index)-'a'].insert(index);
		}
		else{
			lli x,y;
			cin>>x>>y;
			x--,y--;
            lli cnt=0;
            REP(j,0,26){
                set<lli> &nowS = sets[j];
                auto itr = nowS.lower_bound(x);
                if(DEBUG)cout<<"j="<<j<<" ITR="<<*itr<<endl;
                if(x<=*itr && *itr<=y)cnt++;
            }
            cout<<cnt<<endl;
		}
	}

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<double>x(N);
    vector<double>y(N);
    vector<int>z(N);
    double cnt = 1.0;
    double heikin = 0.0;
    for(int i = 0; i < N; i++) {
        cin >> x[i];
        cin >> y[i];
        z[i] = i;
        cnt *=i+1;
    }
    for(int i = 0; i < cnt; i++) {
        for(int j = 1; j < N; j++) {
            double X = x[z[j-1]]-x[z[j]];
            double Y = y[z[j-1]]-y[z[j]];
            heikin += sqrt(X*X+Y*Y);
        }next_permutation(z.begin(), z.end());
    }
    cout << fixed << setprecision(20) << heikin/cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void swap(int *a, int *b);

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

	swap(&x, &y);
	swap(&x, &z);

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

	return 0;
}


void swap(int *a, int *b){
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

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

int main(){
  char a;
  cin >> a;
  if(a == 'A') cout << "T" << endl;
  else if(a == 'T') cout << "A" << endl;
  else if(a == 'C') cout << "G" << endl;
  else cout << "C" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){

    int n;
    cin >> n;

    int cnt = 0;

    cnt = (n-1)/2;

    cout << cnt << endl;

    return 0;
};




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   int a,b,c;

   scanf("%d %d %d",&a ,&b ,&c);

   if(a <= b && b <= c){
      printf("%d %d %d\n",a ,b ,c);
   }else if(a <= c && c <= b){
      printf("%d %d %d\n",a ,c ,b);
   }else if(b <= a && a <= c){
      printf("%d %d %d\n",b ,a ,c);
   }else if(b <= c && c <= a){
      printf("%d %d %d\n",b ,c ,a);
   }else if(c <= a && a <= b){
      printf("%d %d %d\n",c ,a ,b);
   }else if(c <= b && b <= a){
      printf("%d %d %d\n",c ,b ,a);
   }
   return 0;
}

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

int i;

int main()
{

    int x;
    cin >> x;

    int a, b; //500,5

    a = x / 500;
    b = (x - 500 * a) / 5;

    cout << a * 1000 + b * 5 << endl;
}

Measured memory_bytes: 256
# ボトムアップ 貰う DP
N = int(input())

INF = 1<<60
dp = [INF]*(N+1)
dp[0] = 0

# 貰う DP --- dp[n] に遷移を集める
for i in range(1, N+1):
  pow6 = 1
  while pow6 <= i:
    dp[i] = min(dp[i], dp[i-pow6] + 1)
    pow6 *= 6
    
  pow9 = 1
  while pow9 <= i:
    dp[i] = min(dp[i], dp[i-pow9] + 1)
    pow9 *= 9

print(dp[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(){
	char read[4];
	scanf(" %c %c %c", &read[0], &read[1], &read[2]);
	read[3] = 0;
	int num;
	sscanf(read, "%d", &num);
	printf("%s\n", num%4 == 0 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int num;
	double w, h;
	char c;

	while(scanf("%d", &num) != EOF){
		cin >> c >> w >> c >> h;
		if((double) w / h / h >= 25){
			cout << num << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include <cstdio>

using namespace std;

int x1,x2,y1,y2;
int x3,x4,y3,y4;

bool lo(int x1,int y1,int x2,int y2,int x3,int y3) {
    return (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)>0;
}

int dis(int x1,int x2) {
    return (x1-x2)*(x1-x2);
}

bool check(int x1,int y1,int x2,int y2,int x3,int y3) {
    return (x3-x2)*(x2-x1)+(y3-y2)*(y2-y1)==0&&dis(x2,x1)+dis(y2,y1)==dis(x3,x2)+dis(y3,y2)&&lo(x1,y1,x2,y2,x3,y3);
}

void f1() {
    for(x3=-400; x3<=400; x3++) {
        for(y3=-400; y3<=400; y3++) {
            if(check(x1,y1,x2,y2,x3,y3)) {
                return ;
            }

        }
    }
}

void f2() {
    for(x4=-400; x4<=400; x4++) {
        for(y4=-400; y4<=400; y4++) {
            if(check(x2,y2,x3,y3,x4,y4)) {
                return ;
            }
        }
    }
}


int main() {
    cin>>x1>>y1>>x2>>y2;
    f1();
    f2();
    printf("%d %d %d %d\n",x3,y3,x4,y4);

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let mut dp = vec![vec![0; t.len() + 1]; s.len() + 1];
    
    for si in 1..=s.len() {
        for ti in 1..=t.len() {
            let inc = if s[si-1] == t[ti-1] { 1 } else { 0 };
            dp[si][ti] = max(max(dp[si-1][ti-1] + inc, dp[si-1][ti]), dp[si][ti-1]);
        }
    }

    let mut ans = Vec::new();
    let mut si = s.len();
    for ti in (1..=t.len()).rev() {
        if dp[si][ti] != dp[si][ti-1] {
            while si > 0 {
                if dp[si][ti] != dp[si-1][ti] {
                    assert_eq!(s[si-1], t[ti-1]);
                    ans.push(s[si-1]);
                    si -= 1;
                    break;
                }
                si -= 1;
            }
        }
    }
    let ans = ans.iter().rev().collect::<String>();
    println!("{}", ans);
}

Measured memory_bytes: 37380
#include <stdio.h>


int A[2000],n;


int solve(int i,int m){
  if (m == 0)return 1;
  if (i >= n)return 0;
  int res =solve(i+1,m)||solve(i+1,m-A[i]);

return res;
  }


int main(){

  int q,i;
  int m;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m))
       printf("yes\n");
    else printf("no\n");
       
  }

  return 0;
}

  
  
  



  



Measured memory_bytes: 2044
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		long A = sc.nextLong();
		long B = sc.nextLong();

		long[] X = new long[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextLong();
		}

		sc.close();

		long ans = 0;
		for (int i = 1; i < N; i++) {
			ans += Math.min(A * (X[i] - X[i - 1]), B);
		}

		out.println(ans);

	}

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


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

long long l[90] = {2, 1};

long long lucas(int a){
  if(l[a]>0)return l[a];
  else return l[a] = lucas(a-1) + lucas(a-2);
}

int main(){
  int n;
  cin >> n;
  cout << lucas(n);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

map<char, int> SK,TK;

int main(void) {
    string s,t;
    cin>>s>>t;

    for(int i = 0;i < s.size();i++) {
        SK[s[i]]++;
        TK[t[i]]++;
    }

    if(SK.size() != TK.size()) {
        cout<<"No"<<endl;

        return 0;
    }

    vector<int> a,b;
    for(auto v:SK) {
        a.push_back(v.second);
    }
    for(auto v:TK) {
        b.push_back(v.second);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i = 0;i < a.size();i++) {
        if(a[i] != b[i]) {
            cout<<"No"<<endl;

            return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}




Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n,m;
    cin>>n>>m;
    ll a[n],b[n],c[m],d[m];
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    rep(i,m){
        cin>>c[i]>>d[i];
    }
    for(int i=0;i<n;i++){
        ll dis=LINF,ans;
        for(int j=0;j<m;j++){
            ll tmp=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(tmp<dis){
                ans=j;
                dis=tmp;
            }
        }
        cout<<ans+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a,b,c,t;
    scanf("%d",&n);
    if(n>=100&&n<=999)
    {
        c=n%10;
        b=(n/10)%10;
        a=((n/10)/10)%10;
        t=(a*100+a*10+a);
        if(a==b&&b==c&&c==a)
            printf("%d\n",n);
        else if(n<t)
            printf("%d\n",t);
        else
            printf("%d\n",t+111);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>
#include <utility>
using namespace std;

const int INF = 1e9;
const int MAX_H = 50 + 2;
const int MAX_W = 50 + 2;
int H, W, d[MAX_H][MAX_W];
string S[MAX_H];
queue<pair<int, int>> q;

int bfs(){
    q.push(make_pair(0, 0));
    while (!q.empty()){
        auto p = q.front(); q.pop();
        int y = p.first;
        int x = p.second;
        if (y == H-1 && x == W-1) return d[y][x];
        if (0   <= y-1 && d[y-1][x] == INF && S[y-1][x] == '.') {q.push(make_pair(y-1, x)); d[y-1][x] = d[y][x] + 1;}
        if (y+1 <= H-1 && d[y+1][x] == INF && S[y+1][x] == '.') {q.push(make_pair(y+1, x)); d[y+1][x] = d[y][x] + 1;}
        if (0   <= x-1 && d[y][x-1] == INF && S[y][x-1] == '.') {q.push(make_pair(y, x-1)); d[y][x-1] = d[y][x] + 1;}
        if (x+1 <= W-1 && d[y][x+1] == INF && S[y][x+1] == '.') {q.push(make_pair(y, x+1)); d[y][x+1] = d[y][x] + 1;}
    }
    return -1;
}

int main() {
    int ans = 0;
    cin >> H >> W;
    for (int i = 0; i < H; ++i){
        cin >> S[i];
        for (int j = 0; j < S[i].length(); ++j){
            if (S[i][j] == '.') ans++;
        }
    }
    for (int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            d[i][j] = INF;
        }
    }
    d[0][0] = 1;
    int k = bfs();
    if (k == -1){
        cout << -1 << endl;
    }else{
        cout << ans - k << endl;
    }    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    int sum=0;
    scanf("%d %d", &a,&b);
    for(int i=a;i<=b;i++){
        int x=i;
        int digit=0;
        while(x!=0){
            digit+=1;
            x/=10;
        }
        x=i;
        int arr[6];
        for(int i=0;i<digit;i++){
            int n=x%10;
            arr[i]=n;
            x/=10;
        }
        int check=0;
        for(int i=0;i<digit;i++){
            if(arr[i]!=arr[digit-1-i]){
                check+=1;
            }
        }
        if (check==0){
            sum+=1;
        }
    }
    printf("%d", sum);
}

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

int main() {
  int N, M, i, j, tmp, max=0;
  vector<string> list;
  
  cin >> N;
  vector<string> b(N);
  for(i=0; i<N; i++) {
    cin >> b.at(i);
    
    if(i==0)
      list.push_back(b.at(j));
    else
      for(j=0; j<list.size(); j++)
        if(b.at(i) == list.at(j))
          break;
    
    if(j == list.size())
      list.push_back(b.at(i));
  }
  
  cin >> M;
  vector<string> r(M);
  for(i=0; i<M; i++)
    cin >> r.at(i);
  
  for(i=0; i<list.size(); i++) {
    tmp = 0;
    for(j=0; j<b.size(); j++)
      if(list.at(i) == b.at(j))
        tmp++;
    for(j=0; j<r.size(); j++)
      if(list.at(i) == r.at(j))
        tmp--;
    if(tmp > max)
      max = tmp;
  }
  
  cout << max << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))

    ans = 0
    for i in x:
        ans += min(i, k-i) * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060