akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
lst=list(map(int,input().split()))
ans=float("inf")
for i in range(n-k+1):
    left=lst[i]
    right=lst[i+k-1]
    if left==0 and right==0:
        print(0)
        exit()
    if left<0 and right<=0:
        ans=min(ans,abs(left))
    elif left<0 and right>0:
        if abs(left)>abs(right):
            ans=min(ans,abs(left)+right*2)
        else:
            ans=min(ans,abs(left)*2+right)
    else:
        ans=min(ans,right)
print(ans)

Measured memory_bytes: 85240
n,x=map(int,input().split())
l=list(map(int,input().split()))
ll=[0]*(n+2)
for i in range(n):
    ll[i+1]=ll[i]+l[i]
c=0
for i in range(n+1):
    if x<ll[i]:
        break
    c+=1
print(c)


Measured memory_bytes: 38384
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

#define N 10

int main(){
  int tc; //test case
  cin >> tc;

  while(tc-->0){
    //maximun 1024 pattern. try all

    int n[10];
    for(int i=0; i<N; i++){ scanf("%d", &n[i]); }

    int b, c; //tube
    bool ans = false;
    for(int i=0; i<(1<<N); i++){
      int bit=i; b=c=0;
      for(int j=0; j<N; j++){
	if(bit%2==0){ // to B
	  if(b < n[j]) b=n[j];
	  else break;
	} else { // to C
	  if(c < n[j]) c=n[j];
	  else break;
	}
	if(j==N-1){
	  ans=true;
	  goto OUT;
	}
	bit /= 2;
      }
    }

  OUT:
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

  }
}

Measured memory_bytes: 3052
#include<iostream>
using namespace std;
int main(){
long long n,s=1,ans=0;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++)
  {
     cin>>a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]==s){
      ans++;
      s++;
    }
  }
  if(ans==0) cout<<-1<<endl;
  else cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int a,b,c;cin>>a>>b>>c;
	cout<<max({a,b,c})-min({a,b,c})<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_103
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            for (int i = 0; i < s.Length; i++)
            {
                if (s.Equals(t))
                {
                    Console.WriteLine("Yes");
                    return;
                }
                string sub = s.Substring(0, s.Length - 1);
                s = s.Substring(s.Length - 1);
                s += sub;
            }
            Console.Write("No");
        }
    }
}


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < A.size(); i++)
	{
		cin >> A[i];
	}
	
	map<int, int> m;
	vector<int> SUM(N + 1);
	SUM[0] = 0;
	for (int i = 0; i < N; i++)
	{
		SUM[i + 1] = (SUM[i] + A[i]) % M;
	}

	long ans = 0;
	for (int i = 0; i < SUM.size(); i++)
	{
		ans += m[SUM[i]];
		m[SUM[i]]++;
	}

	cout << ans << endl;
}

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

int main() {
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	int ans = 1001001001;
	rep(i, n) {
		int last_a = 0, last_b = 0;
		if(i < n-1){
			last_a = a[i+1];
		} else {
			last_a = a[0]+k;
		}
		if(i >0){
			last_b = a[i-1];
		} else {
			last_b = a[n-1]-k;
		}
		
		ans = min( ans, k-abs(a[i]-last_a) );
		ans = min( ans, k-abs(a[i]-last_b) );
		
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>  
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define REP(i, a, op1, n, op2) for(int i=a; i op1 (int)(n); op2 ## op2 i)
#define cout(val) cout << (val) << endl

using namespace std;  

int main(){
    string s;
    cin >> s;
    int sum, result = 7;
    vector<int> num(3);
    num[0] = s[1] - '0';
    num[1] = s[2] - '0';
    num[2] = s[3] - '0';
    result -= s[0] - '0';

    rep(i, 1<<3){
        sum = 0;
        rep(j, 3){
            if(i&1<<j) sum += num[j];
            else sum -= num[j];
        }
        if(sum == result){
            cout << s[0] - '0';
            rep(j, 3){
                cout << (i&1<<j ? '+' : '-');
                cout << num[j];
            }
            cout("=7");
            return 0;
        }
    }
}


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

int main(void){
    int n, k;
    cin >> n >> k;
    
    int count = 0;
    long long i = 1;
    while(n >= i){
        i *= k;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
A=[a,b,c,d,e]
B=[]
C=[]
for i in range(5):
    if A[i]%10==0:
        B.append(10)
        C.append(A[i])
        
    else:
        B.append(A[i]%10)
        C.append((A[i]//10+1)*10)
j=B.index(min(B))
print(sum(C)-C[j]+A[j])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int n, m, a[100001], dp[100001];

const int mod = 1000000007;
int add(int a, int b) { return (a += b) < mod? a : a - mod; }
int sub(int a, int b) { return (a -= b) >=  0? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int& a, int b) { a = add(a, b); }
void subs(int& a, int b) { a = sub(a, b); }
void muls(int& a, int b) { a = mul(a, b); }
void maxs(int& a, int b) { a = max(a, b); }
void mins(int& a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(a, pwr(a, p - 1));
    return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }

int f(int k)
{
    if (k >= n) return k == n;
    if (a[k]) return 0;
    if (dp[k] != -1) return dp[k];
    return dp[k] = add(f(k + 1), f(k + 2));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int x;
        cin >> x;
        a[x] = 1;
    }
    memset(dp, -1, sizeof dp);
    cout << f(0);
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int bit[8]={1,2,4,8,16,32,64,128};
typedef struct{
	int b[125];
}B;

int c[256]={0};
void init(){
	for(int i=0;i<256;i++){
		for(int j=0;j<8;j++){
			if(i&bit[j])c[i]++;
		}
	}
}

void bitout(int num){
	for(int i=0;i<8;i++){
		cout<<(bit[i]&num?1:0);
	}
}

int main(){
	srand(time(NULL));
	init();
	int n,k;cin>>n>>k;
	B z;
	for(int i=0;i<125;i++)z.b[i]=0;
	vector<B>V(k);
	for(int i=0;i<k;i++){
		for(int j=0;j*2<n;j++){
			int t;cin>>t;
			t--;
			V[i].b[t/8]+=bit[t%8];
		}
	}
	while(true){
		B tmp;
		int flg=1;
		for(int i=0;i<n/8;i++){
			tmp.b[i]=rand()&255;
		}
		for(int i=0;i<k && flg;i++){
			int cnt=0;
			for(int j=0;j<n/8;j++){
				cnt+=c[tmp.b[j]&V[i].b[j]];
			}
			if(cnt<n/8 || 3*n/8<cnt)flg=0;
		}
		if(flg){
			for(int i=0;i<n/8;i++)bitout(tmp.b[i]);
			cout<<endl;
			break;
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 1324
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class point {
		double x;
		double y;

		point(double x, double y) {
			this.x = x;
			this.y = y;
		}

		point[] getP(point tar) {
			double nx = tar.x + x;
			double ny = tar.y + y;
			nx /= 2;
			ny /= 2;
			point np = new point(nx, ny);
			double v = np.d2(this);
			if (v > 1) {
				return null;
			}
			double dx = tar.y - y;
			double dy = x - tar.x;

			double len = dx * dx + dy * dy;
			len = Math.sqrt(len);

			dx /= len;
			dy /= len;

			point[] ret = new point[2];

			ret[0] = new point(np.x + dx * Math.sqrt(1 - v), np.y + dy
					* Math.sqrt(1 - v));
			ret[1] = new point(np.x - dx * Math.sqrt(1 - v), np.y - dy
					* Math.sqrt(1 - v));
			return ret;
		}

		double d2(point tar) {
			return (tar.x - x) * (tar.x - x) + (tar.y - y) * (tar.y - y);
		}
		boolean near(point tar){
			return d2(tar) < 1;
		}
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if(n==0){
				break;
			}
			point p[] = new point[n];

			
			for(int i= 0; i <n ;i++){
				p[i] = new point(sc.nextDouble(),sc.nextDouble());
			}
			
			int ans = 1;
			for(int i = 0; i < n; i ++){
				for(int j =i+1 ; j < n ; j++){
					point np[] = p[i].getP(p[j]);
					if(np == null){
						continue;
					}
					for(point c : np){
						int a = 2;
						for(int z = 0; z < n ; z++){
							if(z == i || z==j){
//								System.out.println(c.d2(p[z]));
								continue;
							}
							if(c.near(p[z])){
								a++;
							}
						}
						ans = Math.max(a,ans);
					}
				}
			}
			System.out.println(ans);
			
		}
	}

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

Measured memory_bytes: 13000
n = int(input())
li = list(map(int,input().split()))
lis = []
x = 0
y = 0
z = 0
for i in range(n):
    if li[i] % 4 == 0:
        x += 1
    elif li[i] % 2 == 0:
        y = 1
    else:
        z += 1
if y == 0:
    if x + 1 >= z:
        print("Yes")
    else:
        print("No")
else:
    if x >= z:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 20068
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> l(n), r(n);
  rep(i, n) cin >> l[i] >> r[i];

  sort(l.begin(), l.end(), greater<ll>());
  sort(r.begin(), r.end());
  rep(i, n - 1) l[i + 1] += l[i];
  rep(i, n - 1) r[i + 1] += r[i];
  ll ans = 0;
  rep(i, n / 2 + 1) {
    if (i != 0) chmax(ans, (l[i] - r[i - 1]) * 2);
    chmax(ans, (l[i] - r[i]) * 2);
    chmax(ans, (l[i] - r[i + 1]) * 2);
  }
  cout << ans << '\n';


  




  
  return 0;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
vector<int> vet;
int n;
int main(){
  cin >> n;
  vet.resize(n);
  for(int i=0;i<n;i++) {cin >> vet[i]; vet[i]--;}
 
  vector<int> ans;
  bool f = 1;
  while(f and vet.size()){
    f = 0;
    for(int i = vet.size()-1;i>=0;i--){
    	if(vet[i] == i){
        vet.erase(i+vet.begin());
        ans.push_back(i+1);
        f = 1;
        break;
      }
    }
  }
	if(vet.size())
    cout<<-1;
	else{
	    reverse(ans.begin(),ans.end());
	    for(auto it: ans)
	        cout<<it<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    VI a(3); cin >> a;
    SORT(a);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}


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

int gcd(int a,int b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
int main(){
  int n;cin>>n;
  int x_ini;cin>>x_ini;
  vector<int>x(n);
  int tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    x.at(i)=abs(x_ini-tmp);
  }
  int d=x.at(0);
  for(int i=1;i<n;i++){
    d=gcd(x.at(i),d);
  }
  cout <<d<<endl;
}

Measured memory_bytes: 3708
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    var ans = 1

    while (n > ans) {
        ans *= 2
    }

    println(if (ans > n) ans/2 else ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33528
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int fun(int x){
	if(x%2==0)return x/2;
	else return 3*x+1;
}
int vis[100000]={0};
int main(){
	ios;
	int s;cin>>s;
	int cnt=1;
	int b=s;
	vis[s]=1;
	while(1){
		cnt++;
		b=fun(b);
		if(vis[b])return cout<<cnt,0;
		vis[b]=1;
	}
}


Measured memory_bytes: 256
/** https://atcoder.jp/contests/dp/tasks/dp_l */
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int n;
long long a[3003], f[3003][3003], s[3003];
#define sum(l, r) (s[r] - s[l-1])

int main()
{
    cin >> n;
    for(int i = 1; i<= n; i++) cin >> a[i];

    for(int i = 0; i<= n; i++) for(int j = 0; j<= n; j++) f[i][j] = 0;

    s[0] = 0;
    for(int i = 1; i<= n; i++) f[i][i]= a[i], s[i] = s[i-1] + a[i];

    for(int l = n-1; l>0; l--)
    for(int r = l+1; r<=n; r++)
        f[l][r] = sum(l, r) - min(+ f[l+1][r], f[l][r-1] );

    cout << 2ll*f[1][n] - sum(1, n);

    return 0;
}



Measured memory_bytes: 70656
/*
    handle - pruvi007
    questionName - 
    Contest - 
    Topic - 
    Platform - 
*/
#include<bits/stdc++.h>
using namespace std;
#define ll          long long int
#define fast         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INF          1e18
#define MOD          1000000007
#define Vi           vector<ll> 
#define Vs           vector<string>
#define VI           vector<vector<ll> >
#define PII          pair<ll,ll> 
#define PSI          pair<string,ll>
#define PB           push_back


int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
int DX[] = {0,-1,-1,-1,0,1,1,1};
int DY[] = {-1,-1,0,1,1,1,0,-1};

int main()
{
    fast;
    int n,x,t;
    cin >> n >> x >> t;
    int q = ceil((double)n/(double)x);
    cout << t*q << '\n';
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    string s;
    cin >> s;
    cout << "2018" + s.substr(4) << endl;
}

int main() {
    resolve();
    
    return 0;
}

Measured memory_bytes: 764
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

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

int main()
{      
  fastio();
  //input();
  int n,k,i,j,t;
  cin>>k>>n;
  int a[n];
  for(i=0;i<n;i++)
  {
  	cin>>a[i];
  }
  int dis[n];
  ll tot=0;
  for(i=0;i<n;i++)
  {
  	if(i>0)
  		dis[i]=a[i]-a[i-1];
  	else
  		dis[i]=a[i]+(k-a[n-1]);
  	tot+=dis[i];
  }
  ll ans=inf;
  for(i=0;i<n;i++)
  {
  	ans=min(ans,tot-dis[i]);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>

using namespace std;

int n, m, dx[5] = { 0,1,0 }, dy[5] = { 0,0,1 };
char c[10][10];
bool vis[10][10] = { false };

void bfs()
{
	queue<pair<int, int> >Q;
	Q.push(make_pair(1, 1));
	vis[1][1] = true, c[1][1] = '.';
	while (!Q.empty())
	{
		int nowx = Q.front().first, nowy = Q.front().second, tmp = 0;
		for (int i = 1; i <= 2; i++)
		{
			int newx = nowx + dx[i], newy = nowy + dy[i];
			if (newx >= 1 && newy >= 1 && newx <= n && newy <= m && !vis[newx][newy] && c[newx][newy] == '#')
			{
				tmp++;
				Q.push(make_pair(newx, newy));
				vis[newx][newy] = true, c[newx][newy] = '.';
			}
			if (tmp == 2) return;
		}
		Q.pop();
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> c[i][j];
	bfs();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (c[i][j] == '#')
				return cout << "Impossible" << endl, 0;
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,A,B,C,D,x,y,X,Y;
	cin>>N>>A>>B>>C>>D;

		x=N/A;
		y=x*B;
		X=N/C;
		Y=X*D;

		if(N%A!=0){
			y=y+B;
		}
		if(N%C!=0){
			Y=Y+D;
		}
		if(y>Y){swap(y,Y);}

		cout<<y<<endl;

		return 0;
}


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main(){
  int X,Y,Z;
  cin >> X >> Y >> Z;
  int cnt=0;
  X-=Z;
  while(true){
    X-=(Y+Z);
    if(X<0)break;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

ll c[10][1005];

signed main() {
  init();
  ll h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  ll ans = INF;
  rep(div, 1 << (h - 1)) {
    ll g = 0;
    vll id(h);
    rep(i, h) {
      id[i] = g;
      if (div >> i & 1) ++g;
    }
    ++g;
    rep(i, g) rep(j, w) c[i][j] = 0;
    rep(i, h) rep(j, w) c[id[i]][j] += (s[i][j] - '0');

    ll num = g - 1;
    vll now(g);

    auto add = [&](ll j) {
      rep(i, g) now[i] += c[i][j];
      rep(i, g) if (now[i] > k) return false;
      return true;
    };

    rep(j, w) {
      if (!add(j)) {
        num++;
        now = vll(g);
        if (!add(j)) {
          num = INF;
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  ANS;
  return 0;
};

Measured memory_bytes: 3672
use std::io::*;
use std::str::FromStr;
use std::cmp::max;

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 n: usize = read();
    let W: usize = read();
    let mut w: Vec<usize> = (0..n).map(|_| 0).collect();
    let mut v: Vec<usize> = (0..n).map(|_| 0).collect();
    let m = n + 1;
    let w1 = W + 1;
    let mut dp: Vec<Vec<usize>> = (0..m).map(|_| (0..w1).map(|_| 0).collect()).collect();
    for i in 0..n {
        w[i] = read();
        v[i] = read();
    }

    for i in 0..n {
        for j in 0..w1 {
            dp[i + 1][j] = dp[i][j];
            if w[i] <= j {
                dp[i + 1][j] = std::cmp::max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    println!("{}", dp[n][W]);
}


Measured memory_bytes: 106748
#include <stdio.h>
#define N 100

int main(){
  int i = 0, j = 0, k = 0, n = 0;
  int key = 0;
  int A[N];

  scanf("%d\n",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  for(i = 1; i <= n; i++){
    
    for(k = 0; k < n; k++){
      printf("%d",A[k]);
      if(k == n-1){
	printf("\n");
      }
      else printf(" ");
    }
    
    key = A[i];
    j = i - 1;
    
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    
    A[j+1] = key;
  }
  
  return 0;
}



Measured memory_bytes: 2060
// AOJ DPL_2_C Bitonic Traveling Salesman Problem
// 2018.5.9 bal4u

#include <stdio.h>
#include <string.h>
#include <math.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') { c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF    1e12
#define MAX_N  1002

int N;
int x[MAX_N], y[MAX_N];
double d[MAX_N][MAX_N];

double dist(x1, y1, x2, y2) {
	int dx = x1-x2, dy = y1-y2;
	return sqrt(dx*dx + dy*dy);
}

double bitonic_tsp()
{
	int i, j, k, n1;
	double t, ans;

	for (j = 1; j < N; j++) {
		for (i = 0; i < j; i++) {
			if (i == 0 && j == 1) d[i][j] = dist(x[i], y[i], x[j], y[j]);
			else if (i < j - 1)
				d[i][j] = d[i][j-1] + dist(x[j-1], y[j-1], x[j], y[j]);
			else {
				d[i][j] = INF;
				for (k = 0; k < i; k++) {
					t = d[k][i] + dist(x[k], y[k], x[j], y[j]);
					if (t < d[i][j]) d[i][j] = t;
				}
			}
		}
	}

	ans = INF, n1 = N-1;
	for (i = N-2; i >= 0; i--) {
		t = d[i][n1] + dist(x[i], y[i], x[n1], y[n1]);
		if (t < ans) ans = t;
	}
	return ans;
}

int main()
{
	int i;

	N = in();
	for (i = 0; i < N; i++) x[i] = in(), y[i] = in();
	printf("%.10lf\n", bitonic_tsp());
	return 0;
}


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

int main(){
  string c = "War";
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  int x[N],y[M];
  for(int i=0;i<N;i++)
    cin >> x[i];
  for(int j=0;j<M;j++)
    cin >> y[j];
  sort(x,x+N);
  sort(y,y+M);
  for(int i=-100;i<101;i++){
 	 if(X<i&&i<=Y&&x[N-1]<i&&i<=y[0])
       c = "No War";
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL MOD = 1e9 + 7;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    LL n, k; cin >> n >> k;
    LL sum1 = 0, sum2 = 0, ans = 0;
    for (int i = 0 ; i < k - 1 ; i++)
        sum1 += i, sum1 %= MOD,
        sum2 += (n - i), sum2 %= MOD;
    for (int i = k - 1 ; i <= n ; i++) {
        sum1 += i, sum1 %= MOD;
        sum2 += (n - i), sum2 %= MOD;
        ans += (MOD + sum2 - sum1 + 1) % MOD;
        ans %= MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3648
import sys

n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    print(0)
    sys.exit(0)

x.sort()
d = [x[i+1] - x[i] for i in range(m-1)]
d.sort(reverse=True)
print(sum(d[n-1:]))


Measured memory_bytes: 13960
N, K = map(int, input().split())
V = list(map(int, input().split()))

MAX = 0
for k in range(1, K+1):
    for ka in range(k+1):
        for kb in range(k+1-ka):
            kcd = k - ka - kb
            
            if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
            s = V[:ka] + V[-kb:] if kb != 0 else V[:ka]
            s.sort()
            #print(s[kcd:], sum(s[kcd:]))
            MAX = max(MAX, sum(s[kcd:]))

print(MAX)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
int b[111];
int grid[111][111];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, c, i, j;
    cin>>n>>m>>c;
    for(j=1; j<=m; ++j){
        cin>>b[j];
    }
    for(i=1; i<=n; ++i){
        for(j=1; j<=m; ++j){
            cin>>grid[i][j];
        }
    }
    int ans = 0;
    for(i=1; i<=n; ++i){
        int cek  = 0;
        for(j=1; j<=m; ++j){
            cek += grid[i][j]*b[j];
        }
        cek += c;
        if(cek>0){
            ans++;
        }
    }cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;cin >> N;
    vector<int> vec(N);

    for(int i=1;i<N;i++){
        int K;
        cin >> K;
        vec.at(K-1) += 1;
    }
    for(int i=0;i<N;i++){
        cout <<  vec.at(i) << endl;
    }

 
}


Measured memory_bytes: 4064
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, k, q; cin >> n >> k >> q;
    vector<int> s(n);
    rep(i,q) {
        int a; cin >> a;
        a--;
        s[a]++;
    }
    rep(i,n) {
        if (q-s[i] >= k) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI a, b, n;
	cin >> a >> b >> n;

	if (b == 1)
	{
		cout << 0;
		return 0;
	}


	LLI x = _min(b - 1, n);

	cout << (a * x / b) - a * (x / b);
	return 0;
}

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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> v = {a,b,c};
    sort(v.begin(),v.end());
    if(v[2] == v[0] + v[1])
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import math
X=int(input())

def check_p(X,b):
	p = 0
	while b**(p+1) <= X:
		p+=1
	return b**p

ans=1
for b in range(2,int(math.sqrt(X))+1):
	ans = max(ans,check_p(X,b))

print(ans)

Measured memory_bytes: 8788
#include <stdio.h>

const int mod = 1000000007;
int N;
int M;
int a[100005];
int dp[100005];
int a_cur = 0;

int main()
{
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; ++i) scanf("%d", &a[i]);

	dp[0] = 1;

	for (int i = 1; i <= N; ++i)
	{
		if (i == a[a_cur])
		{
			a_cur++;
			continue;
		}
		if (i - 1 >= 0) dp[i] = (dp[i] + dp[i - 1]) % mod;
		if (i - 2 >= 0) dp[i] = (dp[i] + dp[i - 2]) % mod;
	}

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

	return 0;
}

Measured memory_bytes: 768
temp = list(map(int,input().split()))
n = temp[0]
a = temp[1]
b = temp[2]

if a >= b:
  big = a
  small = b
else:
  big = b
  small = a

if (big-small) % 2 ==0:
  print((big-small)//2)
else:
  if a+b <= n:
    if (big-small)<=2:
      print(small)
    else:
      print(small + (big-small)//2)
  else:
    if (big-small)<=2:
      print(n-big+1)
    else:
      print(n-big+1+(big-small)//2)


Measured memory_bytes: 3064
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug == false) {
            return;
        }
        System.out.println(str);
    }

    public static class Edge {
        int u;
        int v;
        int w;

        public Edge(int u, int v, int w) {
            this.u = u;
            this.v = v;
            this.w = w;

        }
    }

    public static void main(String[] args) {

        int N;
        HashMap<Integer,List<Edge>> set;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            set = new HashMap<>();
            for (int i = 0; i < N - 1; i++) {
                int u = sc.nextInt();
                int v = sc.nextInt();
                int w = sc.nextInt();
                Edge e = new Edge(u, v, w);
                setSet(set,e,u);
                setSet(set,e,v);
            }
        }
        int[] distans = new int[N];
        HashSet<Edge> visited = new HashSet<>();
        Deque<Integer> queue = new ArrayDeque<>();
        queue.push(1);
        distans[0] = 0;
        Integer target;
        while((target = queue.pollFirst()) != null){
            List<Edge> list = set.get(target);
            for(Edge e : list){
                if(visited.contains(e)){
                    continue;
                }else{
                    int d = (distans[target-1] + e.w) %2;
                    int i;
                    if(e.u != target ){
                        i = e.u;
                    }else{
                        i = e.v;
                    }
                    queue.addLast(i);
                    distans[i  -1] = d;
                    debug(i+":"+distans[i  -1]);
                    visited.add(e);
                }
            }
        }
        for(int i : distans){
            System.out.println(i%2);
        }
    }

    private static void setSet(HashMap<Integer,List<Edge>> set,Edge e, int i){
        List<Edge> list = set.get(i);
        if(list == null){
            list = new ArrayList<>();
        }
        list.add(e);
        set.put(i, list);
    }

}


Measured memory_bytes: 112992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e5+5;
int main()
{
    int a,b,t;
    scanf("%d%d%d",&a,&b,&t);
    printf("%d\n",t/a*b);
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void){
    int N;
    int A, B;
    int sum;
    cin >> N;
    if(N == 1)
        cout << "Hello World" << endl;
    else if(N == 2){
        cin >> A;
        cin >> B;
        sum = A + B;
        cout << sum << endl;
    }
    return 0;

}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,M;
    cin>>N>>M;
    
    int ans=1;
    for(int i=1;i*i<=M;i++){
        if(M%i)continue;
        if(i>=N)chmax(ans,M/i);
        if(M/i>=N)chmax(ans,i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n;
    cin >> n;
    vector<int> V(n);
    ll x = 0;
    for (auto &i : V) {
        cin >> i;
        x ^= i;
    }
    for (auto i : V)
        cout << (i ^ x) << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 3936
#include <cstdio>
#include <cctype>
using namespace std;
#ifdef ONLINE_JUDGE
char buf[1<<21],*p1=buf,*p2=buf;
#define mgetc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*(p1++))
#else
#define mgetc getchar()
#endif
void Read(int &x){
    static char c;
    while(!isdigit(c=mgetc));
    x=(c^48);
    while(isdigit(c=mgetc))
        x=x*10+(c^48);
    return;
}
void Print(int x){
    static int i;
    for(i=1;i*10LL<=x;i*=10);
    for(;i;i/=10)
        putchar(x/i%10|48);
    putchar(' ');
    return;
}
struct LnkNode{
    int v,nxt;
}edge[6000];
int etot=0,fst[3005]={};
inline void addedge(int u,int v){
    ++etot;
    edge[etot].v=v;
    edge[etot].nxt=fst[u];
    fst[u]=etot;
    return;
}
int n,a[3005];
bool dfs(int x,int f=0){
    for(int i=fst[x];i;i=edge[i].nxt)
        if(edge[i].v!=f)
            if(a[x]>a[edge[i].v] && !dfs(edge[i].v,x))
                return true;
    return false;
}
int main(){
    int x,y;
    Read(n);
    for(int i=1;i<=n;++i)
        Read(a[i]);
    for(int i=1;i<n;++i){
        Read(x),Read(y);
        addedge(x,y);
        addedge(y,x);
    }
    for(int i=1;i<=n;++i)
        if(dfs(i))
            Print(i);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    map<int,int> m;
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            m[i*j]++;
        }
    }
    if(m[n]==0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

int main() {
  char ch;
  char str[11];
  scanf("%s", str);
  ch = str[strlen(str)-1];
  scanf("%s", str);
  if(ch != str[0]) {
    printf("NO\n");
  } else {
    ch = str[strlen(str)-1];
    scanf("%s", str);
    if(ch != str[0]) {
      printf("NO\n");
    } else {
      printf("YES\n");
    }
  }
  return 0;
}


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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	multiset<int> L,R(a.begin(),a.end());
	L.insert(0);
	R.insert(0);
	rep(i,n){
		R.erase(R.find(a[i]));
		printf("%d\n",max(*L.rbegin(),*R.rbegin()));
		L.emplace(a[i]);
	}

	return 0;
}


Measured memory_bytes: 11776
#!/usr/bin/env python
# coding:utf-8
import os, sys
import math
from collections import defaultdict
n=input()
S=[]
c = defaultdict(lambda:1000000)
chars = set()
for _ in range(n):
    s=raw_input()
    chars |= set(s)

    co = defaultdict(int)
    for w in s:
        co[w]+=1
    S.append(co)

M = defaultdict(lambda:1000)
for c in chars:
    for s in S:
        M[c] = min(M[c], s[c])

w = ""
for k,v in M.iteritems():
    w += k*v
print "".join(sorted(w))







Measured memory_bytes: 2936
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  // the remainder of the three numbers should be the same
  // if k is odd: (0, 0, 0)
  // if k is even: (0, 0, 0) or (k/2, k/2, k/2)
  ll ans = 0;
  ll n, k;
  cin >> n >> k;
  ans += pow(n / k, 3);
  if(k % 2 == 0) {
    int num = n / k;
    if(n % k >= k / 2) num++;
    ans += pow(num, 3);
  }
  cout << ans << endl;
  return 0;
}



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


int main(){
   int N,A,B,C,D;
   cin>>N>>A>>B>>C>>D;
  
  if((N/A)*B <= (N/C)*D && N%A == 0 && N%C == 0 ) cout<<(N/A)*B<<endl;
  if((N/A+1)*B <= (N/C)*D && N%A > 0 && N%C == 0) cout<<(N/A+1)*B<<endl;
  if((N/A)*B >= (N/C+1)*D && N%C > 0 && N%A == 0 ) cout<<(N/C+1)*D<<endl;
  if((N/A+1)*B <= (N/C+1)*D && N%A > 0 && N%C > 0) cout<<(N/A+1)*B<<endl;
  if((N/A)*B > (N/C)*D && N%A == 0 && N%C == 0 ) cout<<(N/C)*D<<endl;
  if((N/A+1)*B > (N/C)*D && N%A > 0 && N%C == 0) cout<<(N/C)*D<<endl;
  if((N/A)*B < (N/C+1)*D && N%C > 0 && N%A == 0 ) cout<<(N/A)*B<<endl;
  if((N/A+1)*B > (N/C+1)*D && N%A > 0 && N%C > 0) cout<<(N/C+1)*D<<endl;

  return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
 
		int b = n % 500;
		System.out.println(b <= a ? "Yes" : "No");
	}
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i=0;i<N;i++) cin >> P[i];
    vector<int> mn(N);
    mn[0] = P[0];
    for (int i=0;i<N-1;i++) mn[i+1] = min(mn[i],P[i+1]);
    int count = 0;
    for (int i=0;i<N;i++) if (P[i]<=mn[i]) count++;
    cout << count << endl;  

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str1,first,last,mix;
    int n,h,a;
    while(true){
        cin >> str1;
        if(str1=="-")break;
        cin >> n;
        for(int i = 0;i<n;i++){
            cin >> h;
            first = str1.substr(0,h);
            last=str1.substr(h,a-h);
            mix=last+first;
            str1=mix;
        }
    cout << mix << endl;
    }return 0;
    
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int dekai=0;
    int cnt=0;
    rep(i,n){
        if(h[i]>dekai){
            cnt++;
            dekai = h[i];
        }
        else if(h[i] == dekai) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3616
n, k = map(int, input().split())
d = []
a = []
for _ in range(k):
    d.append(input())
    a.extend(list(map(int, input().split())))

a = set(a)
ans = 0

for i in range(1, n+1):
    if not i in a:
        ans += 1

print(ans)


Measured memory_bytes: 9184
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5+7;
vector<int> edges[N];
ll res = 0;
int n;
int main()
{
	scanf("%d",&n);
	
	for(int i = 1;i <= n;++i)	res += 1ll * i * (n - i + 1);
	for(int i = 1;i < n;++i)
	{
		int u,v;scanf("%d%d",&u,&v);
		if(u > v)	swap(u,v);
		res -= 1ll * u * (n - v + 1);
	}	
	printf("%lld",res);
    return 0;
}


Measured memory_bytes: 7940
#include <iostream>

using namespace std;
long A[31];
int main(){
  A[0] = 1;
  A[1] = 1;
  A[2] = 2;
  int n;
  while(cin>>n&&n>0){
    for(int i=3;i<=n;++i){
      A[i] = A[i-1]+A[i-2]+A[i-3];
    }
    cout<<A[n]/3650+1<<endl;
  }
  return 0;
}

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

bool solve() {
    string s;
    cin >> s;

    int n = s.size();

    vector<bool> dp(n + 1);
    dp[0] = true;

    for (int i = 0; i < n; i++) {
        if (!dp[i]) {
            continue;
        }
        if (i + 7 <= n && s.substr(i, 7) == "dreamer") {
            dp[i + 7] = true;
        }
        if (i + 5 <= n && s.substr(i, 5) == "dream") {
            dp[i + 5] = true;
        }
        if (i + 6 <= n && s.substr(i, 6) == "eraser") {
            dp[i + 6] = true;
        }
        if (i + 5 <= n && s.substr(i, 5) == "erase") {
            dp[i + 5] = true;
        }
    }

    return dp[n];
}

int main() {
    puts(solve() ? "YES" : "NO");
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	LL X;
	cin >> X;
	LL sum = 0;
	int i = 1;
	while (1) {
		sum += i;
		if (X <= sum) break;
		i++;
	}
	cout << i << endl;
}

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

typedef vector <int> vi;
typedef pair< int , int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	FIO;
	ll a, b;
	cin >> a >> b;
	cout << a*b << "\n";
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    int a[4]={0};
    for(int i;i<N;i++){
        string str;
        cin>>str;
        if(str=="AC"){a[0]++;}
        if(str=="WA"){a[1]++;}
        if(str=="TLE"){a[2]++;}
        if(str=="RE"){a[3]++;}
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a[0],a[1],a[2],a[3]);
    return 0;
}


Measured memory_bytes: 3724