akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

#define roop(i, n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, a, b;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	} else {
		cin >> a >> b;
		cout << a+b << endl;
	}

	return 0;
}

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

int main() {
    string S; cin >> S;
    rep(i, S.size()){
        if(i%2 == 1){
            if(S[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        } else {
            if(S[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i=0,N;
	do
	scanf("%d", &N);
	while (N < 0 || N>1000);
	while (N - 3 != 4 && N - 3 != 5 && N-3>=0)
	{
		N -= 3;
		i++;
	}
	if (N - 3 == 4 || N - 3 == 5)
	{
		i += 2;
	}
	printf("%d", i);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int v[3][105];
int n;

int srch(int y, int x, int u){
    if(y>=2 || x>=n) return u;
    return max(srch(y+dy[0], x+dx[0], u+v[y][x]), srch(y+dy[1], x+dx[1], u+v[y][x]));
}

int32_t main(){
    cin >> n;
    REP(i, 2){
        REP(j, n){
            cin >> v[i][j];
        }
    }

    cout << srch(0, 0, 0) << endl;
}

Measured memory_bytes: 256
num = 1
while true
  w = gets().to_i
  break if w==0
  n = gets().to_i
  v = []
  h = []
  n.times do |i|
    v[i],h[i] = gets().split(",").map(&:to_i)
  end
  dp = Array.new(n){Array.new(w+1,0)}
  n.times do |i|
   (1+w).times do |j|
     if h[i] > j
       dp[i][j] = dp[i-1][j]
     else
       dp[i][j] = [dp[i-1][j],dp[i-1][j-h[i]]+v[i]].max
     end
   end
  end
  weight = (0..w).map.select{|x| dp[n-1][x] == dp[n-1][w]}.min
  puts "Case #{num}:"
  puts dp[n-1][w]
  puts weight
  num += 1
end

Measured memory_bytes: 14132
#include <cstdio>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;

int main(void){
  long long int n,i;
  cin >> n;
  long long int c[n],v[n];
  for(i=0;i<n;i++){
    cin >> v[i];
  }
  for(i=0;i<n;i++){
    cin >> c[i];
  }

  long long int value = 0;
  for(i=0;i<n;i++){
    long long int tmp = v[i]-c[i];
    if(tmp>0){
      value += tmp;
    }
  }
  
  cout << value << endl;
  return 0;
}




Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] A = new int[N + 1];

		for (int i = 0; i < N-1; i++) {
			int a = sc.nextInt();
			A[a]++;
		}

		for (int i = 1; i <= N; i++) {
			System.out.println(A[i]);
		}
	}
}


Measured memory_bytes: 62288
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  ll lcm=C/gcd(C,D)*D;
  cout<<B-(B/C+B/D-B/lcm)-(A-1-((A-1)/C+(A-1)/D-(A-1)/lcm))<<endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		int N = (int)reader.nextLong();
		int[] A = new int[N];
		for (int i=0; i<N; i++) {
			A[i] = (int)reader.nextLong();
		}
		solver(N, A);
	}

	public static void solver(int N, int[] A) {
		ArrayList<Integer> L = new ArrayList<Integer>();
		for (int i=0; i<N; i++) {
			if (L.size() == 0) {
				L.add(A[i]);
			} else if (L.size() == 1){
				if (A[i] <= L.get(0)) L.set(0, A[i]);
				else L.add(A[i]);
			} else if(L.get(L.size() - 1) < A[i]){
				L.add(A[i]);
			} else {
				Integer[] list = L.toArray(new Integer[0]);
				int search = Arrays.binarySearch(list, A[i]);
				if (search < 0) {
					search = ~search;
					if (search == L.size()) L.add(A[i]);
					else L.set(search, A[i]);
				}
			}
		}
		System.out.println(L.size());
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 67504
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,q,x[100010],a,b,c,t;
inline void orz(int t,int k)
{
	if(k==1)
	  {
	   c+=t;
	   if(b+c>m)
	     b=m-c;
	   if(a>b)
	     a=b=0,c=m;
	  }
	else
	  {
	   c-=t;
	   if(a+c<0)
	     a=-c;
	   if(a>b)
		 a=b=c=0;
	  }
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l;
	scanf("%d%d",&m,&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	b=m;
	k=1;
	l=-1;
	scanf("%d",&q);
	while(q--)
	  {
	   scanf("%d%d",&i,&j);
	   while(k<=n && i>=x[k])
	     {
		  orz(x[k]-t,l);
		  t=x[k];
		  l*=-1;
		  k++;
		 }
	   orz(i-t,l);
	   t=i;
	   if(j<=a)
	     printf("%d\n",a+c);
	   else if(j<=b)
	     printf("%d\n",j+c);
	   else
	     printf("%d\n",b+c);
	  }
	return 0;
}


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

using ll = long long;
constexpr int mod = 1e9 + 7;
constexpr ll inv2 = (mod + 1) / 2;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(auto& x : a) cin >> x;

    ll ans = 0, all_inv = 0;
    vector<ll> cnt(2010);
    for(int i = 0; i < n; ++i) {
        cnt[a[i]] += 1;
        for(int j = i + 1; j < n; ++j) {
            all_inv += a[i] > a[j];
        }
    }

    ans = all_inv * k % mod;
    for(int i = 1; i <= 2000; ++i) {
        if(cnt[i] != 0) {
            (ans += (cnt[i] * cnt[i - 1] * k % mod) * (k - 1) % mod * inv2) %= mod;
        }
        cnt[i] += cnt[i - 1];
    }
    cout << ans << endl;
}


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

typedef complex<double> P;

const int N = 20;
const int MAXC = 10010;
const double INF = 1e+9;
const double EPS = 1e-8;

struct edge{
  int to;
  double cost;
  edge(int t=0, double c=0):to(t),cost(c){}
};

struct state{
  int prev, now, cnt;
  double dis;
  state(int p=0, int n=0, int c=0, double d=0):prev(p),now(n),cnt(c),dis(d){}
  bool operator < (const state &s) const {
    return dis > s.dis;
  }
};

bool equal(double a, double b){
  return fabs(a-b) < EPS;
}

double angle(P a, P b1, P b2){
  double A = abs(b1 - b2);
  double B = abs(a - b1);
  double C = abs(a - b2);
  return acos((B*B + C*C - A*A) / (2.0*B*C));
}


int n;
double r, rad;
vector<P> v;

double d[N][N][MAXC];

int solve(){
  int ans = 0;
  priority_queue<state> pq;
  state u, u2;
  vector<edge> g[N][N];
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        if(j != k && (i == j || M_PI - angle(v[j], v[i], v[k]) < rad + EPS)) {
          g[i][j].push_back(edge(k, abs(v[j] - v[k])));
          //if(i != j) cout << v[i] << " -> " << v[j] << " -> " << v[k] << " : " << abs(v[j]-v[k]) << endl;
        }
      }
    }
  }

  for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<MAXC;k++) d[i][j][k] = INF;

  for(pq.push(state(0, 0, 0, 0)); !pq.empty();){
    u = pq.top();
    pq.pop();

    for(int i=0;i<g[u.prev][u.now].size();i++){
      edge next = g[u.prev][u.now][i];
      u2 = state(u.now, next.to, u.cnt+1, u.dis+next.cost);
      assert(u2.cnt < MAXC);
      if(u2.dis > r + EPS || d[u2.prev][u2.now][u2.cnt] < u2.dis + EPS) continue;
      d[u2.prev][u2.now][u2.cnt] = u2.dis;
      ans = max(ans, u2.cnt);
      pq.push(u2);
    }
  }

  return ans;
}

int main(){
  while(cin >> n){
    v.clear();
    cin >> r >> rad;
    rad *= M_PI / 180.0;
    for(int i=0;i<n;i++){
      double x,y;
      cin >> x >> y;
      v.push_back(P(x,y));
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 32788
#include <iostream>
#include <string>

int main()
{
    std::string N;

    std::cin >> N;

    switch (N.back())
    {
    case '2':
    case '4':
    case '5':
    case '7':
    case '9':
        std::cout << "hon" << std::endl;
        break;
    case '0':
    case '1':
    case '6':
    case '8':
        std::cout << "pon" << std::endl;
        break;
    case '3':
        std::cout << "bon" << std::endl;
        break;
    }

    return 0;
}


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

using namespace std;

const int N = 222;

char s[N][N];
int n, dist[N];
bool done[N];

void bfs(int v) {
  memset(dist, -1, sizeof dist);
  dist[v] = 0;
  queue<int> que;
  que.push(v);
  while (!que.empty()) {
    v = que.front(); que.pop();
    for (int j = 0; j < n; ++j) {
      if (s[v][j] == '0') continue;
      if (dist[j] != -1) continue;
      dist[j] = dist[v] + 1;
      que.push(j);
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%s", s[i]);
  int ans = -1;
  for (int i = 0; i < n; ++i) {
    bfs(i);
    bool ok = 1;
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        if (s[j][k] == '0') continue;
        ok &= abs(dist[j] - dist[k]) == 1;
      }
    }
    if (ok)
      ans = max(ans, 1 + * max_element(dist, dist+n));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>
#define SIZE 100005
#define MOD 1000000007

using namespace std;

class BIMissYou {
public:
    static void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        for (int i = 0; i < s.size(); ++i) {
            cout << "x";
        }
        cout << endl;
    }
};


int main() {
    BIMissYou solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int MAX = 0;
  int ans = 0;
  REP(i, N){
    if(A[i] == MAX+1){
      MAX++; continue;
    }

    int now = (A[i]-(MAX+1)-1)/(MAX+1)+1;
    if(A[i] <= MAX) now = 0;
    ans += now;
    if(i == 0) MAX = 1;
  }
  cout << ans << "\n";

  return 0;
}

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

int main(){
  int N, D, X, A[105],b=0;

  cin>>N;
  cin>>D>>X;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
    if(A[i]*j+1<D+1)
    b++;
    }
  }
  cout<<b+X<<endl;
  return 0;
}



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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	int N; cin >> N;
	int K; cin >> K;
	vector<ll> B(N);
	REP(i,N){
	    cin >> B[i];
	}

	ll ans = 1e15;

	for (int b = 0; b < (1<<N); b++){
		if (__builtin_popcount(b) != K) continue;
		vector<ll> A;
		A = B;
		ll nowH = A[0];
		ll nowc = 0;
		REP(i,N){ //bit loop
			if (i == 0) continue;
			if (b & (1<<i)){ //i-th digit(bitにi-thのフラグが立っているかどうか)
				if (nowH >= A[i]){
					nowc += nowH - A[i] + 1;
					A[i] = nowH + 1;
					nowH = A[i];
				}else{
					nowH = A[i];
				}
			}else{
				if (nowH <= A[i]){
					//nowc += nowH - A[i] + 1;
					//A[i] = nowH + 1;
					nowH = A[i];
				}
			}
		}

		//cout << nowc << " (bit = " << b << ")" << "\n";
		chmin(ans,nowc);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
import math
def prime_divisor(n):
    ls = []
    i = 2
    while i <= math.floor(n**0.5):
        if n%i == 0:
            ls.append(i)
            ls.append(n//i)
            i += 1
        else:
            i += 1
    if n > 1:
        ls.append(n)
    return ls
N = int(input())
ls1 = prime_divisor(N)
ls2 = [x-1 for x in list(set(ls1)) if x >= 2]
ls2.sort()
ls2.reverse()
ans = 0
for i in range(len(ls2)):
    if N // ls2[i] == N % ls2[i]:
        ans += ls2[i]
print(ans)

Measured memory_bytes: 69808
#include <iostream>
using namespace std;
int main(){
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int lima = F / (100*A);
    int sum = lima * A * 100;
    int ans = 0;
    for(int i = 0; i <= lima; i++){
        int limb = (F - (100*A*i)) / (100*B);
        for(int j = 0; j <= limb; j++){
            int limsu = (A * i + B * j) * E;
            int water = (A * i + B * j) * 100;
            int limf = F - water;
            int limc = min(limf / C, limsu / C);
            for(int k = 0; k <= limc; k++){
                int d = min((limf - C * k) / D, (limsu - C * k) / D);
                int s = water + C * k + D * d;
                int temp = C * k + D * d;
                int res1 = ans * s, res2 = temp * sum;
                if(res1 < res2){
                    ans = temp;
                    sum = s;
                }
            }
        }
    }
    cout << sum << ' ' << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  string b;
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == '1' || a[i] == '0') {
      b.push_back(a[i]);
    } else {
      if (b.size() == 0) {
        continue;
      } else {
      b.pop_back();
      }
    }
  }
  cout << b;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
map<ll, int> factorize(ll x)
{
    ll n = x;
    map<ll, int> m;
    for (ll i = 2; i * i <= n && x > 1; ++i)
        while (x % i == 0)
            m[i]++, x /= i;
    if (x > 1)
        m[x]++;
    return m;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, ans = 0;
    cin >> n;
    auto f = factorize(n);
    for (auto p : f)
    {
        ll e = p.second;
        ll x = (-1 + sqrtl(1 + 8 * e)) / 2;
        ans += x;
    }
    cout << ans;
}


Measured memory_bytes: 3684
# -*- coding: utf-8 -*-
# 整数の入力
import math
N = int(input())


# primes from [Pythonで素数列挙と素数判定 - Qiita](https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f)
def calcPrimes(x):
    if x < 2:
        return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for prime in primes:
        if prime > math.sqrt(x):
            break
        if prime == 0:
            continue
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


# is_prime from [Pythonで素数列挙と素数判定 - Qiita](https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f)
def isPrime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True  # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0:
            return False
        prime += step
        step = 6 - step
    return True


def calcFiveFivePrimes(N):
    primes = calcPrimes(2000)
    fiveFivePrimes = [prime for prime in primes if prime % 5 == 1]
    return fiveFivePrimes[:N]


print(" ".join(map(str, calcFiveFivePrimes(N))))


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

#define ll long long int 
ll mod=1e9+7;

// vector<int> g[200005];
// int vis[200005];
// queue<int> q;
// int level[200005];

// void dfs(int i)
// {
//     vis[i] = 1;
//     for(int j=0;j<g[i].size();j++)
//     {
//         int child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(int i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         int top = q.front();
//         int len_adj = g[top].size();
//         int j;
//         for(j=0;j<len_adj;j++)
//         {
//             int v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }   
//         q.pop();
//     }
// }

ll modular_exponentiation(ll base, ll power)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    int t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j,k,a,b;
        cin >> k;
        cin >> a >> b;
        // ll arr[n];

        for(i=a;i<=b;i++)
        {
            if(i % k == 0)
            {
                cout << "OK\n";
                return 0;
            }
        }

        cout << "NG\n";
        return 0;
    }

    
    
}

Measured memory_bytes: 3624
w = input()
counter = {}
flg = -1
for c in w:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1
for i in counter.values():
    if i % 2 == 0:
        flg = 1
    else:
        flg = 0
        break
if flg == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>

using namespace std;

const int maxn=1e7+10;
int A[maxn];

void partition(int l,int r)
{
	int flag;
	int x=A[r];
	int i=l-1;
	for(int j=l;j<r;j++){
		if(A[j]<=x){
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	flag=i+1;
	for(int i=l;i<=r;i++){
		if(i>1)printf(" ");
		if(i==flag)printf("[");
		printf("%d",A[i]);
		if(i==flag)printf("]");
	}
	printf("\n");
}

int main()
{
	int n;
	scanf("%d",&n);
	memset(A,0,sizeof(A));
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	partition(1,n);
	return 0;
}


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


int main(){
  string s;
  cin >> s;
  int ans;
  if(s=="SUN"){
    ans=7;
  }else if(s=="MON"){
    ans=6;
  }else if(s=="TUE"){
    ans=5;
  }else if(s=="WED"){
    ans=4;
  }else if(s=="THU"){
    ans=3;
  }else if(s=="FRI"){
    ans=2;
  }else if(s=="SAT"){
    ans=1;
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);		
		int N = a.nextInt();
		int M = a.nextInt();
		Integer[] MArray = new Integer[M];
		for(int i = 0; i < M ; i++) {
			MArray[i] = a.nextInt();
			N -= MArray[i];
		}
		if(N < 0) {
			System.out.println("-1");
		}else {
			System.out.println(N);
		}
	}
}

Measured memory_bytes: 46588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

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

    private void solve() {
        try {
            //life takahashi
            int A = sc.nextInt();
            //attack takahashi
            int B = sc.nextInt();
            //life aoki
            int C = sc.nextInt();
            //attack aoki
            int D = sc.nextInt();

            while(true) {
                C -= B;
                if(C<=0) {
                    System.out.println("Yes");
                    break;
                }
                A -= D;
                if(A<=0) {
                    System.out.println("No");
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 32804
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

std::vector<bool> IsPrime;

void sieve(size_t max)
{
  if (max + 1 > IsPrime.size())
  {                                // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

class Pointer{
public:
  long long p;
  long long w;
};

int main()
{
  int N;
  cin >> N;
  long long mx = 0;
  long long mi = INF;
  for (int i = 0; i < N; i++)
  {
    long long a;
    cin >> a;
    mx = max(mx, a);
    mi = min(mi, a);
  }

  cout << mx - mi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int64_t answer = 0;
  int64_t before_two = 0;
  int64_t before_one = 0;
  for (int i = 0; i < N; i++) {
	if (i == 0) {
      answer = 1;
      before_one = 1;
      before_two = 2;
    } else {
      answer = before_one + before_two;
      before_two = before_one;
      before_one = answer;
    }
  }
  cout << answer << endl;
  
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    ll H,W; cin >> H >> W;
    if(H == 1 or W == 1) {
        cout << 1 << endl;
        return 0;
    }

    if(H%2 == 0 or W%2 == 0) {
        cout << H * W / 2 << endl;
        return 0;
    }

    cout << (H * W + 1) / 2 << endl;
    return 0;



}

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

int main() {
  int A, B;
  cin >> A >> B;

  for (int i = 1; i <= 10000; i++) {
    if (A == floor(i * 0.08) && B == floor(i * 0.1)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int sg[maxn];
vector<int> G[maxn]; 
void dfs(int u, int last) {
	for(int i = 0; i < G[u].size(); ++i) {
		int v = G[u][i];
		if(v == last) {
			continue;
		}
		dfs(v, u);
		sg[u] ^= sg[v] + 1;
	}
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 13952
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int a[4];
int main()
{
int n,l;
scanf("%d %d",&n,&l);
int a,b,sum=0;
if(l>=0)
{
   for(int i=2;i<=n;i++)
   {
   a=l+i-1;
   sum+=a;
   }
}
else
{
b=1-l;
if(b<=n)
{
   for(int i=1;i<=n;i++)
   {
    a=l+i-1;
   sum+=a;
   }
}
else
{
for(int i=1;i<n;i++)
{
a=l+i-1;
   sum+=a;
}
}

}
printf("%d\n",sum);
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


long long bitnum[50];
long long bitk[50];
int main() {
	long long n;
	long long k;
	cin >> n >> k;
	long long temp = k;
	for (int j = 0; j < 50; j++) {
		if (temp % 2 == 1) {
			bitk[j]++;
		}
		temp /= 2;
		if (temp == 0)break;
	}
	long long *a = new long long[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j=0;j<50;j++){
			if (a[i] % 2 == 1) {
				bitnum[j]++;
			}
			a[i] /= 2;
			if (a[i] == 0)break;
		}
	}
	bitk[49] = 1;
	long long max = 0;
	long long limit = 0;
	for (int j = 49; j >= 0; j--) {
		long long sum = 0;
		if (bitk[j] == 0) {
			continue;
		}
		for (int i = 48; i >= 0; i--) {
			if (j == 49) {
				if (bitk[i] == 1) {
					sum += (n - bitnum[i])*(long long)pow(2, i);
				}
				else {
					sum += bitnum[i] * (long long)pow(2, i);
				}
			}
			else {
				if (i < j) {
					if (n - bitnum[i] > bitnum[i]) {
						sum += (n - bitnum[i])*(long long)pow(2, i);
					}
					else {
						sum += bitnum[i] * (long long)pow(2, i);
					}
				}
				else if (i == j) {
					sum += bitnum[i] * (long long)pow(2, i);
				}
				else {
					if (bitk[i] == 1) {
						sum += (n - bitnum[i])*(long long)pow(2, i);
					}
					else {
						sum += bitnum[i] * (long long)pow(2, i);
					}
				}
			}
		}
		if (max < sum)max = sum;
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 1024
use itertools::Itertools;
use proconio::{fastout, input};
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        x: i32,
        ca: [[i32; m + 1]; n]
    }
    let mut ans = None;

    for i in 1..=n {
        for vs in ca.iter().combinations(i) {
            let mut sum = vec![0; m + 1];
            for v in vs {
                for j in 0..m + 1 {
                    sum[j] += v[j];
                }
            }

            if sum[1..].iter().all(|e| *e >= x) {
                ans = match ans {
                    Some(x) => Some(min(x, sum[0])),
                    None => Some(sum[0]),
                }
            }
        }
    }

    println!("{}", ans.unwrap_or(-1));
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

bool comp(pair<ll,ll> &p1,pair<ll,ll> &p2) {
    if(p1.first > p2.first){
        return true;
    }else{
        return false;
    }

}

int main(){

    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    ll z = a+b+c;

    vector<pair<ll,ll>> p(a+b+c);
    rep(i,a){
        cin >> p[i].first;
        p[i].second = 1;
    }
    rep(i,b){
        cin >> p[i+a].first;
        p[i+a].second = 2;
    }
    rep(i,c){
        cin >> p[i+a+b].first;
        p[i+a+b].second = 0;
    }

    sort(p.begin(),p.end(),comp);
    // rep(i,z){
    //     cout << p[i].first << " " << p[i].second << endl;
    // }

    ll ans = 0;
    ll id = 0;
    ll muzi = 0;
    while(x>0 || y > 0){
        ll s = p[id].second;
        if(s==1&&x>0){
            x --;
            ans += p[id].first;
            id++;
        }else if(s==2&&y>0){
            y --;
            ans += p[id].first;
            id++;
        }else if(s==0){
            muzi ++;
            ans += p[id].first;
            id++;
        }else{
            id++;
        }

        if(muzi == x+y){
            break;
        }
    }
    cout << ans << endl;

    return 0;
}  

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

using namespace std;

int main()
{
    int n,count = 0;
    cin>>n;
    int ar[n];
    for(int i = 0;i < n;i++)
    cin>>ar[i];
    int dp[n];
    dp[0] = ar[0];
    for(int i = 1;i < n;i++)
    {
        dp[i] = min(dp[i-1],ar[i]);
    }
    for(int i= 0;i < n;i++)
    {
        if(ar[i] <= dp[i])
        count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    ll N = S.length();
    if(T.substr(0, N)==S) cout<<YES<<endl;
    else cout<<NO<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3048
#include <stdio.h>
int main(void){
	long long int a,sum=0,max,min;
	int i,j;
	scanf("%d",&j);
	for(i=0;i < j;i++){
		scanf("%lld",&a);
		sum += a;
		if(i==0){
			max=min=a;
		}
		if(max < a){
			max = a;
		}else if(min > a){
			min = a;
		}
	}
	printf("%lld %lld %lld\n",min,max,sum);
return 0;
}


Measured memory_bytes: 2000
#include <iostream>
#include <stdio.h>

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define swap(a,b) {a+=b;b=a-b;a-=b;}
#define ll long long

using namespace std;

main(){
  int N;
  scanf("%d",&N);
  int B[N]={};
  int A;
  rep(i,1,N){
    scanf("%d",&A);
    B[A-1]++;
  }
  rep(i,0,N)printf("%d\n",B[i]);
}

Measured memory_bytes: 4608
// https://atcoder.jp/contests/dp/tasks/dp_a
# include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define scn(n) scanf("%d", &n)
#define pri(n) printf("%d",n)
#define priln(n) printf("%d\n",n)
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 gcd(int a,int b) { return b ? gcd(b,a%b) : a; }

// 配るDP
int main()
{
  int n;
  scn(n);

  int a[n];
  rep(i, n) scn(a[i]);

  int dp[n];
  rep(i, n) dp[i] = INF;
  dp[0] = 0;

  rep(i, n - 1) {
    chmin(dp[i+1], dp[i] + abs(a[i+1] - a[i]));
    chmin(dp[i+2], dp[i] + abs(a[i+2] - a[i]));
  }

  pri(dp[n - 1]);
  return 0;
}


Measured memory_bytes: 1024
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

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

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


int n, k;
vector<ll> h;

void solve() {
    ll dp[half_inf + k];
    rep(i, half_inf + k) dp[i] = inf;
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[n - 1] << endl;
}

int main() {
    cin >> n >> k;
    h.resize(n);
    rep(i, n) cin >> h[i];
    solve();
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;

    vector<ll> x;
    for(int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    auto first_pos = lower_bound(x.begin(), x.end(), 0);
    int zero_ind = distance( x.begin(), first_pos);
    x.insert(first_pos, 0);

    int left, right;
    ll min_val = 9999999999999999;
    for(int i = 0; i < N - K + 1; i++) {
        left = i;
        right = left + K - 1 + 1;
        if(left > zero_ind || right < zero_ind) continue;

        ll ret;

        if(x[left] < 0 && x[right] >= 0) {
            ll left_path = 2 * abs(x[left]) + abs(x[right]);
            ll right_path = 2 * abs(x[right]) + abs(x[left]);
            ret = min(left_path, right_path);
        } else if(x[left] < 0) {
            ret = x[left];
        } else {
            ret = x[right];
        }
        min_val = min(min_val, ret);
    }

    cout << min_val << endl;

}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int h, w;
    cin >> h >> w;
    auto v = make_v(h+2, w+2, 0);
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            v[i+1][j+1] = (s[j] == '.');
        }
    }
    int ans = 0;
    array<int, 4> dy{-1, 1, 0, 0}, dx{0, 0, -1, 1};
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(!v[i+1][j+1]) continue;
            auto dist = make_v(h+2, w+2, INF<int>);
            queue<pair<int, int>> Q;
            Q.emplace(i+1, j+1);
            dist[i+1][j+1] = 0;
            while(!Q.empty()){
                int y, x; tie(y, x) = Q.front(); Q.pop();
                for (int k = 0; k < 4; ++k) {
                    if(!v[y+dy[k]][x+dx[k]]) continue;
                    if(dist[y+dy[k]][x+dx[k]] > dist[y][x]+1){
                        dist[y+dy[k]][x+dx[k]] = dist[y][x]+1;
                        Q.emplace(y+dy[k], x+dx[k]);
                    }
                }
            }
            for (int k = 0; k < h; ++k) {
                for (int l = 0; l < w; ++l) {
                    if(dist[k+1][l+1] != INF<int>){
                        ans = max(ans, dist[k+1][l+1]);
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N; cin >> N;

	int ans = 1;
	for (int i = 2;i*i <= N;i++){
		int a = i*i;
		for (;a <= N;a*=i){
			ans = max(ans,a);
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int A = sc.nextInt();
			int B = sc.nextInt();
			int C = sc.nextInt();
			if( A <= C && B >= C){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	} 
}

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

vector<vector<int>> bfs(1000,vector<int>(1000,0));
vector<string> B;
queue<pair<int,int>> tsugi;
int H,W;

int main(){
  cin>>H>>W;
  string sc;
  for(int i=0;i<H;i++){
    cin>>sc;
    B.push_back(sc);
    for(int j=0;j<W;j++){
      if(sc[j]=='#'){
        tsugi.push({i,j});
      }
    }
  }
  pair<int,int> Pt;
  int ans=0;
  while(!tsugi.empty()){
    Pt=tsugi.front();
    int h=Pt.first;
    int w=Pt.second;
    if(h>0 && B[h-1][w]=='.'){
      if(bfs[h-1][w]==0){
        bfs[h-1][w]=bfs[h][w]+1;
        tsugi.push({h-1,w});
        ans=max(ans,bfs[h-1][w]);
      }else{
        bfs[h-1][w]=min(bfs[h-1][w],bfs[h][w]+1);
      }
    }
    if(w>0 && B[h][w-1]=='.'){
      if(bfs[h][w-1]==0){
        bfs[h][w-1]=bfs[h][w]+1;
        tsugi.push({h,w-1});
        ans=max(ans,bfs[h][w-1]);
      }else{
        bfs[h][w-1]=min(bfs[h][w-1],bfs[h][w]+1);
      }
    }
    if(h!=H-1&&B[h+1][w]=='.'){
      if(bfs[h+1][w]==0){
        bfs[h+1][w]=bfs[h][w]+1;
        tsugi.push({h+1,w});
        ans=max(ans,bfs[h+1][w]);
      }else{
        bfs[h+1][w]=min(bfs[h+1][w],bfs[h][w]+1);
      }
    }
    if(w!=W-1&&B[h][w+1]=='.'){
      if(bfs[h][w+1]==0){
        bfs[h][w+1]=bfs[h][w]+1;
        tsugi.push({h,w+1});
        ans=max(ans,bfs[h][w+1]);
      }else{
        bfs[h][w+1]=min(bfs[h][w+1],bfs[h][w]+1);
      }
    }
    tsugi.pop();
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 13456
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

//D日目時点のスコアを計算
int score(int D, int c[], int s[][26], int t[]){
    int pen_day[26];
    for(int i=0; i<26; i++){
        pen_day[i]=1;
    }
    int score=0;
    
    for(int i=0; i<D; i++){
        int type=t[i]-1;
        pen_day[type]=0;
        //満足度増加
        score+=s[i][type];
        //満足度低下
        for(int j=0; j<26; j++){
            int dec=c[j]*pen_day[j];
            score-=dec;
        }
        //日数追加
        for(int j=0; j<26; j++){
            pen_day[j]++;
        }        
    }
    return score;
}

//満足度の変移
int hen_pen(int st, int end, int c[], int s[][26], int t[], int type1, int type2){
    int sum=0;
    int de_type1=0;
    int de_type2=0;
    int last1=0, last2=0;

    for(int i=st; i<=end; i++){
        if(t[i]==type1){
            de_type1++;
            last1=i;
        }
        if(t[i]==type2){
            de_type2++;
            last2=i;
        }
    }

    sum+=c[type1]*de_type1;
    sum+=c[type2]*de_type2;
    sum+=(end-last1)*c[type1];
    sum-=(last2-st)*c[type2];

    return sum;
}

void Greedy(int D, int c[], int s[][26]){
    int t[D], max_type=0, max_score=0;

    for(int i=0; i<D; i++){
        max_score=0;
        for(int j=0; j<26; j++){
            t[i]=j+1;
            int S=score(i+1, c, s, t);
            if(max_score < S){
                max_score = S;
                max_type=j+1;
            }
        }
        t[i]=max_type;
    }

    //局所探索
    int tmp;
    int roop_num=0;
    int MAX=max_score;
    while(1){
        int a=rand()%D;
        int b=rand()%D;

        //t[a],t[b]を入れ替え
        tmp=t[a];
        t[a]=t[b];
        t[b]=tmp;

        //scoreを計算
        int now_score=score(fmax(a, b)+1, c, s, t);
        if(MAX<now_score) MAX=now_score;
        else{
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;  
        }

        roop_num++;
        if(roop_num==D*500) break;
    }

    for(int i=0; i<D; i++){
        printf("%d\n", t[i]);
    }
}

int main(void){
    int D, c[26], s[365][26];

    //入力
    scanf("%d", &D);
    for(int i=0; i<26; i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            scanf("%d", &s[i][j]);
        }
    }

   /*ここから処理*/
   /*
    int num=1;
    for(int i=0; i<D; i++){
        printf("%d\n", num);
        num++;
        if(num>26) num=1;
    }
    */

   Greedy(D, c, s);


    return 0;
}

Measured memory_bytes: 2208