akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int main(void) {

	
	int number1,number2,number3,number;

	scanf("%d %d %d", &number1, &number2, &number3);

	number = number1 * 100 + number2 * 10 + number3;

	if (number % 4 == 0) {
		printf("YES\n");
	}

	else {
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long i64;
const int MOD = 1000000007;

int N, K, tot;
int divisor[100005];
i64 f[100005];

i64 fpm(i64 x, i64 y) {
  i64 res = 1;
  while (y) {
    if (y & 1) res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return res;
}

int main() {
  scanf("%d%d", &N, &K);
  
  for (int i = 1; i * i <= N; ++i)
    if (N % i == 0) {
      divisor[++tot] = i;
      if (N / i != i) divisor[++tot] = N / i;
    }

  sort(divisor + 1, divisor + tot + 1);
  
  for (int i = 1; i <= tot; ++i) {
    f[i] = fpm(K, (divisor[i] + 1) / 2);
    for (int j = 1; j < i; ++j)
      if (divisor[i] % divisor[j] == 0)
	f[i] = (f[i] - f[j]) % MOD;
  }

  i64 res = 0;

  for (int i = 1; i <= tot; ++i)
    if (divisor[i] & 1)
      res = (res + f[i] * divisor[i] % MOD) % MOD;
    else
      res = (res + f[i] * divisor[i] / 2 % MOD) % MOD;

  printf("%lld\n", (res + MOD) % MOD);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
                                                                                                
  
int main(){
                                                                     

    int k, i;

    vector<int> v(3);

    cin >> v.at(0) >> v.at(1) >> v.at(2) >> k;

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


    for( i = 1 ; i <= k ; i = i + 1 ){

        v.at(0) = v.at(0) * 2;

        }


    cout << v.at(0) + v.at(1) + v.at(2) << endl;


    return 0;

    }

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

int p[1130];
int p_size;

void sieve(){
	p[0] = 2;
	p_size = 1;
	for(int i = 3 ; i <= 1120 ; i += 2 ){
		bool flag = true;
		for(int j = 0 ; j < p_size ; j++ ){
			if( i < p[j] * p[j] ){
				break;
			}else if( i % p[j] == 0 ){
				flag = false;
				break;
			}
		}
		if( flag ){
			p[p_size++] = i;
		}
	}
}

int dp[1130][15][200];

int solve(int n, int k, int last = 0){
	if( n == 0 && k == 0 ){
		return 1;
	}else if( n == 0 || k == 0 ){
		return 0;
	}else if( dp[n][k][last] != -1 ){
		return dp[n][k][last];
	}
	
	int res = 0;
	for(int i = last ; i < p_size ; i++ ){
		if( n < p[i] ){
			break;
		}else{
			res += solve(n-p[i], k-1, i+1);
		}
	}
	return dp[n][k][last] = res;
}

int main(){
	int n, k;
	sieve();
	for(int i=0 ; i < 1130 ; i++ )
		for(int j=0 ; j < 15 ; j++ )
			for(int k=0 ; k < 200 ; k++ )
				dp[i][j][k] = -1;
	
	while( cin >> n >> k , n || k ){
		cout << solve(n, k) << endl;
	}
}

Measured memory_bytes: 14404
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int h, w, ch, cw;
  cin >> h >> w >> ch >> cw;
  P(h * w - (ch * w + cw * h - ch * cw));
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0) cout << s[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

vector<int> graph[100005];
vector<bool> used(100005);
vector<int> ans;
bool finished = false;

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

  unordered_map <int, int> mp;
  ll n, p; cin >> n >> p;

  if(n==1) {
    cout << p << endl;
    return 0;
  }

  ll now = p;
  for(ll i=2; i*i<=p; i++) {
    while (now%i == 0) {
      now/=i;
      mp[i]++;
    }
  }

  ll ans = 1;
  for(auto e: mp) {
    auto cnt = e.second/n;
    rep(i, cnt) {
      ans*=e.first;
    }
  }
  cout << ans << endl;
}

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

int main(int argc, char **argv)
{
    int a[105];
    int i, j;
    int N = 0, A = 0, B = 0;

    memset(a, 0, sizeof(a));
    while(scanf("%d%d%d", &N, &A, &B) != -1){
        if(abs(A - B + 1) % 2){
            printf("Alice\n");
        }
        else{
            printf("Borys\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
using System;

namespace abc111_a
{
	class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			for (int i = 0; i < 3; i++) Console.Write(s[i] == '1' ? 9 : 1);
			Console.WriteLine();
		}
	}
}


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

#define rep1(i, a, n) for (int i = a; i < n; i++)
#define rep2(i, a, n) for (int i = n; i >= a; i--)
#define asc(v) sort(v.begin(), v.end())
#define desc(v) sort(v.begin(), v.end(), greater<int>())

using namespace std;

int main() {
  long long N, A, B;
  long long ans;
  cin >> N >> A >> B;
  if (A > B || (A != B && N == 1)) {
    ans = 0;
  } else {
    long long min_s = B + (N - 1) * A;
    long long max_s = A + (N - 1) * B;
    ans = max_s - min_s + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
const int MAX_N=200001;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}

ll A,B,P;
// 1baseでs1,...,snの和を計算
class BIT{
private:
  ll bit[MAX_N];
  int n;
public:
  BIT(int sz){
    n=sz;
    memset(bit,0,sizeof(bit));
  }
  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      s%=P;
      i-=i&-i;
    }
    return s;
  }
  void add(int i,ll x){
    while(i<=n){
      bit[i]+=x;
      bit[i]%=P;
      i+=i&-i;
    }
  }
};

ll dp[MAX_N];
int main(){
  while(cin>>A>>B>>P&&(A|B|P)){
    memset(dp,0,sizeof(dp));
    vector<pair<string,ll> > v;
    for(ll i=A;i<=B;i++){
      stringstream ss;
      ss<<i;
      v.push_back(make_pair(ss.str(),i));
    }
    sort(v.begin(),v.end());
    BIT bit(B-A+1);
    // 辞書順で小さいものから順番に計算
    for(int i=0;i<v.size();i++){
      ll curNum=v[i].second;
      // 今回の数字以下のものの和を計算
      dp[i]=(bit.sum(curNum-A+1)+1)%P;
      bit.add(curNum-A+1,dp[i]);
    }
    ll res=0;
    for(int i=0;i<v.size();i++)
      res=(res+dp[i])%P;
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
n,m=map(int,input().split())
d=[[]for i in range(m+1)]
from heapq import heappush,heappop,heapify
q=[]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        d[-a-1].append(b)
ans=0
for i in d[::-1]:
    for j in i:
        heappush(q,-j)
    if q:
        ans+=-heappop(q)
print(ans)

Measured memory_bytes: 67232
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353
int dp[3005][3005];
 
int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int n=c-a+1;
	int m=d-b+1;
	dp[1][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i==1&&j==1) continue;
			else
			{
				dp[i][j]=(dp[i-1][j]*(j+b-1)+dp[i][j-1]*(i+a-1)-dp[i-1][j-1]*(j-1+b-1)%mod*(i-1+a-1)%mod+mod)%mod;
			}
		}
	}
	cout<<dp[n][m]<<"\n";
	return 0;
}

Measured memory_bytes: 73956
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

int eq(string a, string b) {
	int ok = 1;
	assert(a.size() == b.size());
	for (int i = 0; i < (int)a.size(); i++) {
		if (a[i] != '?' && b[i] != '?') ok &= (a[i] == b[i]);
	}
	return ok;
}

int eqc(char a, char b) {
	return (a == '?') || (b == '?') || (a == b);
}

int ok(string a, string b, int move) {
	int ans = 1;
	for (int j = 0; j + move < (int)a.size() && j < (int)b.size(); j++){
		ans &= eqc(a[j + move], b[j]);
	}
	return ans;
}

int proc(string a, string b, string c) {
	vector<int> c1(a.size());
	vector<int> c2(b.size());
	vector<int> c3(a.size());
	for (int i = 0; i < (int)a.size(); i++) {
		c1[i] = ok(a, b, i);
	}
	for (int i = 0; i < (int)b.size(); i++) {
		c2[i] = ok(b, c, i);
	}
	for (int i = 0; i < (int)a.size(); i++) {
		c3[i] = ok(a, c, i);
	}
	auto gc1 = [&](int mv) {
		if (mv >= (int)a.size()) {
			return 1;
		} else {
			return c1[mv];
		}
	};
	auto gc2 = [&](int mv) {
		if (mv >= (int)b.size()) {
			return 1;
		} else {
			return c2[mv];
		}
	};
	auto gc3 = [&](int mv) {
		if (mv >= (int)a.size()) {
			return 1;
		} else {
			return c3[mv];
		}
	};
	int n = (int)a.size() + (int)b.size() + (int)c.size();
	int ans = (int)a.size() + (int)b.size() + (int)c.size();
	for (int da = 0; da <= n; da++) {
		for (int dc = 0; dc <= n; dc++) {
			int cn = 1;
			cn &= gc1(da);
			cn &= gc2(dc);
			cn &= gc3(da + dc);
			if (cn) {
				ans = min(ans, da + max({(int)b.size(), dc + (int)c.size(), (int)a.size() - da}));
			} 
		}
	}
	return ans;
} 


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

	vector<string> a(3);
	for (auto &t : a) cin >> t;
	vector<int> ind(a.size());
	iota(ind.begin(), ind.end(), 0);
	int ans = (int)a[0].size() + (int)a[1].size() + (int)a[2].size();
	do {
		int v = proc(a[ind[0]], a[ind[1]], a[ind[2]]);
		ans = min(ans, v);
	} while (next_permutation(ind.begin(), ind.end()));
	cout << ans << endl;
}

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

int main()
{
    int x,n;
    cin>>x>>n;
    int arr[n];
    int present[105]={0};
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        present[arr[i]]=1;
    }
    int diff,ans;
    for(int i=x;;i--)
    {
        if(!present[i])
        {
            diff=x-i;
            ans=i;
            break;
        }
    }
    for(int i=x+1;;i++)
    {
        if(!present[i])
        {
            if((i-x) < diff)
                ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=1e5+10;
typedef pair<int,int>pii;

int main(){
    int n,k,s;
    scanf("%d%d%d",&n,&k,&s);
    for(int i=0;i<k;i++)printf("%d ",s);
    for(int i=k;i<n;i++)printf("%d ",s==1000000000?1:(s+1));
}

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

int main(){
  int N;
  cin >> N;
  int H[N];
  for(int i = 0; i < N; ++i){
    cin >> H[i];
  }
  
  int count = 0;
  int count_max = 0;
  int min = H[0];
  
  for(int i = 1; i < N; ++i){
    if(min >= H[i]){
      min = H[i];
      ++count;
    }
    else{
      count = 0;
      min = H[i];
    }
    if(count_max < count){
      count_max = count;
    }
  }
  
  cout << count_max << endl;
  
}


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

int main()
{
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }

  unordered_map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    m[v.at(i)]++;
  }

  long long res = 0;
  for (auto p : m) {
    res += p.second * (p.second - 1) / 2;
  }

  for (int i = 0; i < n; i++) {
    long long ak = v.at(i);
    cout << res - m[ak] * (m[ak]-1) / 2 + (m[ak]-1) * (m[ak]-2) / 2 << '\n';
  }

  return 0;
}


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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  
  int number = 0;
  
  number = x / (y+z);
  
  if(x % (y+z) < z)
    number--;
  
  cout << number << endl;
}

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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

using pint = pair<int,int>;
int main () {
    int N, M;
    cin >> N >> M;
    vector<set<int> > dame(N);
    UnionFind uf(N);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a, b);
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int mem = uf.size(i);
        ans = max(ans,mem);
    }
    cout << ans << endl;
}

Measured memory_bytes: 32236
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> G(n);
    vector<string> v(n);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x >> v[i];
        if(x){
            G[x-1].emplace_back(i);
            G[i].emplace_back(x-1);
        }
    }
    for (int i = 0; i < n; ++i) {
        reverse(G[i].begin(),G[i].end());
    }
    stack<int> s;
    vector<int> visited(n, 0), num(n);
    s.emplace(0);
    vector<int> dp(n);
    while(!s.empty()){
        int a = s.top(); s.pop();
        visited[a]++;
        cout << string(dp[a], '.') << v[a] << "\n";
        for (auto &&i : G[a]) {
            if(!visited[i]) {
                dp[i] = dp[a]+1;
                s.emplace(i);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3376
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

ans=1

for i in range(1,n+1):
    ans=mul(i,ans)
print(ans)

Measured memory_bytes: 63596
#include<stdio.h>
#include<iostream>
#include<stack>
#include<algorithm>
#define MAX 1400

using namespace std;

struct Rectangle { int height; int pos; };

int getLargestRectangle(int size, int buffer[]) {
  stack<Rectangle> S;
  int maxv = 0;
  buffer[size] = 0;

  for ( int i = 0; i <= size; i++ ) {
    Rectangle rect;
    rect.height = buffer[i];
    rect.pos = i;
    if ( S.empty() ) {
      S.push(rect);
    } else {
      if ( S.top().height < rect.height ) {
        S.push(rect);
      } else if ( S.top().height > rect.height ) {
        int target = i;
        while ( !S.empty() && S.top().height >= rect.height ) {
          Rectangle pre = S.top(); S.pop();
          int area = pre.height * (i - pre.pos);
          maxv = max(maxv, area);
          target = pre.pos;
        }
        rect.pos = target;
        S.push(rect);
      }
    }
  }
  return maxv;
}

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle() {
  for ( int j = 0; j < W; j++ )
    for ( int i = 0; i < H; i++ ) {
      if ( buffer[i][j] )
        T[i][j] = 0;
      else
        T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
    }

  int maxv = 0;
  for ( int i = 0; i < H; i++ )
    maxv = max(maxv, getLargestRectangle(W, T[i]));

  return maxv;
}

int main() {
  scanf("%d %d", &H, &W);
  for ( int i = 0; i < H; i++ )
    for ( int j = 0; j < W; j++ )
      scanf("%d", &buffer[i][j]);
  cout << getLargestRectangle() << endl;

  return 0;
}


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

int main(){

  int n, q, m[200], a[20],sum;
  cin >> n;
  rep(i,n) cin >> a[i];
  cin >> q;
  rep(i,q) cin >> m[i];
  rep(i,q){
    bool isCollect =false;
    for(ll j =0; j<= 1<<n; j++){
      sum = 0;
      ll bit = j;
      for(int k=0; k<n;k++){
        if(bit%2 ==1) sum += a[k];
        bit>>=1;
      }
      if(sum == m[i]) {
        isCollect=true;
        break;
      }
    }
  if(isCollect) cout << "yes" << endl;
  else cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 3100
import java.io.*;

public class Main{
  public static void main(String args[]) throws IOException {
    int b = 380000;
    double d=0;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int il=Integer.parseInt(in.readLine());
    for(int i=0;i<il;i++) {
      String[] s=in.readLine().split(" ");
      if(s[1].equals("JPY")) {
        d+=Integer.parseInt(s[0]);
      }
      else{
        d+=Double.parseDouble(s[0])*b;
      }
    }
    System.out.println(d);
  }
}

Measured memory_bytes: 21076
#include <iostream>

using namespace std;

int main() {
	while(true) {
		int a, b;
		char op;
		cin >> a >> op >> b;
		
		if(op == '?') {
			break;
		}
		switch(op) {
			case '+':
				cout << a+b << endl;
				break;
			case '-':
				cout << a-b << endl;
				break;
			case '*':
				cout << a*b << endl;
				break;
			case '/':
				cout << a/b << endl;
				break;
		}
	}

	return 0;
}


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

int main()
{
    int A, B, C, D, P;
    int X, Y;

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    cin >> P;

    X = A * P;
    if (P < C){
        Y = B;
    }
    else if(C < P){
        Y = ((P - C) * D) + B;
    }
    
    cout << min(X, Y) << endl;
    return (0);
}

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


int main()
{
  int k,s,c=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++)
    for(int j=0;j<=k;j++)
      if(s-i-j>=0&&s-i-j<=k)
        c++;
  cout<<c<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN=2020;
const int INF=1e9+10;
int a[MAXN];
int g[MAXN];

int N, x;
int lst(int x) {
	x--;
	if(x<0) return N-1;
	return x;
}

int main() {
	scanf("%d%d",&N,&x);
	for(int i=0;i<N;i++) scanf("%d",a+i);
	ll ans=1e18;
	fill(g, g+N, INF);
	for(int t=0;t<N;t++) {
		ll now=1ll*t*x;
		for(int i=0;i<N;i++) {
			int j=i-t;
			if(j<0) j+=N;
			g[i]=min(g[i], a[j]);
			now+=g[i];
		}
		ans=min(ans, now);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int x,y,i,j,n;
     deque<int >v;
     cin >> n;
     for(i = 0 ;i<n ;i++)
     {
         cin >> x;
         deque<int >:: iterator it;
         it = upper_bound(v.begin(),v.end(),x);
         if(v.begin()== it)
            v.push_front(x);
         else
            v[it -v.begin()]==x ;
     }
     cout<<v.size()<<endl;
 }


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t Kaijo(int n){
    int64_t v=1;
    _rep(i,n,1) {v*=i; v%=MOD;}
    return v;
}

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

    if(abs(N-M)>1) {cout<<0<<endl; return 0;}
    
    int64_t ans=1;
    ans*=Kaijo(N)%MOD;
    ans*=Kaijo(M)%MOD;
    ans%=MOD;

    if(N==M) {ans*=2; ans%=MOD;}

    cout<<ans<<endl;
}

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

int main(){
  string s;
  cin >> s;
  if(s[1] == s[2]){
    if(s[0] == s[1] || s[2] == s[3]){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


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


Measured memory_bytes: 2764
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(s: String) -> usize {
    s.chars().filter(|&c| c == '1').count()
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next()))
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

//mt19937 random(566);
//uniform_int_distribution<ll> distr;
//ll rnd(ll a, ll b) {return a + distr(random) % (b - a + 1);}

const int N = 2e5 + 1;
const ll MOD = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) cout << "Yes\n";
    else cout << "No\n";
    return 0;

}

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

int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N=in(), M=in();
	int V[111111]; for(int l=1; l<=N; ++l) V[l] = N+1;
	while(M--){
		int l=in(), r=in();
		V[l] = min(V[l], r);
	}
	int ans = 0, R = 0;
	for(int l=1; l<N; ++l){
		int r = V[l];
		if(r > N) continue;
		if(l >= R){
			ans++;
			R = r;
		}
		else if(r < R){
			R = r;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
  for (int d = 1; d <= N; d++){
    for (int i = 0; i <= N - d; i++){
      int j = i + d;
      if ((N - d) % 2 == 0){
        dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
      } else {
        dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
      }
    }
  }
  cout << dp[0][N] << endl;
}

Measured memory_bytes: 70784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String str;
		
		int n, sum = 0, count;
		while(!(str = reader.readLine()).equals("0")){
			n = Integer.valueOf(str);
			
			count = 0;
			for(int i = 1; i <= n ; i++){
				for(int j = i; j <= n ; j++){
					sum += j;
					if(sum == n && i != j){
						count++;
					}
					if(sum >= n){
						break;
					}
				}
				sum = 0;
			}
			System.out.println(count);
		}
		reader.close();
	}
}

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

namespace Test
{
    class AIZU
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            bool[,] card = new bool[4,13];

            for(int i = 0; i < n; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                card[MarkToNum(str[0]), int.Parse(str[1])-1] = true;
            }
            for(int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 13; j++)
                {
                    if (card[i, j] == false)
                    {
                        Console.WriteLine("{0} {1}", NumToMark(i), j + 1);
                    }
                }
            }
        }
        static int MarkToNum(string mark)
        {
            switch (mark)
            {
                case "S":
                    return 0;
                case "H":
                    return 1;
                case "C":
                    return 2;
                case "D":
                    return 3;
                default:
                    return -1;
            }
        }
        static string NumToMark(int num)
        {
            switch (num)
            {
                case 0:
                    return "S";
                case 1:
                    return "H";
                case 2:
                    return "C";
                case 3:
                    return "D";
                default:
                    return "";
            }
        }
    }
}



Measured memory_bytes: 17924
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
int a[60];
int n;
bool done[60];
bool F(int lim){
	lol(i,n)done[i]=false;
	int bef=-100;
	lol(i,n){
		if(a[i]-bef<lim)continue;
		bef=a[i];
		done[i]=true;
	}
	for(int i=n-1;i>=0;i--){
		if(done[i]==false){
			int x=24-a[i];
			if(x>24-lim)return false;
			if(x-bef<lim)return false;
			bef=x;
		}
	}
	return true;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	a[n]=0;
	n++;
	sort(a,a+n);
	int maxi=-1;
	for(int i=0;i<=12;i++){
		if(F(i)==true)maxi=i;
	}
	cout<<maxi<<endl;
	return 0;
}


Measured memory_bytes: 256
N = input()
mylist = []
for i in range(len(N)):
  mylist.append(N[i])
newlist = [int(s) for s in mylist]
divisor = 0
for j in range(len(newlist)):
  divisor += newlist[j]
N = int(N)
if N%divisor == 0:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
#include <stdio.h>

static int keta (int n)
{
  if (n<0)
    return keta(-n);
  
  int digits = 1;
  while (n /= 10)
    digits++;
  return digits;
}

int main(void)
{
  int n;
  int digits;
  int ans;
  
  scanf("%d",&n);
  digits = keta(n);
  
  switch(digits) {
    case 1: ans = n; break;
    case 2: ans = 9; break;
    case 3: ans = 9 + (n - 99); break;
    case 4: ans = 909; break;
    case 5: ans = 909 + (n - 9999); break;
    case 6: ans = 90909; break;
  }
  
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;

int h, w;
string s[2000];
int H, W;
bool isBlock[3999][3999];
int tate[3999][3999];

//ヒストグラムが覆う最大面積の長方形を求める. その長方形の高さがh, 幅がwのとき、(h + 1) / 2 * (w + 1) / 2を返す.
int maxArea(int height[], int n) {
	stack<int> ls, rs;
	int l[4000], r[4000];
	int i;
	
	//各iについて, i番目の棒を使う長方形(高さheight[i]の長方形)の, 左端(の番号)を求める.
	for (i = 0; i < n; i++) {
		while (!ls.empty() && height[ls.top()] >= height[i]) { ls.pop(); }
		if (ls.empty()) l[i] = 0;
		else l[i] = ls.top() + 1;
		ls.push(i);
	}
	
	//右端の番号も同様に
	for (i = n - 1; i >= 0; i--) {
		while (!rs.empty() && height[rs.top()] >= height[i]) { rs.pop(); }
		if (rs.empty()) r[i] = n - 1;
		else r[i] = rs.top() - 1;
		rs.push(i);
	}
	
	//あとは、高さをnパターン試す
	int ret = 0;
	for (i = 0; i < n; i++) {
		int width = (r[i] - l[i] + 1);
		int area = (width + 1) / 2 * (height[i] + 1) / 2;
		ret = max(ret, area);
	}
	return ret;
}

int main() {
	int i, j;
	
	cin >> h >> w;
	for (i = 0; i < h; i++) cin >> s[i];
	H = h * 2 - 1;
	W = w * 2 - 1;
	
	for (i = 0; i < h - 1; i++) {
		for (j = 0; j < w - 1; j++) {
			int cnt = (s[i][j] == '#') + (s[i + 1][j] == '#') + (s[i][j + 1] == '#') + (s[i + 1][j + 1] == '#');
			if (cnt % 2) {
				isBlock[2 * i + 1][2 * j + 1] = true;
			}
		}
	}
	
	for (j = 0; j < W; j++) {
		for (i = 0; i < H; i++) {
			if (isBlock[i][j]) { tate[i][j] = 0; }
			else if (i == 0) { tate[i][j] = 1; }
			else { tate[i][j] = tate[i - 1][j] + 1; }
		}
	}
	
	int ans = 0;
	for (i = 0; i < H; i++) {
		int area = maxArea(tate[i], W);
		ans = max(ans, area);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 82432
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
//    func enumerated() -> [(Int, Element)] {
//        return self.enumerate()
//    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (N, M) = (input[0], input[1])
var maxL = 1
var minR = N
for _ in 0..<M {
    let input = readIntSplit(by: " ")
    let (l, r) = (input[0], input[1])
    maxL = max(l, maxL)
    minR = min(r, minR)
}
print(max(minR-maxL+1, 0))


Measured memory_bytes: 7908
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <tgmath.h>
#define MOD 1000000007
using namespace std;
#define INT_MAX 2147000000
#define LONG_MAX 9223372036854775806

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

int main(){
    int a;
    int tmp = 0;
    cin >> a;
    for(int i=1;i<=9;i++)for(int j=1;j<=9;j++){
        if(a==i*j){
            tmp =1;
            break;
        }
    }
    if(tmp==1)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')

def main():
	n,m,k=MI()
	mod=998244353
	
	f=[1]
	for i in range(1,2*10**5+100):
		f.append((f[-1]*i)%mod)
	finv=[]
	for i in f:
		finv.append(pow(i,mod-2,mod))
	
	mp=[1]
	for i in range(1,2*10**5+100):
		mp.append((mp[-1]*(m-1))%mod)
		
	
	ans=0
	for kk in range(k+1):
		cnt=f[n-1]*finv[kk]*finv[n-1-kk]
		cnt%=mod
		cnt*=m*mp[n-kk-1]
		cnt%=mod
		ans+=cnt
	print(ans%mod)













if __name__=="__main__":
	main()


Measured memory_bytes: 113648
# include <iostream>
# include <vector>
# include <iomanip>
typedef long long ll;
using namespace std;

int main () {
    ll n, k;
    long double in;
    cin >> n >> k;
    vector <long double> exp;
    while (n--) {
        cin >> in;
        exp.push_back((in + 1) / 2);
    }

    // implement the sliding window
    long double sum(0);
    for (int i = 0; i < k; i++) {
        sum += exp[i];
    }
    long double maxSum(sum);
    for (int i = k; i < exp.size(); i++) {
        sum += exp[i] - exp[i - k];
        if (sum > maxSum) maxSum = sum;
    }
    cout << fixed << setprecision(12);
    cout << maxSum << "\n";
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int len = s.size();

    long long ans = 0;

    for (int i = 0; i < 1 << len - 1; i++)
    {
        bitset<9> bit(i);
        long long num = s[0] - '0';
        for (int j = 0; j < len - 1; j++)
        {
            if(bit[j])
            {
                ans += num;
                num = s[j + 1] - '0';
            }
            else
            {
                num *= 10;
                num += s[j + 1] - '0';
            }
        }
        ans += num;
    }
    
    cout << ans;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  vector<ll> b(n);
  
  rep(i, 0, n) {
    cin >> a[i];
    b[a[i]-1]++;
  }
  
  ll ans = 0;
  rep(i, 0, n)
    ans += b[i]*(b[i]-1)/2; 
  
  rep(i, 0, n) {
    if(b[a[i]-1] != 0) {
      ll answer = ans - b[a[i]-1]*(b[a[i]-1]-1)/2 + (b[a[i]-1]-1)*(b[a[i]-1]-2)/2;
      cout << answer << "\n";
    }
    else {
      ll answer = ans - b[a[i]-1]*(b[a[i]-1]-1)/2;
      cout << answer << "\n";
    }
  }

}


Measured memory_bytes: 5760
N, A, B = map(int,input().split())
ans = 0
C = 0

for n in range(1, N+1):
    n = str(n)
    for i in range(len(n)):
        C += int(n[i])
    if A <= C and C <= B:
        ans += int(n)
    C = 0

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x;
  cin >>n>>m>>x;
  vector<int> vec(m);
  int i;
  for(i=0;i<m;i++){
    cin >> vec.at(i);
  }
  int sum_1=0,sum_2=0;
  for(i=x+1;i<n;i++){
    for(int j=0;j<m;j++){
      if(vec.at(j)==i){
        sum_1++;
      }
    }
  }
  for(i=x-1;i>0;i--){
    for(int j=0;j<m;j++){
      if(vec.at(j)==i){
        sum_2++;
      }
    }
  }
  cout << min(sum_1,sum_2);
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  string S;
  cin >> S;
  int cost = 700;
  for(int i=0; i<3; ++i) if(S[i] == 'o') cost += 100;
  cout << cost << endl;
}

Measured memory_bytes: 256
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
     A, B = map(int, sys.stdin.readline().split())
     if (A + B) % 2 == 0:
          print(int((A + B) / 2))
     else:
          print("IMPOSSIBLE")


Measured memory_bytes: 5196
n=list(input())
n.reverse()
if n[0]=='3':
  print('bon')
elif n[0]=='0' or n[0]=='1' or n[0]=='6' or n[0]=='8':
  print('pon')
  
elif n[0]=='2' or n[0]=='4' or n[0]=='5' or n[0]=='7' or n[0]=='9':
  print('hon')

Measured memory_bytes: 9064
#include <iostream>

using namespace std;

// Function to trace the order of elements of array
void trace(int A[], int n)
{
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

// Function to do bubble sort
void bubbleSort(int A[], int n)
{
	int numberOfSwap = 0;
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				numberOfSwap++;
			}
		}
	}
	trace(A, n);
	cout << numberOfSwap << endl;
}

//Function to do insertion sort
void insertionSort(int A[], int n)
{
	int numberOfSwap = 0;
	for (int i = 0; i < n; i++) {
		int min = i;
		for (int j = i; j < n; j++) {
			if (A[j] < A[min]) {
				min = j;
			}
		}
		if (i != min) {
			int tmp = A[i];
			A[i] = A[min];
			A[min] = tmp;
			numberOfSwap++;
		}
	}

	// Print the result
	trace(A, n);
	cout << numberOfSwap << endl;
}

// MAIN FUCNTION
int main()
{
	int n;
	int A[100];
	int key;

	// Input data
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	insertionSort(A, n);

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define SZ(v)      ((int)(v).size())
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

/*繰り返し二乗法*/
template<typename T,typename U>
T ipow(T n,U k){//n^k. O(log K).
	if(k==0) return 1;
	T res=ipow(n*n,k/2);
	if(k&1) res*=n;
	return res;
}

int main(){//Refering other editorials.
	int n,m;
	cin>>n>>m;
	
	llong ans=(1800*m+100*n)*ipow(2,m);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3604
from collections import deque
n,m=map(int,input().split())
d=[set() for _ in range(n)]

for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  d[a].add(b)
  d[b].add(a)
dist=[-1]*n
dist[0]=0
prev=[-1]*n
queue=deque()
queue.append(0)

while queue:
  q=queue.popleft()
  for next in d[q]:
    if dist[next]!=-1:
      continue
    dist[next]=dist[q]+1
    prev[next]=q
    queue.append(next)

print('Yes')
for i in range(1,n):
  ans=prev[i]+1
  print(ans)


Measured memory_bytes: 118660
N,K=map(int,input().split())
p=list(map(int,input().split()))
a=sum(p[0:K])
k=[a]+[0]*(N-K)
for i in range(N-K):
    a=a-p[i]+p[K+i]
    k[i+1]=a
print((max(k)+K)/2)

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){

    bool flag=false;

    ll ans=0,sum=0;


    int n,m;
    cin >>n>>m;

    unordered_map<int,vector<pii>> city;
    vector<string> ids(m);
    string zero = "0";

    for (int i = 0; i < m; i++){
        int p,y;
        cin >>p>>y;
        city[p].emplace_back(y,i);
    }
    
    for(auto it:city){
        sort(it.second.begin(),it.second.end());

        //cout <<"pref "<<it.first<<"::";
        for (int i = 0; i < it.second.size(); i++){
            int y = it.second[i].first;
            int at = it.second[i].second;

            //cout <<"("<<y <<","<<at+1<<") ";

            string x = to_string(i+1);
            string pi = to_string(it.first);

            //cout << "city "<<at+1<<" is " <<i+1<<"th in pref:"<<it.first<< endl; 

            while(x.size() < 6)x = zero + x;
            while(pi.size() < 6)pi = zero + pi;

            
            ids[at] = pi+x;

        }
        //puts("");
    }



    /*for(auto it:city){
        for (int i = 0; i < it.second.size(); i++){

        }
    }*/

    for (int i = 0; i < m; i++){
        cout << ids[i] << endl;
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 15780
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

ll gcd(ll p,ll q){
    if(p>q)swap(p,q);
    if(p==0)return q;
    return gcd(q%p,p);
}

int main(){
    int X;
    cin>>X;
    cout<<(360/gcd(360,X))<<endl;
}


Measured memory_bytes: 3572
def solve():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, N):
        lst = []
        for k in range(1,i+1):
            if k > K:
                break
            lst.append(abs(h[i] - h[i-k]) + dp[i-k])
        
        lst.append(dp[i])
        dp[i] = min(*lst)
    
    print(dp[N-1])

if __name__ == '__main__':
    solve()


Measured memory_bytes: 55136