akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=1e6+11,mod=1e9+7;
char s[N];
int cnt[N],ans=1,n;
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	rep(i,1,n)
		++cnt[s[i]-'a'];
	rep(i,0,25)
		ans=1ll*ans*(1+cnt[i])%mod;
	ans=(ans-1+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int a,p; cin >> a >> p;
    cout << (a*3+p)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
#define mod 1000000007
using namespace std;
int mpp[1000001]={0};
void Onigiri()
{
  int n;
  cin>>n;
  
  int a[n];
  rep(i,0,n)
  {cin>>a[i];mpp[a[i]]++;}
  
  int ans=0;
  rep(i,0,n)
  {
   int x=a[i];
   int ok=1;
   if(mpp[x]>1){continue;}
   if(x==1)
   {
      ans++;
      continue;
   }

   for(int j=1;j*j<=x;j++)
   {
      if(x%j==0)
      {
         if(mpp[j]>0)ok=0;
         if(x/j!=x&&mpp[x/j]>0)ok=0;
      }
   }
   if(ok)
      ans++;
  }
  cout<<ans;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("in", "r", stdin);freopen("out", "w", stdout);
   #endif  
 
   int t=1; 
   //cin>>t;
 
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}

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

void insertionSort(int A[],int N){
    int j,i,v;
    for (i=1 ; 1<=i && i<N ;i++){
        v = A[i];
        j = i - 1;
        while (j >=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
        for (int p=0; p<=N-1;p++){
            cout << A[p];
            if (p < N-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}

int main(){
    int N,i,j;
    int A[100];
    cin >> N;
    for (i=0;i<=N-1;i++){
        cin >> A[i];
    }
    for (int p=0; p<=N-1;p++){
        cout << A[p];
        if (p < N-1) {
        cout << " ";
        }
    }
    cout << endl;    
    insertionSort(A,N);
    return 0;
}


Measured memory_bytes: 3088
import sys
sys.setrecursionlimit(10**6)

def main(n):
	s = int(n*(n+1)/2)
	a = []
	b = []
	if s % 2 == 0:
		i = n
		ts = s/2
		while i != 0:
			if i <= ts:
				a += [min(i, ts)]
				ts -= min(i, ts)
			else:
				b += [i]
			i -= 1
		print(len(a)*len(b))
		for i in a:
			for j in b:
				print("{} {}".format(i, j))
	else:
		nn = (n if n % 2 == 1 else n+1)
		mm = int(n/2 if n % 2 == 0 else (n+1)/2)
		lst = [[]]*mm
		for i in range(n, 0, -1):
			flg = True
			for l in range(mm):
				if (sum(lst[l]) + i <= nn) and flg:
					lst = lst[:l] + [lst[l] + [i]] + lst[l+1:]
					flg = False
		m = 0
		for i in range(mm):
			m += len(lst[i%mm])*len(lst[(i+1)%mm])
		print(m)
		for i in range(mm):
			for l in lst[i]:
				for ll in lst[(i+1)%mm]:
					print("{} {}".format(l, ll))
		
		

main(int(input()))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const int maxN = 305;
const int64_t INF = 1e18;

int n, k;
int h[maxN], minIdx;

int64_t memo[maxN][maxN][maxN];

int64_t dp(int i, int rem, int idx) {
    if(i == n + 1)
        return 0;

    if(memo[i][rem][idx] != -1)
        return memo[i][rem][idx];

    int64_t ans = INF;

    int64_t cost = 0;

    if(h[idx] < h[i])
        cost = h[i] - h[idx];

    ans = min(ans, dp(i + 1, rem, i) + cost);

    if(rem - 1 >= 0) {
        ans = min(ans, dp(i + 1, rem - 1, idx));
    }

    return memo[i][rem][idx] = ans;
}

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

    cin >> n >> k;

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

    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            for(int k = 0; k <= n; k++)
                memo[i][j][k] = -1;

    cout << dp(1, k, 0) << '\n';

    return 0;
}


Measured memory_bytes: 220740
#define Bobyama
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N;

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

  cin >> N;

  cout << (N-2)*180 << endl;

  return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

const int INF = 0x7ffffff;
typedef long long ll;

inline void scan_d(int &ret)
{
    char c;
    ret = 0;
    while ((c = getchar()) < '0' || c > '9');
    while (c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0'), c = getchar();
    }
}

int a[111111];

int main(void)
{
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i) scan_d(a[i]);
    sort(a+1,a+1+n);
    ll r[2] = {0,0}, cnt = 0;
    ll ans;
    for(int i = n; i >= 1; --i){
        if(a[i]==a[i-1]) r[cnt++] = a[i], --i;
        if(cnt==2) break;
    }
  //  cout << r[0] << ' ' << r[1] << endl;
    ans = r[0] * r[1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
s = input()
p = input()

#??????????????????
if p in s:
    print("Yes")
#????????°??¶???????????????????????????
else:
    s_list = list(s)
    len_s = len(s)
    len_p = len(p)
    string = ''
    #s???????????¨?§???????p???????????°?????????????????????????????????
    string = string.join(s_list[(len_s - len_p):len_s] + s_list[0:len_p])
    #??????????????????
    if p in string:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 7468
def run(n, m, x, y, z):
    s1 = [x[i] + y[i] + z[i] for i in range(n)]
    s1.sort(reverse=True)
    s2 = [-x[i] + y[i] + z[i] for i in range(n)]
    s2.sort(reverse=True)
    s3 = [x[i] - y[i] + z[i] for i in range(n)]
    s3.sort(reverse=True)
    s4 = [-x[i] - y[i] + z[i] for i in range(n)]
    s4.sort(reverse=True)
    s5 = [x[i] + y[i] - z[i] for i in range(n)]
    s5.sort(reverse=True)
    s6 = [-x[i] + y[i] - z[i] for i in range(n)]
    s6.sort(reverse=True)
    s7 = [x[i] - y[i] - z[i] for i in range(n)]
    s7.sort(reverse=True)
    s8 = [-x[i] - y[i] - z[i] for i in range(n)]
    s8.sort(reverse=True)
    max_sum = sum(s1[0:m])
    tmp_sum = sum(s2[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s3[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s4[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s5[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s6[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s7[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s8[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    return max_sum


def read_line():
    n, m = map(int, input().split())
    x = []
    y = []
    z = []
    for i in range(n):
        tx, ty, tz = map(int, input().split())
        x.append(tx)
        y.append(ty)
        z.append(tz)
    return (n, m, x, y, z)


def main():
    n, m, x, y, z = read_line()
    print(run(n, m, x, y, z))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <stdio.h>
#define T 20

int main(void) {
	int N, i,max,count=1;
	scanf("%d",&N);
	int H[T];
	for (i = 1; i < N + 1; i++) scanf("%d", &H[i]);
    max=H[1];
	for (i = 2; i < N + 1; i++) {
        if(max<=H[i]) {
          count++;
          max=H[i];
			}
		}
	

	printf("%d\n", count);
	return 0;
}




Measured memory_bytes: 128
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    cin >> N;
    int d = 1, b = 10;
    while (N/b) {
        d++; b *= 10;
    }
    int X = 0;
    b = 1;
    for (int i=1;i<d;i+=2) {
        X += 9*b;
        b *= 100;
    }
    if (d%2 == 1) {
        b = 1;
        for (int i=1;i<d;i++) b *= 10;
        X += N-b+1;
    }
    cout << X << endl;

    return 0;
}


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

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};


typedef struct node * Node;


Node root = NIL;


Node treeSearch(Node, int);
void insert(int);
void inorder(Node);
void preorder(Node);


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left, k);
  else return treeSearch(x->right, k);
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;


  while(x != NIL){
    y = x;

    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}


void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}


void preorder(Node u){
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}



Measured memory_bytes: 20492
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    bool jed = false;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a[i] == 1)
            jed = true;
    }
    if (!jed)
    {
        cout << "-1";
        return 0;
    }
    int i = 0, x = 1;
    while (i < n)
    {
        if (a[i] == x)
            ++x;
        ++i;
    }
    cout << n - x + 1;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void) {
    int N,M=1,count=0;
    scanf("%d", &N);
    int a[N];
  for(int i=0;i<N;i++)
    scanf("%d",&a[i]);
      while (1) {
        N=M-1;
        M = a[M-1];
        count++;
        if (M == 2) {
            printf("%d", count);
            return 0;
        }
        if(M==-1){
            printf("-1");
            return 0;
   		}
        a[N]=-1;
      }
    return 0;
}

Measured memory_bytes: 2120
n, m = map(int, input().split())

ac = [0]*(n+1)
wa = [0]*(n+1)

for _ in range(m):
    a, b = input().split()
    a = int(a)
    if b == 'AC':
        ac[a] = 1
    else: 
        if ac[a] == 0:
            wa[a] = wa[a] + 1

for i in range(n+1):
    wa[i] = wa[i] * ac[i]

print(sum(ac), sum(wa))



Measured memory_bytes: 4724
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main() {
  long long H, W;
  scanf("%lld", &H);
  scanf("%lld", &W);
  long long ans = 1e15;
  for (int i = 0; i < 2; i++) {

    //横に2回切る
    if (H % 3 == 0) {
      ans = std::min((long long)0, ans);
    } else {
      ans = std::min(W, ans);
    }
    // 横に切った残りを縦に切る
    if (W % 2 == 0) {
      if (H % 3 == 0) {
        ans = std::min((long long)0, ans);
      } else {
        ans = std::min(W/2, ans);
      }
    } else {
      //printf("H=%lld, W=%lld, val1=%lld\n", H, W, ((W + 1) / 2 * H) % ((3 * W + 1) / 2));
      //printf("H=%lld, W=%lld, val2=%lld\n", H, W, (W * H) % ((3 * W - 1) / 2));
      ans = std::min(ans, std::max(((W + 1) / 2 * H) % ((3 * W + 1) / 2), H-((W+1)/2*H)/((3*W+1)/2)));
      ans = std::min(ans, std::max((W * H) % ((3 * W - 1) / 2), (W * H) / ((3 * W - 1) / 2)));
      //      ans = std::min(ans, )
    }
    std::swap(H, W);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

const long long MOD = 998244353;

long long fast_pow(long long a, long long x){
    long long res = 1;
    while (x){
        if (x & 1){
            res *= a;
            res %= MOD;
        }
        
        a *= a;
        a %= MOD;
        x >>= 1;
    }

    return res;
}

long long C(long long n, long long m, vector<long long> &fac, vector<long long> &inv){
    return (fac[n] * inv[m] % MOD) * inv[n - m] % MOD;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, k;
    cin >> n >> m >> k;

    vector<long long> fac(n + 1), inv(n + 1);
    fac[0] = fac[1] = 1;
    for (long long i = 2; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % MOD;

    inv[n] = fast_pow(fac[n], MOD - 2);
    for (long long i = n - 1; i >= 0; i--)
        inv[i] = ((i + 1) * inv[i + 1]) % MOD;
    
    long long ans = 0;
    for (long long kk = 0; kk <= k; kk++){
        ans += (((C(n - 1, kk, fac, inv) * m) % MOD) * fast_pow(m - 1, n - kk - 1)) % MOD;
        ans %= MOD;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6316
using System;

namespace ABC115
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var D = int.Parse(input);

            Console.Write("Christmas");

            var d = 25;
            while (d > D)
            {
                d--;
                Console.Write(" Eve");
            }
        }
    }
}


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

const int N = 20004;
const int mod = 1000000007;
typedef long long  ll;

ll dp[N];
int n;

struct node
{
    int w,s,b;
};
bool cmp(node x,node y)
{
    return x.w+x.s<y.s+y.w;
}
node arr[N];


int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++) scanf("%d %d %d",&arr[i].w,&arr[i].s,&arr[i].b);
    sort(arr+1,arr+n+1,cmp);
    dp[0]=0;
    for(int i=1; i<N; i++) dp[i]=-1e17;
    for(int i=1; i<=n; i++)
    {
        for(int j=arr[i].s; j>=0; j--)
        {
            dp[j+arr[i].w]=max(dp[j+arr[i].w],arr[i].b+dp[j]);
        }
    }
    ll ans=0;
    for(int i=0; i<N; i++) ans=max(ans,dp[i]);
    printf("%lld\n",ans);


}


Measured memory_bytes: 384
s = input()
n = len(s)

w,b = 0,0
p,q = 0,0

for i, j in enumerate(s):
    if j == "W":
        p += 1
        w += i
    else:
        q += 1
        b += i

pp = p * (p - 1) // 2
qq = n * (n - 1) // 2 - pp

# print(pp, qq)
# print(w, b)
print((w - pp + qq - b) // 2)

Measured memory_bytes: 41180
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;
int main(){
  int n,i;
  cin >> n >> i;
  cout << n-i+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)2e6;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int cnt[N];
int freq[N];
bool check_pair(){
    for(int i=2;i<N;i++){
        for(int j=i;j<N;j+=i){
            if(freq[j]){
                cnt[i]+=freq[j];
            }
        }
        if(cnt[i]>1){
            return false;
        }
    }
    return true;
}
bool check_set(int n){
    int gcd =a[0];
    range(i,1,n-1){
        gcd=__gcd(gcd,a[i]);
    }
    if(gcd==1)return true;
    else return false;
}
void _run(){
    int n;
    scanf("%d",&n);
    lp(i,n){
        scanf("%d",&a[i]);
        freq[a[i]]++;
    }
    if(check_pair())puts("pairwise coprime");
    else if(check_set(n))puts("setwise coprime");
    else puts("not coprime");
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int t=1;
    // scanf("%d",&t);
    while(t--)_run();
    
    return 0;
}

Measured memory_bytes: 11784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <functional>
#include <set>
#include <iterator>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

/* Union-find
int par[100010];
int trank[100010];

void init(int n) {
   for (int i=0;i<n;i++) {
      par[i] = i;
      trank[i] = 0;
   }
}
int find(int x) {
   if (par[x] == x) {
      return x;
   } else {
      return par[x] = find(par[x]);
   }
}
void unite(int x, int y) {
   x = find(x);
   y = find(y);
   if (x == y) return;
   if (trank[x] < trank[y]) {
      par[x] = y;
   } else {
      par[y] = x;
      if (trank[x] == trank[y]) trank[x]++;
   }
}
bool same(int x, int y) {
   return find(x) == find(y);
}
*/


string s;
int K;
string smallest[6];
ll dp[6];
int coun = 1;
set<string> a;

int A, B;

int main() {
   cin >> A;
   cin >> B;
   int C = A+B;
   C = max(C, A-B);
   C = max(C, A*B);
   cout << C << endl;;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

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

	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
		return true;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int n,m;
PPI es[11111];

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n>>m;
		if(n==0)break;
		rep(i,m){
			int a,b,w;
			cin>>a>>b>>w;
			a--;b--;
			es[i]=PPI(w,P(a,b));
		}
		sort(es,es+m);
		int l=0;
		int res=INF;
		while(1){
			UnionFind uf(n);
			int idx=l;
			while(idx<m&&uf.size(0)<n){
				if(!uf.same(es[idx].se.fi,es[idx].se.se)){
					uf.unite(es[idx].se.fi,es[idx].se.se);
				}
				idx++;
			}
			if(uf.size(0)<n)break;
			minch(res,es[idx-1].fi-es[l].fi);
			l++;
		}
		if(res==INF)cout<<-1<<endl;
		else cout<<res<<endl;
	}
	return 0;
}

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int max_a=0;
  int score;
  for(int i=0;i<n;i++){
    int ai,bi;
    cin>>ai>>bi;
    if(ai>max_a){
      max_a=ai;
      score=bi;
    }
  }
  cout<<max_a+score<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
int main()
{
	int n,k, tot = 0;
	cin >> n >> k;
	vector<int>v;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for(int i = 0; i<k; i++){
		tot+= v.front();
		v.erase(v.begin());
	}
	cout << tot << endl;
}
		  


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1000200;
typedef long long ll;
const int mod = 1e9 + 7;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
int f[maxn];
int suf[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, f[n] = n, f[n - 1] = (ll) n * n % mod;
	suf[n] = n, suf[n - 1] = (f[n] + f[n - 1]) % mod;
	for(int i = n - 2;i >= 1;--i) {
		f[i] = (f[i + 1] + (ll) (n - 1) * (n - 1) + suf[i + 3] + i + 1) % mod;
		suf[i] = (suf[i + 1] + f[i]) % mod;
	}
	cout << f[1] << '\n';
}


Measured memory_bytes: 8064
n, m = list(map(int, input().split(" ")))
a = []
for i in range(n):
     tmp = m*[0]
     k = list(map(int, input().split(" ")))
     for i in k[1:]:
         tmp[i-1] = 1
     a.append(tmp)


count = m*[0]
for i in a:
    tmp = 0
    for j in range(m):
        if(i[j] == 1): count[j] += 1


ans = 0
for i in count:
    if(i == n): ans += 1

print(ans)

Measured memory_bytes: 3064
def check(x,sample):
    x=str(x)
    for i in x:
        if i in sample:
            return False
    return True

def main():
    n,k=map(int,input().split())
    sample=input().split()
    while 1:
        if check(n,sample):
            print(n)
            return;
        n+=1
main()

Measured memory_bytes: 40812
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	int right_cost = 0;
	for (int i = x; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[j] == i) {
				right_cost++;
			}
		}
	}

	int left_cost = 0;
	for (int i = x; i > 0; i--) {
		for (int j = 0; j < m; j++) {
			if (a[j] == i) {
				left_cost++;
			}
		}
	}

	cout << min(right_cost, left_cost) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI M_PI
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

typedef long long ll;

using namespace std;

void chmin(ll &x, ll &y) {
    x = min(x, y);
}

void solve()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
   
    ll ans = 1001001001001LL;
    ll tmp = A * X + B * Y;
    chmin(ans, tmp);

    tmp = 2 * C * max(X, Y);
    chmin(ans, tmp);

    if (X >= Y) {
        tmp = 0;
        tmp += 2LL * C * min(X, Y);
        tmp += A * (X - Y);
        chmin(ans, tmp);
    } else {
        tmp = 0;
        tmp += 2LL * C * min(X, Y);
        tmp += B * (Y - X);
        chmin(ans, tmp);
    }
    print(ans);

}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
	ll nn;
	cin >> nn;
	if(nn%2)
	{
		cout << "0\n";
	}
	else
	{
		ll t,i,x,j,y,z,k=0,n;
		n=nn;
		ll p2=n/2;
		n=n/2;
		j=0;
		i=5;

	while(n/i>0){
    	j+=n/i;
    	i*=5;
	}
	k=0;
	i=2;

cout << j << "\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
ull gcd(ull a, ull b){
    if(a%b==0) return b;
    else return gcd(b, a%b);
}
ull lcm(ull a, ull b){
    return a * b / gcd(a, b);
}


int main(){
    ull n,m ; cin >> n >> m;
    string s,t ; cin >> s >> t;
    ull l = lcm(n, m);
    ull l_sub = lcm(l/n, l/m);
    bool flg = true;
    if(s.at(0) != t.at(0)){
        flg =false;
        cout << -1 << endl;
        return 0;
    }
    for(int i=0; i<l; i+=l_sub){
        if(s[i/(l/n)] != t[i/(l/m)]){
            cout << -1 << endl;
            return 0;
        }
    }
    if(flg) cout << l << endl;
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
#define pll pair<ll,ll>
int T;
ll n,a,b,c,d,ans;
map<ll,ll> r;
bool valid(ll x,ll y){
    return 2e18 / y > x;
}
ll dfs(ll x){
    if(r.find(x) != r.end()) return r[x];
    ll &ret = r[x];
    if(x == 0){
        return ret = 0ll;
    }
    ret = (valid(d,x) ? d * x : 2e18);
    ll r1 = x % 2;
    ret = min(ret, dfs(x / 2) + a + r1 * d);
    if(r1 > 0) ret = min(ret, dfs(x / 2 + 1) + a + (2 - r1) * d);
    ll r2 = x % 3;
    ret = min(ret, dfs(x / 3) + b + r2 * d);
    if(r2 > 0) ret = min(ret, dfs(x / 3 + 1) + b + (3 - r2) * d);
    ll r3 = x % 5;
    ret = min(ret, dfs(x / 5) + c + r3 * d);
    if(r3 > 0) ret = min(ret, dfs(x / 5 + 1) + c + (5 - r3) * d);
    return ret;
}
void solve()
{
    cin>>n>>a>>b>>c>>d;
    r.clear();
    cout<<dfs(n)<<'\n';
}
int main()
{
    fastio;
    cin>>T;
    while(T--) solve();
    return 0;
}

Measured memory_bytes: 4372
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

double dp[105][105];

int main() {
	int n, t, l, b;
	while(cin >> n >> t >> l >> b) {
		if(n == 0 && t == 0 && l == 0 && b == 0) break;

		memset(dp, 0, sizeof(dp));

		bool lose[105], back[1005];
		memset(lose, 0, sizeof(lose));
		memset(back, 0, sizeof(back));

		rep(i, l) {
			int x;
			cin >> x;
			lose[x] = true;
		}

		rep(i, b) {
			int x;
			cin >> x;
			back[x] = true;
		}

		memset(dp, 0, sizeof(dp));

		dp[0][0] = 1.0;
		rep(i, t) {
			rep(j, n) {
				if(dp[i][j] == 0.0) continue;
				REP(k, 1, 7) {
					int p = j + k;
					if(p > n) p = n - (p - n);

					if(lose[p]) {
						dp[i+2][p] += dp[i][j] * (1.0 / 6.0);
					} else if(back[p]) {
						dp[i+1][0] += dp[i][j] * (1.0 / 6.0);
					} else {
						dp[i+1][p] += dp[i][j] * (1.0 / 6.0);
					}
				}
			}
		}

		double ans = 0;
		rep(i, t + 1) {
			ans += dp[i][n];
		}

		cout << fixed;
		cout.precision(20);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1324
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// Written after the author read the editorial
fn solve() {
    let n: usize = get();
    let mut k: i64 = get();
    // A -> false, B -> true
    let mut s: Vec<bool> = get_word().chars().map(|x| x == 'B').collect();
    assert_eq!(s.len(), n);
    let mut pos = 0;
    for i in 0 .. n {
        s[i] = s[i] ^ ((n + i) % 2 != 1);
    }
    for _ in 0 .. n {
        s.push(false);
    }
    while k > 0 {
        if pos >= n {
            break;
        }
        if s[pos] ^ (n % 2 != 1) { // B
            pos += 1;
        } else { // A
            s[pos] = !s[pos];
        }
        k -= 1;
    }
    if k > 0 && n % 2 == 1 && k % 2 == 1 {
        assert_eq!(pos, n);
        s[n] = !s[n];
    }
    // recons
    let mut out = String::new();
    for i in 0 .. n {
        out.push(if s[pos + i] ^ ((n + i) % 2 != 1) { 'B' } else { 'A' });
    }
    println!("{}", out);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8700
n, yen = gets.split.map(&:to_i)
flag = false
(yen / 10000).downto(0) do |x|
  (n - x).downto(0) do |y|
    z = n - x - y
    if z >= 0 && yen == x * 10000 + y * 5000 + z * 1000
      puts "#{x} #{y} #{z}"
      flag = true
      break
    end
  end
  break if flag
end
puts "-1 -1 -1" if !flag


Measured memory_bytes: 1788
n, m = map(int, input().split())

vec_A = [[] for i in range(n)]
for i in range(n):
    vec_A[i] = list(map(int, input().split()))
    
vec_b = [[0]*1 for i in range(m)]
for i in range(m):
    vec_b[i] = int(input())
    
for row in range(n):
    tmp = 0
    for col in range(m):
        tmp += vec_A[row][col] * vec_b[col]
    print('{}'.format(tmp))


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

/*vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> x;
	ll cou = 0;
	ll mini = INT_MAX;
	for(ll i=0;i<n;i++) {
		cin>>y;
		x-=y;
		mini = min(mini,y);
		cou++;
	}
	cou += (x/mini);
	cout<<cou;

}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 3640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();

		Set<String> set = new HashSet<>();

		for(int i = 0; i < n; i++) {
			String s = stdIn.next();
			set.add(s);

		}

		int cnt = 0;
		for(String x: set) {
			cnt++;
		}
		
		System.out.println(cnt);


	}

}


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

int main() {
	ios::sync_with_stdio(false);

	int n, k, q;

	cin >> n >> k >> q;

	vector<int> ans(n, 0);
	int a;

	for (int i = 0; i < q; i++) {
		cin >> a;
		ans[a - 1]++;
	}

	int nap = k - q;

	for (int i = 0; i < n; i++) {
		if (nap + ans[i] <= 0) {
			cout << "No" << "\n";
		}
		else {
			cout << "Yes" << "\n";
		}
	}

	return 0;
}

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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 1e9
#define MOD 1000000007

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

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

void solve() {
  string v[] = {
    "", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"
  };
  string s;
   cin >> s;
  rep(i, 8) {
    if (v[i] == s) {
      cout << i << endl; 
    }
  }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc134d
int main(){
    int n;
    cin >> n;
    int a[n+1];
    a[0] = 0;
    rep(i, n) cin >> a[i+1];
    int ans = 0;
    int aa[n+1];
    aa[0] = 0;
    for(int i=n; i>=1; i--){
        aa[i] = 0;
        ll tmp = i;
        int sum = 0;
        while(tmp+i<=n){
            tmp += i;
            sum += aa[tmp];
        }
        if (sum%2 != a[i]){
            aa[i] = 1;
        }
        if (aa[i]) ans++;
    }

    cout << ans << endl;
    rep(i, n+1){
        if (aa[i]){
            cout << i << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		int max = 0;;
		for(int i = 0; i < N - 1; i++) {
			max = Math.max(max, A[i + 1] - A[i]);
		}
		max = Math.max(max, K - A[N - 1] + A[0]);
		System.out.println(K - max);
	}
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i=0; i<N; i++) {
    cin >> h.at(i);
  }

  vector<long long int> cost(N, LLONG_MAX);
  cost[0] = 0;
  cost[1] = abs(h[1] - h[0]);
  for (int i=2; i<=min(K, N); i++){
    for (int j=1; j<=i; j++) {
      cost[i] = min(cost[i], cost[i-j] + abs(h[i] - h[i-j]));
    }
  }
  for (int i=K+1; i<N; i++) {
    for (int j=1; j<=K; j++) {
      cost[i] = min(cost[i], cost[i-j] + abs(h[i] - h[i-j]));
    }
  }
  cout << cost[N-1] << endl;

  return 0;
}

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

int main() {
  int N, K, num = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
  	if (2 * num > num + K) {
      num += K;
    } else {
      num *= 2;
    }
  }
  cout << num << endl;
}

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


int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;


    int ans = 0;
    for( int i = 0; i <= N/R; ++i ){
        for( int j = 0; j <= N/G; ++j ){
            int numBalls = R*i + G*j;
            if( numBalls <= N and (N-numBalls)%B == 0 ) ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int[] a = new int[100100];
		Arrays.fill(a, 1);
		a[0] = 0;
		a[1] = 0;

		for (int i = 2; i * i < a.length; i++) {
			for (int j = i * 2; j < a.length; j += i) {
				a[j] = 0;
			}
		}

		for (int i = a.length - 1; i >= 0; i--) {
			if (!(i % 2 == 1 && a[i] == 1 && a[(i + 1) / 2] == 1)) {
				a[i] = 0;
			}
		}

		for (int i = 1; i < a.length; i++) {
			a[i] += a[i - 1];
		}

		int Q = sc.nextInt();

		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			out.println(a[r] - a[l - 1]);

		}

		sc.close();

	}

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


Measured memory_bytes: 65836
#include<stdio.h>
int main(){
  int n,ans=0;
  scanf("%d",&n);
  if(n>=105)ans++;
  if(n>=135)ans++;
  if(n>=189)ans++;
  if(n>=165)ans++;
  if(n>=195)ans++;
  printf("%d\n",ans);
  return 0;
}


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

bool div_ok(int n) {
  if (n % 3 == 0) {
    return true;
  } else {
    return false;
  }
}

bool num_dispear(int n) {
  while (n > 0) {
    if (n % 10 == 3) {
      return true;
    }
    n /= 10;
  }
  return false;
}

int main () {
  bool loop = true;
  int i = 1;
  int n;
  cin >> n;
  bool div_check = false;
  while (i <= n) {
    if (div_ok(i)) {
      cout << " " << i;
      div_check = true;
    }
    if (!div_check && num_dispear(i)) {
      cout << " " << i;
    }
    i++;
    div_check = false;
  }
  cout << endl;
  return 0;
}

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

int main()
{
    int h, w, n;
    cin >> h >> w >> n;

    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; i++) {
        int y, x;
        cin >> y >> x;
        int dx[] = {1, 1, 1, 0, -1, -1, -1, 0, 0};
        int dy[] = {1, 0, -1, -1, -1, 0, 1, 1, 0};
        for (int j = 0; j < 9; j++) {
            int xx = x + dx[j];
            int yy = y + dy[j];
            if (xx - 1 <= 0 || xx + 1 > w || yy - 1 <= 0 || yy + 1 > h) continue;
            mp[pair<int, int> (yy, xx)]++;
        }
    }

    int ans[10] = {};
    for (auto x : mp) {
        ans[x.second]++;
    }

    cout << 1LL * (h - 2) * (w - 2) - mp.size() << endl;
    for (int i = 1; i < 10; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 56448
#include <iostream>

int main(){
   int N, M, C;
   std::cin >> N >> M >> C;
   int B[M];
   for(int i=0; i<M; ++i)
      std::cin >> B[i];
   int A[N][M];
   for(int i=0; i<N; ++i){
      for(int j=0; j<M; ++j)
	 std::cin >> A[i][j];
   }

   int count = 0;
   for(int i=0; i<N; ++i){
     long long sum = C;
     for(int j=0; j<M; ++j)
	sum += A[i][j]*B[j];

     if(sum>0) ++count;
   }
   std::cout << count << std::endl;
   return 0;
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, s, N) for(ll i{N - 1}; i > s - 1; i--)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

ll gcd(ll a, ll b){
  return b != 0 ? gcd(b, a % b) : a;
}

int main(){
  kyopro;
  string a;
  char s;
  cin >> a >> s;
  cout << "A" << s << "C";
}

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


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;


using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    IOS;

    int n;

    cin >> n;

    if(n%1000 == 0)
    {
        cout<<0<<endl;

        return 0;
    }

    cout << (n / 1000 + 1) * 1000 - n << endl;


    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;
	string ans;
	while (n) {
		int p = n % 26;
		if (p == 0) p = 26;
		ans += (char)('a' + p - 1);
		n = (n - p) / 26;
	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<stdio.h>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
    string str;
    int a=0,b=0;
    while(1){
        cin>>str;
        if(str=="0"){
            break;
        }
        for(int i=0+1;i<str.size()-1;i++){
            if(str[i]=='A'){
                a++;
            }
            else if(str[i]=='B'){
                b++;
            }
        }
        if(str[str.size()-1]=='A'){
            a+=2;
        }
        else if(str[str.size()-1]=='B'){
            b+=2;
        }
        cout<<a<<" "<<b<<endl;
        a=0;b=0;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    long long int k,n,temp=0;
    cin >> k>> n;
    long long int a[n],b[n];
    cin >> a[0];
    for(int i=0;i<n-1;i++){
        cin >> a[i+1];
        b[i]=a[i+1]-a[i];
    }
    b[n-1]=a[0]+(k-a[n-1]);
    sort(b,b+n);
    cout << k-b[n-1] << endl;
    return 0;
}

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

struct Edge{
  int weight;
  int to;
  Edge(int w,int t):weight(w),to(t){}
};

const int inf = 1<<28;

bool operator>(Edge e1,Edge e2){
  if(e1.weight != e2.weight) return (e1.weight > e2.weight);
  else return (e1.to > e2.to);
}

int main(){
  int n;
  cin>>n;
  vector<vector<Edge> > Graph(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int temp;
      cin>>temp;
      if(temp != -1){
	Graph[i].push_back(Edge(temp,j));
      }
    }
  }
  priority_queue<Edge,vector<Edge>,greater<Edge> > pq;
  pq.push(Edge(0,0));
  vector<bool> used(n,false);
  vector<int> cost(n,inf);
  int ans = 0;
  while(pq.size()){
    Edge e = pq.top();
    pq.pop();
    if(used[e.to]) continue;
    used[e.to] = true;
    ans += e.weight;
    for(int i=0;i<Graph[e.to].size();i++){
      Edge &edge = Graph[e.to][i]; 
      if(cost[edge.to] > edge.weight){
	cost[edge.to] = edge.weight;
	pq.push(edge);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
int main() {
	int N;
	int K;
	cin >> N >> K;
	int A[200001];
	int flag[200001] = { 0 };
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		flag[A[i]]++;
	}
	sort(A, A + N);
	sort(flag, flag + 200001);
	int sum = 1;
	int count = 0;
	for (int i = 0; i < N-1; ++i) {
		if (A[i] != A[i + 1])
			sum++;
	}
	if (sum <= K)
		cout << 0 << endl;
	else {
		for (int i = 0; i < 200001; ++i) {
			if (flag[i] > 0) {
				sum--;
				count += flag[i];
			}
			if (sum <= K) {
				break;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1792