akhauriyash/Code-Regression huggingface dataset:
N, K = gets.chomp.split(" ").map(&:to_i)
R, S, P = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp.split("")
flag = Array.new(N, true)
ans = 0

N.times do |i|
    if K <= i && t[i-K] == t[i] then
        if flag[i-K] then
            flag[i] = false
            next
        end
    end
    case t[i]
    when "r"
        ans += P
    when "s"
        ans += R
    when "p"
        ans += S
    end
end

puts ans

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

int main() {
  string s;
  cin >> s;
  
  int start, goal;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') {
      start = i;
      break;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'Z') {
      goal = i;
    }
  }
  cout << goal - start + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll int mod=1e9+7;

int main(){
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	vector<ll>dp(k+1,0);
	for(int i=0;i<=k;i++){
		for(auto j:a){
			if(i>=j && !dp[i-j])
			dp[i]=1;
		}
	}
	if(dp[k]) cout<<"First"<<endl;
	else
	cout<<"Second"<<endl;
	return 0;
}

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

int D,N;
int T[200];
int A[200],B[200],C[200];

int memo[200][101];
int calc(int d,int p){
    if(d==D){return 0;}
    if(~memo[d][p])return memo[d][p];

    int ret=0;
    for(int i=0;i<N;i++){
        if(A[i]>T[d]||B[i]<T[d])continue;
        ret=max(ret,calc(d+1,C[i])+(d?abs(C[i]-p):0));
    }

    return memo[d][p]=ret;
}

int main(){
    cin>>D>>N;
    for(int i=0;i<D;i++)cin>>T[i];
    for(int i=0;i<N;i++)cin>>A[i]>>B[i]>>C[i];

    memset(memo,-1,sizeof(memo));
    cout<<calc(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 1264
#include <iostream>

int main()
{
	int n; std::cin >> n;
	
	int* heap = new int[n+1];
	
	for (int i=1; i<=n; i++) std::cin >> heap[i];
	
	for (int i=1; i<=n; i++) {
		std::cout << "node " << i << ": key = " << heap[i] << ", ";
		if (i>1) std::cout << "parent key = " << heap[i/2] << ", ";
		if (2*i<=n) std::cout << "left key = " << heap[2*i] << ", ";
		if (2*i+1<=n) std::cout << "right key = " << heap[2*i+1] << ", ";
		std::cout << std::endl;
	}
	
	delete[] heap;
	
	return 0;
}



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

using namespace std;

const long long MOD = 1e9 + 7;

typedef long long ll;

ll arr[1010];
//√1000は31ちょい



void factors(int x){
  //xを素因数分解した結果をarrに保存
  int c = (int) sqrt( (double) x);
  for(int j = 2; j <= c; j++){
    while( x % j == 0){ x /= j; arr[j]++;}}
  if( x != 1){ arr[x]++;}
}

int main(){
  
int N; cin >> N;
  for(int i = 2; i <= N; i++){
    //iを素因数分解した結果をarrに保存
    factors(i);}
  ll res = 1;
  for(int j = 0; j < 1010; j++){
    res = res * (arr[j] + 1);
    res %= MOD;}
  
  cout << res << endl; return 0;}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
const ll INF = 1e18;
using namespace std;
using namespace atcoder;

// Segment tree
struct F { // max func
  typedef ll TT;
  TT d;
  F(TT d=0):d(d) {}
  F& operator+=(const F& f) {
    maxs(d, f.d);
    return *this;
  }
  F operator+(const F& f) const { return F(*this) += f;}
};
struct seg {
  vector<F> d; int n;
  seg(){}
  seg(int mx) {
    n = 1; while (n < mx) n <<= 1;
    d = vector<F>(n<<1);
  }
  void upd(int i) { d[i] = d[i<<1]+d[i<<1|1];}
  F& operator[](int i) { return d[n+i];}
  void init() { for(int i=n-1;i;--i) upd(i);}
  void add(int i, F f) { for (i+=n,d[i]+=f,i>>=1;i;i>>=1) upd(i);}
  void set(int i, F f) { for (i+=n,d[i]=f,i>>=1;i;i>>=1) upd(i);}
  F get(int l, int r) {
    l += n; r += n;
    F lf, rf;
    while (l < r) {
      if (l&1) lf += d[l++];
      if (r&1) rf = d[--r] + rf;
      l >>= 1; r >>= 1;
    }
    return lf += rf;
  }
};

void Main()
{
    ll n, K;
    cin >> n >> K;

    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    
    ll amax = *max_element(all(A));
    seg t(2+amax+K);

    rep(i, n) {
        ll len = t.get(max(0LL, A[i] - K), A[i]+K+1).d;
        len++;
        t.set(A[i], len);
    }

    ll res = t.get(0, 2+amax+K).d;
    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 22032
#include<iostream>
#include<vector>
#include<map>
 
using namespace std;
 
int n,k,ans;
vector<string> V;
map<string,int> M;
 
void init(){
  V.clear();
  M.clear();
  ans = 0;
}
 
void solve(string s, int rev, int used){
  // cout << "s " << s << endl;
  if(rev == k){
    if(M[s] == 0){
      M[s] = 1;
      ans++;
    }
    return;
  }
 
  for(int i = 0; i < V.size(); i++)
    if(((1<<i)&used) == 0)
      solve(s+V[i],rev+1,used+(1<<i));
   
}
 
int main(){
  while(cin >> n >> k && n+k){
    init();
    for(int i = 0; i < n; i++){
      string in;
      cin >> in;
      V.push_back(in);
    }
    solve("",0,0);
    cout << ans << endl;
  }
  return 0;
}

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

int N;

typedef long long ll;

ll T = 0,AO = 0,ans=0;

struct Data {
  ll  A[100000];
  ll  B[100000];
  ll  C[100000];
};

int main() {
  cin >> N;
  Data data;
  for ( int i = 0; i < 100000; i++ ) data.C[i] = 0;
  for ( int i = 0; i < N; i++ ) {
    cin >> data.A[i] >> data.B[i];
    data.C[i] = data.A[i] + data.B[i];
  }

  sort(data.C,data.C+N);

  for ( int i = 0; i < N; i++ ) ans += data.A[i];
  
  for ( int i = N-2; i >= 0; i-=2 ) {
    ans -= data.C[i];
  }

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


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#define pb push_back
#define for(i,n) for(int i=1;i<n+1;i++)
using namespace std;

int main(){
    int n;
    unsigned long long int power = 1;
    unsigned long long int ans = pow(10,9)+7;
    cin >> n;
    for(i,n){
        power = (power*i)%ans;
    }
    cout << power << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 2 != 0) {
                ans++;
            }
        }

        System.out.println((double) ans / n);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <map>
using namespace std;

long long H, W, A[509][509], sum;

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> A[i][j];
			long long S1 = 1LL * i * (H + 1 - i);
			long long S2 = 1LL * j * (W + 1 - j);
			sum += A[i][j] * S1 * S2;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5088
#include<iostream>
using namespace std;
int ans,m,d,d10,d1;
int main()
{
	cin>>m>>d;
	for(int i=1;i<=m;i++)
		for(int o=10;o<=d;o++)
		{
			if(o%10==0)
				continue;
			d1 = o%10;
			d10 = o/10; 
			if(i==d1*d10 && d1>=2 && d10>=2)
				ans++;
		}
	cout<<ans<<endl;		
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
using namespace std;



int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    if((abs(a - b) % 2) == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;

    
    
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
from queue import Queue
sys.setrecursionlimit(100000)

Delta = [(1, 0), (-1, 0), (0, 1), (0, -1)]
INF = sys.maxsize

def bfs(start, target):
    d = [[INF] * w for i in range(h)]
    
    queue = Queue()
    queue.put(start)
    d[start[1]][start[0]] = 0

    while (queue.qsize()):
        p = queue.get()

        for delta in Delta:
            dx = p[0] + delta[0]
            dy = p[1] + delta[1]
            if not (0 <= dx and dx < w and 0 <= dy and dy < h):
                continue

            value = matrix[dy][dx]

            if value.isdigit() and value == target:
                return d[p[1]][p[0]] + 1, (dx, dy)

            if value != "X" and d[dy][dx] == INF:
                if value == "." or value == "S" or value.isdigit():
                    queue.put((dx, dy))
                    d[dy][dx] = d[p[1]][p[0]] + 1

    
def findStart(matrix):
    for j, row in enumerate(matrix):
        for i, cell in enumerate(row):
            if cell == "S":
                return (i, j)    

while (True):
    line = sys.stdin.readline().rstrip()
    if line == "":
        break

    h, w, c = (int(i) for i in line.split())

    matrix = []
    count = 0
    for i in range(h):
        matrix.append(list(input().rstrip()))
    
                
    start = findStart(matrix)
    for i in range(1, c+1):
        res, start = bfs(start, str(i))
        count += res 

    print(count)




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

int main()
{
  int N, M;

  cin >> N >>M;

  /* vector<int> K(N);
  vector<vector<int>> A(N, vector<int>(30));
  for (int i = 0; i < N; i++)
  {
    cin >> K.at(i);
    for (int j = 0; j < K.at(i); j++)
    {
      cin >> A.at(i).at(j);
    }
  }*/

  cout << (N + ((2 * M + 1) - 1)) / (2 * M + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;
int main() {
  int H,W,N;
  cin>>H>>W>>N;
  int a=max(H,W);
  cout<<(N+a-1)/a<<endl;
  return 0;
}


Measured memory_bytes: 3552
#include <cstdio>
#include <algorithm>

template<int N, typename T, T M>
struct factorial_mod
{
	T mod[N + 1];
	T inv_mod[N + 1];

	constexpr factorial_mod() : mod(), inv_mod()
	{
		mod[0] = 1;
		for (int i = 0; i < N; ++i)
		{
			mod[i + 1] = (mod[i] * (i + 1)) % M;
		}
		inv_mod[N] = power(mod[N], M - 2);
		for (int i = N - 1; i >= 0; --i)
		{
			inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
		}
	}

	constexpr T power(T a, T b) const
	{
		T r = 1;
		while (b > 0)
		{
			if ((b & 1) != 0) r = (r * a) % M;
			a = (a * a) % M;
			b >>= 1;
		}
		return r;
	}

	constexpr T comb(T n, T r) const
	{
		if (r < 0 || r > n || n < 0) return 0;
		return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
	}
};

constexpr long long MOD = 1000000007;
constexpr factorial_mod<2000020, long long, MOD> fmod;

int main()
{
	int r1, r2, c1, c2;
	scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
	long long ans = 0;
	for (int i = c1; i <= c2; ++i)
	{
		ans = (ans + fmod.comb(i + r2 + 1, i + 1) + MOD - fmod.comb(i + r1, i + 1)) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"math"
)

func main() {
	var x int
	fmt.Scan(&x)

	balance := 100
	year := 0
	for balance < x {
		balance = int(math.Floor(float64(balance) * 1.01))
		year++
	}
	fmt.Println(year)
}


Measured memory_bytes: 1776
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=3000000000;
const int MOD=1000000007;

int main()
{
 int m;
 cin >> m;
 ll sum=0,sumc=0,ans;
 for(int i=0;i<m;i++){
   ll d, c;
   cin >> d >> c;
   sum+=d*c;
   sumc+=c;
 }
  ans=((sum-1)/9)+sumc-1;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
    long long a, b, c, x, y;

    cin >> a >> b >> c >> x >> y;
    long long minn = min( x, y );

    long long ans = 0;

    ans += min( 2*c, a+b )*minn;

    x -= minn;
    y -= minn;

    ans += x*min( a, 2*c );
    ans += y*min( b, 2*c );

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll R,G,B,N; cin >> R >> G >> B >> N;
    ll ans = 0;
    for(ll r=0;r<=3000;r++){
        for(ll g=0;g<=3000;g++){
            if(N - r*R - g*G < 0) continue;

            if((N - r*R - g*G) % B == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int contains_3(int);
int main(void){
    int i, n;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        if(i % 3 == 0) printf(" %d", i);
        else if(contains_3(i)) printf(" %d", i);
    }
    printf("\n");
    return 0;
}
int contains_3(int num){
    while(num){
        if(num % 10 == 3) return 1;
        num /= 10;
    }
    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A[NMAX],B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

ll ans = 0;

void solve(){
  // main algorithm
  sort(A , A + N);
  ans = A[N-1] - A[0];
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    scanf("%lld", &A[i]);
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#define fi first
#define se second
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	double x;
	double n=1.0;
	int N;
	while(true){
		cin>>x;
		if (cin.eof())break;
		while(true){
			double t;
			t=5.0*(n-1);
			t/=4.9;
			t=pow(t,0.5);
			if(9.8*t>=x) break;
			n+=1.0;
		}
		N=n;
		cout<<N<<endl;
		n=1.0;
	}
}

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

using ll = long long;
template <class T> using p = pair<T, T>;
template <class T> using vt = vector<T>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
  ios::sync_with_stdio(0), cin.tie(0);

  string s;
  cin >> s;
  int sum = 0;
  rep (i, sz(s)) sum += s[i] - '0';
  cout << ((sum % 9) ? "No" : "Yes") << endl;

  return 0;
}

Measured memory_bytes: 3740
/*#include<bits/stdc++.h>
using namespace std;
const int N=2009;
int n,m;
vector<int>g[N];
int dfn[N],low[N],num,vis[N],co[N],col;
stack<int>S;
int siz[N];
void tarjan(int u){
   // cout<<u<<endl;
    dfn[u]=low[u]=++num;
    vis[u]=1;S.push(u);
    for(auto v:g[u]){
        if(!dfn[v])tarjan(v),low[u]=min(low[u],low[v]);
        else if(vis[v])low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        co[u]=++col;siz[col]++;
        while(S.top()!=u){
            co[S.top()]=col;
            vis[S.top()]=0;
            siz[col]++;
            S.pop();
        }
        vis[u]=0;S.pop();
    }
}
//bool vv[N];
vector<int>ans;
vector<int>uu;
int pre[N],vv[N];
void print(int u,int fa){
    ans.clear();
    while(1){
        ans.push_back(u);
        u=pre[u];
        if(u==fa)break;
        if(ans.size()>1000)break;
    }
    ans.push_back(fa);
    if(uu.size()==0||uu.size()>ans.size())uu=ans;
   // cout<<uu.size()<<endl;
    //cout<<ans.size()<<endl;
   // for(auto v:ans)cout<<v<<endl;
  //  exit(0);
}
//瞎搞bfs
void bfs(int u,int fa){
    queue<int>q;
    q.push(u);vv[u]=1;
    while(!q.empty()){
        int now=q.front();q.pop();
        for(auto v:g[now])if(vv[v]==1){print(now,v);}
        else{
            if(co[v]!=fa)continue;
        //    if(vv[v])memset(vv,0,sizeof(vv)),bfs(now,fa);
            vv[v]=1;q.push(v);pre[v]=now;
        }
    }   
}
int main(){
   // freopen("tt.in","r",stdin),freopen("tt.out","w",stdout);
    cin>>n>>m;
    for(int i=1,u,v;i<=m;i++)cin>>u>>v,g[u].push_back(v);
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
    for(int i=1;i<=col;i++)if(siz[i]>1){
       // cout<<siz[i]<<endl;
        for(int j=1;j<=n;j++)if(co[j]==i){bfs(j,i);break;}
        break;
       // return 0;
    }
    if(uu.empty()){cout<<-1<<endl;return 0;}
    cout<<uu.size()<<endl;
    for(auto i:uu)cout<<i<<endl;
    return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
const int N=3009;
int n,m;
struct Edge{
    int v,nxt;
}e[N<<1];
int head[N],cnt;
inline void add(int u,int v){
    e[cnt]=(Edge){v,head[u]};
    head[u]=cnt++;
}
vector<int>tmp,ans;
vector<int>path;
int vis[N];
void dfs(int u){
    path.push_back(u);vis[u]=1;
    for(int i=head[u],v;~i;i=e[i].nxt){
        v=e[i].v;
        if(vis[v]==2)continue;
        if(vis[v]==0){dfs(v);continue;}
        tmp.clear();
        for(int i=path.size()-1;i>=0;i--){
            tmp.push_back(path[i]);
            if(path[i]==v)break;
        }
        if(ans.empty()||ans.size()>tmp.size())ans=tmp;
    }
    path.pop_back();vis[u]=2;
}
int main(){
  //  freopen("tt.in","r",stdin),freopen("tt.out","w",stdout);
    cin>>n>>m;
    memset(head,-1,sizeof(head));
    for(int i=1,u,v;i<=m;i++)cin>>u>>v,add(u,v);
    for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
    if(ans.empty())cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        for(auto v:ans)cout<<v<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long v[1005];
long long dp[1005];
int p[1005];
int main()
{
	memset(p,-1,sizeof(p));
	int n;
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i++)
		scanf("%lld",&v[i]);
	dp[0] = v[0];
	for(int i = 1 ; i < n ; i++)
	{
		dp[i] = v[i];
		for(int j = i-2; j >= 0; j-= 2)
		{
			if(dp[j] + v[i] > dp[i])
			{
				dp[i] = dp[j] + v[i];
				p[i] = j;
			}
		}
	}
	int r = 0;
	long long ma = -1e18;
	for(int i = 0 ; i < n ; i++)
	{
		if(dp[i] > ma)
		{
			ma = dp[i];
			r = i;
		}
	}
	printf("%lld\n",ma);
	vector<int>ans;
	for(int i = n-1; i >= r+1; i--)
	{
		ans.push_back(i);
	}
	while(1)
	{
		int a = p[r];
		if(a == -1)
			break;
		while(a != r)
		{
//			cout << a << ' ' << r << endl;
			ans.push_back((a+r)/2);
			r -= 2;
		}
	}
	while(r != 0)
	{
		ans.push_back(0);
		r -= 1;
	}
	printf("%d\n",(int)ans.size());
	for(int i = 0 ; i < ans.size(); i++)
	{
		printf("%d\n",ans[i]+1);
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
   public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
 for(;;){
 int n=sc.nextInt(),m=sc.nextInt();
 if(m==0)break;
 int ans=0;
 int []in=new int[n];
 int []bezi=new int[n+1];
 for(int i=0; i<n;i++)in[i]=sc.nextInt();
 Arrays.sort(in);
 for(int i=n-1;i>=0;i--)bezi[n-i]=in[i];
 for(int i=1;i<=n;i++){
	 ans+=bezi[i];
	 if(i%m==0)ans-=bezi[i];
 }
 System.out.println(ans);
   }
 }
}

Measured memory_bytes: 55060
#include<iostream>
#include<iomanip>

int main(){
  int N;
  std::cin >> N;
  long long power = 1;
  for(int i = 1; i < N + 1; i++){
    power *= i;
    power = power % 1000000007;
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(20) << power << std::endl;
}

Measured memory_bytes: 256
// 2020-06-30 19:06:35
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  ll total = 0;
  auto calc = [](ll x) {
    return x * (x - 1) / 2;
  };
  for(auto m : mp) {
    total += calc(m.second);
  }
  rep(i, n) {
    cout << total - calc(mp[a[i]]) + calc(mp[a[i]]-1) << "\n";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main(){
    int n; cin>>n;
    vector<int> first_line(n);for(int i=0;i<n;i++){cin>>first_line[i];}
    vector<int> second_line(n);for(int i=0;i<n;i++){cin>>second_line[i];}

    vector<int> first_line_acc(n);
    vector<int> second_line_acc(n);
    
    int acc = 0;
    for (int i=0;i<n;i++){
        acc += first_line[i];
        first_line_acc[i] = acc;
    }
    acc = 0;
    for (int i=0;i<n;i++){
        acc += second_line[(n-1) - i];
        second_line_acc[(n-1) - i] = acc;
    }

    int temp_max = 0;
    for (int i=0;i<n;i++){
        int temp = first_line_acc[i] + second_line_acc[i];
        if (temp > temp_max){
            temp_max = temp;
        }
    }
    cout << temp_max << endl;
    return 0;
}

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

using namespace std;

int N,Q;
string s;
int dp[112345];
int main(){
    cin>>N>>Q;
    cin >> s;

    for(int i=0;i<N-1;i++){
        string ps=s.substr(i,2);
        if(ps=="AC"){
            dp[i+1]++;
        }
    }

    for(int i=1;i<N;i++)dp[i]+=dp[i-1];

    for(int i=0;i<Q;i++){
        int l,r;
        cin>>l>>r;
        r--;l--;
        cout<<dp[r]-dp[l]<<endl;

    }

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  pair<int,int>a[n];
  for(int i = 0;i<n;i++)
  {
    cin >> a[i].second;
    cin >> a[i].first;
  }
  sort(a,a+n);
  int sum = 0;
  bool ok = 1;
  for(int i = 0;i<n;i++)
  {
    sum += a[i].second;
    if(sum > a[i].first)
    {
     ok = 0;
     break;
    }
  }
  if(!ok) cout << "No";
  else cout << "Yes";
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll f,a;
	f=n/100;
	a=n-f*100;
	if(f>12||f==0){
		if(a>12||a==0){
			cout <<"NA";
		}
		else{
			cout << "YYMM";
		}
	}
	else{
		if(a>12||a==0){
			cout << "MMYY";
		}
		else{
			cout << "AMBIGUOUS";
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
//    https://youtu.be/N3oCS85HvpY

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))

int main(){
    fast;
    ll t,n,m,i,j,k,temp,flag,ans=0;
    cin>>n;
    ll a[n+1][n+1];
    set<pair<ll,ll> >s;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cin>>a[i][j];
            s.insert({i,j});
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                if(j==i || k==i) continue;
                if(a[j][i]+a[i][k]<a[j][k]){
                    cout<<"-1";
                    return 0;
                }else if(a[j][i]+a[i][k]==a[j][k]){
                    auto it=s.lower_bound({j,k});
                    if(it!=s.end() && it->ff==j && it->ss==k)
                        s.erase(it);
                }
            }
        }
    }
    for(auto it=s.begin();it!=s.end();it++){
        i=it->first;
        j=it->second;
        ans+=a[i][j];
        //cout<<i<<" "<<j<<" "<<a[i][j]<<endl;
    }
    cout<<ans/2;
    return 0;
}



Measured memory_bytes: 7292
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
typedef long long LL;
int main()
{
 //LL a[10]={0};
 map<LL,LL>a;
 LL n;
 cin>>n;
 if(n==2||n==4||n==1)
 {
 	printf("4");
 	return 0;
 }
 LL count=1;
  while(a[4]!=2)
  {  count++;
  	 if(n%2==0)
  	   n/=2;
  	   else
  	   n=n*3+1;
  	   a[n]++;
  }
 printf("%d",count);
}



Measured memory_bytes: 256
import sys
eps = sys.float_info.epsilon


def main():
    W, H, x, y = map(float, input().split())
    print(" ".join([str(W * H / 2), "1" if abs(W / 2 - x)
                    < eps and abs(H / 2 - y) < eps else "0"]))
    return


main()


Measured memory_bytes: 2940
import time
import random


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c
        self.answer = [0] * self.D
        self.best_answer = [0] * self.D
        self.best_score = 0
        self.days = [0] * self.D
        self.best_answer_scores = [0] * self.D

    def scoring(self, day, ind):
        day_score = self.s[day][ind]
        minus_score = 0
        for i in range(26):
            if i != ind:
                minus_score += self.c[i] * (day + 1 - self.last_days[i])
        day_score -= minus_score
        return day_score

    def get_all_scores(self, day):
        """全ての選択肢のscoreを返す"""
        minus_score = 0
        all_scores = [0] * 26
        for i in range(26):
            if i == 0:
                for j in range(1, 26):
                    minus_score += self.c[j] * (day + 1 - self.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

            else:
                minus_score += self.c[i - 1] * (day + 1 - self.last_days[i - 1])
                minus_score -= self.c[i] * (day + 1 - self.last_days[i])
                all_scores[i] = self.s[day][i] - minus_score
        return all_scores

    def _strategy_greedy(self, day):
        score = self.scoring(day, self.days[day])
        return score, self.days[day]

    def solve(self):
        self.init()

        sum_score = 0
        scores = []
        for i in range(self.D):
            score, ind = self._strategy_greedy(i)
            self.last_days[ind] = i + 1
            self.answer[i] = ind
            sum_score += score
            scores.append(sum_score)
        return sum_score, self.answer, scores

    def _strategy_perturbation(self):
        # ランダムに１日を取り出し、一番その日の期待コストが大きくなるよう変化させる
        # 貪欲法に摂動を加えてみる
        day = random.randint(0, 3)

        # scores = [self.scoring()]

        random.randint(0, 3)

    def solve_greed(self):
        self.init()

    def init(self):
        self.last_days = [0] * 26
        self.answer = [0] * self.D


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        s.append(list(map(int, input().split())))
    days = []
    for _ in range(D):
        days.append(int(input()) - 1)

    max_score = 0

    problem = Problem(D, s, c)
    problem.days = days
    score, answer,scores = problem.solve()

    for i in range(D):
        # problem.best_answer[i] += 1
        # print(problem.best_answer[i])
        print(scores[i])
    # print(ite)
    # print(max_answer)
    # print(max_score)
    # print(problem.get_all_scores(1))


main()


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

#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define i64 long long int
#define MEM(a,x) memset(a,x,sizeof(x))
#define INF 1000000000
#define mod 998244353

using namespace std ;

typedef pair<int,int> pi ;

#define maxn 1000005

i64 a[maxn] , c[maxn] ;
vector <i64> g[maxn] ;

void dfs( i64 u, i64 par )
{
    if( g[u].size()==1 )
    {
        c[u] = a[u] ;
        return ;
    }

    i64 i , j , v , mx = 0LL , sum = 0LL  ;

    for(i=0 ; i<g[u].size() ; i++)
    {
        v = g[u][i] ;
        if( v==par ) continue ;
        dfs(v,u) ;
        sum += c[v] ;
        mx = max(c[v],mx) ;
    }
    i64 x = sum - a[u] ;
    if( x<0 || x > min( a[u] , min( sum-mx , sum/2 ) ) )
    {
        printf("NO\n") ;
        exit(0) ;
    }
    c[u] = a[u] - x ;
}

int main()
{
    i64 i , j , k , l , m , n ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    for(i=1 ; i<n ; i++)
    {
        i64 u , v ;
        scanf("%lld %lld",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }

    if( n==2 )
    {
        if( a[1]==a[2] ) printf("YES\n") ;
        else printf("NO\n") ;
        return 0 ;
    }

    i64 id = 1;

    for(i=2 ; i<=n ; i++)
    {
        if( g[i].size() > g[id].size() ) id = i ;
    }

    dfs(id,0) ;

    if( c[id]==0 ) printf("YES\n") ;
    else printf("NO\n") ;

    return 0 ;
}


Measured memory_bytes: 38016
#include<cstdio>
#include<algorithm>
using namespace std;
int Gcd(int a,int b){
	int bri;
	while(b){
		bri=b;
		b=a%b;
		a=bri;
	}
	return a;
}
int map[100001],n,x,beg;
int main(){
	scanf("%d%d",&n,&x);bool flag=0;
	for(register int i=1;i<=n;i++){
		scanf("%d",&map[i]);
		if(map[i]==x)flag=1;
	}
	if(!flag){
		map[n+1]=x;
		n=n+1;
	}
	sort(map+1,map+1+n);
	if(n==2){
		printf("%d",map[2]-map[1]);return 0;
	}
	beg=Gcd(map[2]-map[1],map[3]-map[2]);
	for(int i=4;i<=n;i++){
		beg=Gcd(map[i]-map[i-1],beg);
	}
	printf("%d",beg);
	return 0;
}

Measured memory_bytes: 512
N = int(input())

name = []

def func(num):
    global name
    if num%26 == 0:
        name.insert(0, "z")
        if (num-26)//26 > 0:
            func((num-26)//26)
    else:
        name.insert(0, chr(96 + num%26))
        if num//26 > 0:
            func(num//26)

func(N)

print("".join(name))

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< int > a(n+1);
  for (int i=1; i<=n; ++i) cin >> a[i];
  vector< int > b(n+1, 0), c(n+1, 0);
  for (int i=n; i>0; --i) {
    if ((a[i]+c[i])%2==1) {
      b[i] = 1;
      for (int j=1; j*j<=i; ++j) {
        if (i%j==0) {
          c[j]++;
          if (i/j!=j) c[i/j]++;
        }
      }
    }
  }
  int cnt = 0;
  for (int i=1; i<=n; ++i) {
    if (b[i]==1) cnt++;
  }
  cout << cnt << endl;
  if (cnt==0) return 0;
  for (int i=1; i<=n; ++i) {
    if (b[i]==1) cout << i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int a[5],k;
  for(int i=0;i<5;++i)cin>>a[i];
  cin>>k;
  for(int i=0;i<5;++i){
    for(int j=i+1;j<5;++j){
      if(abs(a[i]-a[j])>k){cout<<":(\n";return 0;}
    }
  }
  cout<<"Yay!\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	ll a,b,v,w,t; cin >> a >> v >> b >> w >> t;

	ll dist = abs(a-b);

	if (dist + t*w > t*v) cout << "NO" << endl;
	else cout << "YES" << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int count_a = a % d > 0 ? a / d + 1 : a / d;
  int count_c = c % b > 0 ? c / b + 1 : c / b;
  string result = count_a < count_c ? "No" : "Yes";
  cout << result << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	string s;
	cin>>n>>s;
	for(i=0;i<s.length();i++)
		if(s[i]+n>'Z')
			s[i]=s[i]-26+n;
		else
			s[i]+=n;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 503;
int n, m, h, w, a[N][N], dp[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n >> m >> h >> w;
    if (n % h == 0 && m % w == 0) {
        cout << "No";
        return 0;
    }
    if (m % w) {
        dp[m] = 1;
        for (int i = w; i <= m; i += w) {
            dp[i] = dp[i - w] - 1;
        }
        for (int i = m - 1; i > 0; i--) {
            if (i % w && i + w <= m) {
                dp[i] = dp[i + w] + 1;
            }
        }
        for (int i = 1; i <= m; i++) {
            int x = dp[i] - dp[i - 1];
            for (int j = h; j <= n; j += h) {
                a[j][i] = x;
            }
        }
    }   else {
        dp[n] = 1;
        for (int i = h; i <= n; i += h) {
            dp[i] = dp[i - h] - 1;
        }
        for (int i = n - 1; i > 0; i--) {
            if (i % h && i + h <= n) {
                dp[i] = dp[i + h] + 1;
            }
        }
        for (int i = 1; i <= n; i++) {
            int x = dp[i] - dp[i - 1];
            for (int j = w; j <= m; j += w) {
                a[i][j] = x;
            }
        }
    }
    cout << "Yes\n";
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << a[i][j] << ' ';
        }
        cout << '\n';
    }
}


Measured memory_bytes: 2304
/* Author : Prasuk Jain */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int              long long int
#define ull              unsigned long long
#define ld               long double
#define fo(i, n)         for(int i=0; i<n; i++)
#define FOR(i, a, b)     for(int i=a; i<b; i++)
#define rfor(i, n)       for(int i=n-1; i>=0; i--)
#define RFOR(i, a, b)    for(int i=b-1; i>=a; i--)
#define tr(it, v)        for(auto it=a.begin(); it!=a.end(); it++)
#define vi               vector<int>
#define pii              pair<int,int>
#define mii              map<int,int>
#define pqb              priority_queue<int>
#define pqs              priority_queue<int,vi,greater<int>>
#define mp               make_pair
#define pb(x)            push_back(x)
#define hcf(x, y)        __gcd(x, y)
#define lcm(x, y)        boost::math::lcm(x,y)
#define setpre(x, y)     fixed << setprecision(y) << x
#define setbits(x)       __builtin_popcountll(x)
#define zerolead(x)      __builtin_clzll(x)
#define zerotrail(x)     __builtin_ctzll(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define PI               3.1415926535897932384626
const int mod = 1e9+7;
const int inf = 1e18;
int mpow(int base, int exp);
bool isprime(int num);
void prifact(int num);

//*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!//

void coderprasukj(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    //coderprasukj();
    int t, n, k, x, y;
    cin >> k >> x;
    if(500*k>=x) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

//*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!//

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
        if (exp & 1) result = ((int)result * base) % mod;
        base = ((int)base * base) % mod;
        exp >>= 1;
    }
  return result;
}

bool isprime(int num) {
    if(num <= 1) return false;
    for(int i=2; i*i <= num; i++)
        if(num%i == 0) return false;
    return true;
}

void prifact(int num){
    for(int i=2; i<=num; i++)
    if(num%i == 0){
        int cnt = 0;
        while(num%i == 0)
        cnt++ , num /= i;
        cout << i << "^" << cnt << " ";
    }
    if(num > 1)
    cout << num << "^" << "1" << " ";
}


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

long long int N, M, d, n, m;
string S, T;

int main(){
    cin >> N >> M >> S >> T;
    d = __gcd(N, M);
    n = N / d;
    m = M / d;
    for(int i = 0; i < d; ++i){
        if(S[i * n] != T[i * m])return 0 & puts("-1");
    }
    cout << n * m * d << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main() {
    long long n, Bnum, Rnum,ans;
    scanf("%ld %ld %ld", &n, &Bnum, &Rnum);
    ans = (n / (Bnum + Rnum)) * Bnum;
    if (n % (Bnum + Rnum) < Bnum) {
        ans += n % (Bnum + Rnum);
    }
    else {
        ans += Bnum;
    }
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N, M;
	cin >> N >> M;

	if (N == M) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 888
#include<stdio.h>

int main(int argc, char *argv[]){
    int A;
    int B;
    int C;
    int D;
    char buf[128];

    if(argc==1){
      
        fgets(buf, 127, stdin);
        sscanf(buf, "%d", &A);
    
        fgets(buf, 127, stdin);
        sscanf(buf, "%d", &B);

        fgets(buf, 127, stdin);
        sscanf(buf, "%d", &C);
        
        fgets(buf, 127, stdin);
        sscanf(buf, "%d", &D);
    }else if(argc==3){
        printf("A: %s\n", argv[1]);
        sscanf(argv[1], "%d", &A);
        printf("B: %s\n", argv[2]);
        sscanf(argv[2], "%d", &B);
        printf("C: %s\n", argv[1]);
        sscanf(argv[1], "%d", &C);
        printf("D: %s\n", argv[2]);
        sscanf(argv[2], "%d", &D);
    }

if(A<B){
    if(C<D){
         printf("%d\n",A+C);
    }else if(C>=D){
        printf("%d\n",A+D);
    }
}else if(A>=B){
    if(C<D){
         printf("%d\n",B+C);
    }else if(C>=D){
        printf("%d\n",B+D);
    }
}
    return 0;
}

Measured memory_bytes: 128
package main

import (
	f "fmt"
	"strings"
)

func main() {
	var s, t string
	f.Scan(&s, &t)
	arrS := strings.Split(s, "")
	arrT := strings.Split(t, "")
	ans := len(arrT)

	for j := 0; j <= len(arrS)-len(arrT); j++ {
		diff := 0
		for i := 0; i < len(arrT); i++ {
			if arrT[i] != arrS[j+i] {
				diff++
			}
		}
		if ans > diff {
			ans = diff
		}
	}
	f.Println(ans)
}


Measured memory_bytes: 1888
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

const int INF = 1001001001;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int n,k;
    cin >> n >> k;
  
    vector<int> h(n);
    rep(i,n) cin >> h[i];
  
    vector<int> dp(n,INF);
    dp[0] = 0;
    rep(i,n){
      if(i==0) continue;
      if(i<k){
        rep(j,i+1) dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]) );
      }
      if(i>=k){
        rep(j,k+1) dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]) );
      }
    }
	cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	for(int64 ii = 0;4 * ii <= nn;ii++)
	{
		if((nn - ii * 4) % 7 == 0)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3644
n  = int(input())
a  = [int(input()) for _ in range(n)]
dp = [0 for _ in range(n)]

for i in range(n):
    if i%2 == n%2:
        dp = [ dp[(l+1)%n] if a[l]>a[(l+i)%n] else dp[l] for l in range(n)]
    else:
        dp = [ max( a[l]+dp[(l+1)%n], a[(l+i)%n]+dp[l] ) for l in range(n)]

print(max(dp))

Measured memory_bytes: 6576