akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

namespace unweighted_graph_n {
template<class EDGE, class VERTEX>
struct Graph {
	using u32 = uint_fast32_t;
	using i32 = int_fast32_t;
	using u64 = uint_fast64_t;
	struct graph_tag {};
	const u32 n;
	vector<vector<EDGE>> e;
	vector<VERTEX> v;
	vector<u64> idx;
	Graph(u32 N) : n(N), e(n), v(n) {}
	template<class...  Args> void add_edge(u32 from, u32 to, Args... args) {
		idx.push_back((static_cast<u64>(from) << 32) | e[from].size());
		e[from].emplace_back(to, args...);
	}
	u32 size() const {return n;}
	using EDGE_TYPE = EDGE;
	using VERTEX_TYPE = VERTEX;
};
using u32 = uint_fast32_t;
struct Vertex {};
struct Edge {
	u32 to;
	Edge(u32 x) : to(x) {}
};
using UnWeightedGraph = Graph<Edge, Vertex>;
UnWeightedGraph make_unweighted_graph(u32 N) {
	return UnWeightedGraph(N);
}
}
using unweighted_graph_n::UnWeightedGraph;
using unweighted_graph_n::make_unweighted_graph;

using u32 = uint32_t;
template<class MC, class CU, class MA>
struct Rerooting {
	MC merge_child;
	CU child_unity;
	MA merge_all;
	vector<CU> dp, dp_reroot;
	Rerooting(MC mc, CU cu, MA ma) : merge_child(mc), child_unity(cu), merge_all(ma) {}
	template<class graph>
	void build(const graph& g, u32 root = 0) {
		dp.resize(g.size(), child_unity);
		dp_reroot.resize(g.size(), child_unity);

		auto dfs = [&](auto&& f, u32 v, u32 parent = -1) -> CU {
			for (auto& e : g.e[v]) {
				if (e.to == parent) continue;
				dp[v] = merge_child(dp[v], f(f, e.to, v));
			}
			return dp[v] = merge_all(dp[v], v);
		};
		dfs(dfs, root);
		auto dfs_reroot = [&](auto&& f, u32 v, CU parent_data, u32 parent = -1) -> void {
			vector<CU> left_accum(g.e[v].size()+1, child_unity);
			vector<CU> right_accum(g.e[v].size()+1, child_unity);
			{
				u32 i = 0;
				for (auto& e : g.e[v]) {
					i++;
					left_accum[i] = right_accum[i-1] = (e.to == parent ? parent_data : dp[e.to]);
				}
			}
			for (u32 i = 1; i < left_accum.size(); i++) left_accum[i] = merge_child(left_accum[i-1], left_accum[i]);
			for (u32 i = right_accum.size() - 1; 0 < i; i--) right_accum[i-1] = merge_child(right_accum[i-1], right_accum[i]);
			dp_reroot[v] = merge_all(left_accum.back(), v);
			{
				u32 i = 0;
				for (auto& e : g.e[v]) {
					i++;
					if (e.to == parent) continue;
					f(f, e.to, merge_all(merge_child(left_accum[i-1], right_accum[i]), v), v);
				}
			}
		};
		dfs_reroot(dfs_reroot, root, child_unity);
	}
};

template<class MC, class CU, class MA>
Rerooting<MC, CU, MA> make_rerooting(MC mc, CU cu, MA ma) {
	return Rerooting<MC, CU, MA>(mc, cu, ma);
}

using ll = long long;

int main() {
	int N, M; cin >> N >> M;
	auto rerooting = make_rerooting(
		[&](ll a, ll b) {return a * b % M;},
		1ll,
		[&](ll a, u32 b) -> ll {return (a+1) % M;}
	);
	auto g = make_unweighted_graph(N);
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b; a--; b--;
		g.add_edge(a, b);
		g.add_edge(b, a);
	}
	rerooting.build(g);
	for (int i = 0; i < N; i++) {
		cout << (rerooting.dp_reroot[i] + M - 1) % M << endl;
	}
}

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

int main()
{
	std::vector<char> S(4);
	for (auto& e: S) scanf(" %c", &e);
	std::sort(S.begin(), S.end());
	if (S[0] == S[1] && S[2] == S[3] && S[0] != S[3])
		puts("Yes");
	else
		puts("No"); 

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n, k;
	cin>>n>>k;
	vector<int> a(n);
	rep(i, n) cin>>a[i];
	sort(a.begin(), a.end());
	int g = a[0];
	rep(i, n) g = __gcd(g, a[i]);
	if(k>a[n-1] || k%g) cout<<"IMPOSSIBLE"<<endl;
	else cout<<"POSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
vector<vector<char> > A;
vector<bool> B;
vector<bool> C;
int main(){
    int H,W;
    cin >> H >> W;
    A.resize(H);
    B.resize(H);
    C.resize(W);
    rep(i,0,H){
        A[i].resize(W);
        rep(j,0,W){
            char temp;
            cin >> temp;
            A[i][j] = temp;
            if(temp == '#'){
                B[i]=true;
                C[j]=true;
            }
        }
    }    
  
    rep(i,0,H){
        rep(j,0,W){
            if(B[i]==true && C[j]==true) cout << A[i][j];
        }
        if(B[i]==true) cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
#define endl '\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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll K, A, B;
    while(cin >> K >> A >> B){
        ll ans = K + 1;
        K -= A - 1;
        ans = max(ans, A + (K / 2) * (B - A) + K % 2);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [int(_) for _ in input().split()]
q = int(input())
t = [int(_) for _ in input().split()]
dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1

c = 0
for i in t:
    if i in dic:
        c += 1
print(c)


Measured memory_bytes: 16896
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0; i <(n); i++)

int compint(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

int main(){
  int n;
  scanf("%d",&n);
  int s[100001][2];
  rep(i,n){
    rep(j,2){
      scanf("%d",&s[i][j]);
    }
  }
  long cnt=0;
  rep(k,n){
    cnt+=(s[k][1]-s[k][0])+1;
  }
  printf("%ld\n",cnt );
  return 0;
}


Measured memory_bytes: 1740
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	//input = input.split("\n");

  if(input.match("A") && input.match("B")){
    console.log("Yes");
  }else{
    console.log("No");
  }

}
//*この行以降は編集しない
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <stdio.h>
int main() {
  int N, M, a, b, c, i, j;
  int K[31];
  
  a = b = c = 0;
  
  scanf("%d", &N);
  scanf("%d", &M);
  
  for(i = 1; i < M + 1; ++i) {
    K[i] = 0;
  }
  
  for(i = 0; i < N; ++i) {
    scanf("%d", &a);
    for(j = 0; j < a; ++j) {
      scanf("%d", &b);
      ++K[b];
    }
  }
  
  for(i = 1; i < M + 1; ++i) {
    if(K[i] == N) {
      c += 1;
    }
  }
  
  printf("%d\n", c);
  
  return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  char a,b;cin>>a>>b;
  if(a==b)cout<<'H'<<endl;
  else cout<<'D'<<endl;


  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int X = reader.nextInt();
		int Y = reader.nextInt();
		int Z = reader.nextInt();
		X -= Z;
		int ans = X / (Y + Z);



		System.out.print(ans);
		reader.close();
	}
}





Measured memory_bytes: 24916
import java.util.*;
import java.util.Collections;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int cnt = 0;
    for (int i = 0; i < N - 2; i++) {
      if (S.charAt(i) == 'A' & S.charAt(i + 1) == 'B' & S.charAt(i + 2) == 'C') {
        cnt++;
      }
    }
    System.out.println(cnt);

  }

  public static void primeFactorization(int num) {
    int Z = 0;
    for (int i = 2; num > i; i++) {
      while (num % i == 0) {
        System.out.println(i);
        num /= i;
        Z = num;
      }
    }
    System.out.println(Z);
  }

  public static boolean isPrime(int num) {
    if (num < 2)
      return false;
    else if (num == 2)
      return true;
    else if (num % 2 == 0)
      return false;

    for (int i = 3; i < num; i += 2) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	int a;
	cin >> a;
	if(a%10 == 2 || a%10 == 4 || a%10 == 5 || a%10 == 7 || a%10 == 9)
	{
		cout << "hon";
	}
	else if(a%10 == 0 || a%10 == 1 || a%10 == 6 || a%10 == 8)
	{
		cout << "pon";
	}
	else
	{
		cout << "bon";
	}
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long x, y, a, b, c;
int main() {
    cin >> x >> y >> a >> b >> c;
    vector<long long> p(a, 0);
    for(int i = 0; i < a; ++i) cin >> p.at(i);
    vector<long long> q(b, 0);
    for(int i = 0; i < b; ++i) cin >> q.at(i);
    vector<long long> r(c, 0);
    for(int i = 0; i < c; ++i) cin >> r.at(i);

    sort(p.begin(), p.end(), greater<long long>());
    sort(q.begin(), q.end(), greater<long long>());
    sort(r.begin(), r.end());

    int pmin = x-1;
    int qmin = y-1;

    int pno = lower_bound(r.begin(), r.end(), p.at(pmin)) - r.begin();
    int qno = lower_bound(r.begin(), r.end(), q.at(qmin)) - r.begin();

    vector<long long> rpq;
    if(pno != c && qno != c) {
        for(int i = min(pno, qno); i < c; ++i) rpq.push_back(r.at(i));
    }else if(pno != c) {
        for(int i = pno; i < c; ++i) rpq.push_back(r.at(i));
    }else {
        for(int i = qno; i < c; ++i) rpq.push_back(r.at(i));
    }

    sort(rpq.begin(), rpq.end(), greater<long long>());
    vector<long long> psub;
    vector<long long> qsub;
    for(int i = 0; i <= pmin; ++i) psub.push_back(p.at(i));
    for(int i = 0; i <= qmin; ++i) qsub.push_back(q.at(i));

    /*for(int i = 0; i < psub.size(); ++i) {
        cout << p.at(i) << " ";
    }
    cout << endl;

    for(int i = 0; i < qsub.size(); ++i) {
        cout << q.at(i) << " ";
    }
    cout << endl;

    for(int i = 0; i < rpq.size(); ++i) {
        cout << rpq.at(i) << " "; 
    }
    cout << endl;*/

    int pnow = pmin;
    int qnow = qmin;
    for(int i = 0; i < rpq.size(); ++i) {
        if(rpq.at(i) <= psub.at(pnow) && rpq.at(i) <= qsub.at(qnow)) {
            break;
        }else {
            long long pch = rpq.at(i) - psub.at(pnow);
            long long qch = rpq.at(i) - qsub.at(qnow);
            if(pch > qch) {
                psub.at(pnow) = rpq.at(i);
                if(pnow != 0) pnow--;
            }else {
                qsub.at(qnow) = rpq.at(i);
                if(qnow != 0) qnow--;
            }
        }
    }

    long long sum = 0;
    for(int i = 0; i <= pmin; ++i) sum += psub.at(i);
    for(int i = 0; i <= qmin; ++i) sum += qsub.at(i);

    cout << sum << endl;
}

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

using namespace std;

char str[100];
int cnt['z' + 1];
int odd;
int main(void)
{
	cin >> str;
	for (int i = 0; str[i]; i++)
	{
		cnt[str[i]]++;
	}

	for (int i = 'a'; i <= 'z'; i++)
	{
		if (cnt[i] % 2)
		{
			odd = 1;
			break;
		}
	}

	if (odd) printf("No\n");
	else printf("Yes\n");

	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = str(input())

dp = [[0 for _ in range(N)] for _ in range(N)]
#dp[i][j]:= i 文字目からと j 文字目からとで一致する最長の長さ
#(この時点では文字列がかぶっても OK とする)

for i in range(N):
  for j in range(i+1,N):
    if S[i] != S[j]:
      dp[i][j] = 0
    else:
      if i == 0:
        dp[i][j] = 1
      else:
        dp[i][j] = dp[i-1][j-1]+1
ans = 0
for i in range(N):
  for j in range(N):
    temp = min(dp[i][j],j-i)
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 245768
#include<bits/stdc++.h>
#define int long long
#define ls (w*2)
#define rs (w*2+1)
#define mid ((l+r)/2)
using namespace std;
const int N=2e5+5;
const int p=998244353;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
int t[N*4],tag[N*4],ten[N];
void build(int w,int l,int r)
{
	tag[w]=0;
	if (l==r) return void(t[w]=((ten[r]-ten[l-1])%p+p)%p);
	build(ls,l,mid);
	build(rs,mid+1,r);
	t[w]=(t[ls]+t[rs])%p;
}
void update(int w,int l,int r,int x)
{
	t[w]=((ten[r]-ten[l-1])%p+p)%p*x%p;
	tag[w]=x;
}
void pushdown(int w,int l,int r)
{
	if (!tag[w]) return;
	update(ls,l,mid,tag[w]);
	update(rs,mid+1,r,tag[w]);
	tag[w]=0;
}
void change(int w,int l,int r,int L,int R,int x)
{
	if (r<L||R<l) return;
	if (L<=l&&r<=R) return update(w,l,r,x);
	pushdown(w,l,r);
	change(ls,l,mid,L,R,x);
	change(rs,mid+1,r,L,R,x);
	t[w]=(t[ls]+t[rs])%p;
}

signed main()
{
	int n=read(),m=read();
	ten[0]=0;
	ten[n]=1;
	for (int i=n-1;i>=1;i--) ten[i]=ten[i+1]*10ll%p;
	for (int i=1;i<=n;i++) ten[i]=(ten[i]+ten[i-1])%p;
	build(1,1,n);
	for (int i=1;i<=m;i++)
	{
		int l=read(),r=read(),x=read();
		change(1,1,n,l,r,x);
		print(t[1]);
	}

	return 0;
}

Measured memory_bytes: 13356
import sys
input = sys.stdin.readline
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
a = make_divisors(N)
b = make_divisors(N - 1)
s = set(a + b)
res = 0
for x in s:
  if x == 1: continue
  t = N + 0
  while t % x == 0: t //= x
  res += (t % x == 1)
print(res)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
vector<int> pl[200009];
int main(){
	int h,w,n,aom=1;
	cin>>h>>w>>n;
	for(int i=0;i<200008;i++){
		pl[i].pb(w+1);
	}
	for(int i=0;i<200008;i++){
		pl[h+1].pb(i);
	}
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		pl[x].pb(y);
	}
	for(int i=1;i<200008;i++){
		sort(pl[i].begin(),pl[i].end());
	}
	for(int i=1;i<200008;i++){
		if(pl[i+1][0]<=aom){
			cout<<i<<endl;
			return 0;
		}
		else{
			int fl = 0;
			for(int j=0;j<pl[i+1].size();j++){
				if(aom+1 == pl[i+1][j])fl = 1;
			}
			if(fl==0)aom++;
		}
	}
	return 0;
}

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

int main() {
    int A[3][3];
    int N;

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> A[i][j];
        }
    }

    cin >> N;
    int b;
    for (int k = 0; k < N; ++k) {
        cin >> b;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (b == A[i][j]) A[i][j] -= b;
            }
        }
    }

    if((A[0][0]+A[0][1]+A[0][2]==0)||(A[1][0]+A[1][1]+A[1][2]==0)||(A[2][0]+A[2][1]+A[2][2]==0)||(A[0][0]+A[1][0]+A[2][0]==0)||(A[0][1]+A[1][1]+A[2][1]==0)||(A[0][2]+A[1][2]+A[2][2]==0)||(A[0][0]+A[1][1]+A[2][2]==0)||(A[0][2]+A[1][1]+A[2][0]==0)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

static class CodeJam
{
    static long Solve(int N, long K, int[] A, int[] F)
    {
        Array.Sort(A, (a, b) => a.CompareTo(b));
        Array.Sort(F, (a, b) => b.CompareTo(a));
        Func<long, long> count = t =>
        {
            long k = 0;
            for (int i = 0; i < N; ++i)
            {
                long a = t / F[i];
                k += Math.Max(A[i] - a, 0);
            }
            return k;
        };
        if (count(0) <= K) { return 0; }
        long ng = 0;
        long ok = long.MaxValue;
        while (ok - ng >= 2)
        {
            long t = (ng + ok) / 2;
            if (count(t) <= K) { ok = t; } else { ng = t; }
        }
        return ok;
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        int N = (int)V[0];
        long K = V[1];
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var F = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(N, K, A, F));
    }
}


Measured memory_bytes: 47456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll res=0;
    string s,t;cin >> s>>t;
    rep(i,s.size()){
        if(s[i]!=t[i])res++;
    }
    cout << res <<endl;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long double a,b,h,m;
 cin>>a>>b>>h>>m;
 static const long double pi = 3.141592653589793238462643;
long double kaku=0.00000000000000;
long double rag=0.0000000000000;
long double ans;
 if (h*30+m/2>m*6)
 {
    kaku=h*30+m/2-m*6;
 }
 else
 {
      kaku=m*6-(h*30+m/2);
 }
if (kaku>180)
{
    kaku=360-kaku;
}
 
 
rag=kaku*pi/180.000000000000;
 ans=sqrt(a*a+b*b-2*a*b*cos(rag));
 cout<< std::setprecision(20)<<ans<<endl;
 
 
 
}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj));
typedef string str;

#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define print(a) cout << a << endl

int main(){
    int a;cin >> a;
    if(a==7||a==5||a==3){
        print("YES");
    }else{
        print("NO");
    }
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  def fib(a:Int, b: => Int, c:Int, n:Int):Int = {
    if (n ==  0)
      a
    else
      fib(a+b, a, b, n-1)
  }

  def main(args: Array[String]) = {
    val n = readInt()
    println(fib(1, 0, 0, n))
  }
}

Measured memory_bytes: 43872
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int dh[4] = {0, 1, 0, -1};
const int dw[4] = {1, 0, -1, 0};

int main() {
    int K, X;
    cin >> K >> X;
    cout << ((K*500 >= X) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 764
import math
num = input().split()
A = int(num[0])
B = int(num[1])
H = int(num[2])
M = int(num[3])
M1 = 6*M
H1 = 30*H + 30*M/60
c = min((360-(max(H1, M1)-min(H1, M1))), (max(H1, M1)-min(H1, M1)))
C = A**2 + B**2 - (2 * A * B * (math.cos(math.radians(c))))
print(math.sqrt(C))

Measured memory_bytes: 9520
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin>>n;
    string b=n;
    reverse(n.begin(),n.end());
    for(int i=0;i<n.size();++i)
    {
        if(n[i]=='b') n[i]='d';
        else if(n[i]=='d') n[i]='b';
        else if(n[i]=='p') n[i]='q';
        else if(n[i]=='q') n[i]='p';
    }
    if(n==b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 512
#include <stdio.h>

main() {
    int N, T;
    scanf("%d%d", &N, &T);
    int tmpN,tmpT,ansN=10000,ansT=0;

    for (int i = 0; i < N; ++i) {
        scanf("%d%d",&tmpN,&tmpT);
        if(tmpT<=T){
            if(tmpN<=ansN){
                ansN=tmpN;
            }
        }
    }

    if(ansN<=1000) printf("%d",ansN);
    else printf("TLE");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll l, r;
    cin >> l >> r;

    const ll MX = 1000000;
    vector<ll> pnum(MX+1, 0);
    vector<ll> v(MX+1);
    FOR(i, l, r+1) v[i-l] = i;
    vector<bool> isprime(MX+1, true);
    isprime[0] = isprime[1] = false;
    for(ll i=2; i<=MX; ++i) {
        if(isprime[i]) {
            for(int j=2*i; j<=MX; j+=i) isprime[j] = false;
            for(ll j=max(1LL, (l+i-1)/i)*i; j<=r; j+=i) {
                while(v[j-l]%i==0) pnum[j-l]++, v[j-l]/=i;
            }
        }
    }

    ll ret = 0;
    FOR(i, l, r+1) {
        ll cnt = pnum[i-l] + (v[i-l]>1);
        if(isprime[cnt]) ret++;
    }
    cout << ret << endl;

    return 0;
}


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

int main() {
    string s1,s2;
    int count=0,len;
    cin >> s1 >> s2;
    len = s1.length();
    for(int i=0;i<len;i++)
    {
        if(s1.at(i)!=s2.at(i))
            count++;
    }
    cout << count;
	return 0;
}


Measured memory_bytes: 3848
n,k=map(int,input().split())
r,s,p=map(int,input().split())
d={'r':p,'s':r,'p':s}
t=input()
ans=0
for i in range(k):
  a=t[i::k]
  flag=a[0]
  cnt=2
  for j in a[1:]:
    if j!=flag:
      ans+=d[flag]*(cnt//2)
      flag=j
      cnt=2
    else:cnt+=1
  ans+=d[flag]*(cnt//2)
print(ans)

Measured memory_bytes: 73540
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    ans = 1
    num = 10**9 + 7
    count = collections.Counter(s)

    for value in count.values():
        ans *= value+1
        ans %= num

    ans -= 1
    ans % num
    print(ans)
        
main()


Measured memory_bytes: 74776
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	int sum = 0;
	
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			for (int k = 0; k <= 9; k++) {
				for (int l = 0; l <= 9; l++) {
					int number = 0;
					number = i * 1000 + j * 100 + k * 10 + l * 1;
					if (number > n) goto FIN;//ループを抜ける

					int tmp = i + j + k + l;
					if ((a <= tmp) && (tmp <= b)) sum += number;
				}
			}
		}
	}
FIN:
	if (n == 10000) {
		if ((a <= 1) && (1 <= b)) sum += 10000;
	}
	printf("%d\n", sum);
	//while (1);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b) {
		for(int i=1;i<=b;i++) cout<<a;
	}
	else for(int i=1;i<=a;i++) cout<<b;
	cout<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct State{
    int y,x,d;
};

const int N = 1000;
const int INF = 19191919;

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

int d[N][N][4];
vector<int> dir[4];



int main(){
    int h,w,n;
    while(cin >>h >>w >>n,h){
        // initialize
        rep(i,N)rep(j,N)rep(k,4) d[i][j][k]=INF;
        rep(i,4) dir[i].clear();

        string c;
        cin >>c;
        vector<string> f(h);
        rep(i,h) cin >>f[i];

        int nd = 0;
        rep(i,n){
            dir[nd].pb(i);
            if(c[i]=='L') nd = (nd+3)%4;
            else nd = (nd+1)%4;
        }
        dir[nd].pb(n);
        rep(i,4) dir[i].pb(INF);

        int sy,sx,gy,gx;
        rep(i,h)rep(j,w){
            if(f[i][j]=='S'){
                sy = i;
                sx = j;
            }
            if(f[i][j]=='G'){
                gy = i;
                gx = j;
            }
        }

        auto IN = [&](int y, int x){ return 0<=y && y<h && 0<=x && x<w; };

        queue<State> que;
        que.push({sy,sx,0});
        d[sy][sx][0] = 0;
        while(!que.empty()){
            State now = que.front();
            que.pop();

            int D = d[now.y][now.x][now.d];

            // 今向いてる方に進む
            int ny = now.y+dy[now.d], nx = now.x+dx[now.d];
            if(IN(ny,nx) && f[ny][nx]!='#'){
                if(d[ny][nx][now.d] > D){
                    d[ny][nx][now.d] = D;
                    que.push({ny,nx,now.d});
                }
            }

            rep(i,4)if(i!=now.d){
                int dd = *lower_bound(all(dir[i]), D);
                if(d[now.y][now.x][i] > dd){
                    d[now.y][now.x][i] = dd;
                    que.push({now.y,now.x,i});
                }
            }
        }

        int ans = INF;
        rep(i,4) ans = min(ans, d[gy][gx][i]);
        cout << (ans<INF?"Yes":"No") << endl;
    }
    return 0;
}



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

ll n,k;

vector<ll> a(200005),f(200005);
ll score(ll s){
    ll tarinai=0;
    rp(i,n) tarinai += max(0ll,a.at(i)-s/f.at(i));
    return tarinai;
}
ll BinarySearch(){
    ll l=0; ll r=1e12;
    while(r-l>1){
        if(score((l+r)/2)>k) l=(l+r)/2;
        else r=(l+r)/2;
    }
    if(score(0)<=k) return 0;
    else return r;
}

int main(){
    cin >> n >> k;
    rp(i,n) cin >> a.at(i);
    rp(i,n) cin >> f.at(i);
    auto aite=a.begin();
    auto fite=f.begin();
    sort(aite,aite+n);
    reverse(aite,aite+n);
    sort(fite,fite+n);
    cout << BinarySearch() << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <numeric>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct frep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr frep(int l_, int r_): l(std::min(l_, r_)), r(r_) {}
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct brep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr brep(int l_, int r_): r(std::max(l_, r_) - 1), l(l_ - 1) {}
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

int main() {
  int H, N;
  std::cin >> H >> N;
  std::vector<int> A(N);
  for (int& x: A) {
    std::cin >> x;
  }
  std::cout << (std::accumulate(A.begin(), A.end(), 0) >= H ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
	int a[3],i,j,wk;
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(i=0;i<2;i++)	{
		for(j=i+1;j<3;j++)	{
			if(a[i]>a[j])	{
				wk=a[i];
				a[i]=a[j];
				a[j]=wk;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>

using namespace std;

int main()
{
    int a,b,x,n;
    cin>>a>>b>>x;
     n=b-a;
    if(a>x){
        cout<<"NO";
    }
    else if(a+b>=x){
            cout<<"YES";
    }
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
hp, atk = input().split()

hp = int(hp)
atk = int(atk)

value = 0

numlist = list((input().split()))

numlist = list(map(int, numlist))

for i in range(atk):
    value = value + numlist[i]

if value >= hp:
    print("Yes")
else:
    print("No")

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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

int main(void) {
	int N;
	cin >> N;
	vec<int> d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	sort(ALL(d));
	cout << d[N / 2] - d[N / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

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

	for (int i = 0; i < (int)n.size(); ++i) {
		if (n[i] == '1')
			n[i] = '9';
		else if (n[i] == '9')
			n[i] = '1';
	}

	cout << n << endl;
}



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

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int dt[3],ans;
    cin>>dt[0]>>dt[1]>>dt[2];
    sort(dt,dt+3);
    ans=abs(dt[1]-dt[0])+abs(dt[2]-dt[1]);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
A = [True for _ in range(N+1)]
for _ in range(M):
    A[int(input())] = False

dp = [1 for _ in range(N + 1)]
for i in range(1, N+1):
    if A[i] == True:
        if i - 2 >= 0:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD
        else:
            dp[i] = (dp[i - 1]) % MOD
    else:
        dp[i] = 0
print(dp[-1] % MOD)

Measured memory_bytes: 7832
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<string> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int a = 0;
	int b = 0;
	int ab = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j < A[i].size(); j++) {
			if (A[i][j - 1] == 'A' && A[i][j] == 'B') {
				res++;
			}
		}
		bool BB = false;
		bool AA = false;
		if (A[i][0] == 'B') {
			BB = true;
		}
		if (A[i].back() == 'A') {
			AA = true;
		}

		if (AA && BB) {
			ab++;
		}
		else if (AA) {
			a++;
		}
		else if (BB) {
			b++;
		}
	}
	while (a > 0 && ab > 0) {
		ab--;
		res++;
	}
	while (b > 0 && ab > 0) {
		ab--;
		res++;
	}
	while (a > 0 && b > 0) {
		a--;
		b--;
		res++;
	}
	while (ab > 1) {
		ab--;
		res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cassert>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int MAX = 502;

int H, W;
char G[MAX][MAX];

bool canGo(int si, int sj, int ti, int tj){
  int di = ti - si;
  int dj = tj - sj;
  if ( abs(di) > 0 ) di /= abs(di);
  if ( abs(dj) > 0 ) dj /= abs(dj);
  
  int pi = si + di;
  int pj = sj + dj;

  while(1){
    if ( G[pi][pj] != '.' ) return false;
    if ( pi == ti && pj == tj ) return true;
    pi += di;
    pj += dj;
  }
}

int solve(){
  vector<pair<int, int> > POS[26];
  bool removed[26];
  rep(i, 26) removed[i] = false;
  
  REP(i, 1, H+1) REP(j, 1, W+1){
    if ( G[i][j] != '.' ){
      char ch = G[i][j];
      POS[ch-'A'].push_back(make_pair(i, j));
    }
  }
  rep(i, 26) assert( POS[i].size() == 2 || POS[i].size() == 0 );

  int score = 0;
  bool isActivated;

  while(1){
    isActivated = false;
    rep(i, 26){
      if ( removed[i] ) continue;
      if ( POS[i].size() == 0 ) continue;
      int i1 = POS[i][0].first;
      int j1 = POS[i][0].second;
      int i2 = POS[i][1].first;
      int j2 = POS[i][1].second;

      bool suc = false;
      if ( i1 == i2 && j1 != j2 ){
	suc =  (canGo(i1, j1, i1, (j1+j2)/2) && canGo(i2, j2, i1, (j1+j2)/2));
      } else if ( i1 != i2 && j1 == j2 ){
	suc =  (canGo(i1, j1, (i1+i2)/2, j2) && canGo(i2, j2, (i1+i2)/2, j1));
      } else {
	suc = (canGo(i1, j1, i1, j2) && canGo(i2, j2, i1, j2) ||
	       canGo(i1, j1, i2, j1) && canGo(i2, j2, i2, j1) );
      }

      if ( suc ){
	G[i1][j1] = G[i2][j2] = '.';
	removed[i] = true;
	score += 2;
	isActivated = true;
      }
    }
    if ( !isActivated ) break;
  }

  return score;
}

main(){
  cin >> H >> W;
  rep(i, H+2) rep(j, W+2) G[i][j] = '#'; // sentinel
  rep(i, H) rep(j, W) cin >> G[i+1][j+1];
  cout << solve() << endl;
}

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

int main()
{
  int n, K;
  cin >> n >> K;
  int A[n];
  for(int i=0;i<n;++i)
  {
    cin >> A[i];
  }
  vector<int> dp(n, INT_MAX);
  dp[0] = A[0];
  dp[1] = abs(A[0] - A[1]);
  for(int i=2;i<n;++i)
  {
    for(int k=1;k<=K;++k)
    {
        if((i-k) == 0) dp[i] = min(dp[i], abs(A[i] - A[i-k]));
        if((i-k) > 0)
        dp[i] = min(dp[i], dp[i-k] + abs(A[i] - A[i-k]));
    }
  }
//   for(auto i: dp) cout << i << " ";
//   cout << endl;
  cout << dp[n-1] << endl;
  
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];

  vector<vector<ll> > s(n + 1, vector<ll>(n + 1));  // 区間ごとの総和を入れておく
  for (int i = 0; i + 1 <= n; i++) s[i][i + 1] = v[i];
  for (int w = 2; w <= n; w++)
    for (int i = 0; i + w <= n; i++)
      s[i][i + w] = s[i][i + 1] + s[i + 1][i + w];

  // dp[i][j] [i,j)を1つにまとめる時の最小コスト
  vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, INFL));
  // 初期化(幅0と1のコストは全て0)
  for (int i = 0; i <= n; i++) dp[i][i] = 0;
  for (int i = 0; i + 1 <= n; i++) dp[i][i + 1] = 0;

  // 区間DPする
  for (int w = 2; w <= n; w++)  // w…横幅
    for (int i = 0; i + w <= n; i++)
      for (int j = i + 1; j < i + w; j++)
        dp[i][i + w] = min(dp[i][i + w], dp[i][j] + dp[j][i + w] + s[i][i + w]);

  cout << dp[0][n] << endl;
}


Measured memory_bytes: 2816
import sys
import math
import numpy as np
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, d = na()
x = [[] for _ in range(n)]
for i in range(n):
    x[i] = na()
x = np.array(x)
c = 0
for i in range(n):
    for j in range(i+1, n):
        s = (np.sum((x[i] - x[j])**2))**0.5
        if s.is_integer():
            c += 1
print(c)

Measured memory_bytes: 21680
#数列に対しy/nの判定をする
def solve(balls):

  #B, Cの一番上の数(ただし常にB <= Cを保つ)
  last_b = last_c = 0

  while balls:
    new = balls.pop(0)
    
    #new <= last_b <= last_c  --> 不可能
    if new <= last_b:
      print("NO")
      return
    
    #last_b < new <= last_c   --> Bを更新
    elif new <= last_c:
      last_b = new
    
    #last_b < last_c < new    --> Cを更新
    else:
      last_c = new
  
  print("YES")
  return

def main():
  n = int(input())

  for _ in range(n):
    balls = list(map(int, input().split()))
    solve(balls)

main()


Measured memory_bytes: 5588
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int m,int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(m,n / 2);
	x *= x;
	if (n % 2 == 1)x *= m;
	return x;
}
ll max(ll a, ll b) {
	if (a < b)return b;
	else return a;
}

int main() {
	int a,b,c;
	cin >> a>>b>>c;
	rep(i, 1, 1000) {
		if ((a * i) % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const ll MOD = TEN(9) + 7;
const ll MAX_N = 100000;
ll n, m;
ll x[MAX_N];
ll y[MAX_N];

int main() {
    fastio();

    cin >> n >> m;
    forn(i, n) cin >> x[i];
    forn(i, m) cin >> y[i];

    ll a = 0, b = 0;
    forn(i, n - 1) {
        a = (a + 1LL * (i + 1) % MOD * (n - i - 1) % MOD * (x[i + 1] - x[i]) % MOD) % MOD;
    }

    forn(i, m - 1) {
        b = (b + 1LL * (i + 1) % MOD * (m - i - 1) % MOD * (y[i + 1] - y[i]) % MOD) % MOD;
    }

    cout << a * b % MOD << endl;

    return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n,m; cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  double sum=0;
  rep(i,n) sum+=a[i];
  sort(all(a));
  reverse(all(a));
  double border=sum/(4*m);
  bool f=1;
  rep(i,m){
    if(a[i]<border) f=0;
  }
  if(f) cout << "Yes" << endl;  
  else cout << "No" << endl;
}

Measured memory_bytes: 256
a,b,c,d,e,f=map(int,input().split())
maxsugar=f*e/(100+e)
maxwater=f*100/(100+e)
#print(maxsugar,maxwater)
sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)
#print(sugar)
water=[]
for i in range(int(maxwater//100+2)//min(a,b)+5):
    for j in range(int(maxwater//100+2)//min(a,b)+5):
        y=i*a+j*b
        water.append(y)
#print(water)
water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)

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

int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  char a=s[0];
  map<char,bool> check;
  
  for(char c:s){//for(変数宣言:範囲)
    if (check.count(c)) continue;
    else {
      int t = count(s.begin(),s.end(),c);//第3引数は探したい対象
      if (t % 2 != 0){
        cout << "No" << "\n";
        return 0;
      }
    }
  }
  cout << "Yes" << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)

{

   int i,j,a,b;

  

   while(scanf("%d %d",&a,&b)!=EOF&&a!=0&&b!=0){

   int kigusu=b%2;

   for(i=0;i<a/2;i++){

       for(j=0;j<b/2;j++)

       printf("#.");

       if(kigusu) putchar('#');

       puts("");

       for(j=0;j<b/2;j++)

       printf(".#");

       if(kigusu) putchar('.');

       puts("");

   }

   if(a%2){

       for(j=0;j<b/2;j++)

       printf("#.");

       if(kigusu) putchar('#');

       puts("");

   }

   puts("");

  }
   return 0;

}


Measured memory_bytes: 2100
#include<stdio.h>
int main(){
  int a,b,c,d,T,A;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(1){
   c=c-b;
    if(c<=0){
    puts("Yes");
      break;
    }
   a=a-d;
    if(a<=0){
    puts("No");
      break;
    }
  }
  return 0;
}

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

 long long int sum(long long int l,long long int r){
   return((l+r)*(r-l+1)/2);
 }

int main() {
  int N,K;
  cin >> N >> K;
  long long int ans;
  long long int r;
  long long int l;
  
  for(int i = K; i <= N+1; i++){
    l = sum(0,i-1); r = sum(N-i+1,N);
    ans += r-l+1;
  }
  ans %= 1000000007;
  cout << ans << endl;
}


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

using namespace std;

int dp[1001][1001], N, W, w[1001], v[1001];

void solve(){
	for(int i=N-1;i>=0;i--){
		for(int j=0;j<=W;j++){
			if(j<w[i]) dp[i][j] = dp[i+1][j];
			else dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]] + v[i]);
		}
	}
}

int main(){
	int q = 1, ans;
	string in;
	while(1){
		cin >> W;
		if(!W) break;
		cin >> N;
		for(int i=0;i<=N;i++){
			w[i]=0;
			v[i]=0;
			for(int j=0;j<=W;j++){
				dp[i][j] = 0;
			}
		}
		for(int i=0;i<N;i++){
			cin >> in;
			int flag=0;
			for(int j=0;j<in.size();j++){
				if(in[j]==',') flag++;
				else if(flag==1) w[i] = w[i]*10 + (in[j] - '0');
				else v[i] = v[i]*10 + (in[j] - '0');
			}
			//cout << w[i] << " " << v[i] << endl;
		}
		solve();
		for(int j=0;j<=W;j++){
			if(dp[0][j]==dp[0][W]){
				//cout << "hoge:" << j << endl;
				ans = j;
				break;
			}
		}
		cout << "Case " << q << ":" << endl;
		cout << dp[0][W] << endl << ans << endl;
		q++;
	}
}

Measured memory_bytes: 5124
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    string N;
    cin >> N;
    if (N[0] == '7' || N[1] == '7' || N[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3628