akhauriyash/Code-Regression huggingface dataset:
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define dbp(x) cout<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define dbv(v) {cout<<#v<<" : ";for (auto x:v) cout<<x<<' ';cout<<endl;}
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
#define die(x) return cout<<x<<'\n', 0;

using namespace std;

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

int32_t main()
{
fastio;

int testcases;
testcases=1;
//cin>>testcases;

while(testcases--)
{
	int x,n;
	cin>>x>>n;
	vector<int> p(n);
	set<int> st;
	rep(i,0,n-1)
		{
			cin>>p[i];
			st.insert(p[i]);
		}
	int ans;
	int mn=INT_MAX;
	rep(i,-1,101)
	{
		if(st.count(i))
			continue;
		int num=abs(i-x);
		if(num<mn)
		{
			mn=num;
			ans=i;
		}
	}
	cout<<ans<<'\n';
}

return 0;
}


Measured memory_bytes: 3580
N, Y = map(int, input().split())

Y //= 1000
a = b = c = -1

for i in range(N+1):
    for j in range(N+1):
        if (N-i-j) >= 0 and 9*i+4*j+N == Y:
            a = i
            b = j
            c = N-i-j
            break
    else:
        continue
    break

print(a, b, c)




Measured memory_bytes: 2940
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q, v, t;

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

  cin >> a >> v >> b >> w >> t;
  if (v <= w)
    Cout("NO");
  else {
    ll dis = abs(b - a);
    ll ikeru;
    ikeru = t * (v - w);
    if (ikeru >= dis)
      Cout("YES");
    else
      Cout("NO");
  }
  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(){
	int i;
	char str[21]={};
	scanf("%s", str);
	for(i=20;i>-1;i--)
	{
		if(str[i]!=0)
		{
			printf("%c", str[i]);
		}
	}
	printf("\n");
	return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int a, b, c, d;
  a = s[0] - '0';
  b = s[1] - '0';
  c = s[2] - '0';
  d = s[3] - '0';
  if (a + b + c + d == 7) {
    cout << a << '+' << b << '+' << c << '+' << d << "=7\n";
    return 0;
  }
  if (a + b + c - d == 7) {
    cout << a << '+' << b << '+' << c << '-' << d << "=7\n";
    return 0;
  }
  if (a + b - c + d == 7) {
    cout << a << '+' << b << '-' << c << '+' << d << "=7\n";
    return 0;
  }
  if (a + b - c - d == 7) {
    cout << a << '+' << b << '-' << c << '-' << d << "=7\n";
    return 0;
  }
  if (a - b + c + d == 7) {
    cout << a << '-' << b << '+' << c << '+' << d << "=7\n";
    return 0;
  }
  if (a - b + c - d == 7) {
    cout << a << '-' << b << '+' << c << '-' << d << "=7\n";
    return 0;
  }
  if (a - b - c + d == 7) {
    cout << a << '-' << b << '-' << c << '+' << d << "=7\n";
    return 0;
  }
  if (a - b - c - d == 7) {
    cout << a << '-' << b << '-' << c << '-' << d << "=7\n";
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;



int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n;
    ll p;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> p;
    ll d = 2, ans = 1;
    while(d * d <= p) {
        int cnt = 0;
        while(p % d == 0) {
            cnt++;
            p /= d;
        }
        if(cnt > 0) {
            for(int j = 0; j < cnt / n; j++) {
                ans *= d;
            }
        }
        d++;
    }
    if(p > 1 && n== 1) {
        ans *= p;
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
l=[]
l.append(s.count("a"))
l.append(s.count("b"))
l.append(s.count("c"))

if max(l)-min(l)<=1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using LL = long long;
const int N = 2005;

int d[N];
int main()
{
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	--x;
	--y;

	for (int j = 0; j < n; ++j)
		for (int i = 0; i < j; ++i)
			++d[min(j - i, abs(i - x) + 1 + abs(j - y))];

	for (int r = 1; r < n; ++r)
		cout << d[r] << endl;
	


	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  while (B > (A - 1) * ans + 1) ans++;
  cout << ans;
}


Measured memory_bytes: 3500
#include <iostream>

#include <cmath>


#define _USE_MATH_DEFINES


using namespace std;
const double pi = 3.14159265358979323846;

int main()
{


    int r;
    cin>>r;

    double area_big = pi*r*r;
    double area_small = pi*1*1;

    cout<<(area_big/area_small)<<endl;
    return 0;
}


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

#define int long long

int func(int);

int x;

signed main(){
	int a,b;
	cin >>a >>b >>x;

	cout <<func(b) - func(a-1) <<endl;
	return 0;
}


int func(int n){
	if(n>=0)
		return n/x + 1;
	else if(n == -1)
		return 0;
}

Measured memory_bytes: 256
// ABC069 B - i18n
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[101];
    scanf("%s", s);
    int slen = strlen(s);

    printf("%c%d%c\n", s[0], slen - 2, s[slen-1]);

    return 0;
}

Measured memory_bytes: 128
s = input()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
typedef pair<int,pair<int, int>> P1;

using Graph = vector<vector<int>>;

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

  int H;
  cin >> H;
  int pow2[100];
  pow2[0] = 1;
  for(int i=1;i<100;i++){
    pow2[i] = pow2[i-1] * 2;
  }
  int ans = 0;
  int i= 0;
  while(H > 0){
    ans += pow2[i];
    i++;
    H /= 2;
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1;i<=900;i++){
        if(a*i%b==c){
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;

int main() {FIN

	ll n, a, i, j, k, c = 0;
	cin >> n >> a;
	vll as(n);
	vvvll dp(n + 1, vvll(n * a + 1, vll(n + 1)));
	
	for (i = 0; i < n; i++)
		cin >> as[i];
	
	dp[0][0][0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = 0; j <= n*a; j++) {
			if (j >= as[i-1]) {
				for (k = 0; k <= i; k++) {
					dp[i][j][k] = dp[i-1][j][k];
					if (k > 0)
						dp[i][j][k] += dp[i-1][j - as[i-1]][k - 1];
				}
			} else
				dp[i][j] = dp[i-1][j];
		}
	}
	
	j = 1;
	for (i = a; i <= n * a; i += a)
		c += dp[n][i][j++];	
	
	cout << c << "\n";
	
	return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<bool> A(N + 1, false);
    int a;
    for (int i = 0; i < M; ++i) {
        cin >> a;
        A[a] = true;
    }

    vector<int> dp(N + 1, 0);
    dp[0] = 1;
    for (int i = 1; i <= N; ++i) {
        if (A[i]) {
            continue;
        }
        if (!A[i - 1]) {
            dp[i] = dp[i - 1];
        }
        if (i - 2 >= 0 && !A[i - 2]) {
            dp[i] = (dp[i] + dp[i - 2]) % 1000000007;
        }
    }
    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;

using std::cin;
using std::cout;

int L, limit, pw, point, E;
struct node { int x, y, l; };
std::vector < node > v;

inline void insert(int x, int y, int z) { v.push_back((node) {x, y, z}), ++E; }

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    cin >> L;
    for (limit = 1; limit <= L; limit <<= 1, ++point);
    /*
    if (limit == L) {
    	for (int i = 1; i <= point; ++i) insert(i, i + 1, 0), insert(i, i + 1, 1 << i - 1);
    	cout << point << ' ' << E << '\n';
		for (int i = 0; i < E; ++i) cout << v[i].x << ' ' << v[i].y << ' ' << v[i].l << '\n';
		return 0;
	} */
	for (int i = 1; i < point; ++i) insert(i, i + 1, 0), insert(i, i + 1, 1 << i - 1);
	for (int i = 1; i < point; ++i) if (L & (1 << i - 1)) L ^= (1 << i - 1), insert(i, point, L);
	cout << point << ' ' << E << '\n';
	for (int i = 0; i < E; ++i) cout << v[i].x << ' ' << v[i].y << ' ' << v[i].l << '\n';
}

Measured memory_bytes: 3620
//srt: 10:40
//end: 11:20
#include<cstdio>
#include<algorithm>
#include<functional>
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c!='-'&&(c<'0'||c>'9'));
	register bool f=c=='-'&&(c=getchar());
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
	f&&(r=-r);
}

const int N=200002,mod=1e9+7;
#define x first
#define v second
#define l second
#define r first
std::pair<int,int>a[N];
int dp[N],b[N],p[N];
int main()
{
	int i,j,n,c,m;read(n);
	for(i=0;i<n;i++)read(a[i].x),read(a[i].v),b[i]=a[i].v;
	std::sort(a,a+n);
	std::sort(b,b+n,std::greater<int>());
	m=std::unique(b,b+n)-b;

	for(i=n-1,c=0;i>=0;i--)
	{
		a[i].v=std::upper_bound(b,b+m,a[i].v,std::greater<int>())-b;
		a[i].v>c&&(c=a[i].v);
		a[i].r=c;
	}

	for(i=0,c=m+1;i<n;i++)
	{
		a[i].v<c&&(c=a[i].v);
		a[i].l=c;
	}

	std::sort(a,a+n);
	a[n].r=m+1;

	dp[0]=p[1]=1;
	for(i=1,j=0;i<=m;i++)
	{
		while(a[j].r==i)
		{
			(dp[i]<<=1)>=mod&&(dp[i]-=mod);
			dp[i]+=p[i]-p[a[j++].l-1];
			dp[i]>=mod&&(dp[i]-=mod);
			dp[i]<0&&(dp[i]+=mod);
		}
		(p[i+1]=dp[i]+p[i])>=mod&&(p[i+1]-=mod);
	}

	printf("%d\n",dp[m]);
}

Measured memory_bytes: 4096
K,N = map(int, input().split())
 
A=[]
 
A=list(map(int, input().split()))

D=[]

for i in range(N-1):
  D.append(int(A[i+1])-int(A[i]))
D.append(K-int(A[N-1])+int(A[0]))

Dmax=0
Sum=0
for i in range(N):
  if int(D[i])>Dmax:
    Dmax=int(D[i])
  Sum=Sum+int(D[i])   
  
print(Sum-Dmax)

Measured memory_bytes: 26444
n, k, q = map(int, input().split())
P = [0 for i in range(n)]
for j in range(q):
    ans = int(input())
    P[ans - 1] += 1
for l in range(n):
    if k - (q - P[l]) > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4620
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

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

//nを素因数分解し、vectorを返す
vector<int>
resolve_number(int n)
{
    vector<int> S;
    vector<int> so;
    //nが素数の場合
    if (is_prime(n))
    {
        so.push_back(n);
    }
    else
    {
        //nまでの素数を保存する
        for (int i = 2; i * i <= n; ++i)
        {
            if (is_prime(i))
                S.push_back(i);
            if (is_prime(n / i))
                S.push_back(n / i);
        }
        for (auto i : S)
        {
            while (n % i == 0)
            {
                so.push_back(i);
                n /= i;
            }
        }
    }
    return so;
}
int main(void)
{
    int N, counta, n = 0;
    cin >> N;
    for (int i = 1; i <= N; i = i + 2)
    {
        counta = 1;
        vector<int> vec = resolve_number(i);
        set<int> st;

        for (auto j : vec)
            st.insert(j);
        for (auto j : st)
        {
            counta *= (count(vec.begin(), vec.end(), j) + 1);
        }
        if (counta == 8)
            n++;
    }
    cout << n << "\n";
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a <= 9 && b <= 9) {
            System.out.println(a * b);
        } else {
            System.out.println(-1);
        }
	}
}


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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  string s[3];
  cin>>s[0]>>s[1]>>s[2];

  cout<<(char)(s[0][0] - ('a' - 'A'))<<(char)(s[1][0] - ('a' - 'A'))<<(char)(s[2][0] - ('a' - 'A'))<<endl;

  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

struct RollingHash{
  vll hash1, hash2;
  vll power1, power2;
  ll base1, base2;
  ll mod1, mod2;
  void Init(string s){
    ll n = s.size();
    hash1.assign(n+1, 0);
    hash2.assign(n+1, 0);
    power1.assign(n+1, 1);
    power2.assign(n+1, 1);
    base1 = 1007;
    base2 = 2009;
    mod1 = 1e9+7;
    mod2 = 1e9+9;

    REP(i, n){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      power1[i+1] = (power1[i]*base1)%mod1;
      power2[i+1] = (power2[i]*base2)%mod2;
    }
  }

  pll getHash(ll l, ll r){
    ll h1 = hash1[r]-hash1[l]*power1[r-l]%mod1;
    if(h1<0)
      h1 += mod1;
    ll h2 = hash2[r]-hash2[l]*power2[r-l]%mod2;
    if(h2<0)
      h2 += mod2;
    return {h1, h2};
  }
};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  string s[n+1], t[n+1];
  REP(i, n){
    cin >> s[i];
    REP(j, n)
      t[j] += s[i][j];
  }

  RollingHash rh_v[303], rh_h[303];
  pll RS2[303][303], RT2[303][303];
  REP(i, n){
    s[i] += s[i];
    t[i] += t[i];
    rh_h[i].Init(s[i]);
    rh_v[i].Init(t[i]);
    REP(j, n){
      RS2[i][j] = rh_h[i].getHash(j, n+j);
      RT2[i][j] = rh_v[i].getHash(j, n+j);
    }

  }




  ll ans = 0;
  REP(a, n){
    REP(b, n){
      bool flag = true;
      REP(k, n){
        if(RS2[(a+k)%n][b] != RT2[(b+k)%n][a])
          flag = false;
      }

      if(flag)
        ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
main (){
int x,y,z;
cin>>x>>y>>z;
if(x+y>=z){
cout<<y+z;}

else if(y>=z){
cout<<y+z;}

else if(x + y == z-1 || x + y == z){
    cout<<y+z;}

else if(y==z-1)
cout<<y+z;

else if(x+y<z-1)
cout<<x + 2 * y + 1;
else if ( x + y >= z){
    cout<<y+z;
}
}

Measured memory_bytes: 256
#include<stdio.h>
 
int gcd(int a,int b){
  if(a%b==0){
    return b;
  }else{
    int c = a%b;
    gcd(b,c);
  }
}
 
int main(void){
  int n,m,i,ans;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&m);
    ans=gcd(ans,m);
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n , m;
	
	while(cin >> n >> m , n ){
		int pos[151][10] ={0};
		int rate[151][10] = {0};
		int cnt[151] = {0};
		for(int i = 1 ; i <= n ;i++){
			int k; cin >> k;
			cnt[i] = k;
			rep(j,k){
				cin >> pos[i][j] >> rate[i][j];
			}
		}
		n++;
		
		int dp[152][10][80] = {0};
		rep(i,151)rep(j,10)rep(k,80)dp[i][j][k] = (1<<29);
		rep(j,10)rep(k,80)dp[0][j][k] = 0;
		rep(j,10)rate[0][j] = 0;
		cnt[0] = 1;
		
		for(int k = m ; k>=0 ; k--){
			for(int i = 1;i<n;i++){
				rep(prev,cnt[i-1]){
					rep(cur,cnt[i]){
						if(i-1){
							dp[i][cur][k] = min(
								dp[i][cur][k], 
								dp[i-1][prev][k] + (rate[i][cur]+rate[i-1][prev]) * abs( pos[i][cur] - pos[i-1][prev] )
							);
						}else{
							dp[i][cur][k] = 0;
						}
					}
				}
			}
			if(k){
				for(int i=2;i<n;i++){
					rep(prev,cnt[i-2]){
						rep(cur,cnt[i]){
							if(i-2){
								dp[i][cur][k-1] = min(
									dp[i][cur][k-1] , 
									dp[i-2][prev][k] + (rate[i][cur]+rate[i-2][prev]) * abs( pos[i][cur] - pos[i-2][prev] )
								);
							}else{
								dp[i][cur][k-1] = 0;
							}
						}
					}
				}
			}
		}
		
		int ret = (1<<29);
		rep(k,m+1){
			if(k)rep(i,cnt[n-2])ret = min(ret,dp[n-2][i][k]);
			rep(i,cnt[n-1])ret = min(ret,dp[n-1][i][k]);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1352
import sys
n, y = map(int, input().split())
 
flg = 0
 
for i in range(n+1):
    for j in range(n - i + 1):
        if y == 10000 * i + 5000 * j + 1000 * (n - i - j):
            print("{} {} {}".format(i, j, n - i - j))
            sys.exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string str;
    cin>>str;
    int sum=0;
    for(int i=0;i<str.size();i++)
    {
        sum+=(str[i]-'0');
        sum%=9;
    }
    if(sum==0)
    cout<<"Yes"<<'\n';
    else
    cout<<"No"<<'\n';
    
    
    
    
    
    return 0;
}

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

int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while(key != A[i])  i++;
    return i != n;
}

int main(){
    int A[10001], n, key, i, q, sum = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%d", &key);
        if(search(A, n, key))  sum++;
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), C(N-1);
    long long ans = 0;
    for( int  i = 0; i < N; i++ ) cin >> A[i];
    for( int  i = 0; i < N; i++ ) cin >> B[i];
    for( int  i = 0; i < N - 1; i++ ) cin >> C[i];

    for( int  i = 0; i < N; i++ ){
        ans += B[i];
        if( i != N-1 && A[i] == A[i+1] - 1 ){
            ans += C[A[i]-1];
        }
    }

    cout << ans << endl;
}

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

#define FOR(i,n) for (int i = 1 ; i <= n ; ++i)

char s[500005];
int nxt[500005][30] ;
int ST[500005][20] ;
int n;

void init () {
  n = strlen(s+1);
  for (int i = 0 ; i <= 'z' - 'a' ; ++i) nxt[n+1][i] = nxt[n+2][i] = n+1;
  for (int i = 0 ; i < 20 ; ++i) ST[n+1][i] = ST[n+2][i] = n + 1;
  for (int i = n ; i >= 1 ; --i) {
    nxt[i][s[i]-'a'] = i;
    for (int j = s[i] - 'a' + 1 ; j <= 'z' - 'a' ; ++j)
      nxt[i][j] = nxt[nxt[i][j-1]+1][j-1];
    ST[i][0] = nxt[i]['z'-'a'];
    for (int j = 1 ; j < 20 ; ++j)
      ST[i][j] = ST[ST[i][j-1]+1][j-1];
    for (int j = 0 ; j < s[i] - 'a' ; ++j)
      nxt[i][j] = nxt[ST[i][1]+1][j];
  }
}

int gao (int l , int r) {
  for (int i = 19 ; l < r && i >= 1 ; --i)
    if (ST[l][i] < r) l = ST[l][i] + 1;
    else if (ST[l][i] == r) return 0;
  return 1;
}

int main (void) {
  scanf("%s",s+1);

  init ();
  int q , l , r ; cin >> q;
  FOR(i,q) {
    scanf("%d%d",&l,&r);
    cout << ((gao(l,r)&1)?"No":"Yes") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 98816
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();

    let mut ans = 0;
    for i in 0..s.len() {
        if s.chars().nth(i) != s.chars().nth(s.len() - i - 1) {
            ans += 1;
        }
    }

    println!("{}", ans / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
VI an;
int cnt[SIZE];
int main(){
    LL N;
    cin>>N;
    int i=1;
    while((1LL<<i)-1<=N)i++;
    i--;
    int big=i;
    N-=(1LL<<i)-1;
    while(N){
        while(N>=(1LL<<i)){
            N-=(1LL<<i);
            cnt[i+1]++;
        }
        i--;
    }
    int now=big;
    for(int i=big;i>=1;i--){
        an.PB(i);
        while(cnt[i]--){
            an.PB(++now);
        }
    }
    reverse(ALL(an));
    REPP(i,1,now+1)an.PB(i);
    printf("%d\n",SZ(an));
    REP(i,SZ(an))printf("%d%c",an[i]," \n"[SZ(an)==i+1]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//string s;
	int n,m;
	cin>>m>>n;
	cout<<m*n<<endl;
	return 0;
}




Measured memory_bytes: 3644
import numpy as np


n = int(input())
r = np.array(list(map(int,input().split())))

pm = np.array([1,-1] * (n//2) + [1])


d = []
tmp = sum(r * pm)
d.append(str(tmp))
tmp -= r[0]

for i in range(n-1):
    tmp = r[i] - tmp
    d.append(str(tmp))
    tmp -= r[i+1]

print(' '.join(d))

Measured memory_bytes: 38440
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int num = 1;
    char groupColor = S[0];
    for (int i = 1; i < N; ++i)
    {
        char color = S[i];
        if (color != groupColor)
        {
            ++num;
            groupColor = color;
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, k,ans=1;
int main() {
	cin >> n >> k;
	rep(i, n) {
		ans = min(ans * 2, ans + k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>


#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)

using namespace std;

int main()
{
    string s;
    long k;
    cin >> s;
    cin >> k;
    if(s.length() < 2)
    {
      cout << k/2;      
      return 0;
    }
   else if(s.length() == 2)
   {
     if(s[0] == s[1])
     {
       cout << k;      
     }
     else
     {
       cout << 0;   
     }
     return 0;
   }
  
  char l,n;
  l = s[0];
  n = s[1];
  long topc=1;
  while(true)
  {
    if(l==n)
    {
      ++topc;
    }
    else
    {
      break;
    }
    
    if(s.length() <=topc)
    {
      cout << topc*k/2;
      return 0;
    }
    n=s[topc];
  }
    int botc =1; 
    l = s[s.length() -1];
    n = s[s.length() -2];
    while(true)
   {
     if(l==n)
     {
       ++botc;
     }
     else
     {
      break;
     }
      n = s[s.length() -1 -botc];
    }
    long botmc=0;
    if(s[0]==s[s.length() -1])
    {
      botmc = topc +botc;
    }
   else
   { 
     botmc =botc;
   }
  
    long count =1;
  
    l = s[topc];
    long midc =0;
    FOR(i,topc+1,s.length() -botc+1)
    {   
      n = s[i];
      if(l==n)
      {
        ++count;
      }
      else
      {
        midc += count /2;
        count =1;
        l = n;
      }
    }
      
    long ret =0;
      if(s[0]==s[s.length() -1])
    {
       ret += (topc/2);
    }
    else
    {
       ret += (topc/2)*k;
    }

    ret += (botmc/2)*(k-1);
    ret += midc*k;
    ret += botc/2;
  
    cout <<ret;
 	return 0;
}





Measured memory_bytes: 256
import math
A,B,H,M=map(int,input().split())
def clockangles(hour, minute):
    ans=abs((hour*30+minute*0.5)-(minute*6))
    return min(360-ans,ans)
degree=math.radians(clockangles(H,M))
print(math.sqrt(A**2+B**2-(2*A*B*math.cos(degree))))

Measured memory_bytes: 9580
num_list = [int(input()) for i in range(5)]
 
remains = []
divs = []
 
for num in num_list:
    remains.append(num % 10)
    divs.append(num // 10)
 
zeros = remains.count(0)
 
for i in range(remains.count(0)):
    remains.remove(0)
 
if len(remains) == 0:
    print(sum(divs) * 10)
else:
    print(sum(divs) * 10 + 40 - zeros * 10 + min(remains))

Measured memory_bytes: 3064
n = int(input())
an = [int(i) for i in input().split()]
an.sort()
ans = 0
for i in range(n-1):
  if an[i]*2 < an[i+1]:
    ans = 0
  else:
    ans += 1
  an[i+1] += an[i]
print(ans+1)

Measured memory_bytes: 14224
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int R, C;
int A[3001][3001];

llong DP[3002][3002][4];

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int K;
   cin >> R >> C >> K;

   REP(k, K) {
      int r, c, v;
      cin >> r >> c >> v;
      A[r][c] = v;
   }

   DP[1][1][0] = 0;
   if (A[1][1])
      DP[1][1][1] = A[1][1];

   FOR(r, 1, R) {
      FOR(c, 1, C) {
         if (r == 1 && c == 1) continue;
         // Do not take item
         if (r > 1) {
            FOR(n, 0, 3)
               DP[r][c][n] = max(DP[r][c][n], DP[r-1][c][n]);
         }
         if (c > 1) {
            FOR(n, 0, 3)
               DP[r][c][n] = max(DP[r][c][n], DP[r][c-1][n]);
         }
         if (A[r][c]) {
            // Take item
            if (r > 1) {
               FOR(n, 0, 3)
                  DP[r][c][1] = max(DP[r][c][1], DP[r-1][c][n] + A[r][c]);
            }
            if (c > 1) {
               FOR(n, 1, 3)
                  DP[r][c][n] = max(DP[r][c][n], DP[r][c-1][n-1] + A[r][c]);
            }
         }
      }
   }

   llong res = 0;
   FOR(n, 0, 3) {
      res = max(res, DP[R][C][n]);
   }

   cout << res << endl;

   return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    ll tmp = 1;
    rep(i, n) {
        if(a[i]%2 == 0) tmp *= 2;
    }
    cout << pow(3, n) - tmp << '\n';
    return 0;
}

Measured memory_bytes: 1020
from time import time
from random import randint

def func(s, x):
    last = [0] * 26
    score = 0
    for i, v in enumerate(x, 1):
        last[v] = i
        c = 0
        for j in range(26):
            c += s[j] * (i - last[j])
        score += s[i * 26 + v] - c
    return score

def main():
    start = time()
    d, *s = map(int, open(0).read().split())
    x = ([*range(26)] * 15)[:d]
    M = func(s, x)
    while time() - start < 1.3:
        y = x[:]
        if randint(0, 1):
            y[randint(0, d - 1)] = randint(0, 25)
        elif randint(0, 1):
            i=randint(0, d - 16)
            j=randint(i + 1, i + 15)
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y)
        if t > M:
            M = t
            x = y
    for t in x:
        print(t + 1)

main()

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

const ll INF = 1LL << 60;

const int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int N, K;
vector<ll> A;

int main() {
    cin >> N >> K;
    A.resize(N);
    rep(i, N) cin >> A[i];

    sort(A.rbegin(), A.rend());

    combination comb(1e5 + 10);
    mint ans = 0;

    // max の選び方
    for (int i = 0; i < N; i++) {
        if (i + K - 1 > N - 1) continue;
        // cout << comb(N - 1 - i, K - 1) << endl;
        mint tmp = A[i];
        ans += (tmp * comb(N - 1 - i, K - 1));
    }
    // cout << ans << endl;

    // min の選び方
    reverse(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        mint tmp = A[i];
        ans -= (tmp * comb(N - 1 - i, K - 1));
    }

    cout << ans << endl;
}

Measured memory_bytes: 5640
# coding:utf-8

N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
threshold = sum(A) / (4 * M)
A.sort(reverse=True)

for i in range(M):
    if A[i] < threshold:
        print('No')
        exit(0)
print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <iomanip>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main()
{
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(10);
    if (x * 2 == w && y * 2 == h)
        cout << 1.0 * w * h / 2 << ' ' << 1 << endl;
    else
        cout << 1.0 * w * h / 2 << ' ' << 0 << endl;
    return 0;
}


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

int main(){
    int x; cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n, k; cin >> n >> k;
  vector<long long> h(n); REP(i, n) cin >> h[i];
  sort(ALL(h));
  long long ans = LINF;
  REP(i, n-k+1) ans = min(ans, h[i+k-1] - h[i]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
n=int(input())
S=input()

def forward(s, n):
  A_id = ord('A')
  num_AtoZ = ord('Z') - ord('A') + 1
  return chr(A_id + (ord(s) - A_id + n) % (num_AtoZ))

print(''.join([forward(s, n) for s in S]))

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // in
            int N = Integer.parseInt(sc.next());
            int X = Integer.parseInt(sc.next());
            int T = Integer.parseInt(sc.next());

            // solve
            System.out.println(T * ((N / X) + ((N % X != 0) ? 1 : 0)));
        }
    }
}

Measured memory_bytes: 35536
#include <cstdio>

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  int s = 0;
  if (x <= 3) s += 4 - x;
  if (y <= 3) s += 4 - y;
  if (x == 1 && y == 1) s += 4;
  printf("%d\n", s * 100000);
  return 0;
}

Measured memory_bytes: 128
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto&& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    CIN(n,x);
    VC1(n,a);
    sort(ALL(a));
    int cnt = 0;
    REP(i,n){
        if(x>=a[i]){
            ++cnt;
            x-=a[i];
        }
    }
    if(x&&cnt==n)
        --cnt;
    COUT(cnt);

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

x1, y1, x2, y2 = Is()
print(x2-y2+y1, y2+x2-x1, x1+y1-y2, y1+x2-x1)

Measured memory_bytes: 66156
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, s.size()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int H, W, D; cin >> H >> W >> D;
	map<int, pair<int,int>> M;
	for(int h=1; h<=H; h++){
		for(int w=1; w<=W; w++){
			int a; cin >> a; a--;
			pair<int, int> p = make_pair(h, w);
			M[a] = p;
		}
	}

	vector<vector<int>> A(D), SA(D);
	for(int i=0; i<D; i++){
		A[i].push_back(0);
		for(int j=0; i+D*j < H*W; j++){
			int a = i + D*j;
			int b = i + D*(j+1);
			if(b >= H*W) b = i;
			auto p1 = M[a];
			auto p2 = M[b];
			A[i].push_back( abs(p1.first - p2.first) + abs(p1.second - p2.second) );
		}
		for(int k=0; k<A[i].size(); k++){
			int sa ;
			if(k == 0){
				sa = A[i][0];
			}
			else{
				sa = SA[i][k-1]+A[i][k];
			}
			SA[i].push_back(sa);
		}
	}

	int Q; cin >> Q;
	for(int i=0; i<Q; i++){
		int l, r; cin >> l >> r;
		l--; r--;
		int d = l%D;
		printf("%d\n", SA[d][r/D]-SA[d][l/D]);
	}
	return 0;
}


Measured memory_bytes: 18596
import collections
n = int(input())
h = list(map(int, input().split()))
result = collections.defaultdict(int)
pos = 0
for i in range(n-1):
    if h[i] >= h[i+1]: result[pos+1] += 1
    else: pos += 1
print(max(result.values()) if result else 0)

Measured memory_bytes: 14636
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   ll a,b,c,d;
   cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*d,b*c)));
    

    


	return 0;
}


Measured memory_bytes: 3636
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define repp(i,a,n)   for(int i=a;i<n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;

const int N = 1e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=min(a,k);
    k-=ans;
    k=max(0,k);
    int cnt=min(b,k);
    k-=cnt;
    k=max(0,k);
    k=min(c,k);
    cout<<ans-k<<nl;
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n, l; cin >> n >> l;
	vector<int> v(n);
	rep(i, n) {
		v[i] = l + (i + 1) - 1;
	}
	sort(v.begin(), v.end());

	int min_diff = 10000000;
	int idx = -1;
	int sum = 0;
	rep(i, n) {
		sum += v[i];
		int diff = abs(v[i]);
		if (min_diff > diff) {
			min_diff = diff; idx = i;
		}
	}
	assert(idx != -1);

	printf("%d\n", sum - v[idx]);
	return 0;
}


Measured memory_bytes: 256