akhauriyash/Code-Regression huggingface dataset:
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    string s;
    cin >> s;
    vi ans;
    rep(i,s.size()) {
      if(s[i]=='0') ans.push_back(0);
      else if (s[i]=='1') ans.push_back(1);
      else {
          if(ans.size()!=0) ans.pop_back();

      }
    }
    rep(i,ans.size()) {
        cout << ans[i];
    }
    PED;
    return 0;
}



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

#define CIN2(a,b) long long a,b;cin >> a >> b;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

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

    int ans1 = 0;
    int ans2 = 0;
    rep(i,s.size()){
        if(i&1){
            (s[i]=='1')?ans1++:ans2++;
        }else{
            (s[i]=='0')?ans1++:ans2++;
        }
    }
    cout << min(ans1,ans2) << endl;
}



Measured memory_bytes: 512
#include <stdio.h>
int main () {
  char S[51];

  scanf ("%s", S);

  if (S[0] == 'S') printf ("Cloudy\n");
  else if (S[0] == 'C') printf ("Rainy\n");
  else if (S[0] == 'R') printf ("Sunny\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  ll x;
  cin >> x;
  ll a = x / 500;
  x %= 500;
  ll b = x / 5;
  cout << 1000 * a + 5 * b << endl;
  return 0;
}


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

int N, P;
vector<int> A;

ll power(ll x, ll n) {
  if (n == 0) {
    return 1;
  } else if (n > 0 && n % 2 == 0) {
    return ((power(x, n / 2)) * (power(x, n / 2)));
  } else if (n > 0 && n % 2 != 0) {
    return ((power(x, (n - 1) / 2)) * (power(x, (n - 1) / 2)) * x);
  } else {
    return 0;
  }
}
void agc017a() {
  int even = 0, odd = 0;
  for (auto a : A) {
    if (a % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  ll ans;
  if (odd == 0) {
    if (P == 0) {
      ans = power(2, even);
    } else {
      ans = 0;
    }
  } else {
    ans = power(2, even) * power(2, odd - 1);
  }
  cout << ans << '\n';
  return;
}

int main() {
  cin >> N >> P;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  agc017a();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int fib(int n);
int main() {
  int n;

  //入力
  cin >> n;

  //出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n){
  int dp[45];
  dp[0] = 1;
  dp[1] = 1;
  for (int i=2 ; i <= n; i++){
    dp[i] = dp[i-1]+dp[i-2];
  }
  return dp[n];
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define ret return
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define FAST ios::sync_with_stdio(false);cin.tie(0);
 
const ll maxn = 2010 , mod = 924844033;
ll dp[maxn][maxn][2] , ep[2 * maxn][maxn] , fac[maxn];
 
int main(){
    int N, K;
    cin >> N >> K;
    dp[0][0][0] = dp[0][0][1] = 1;
    for(int i = 0; i <= 2000; ++i) {
        for(int j = 0; j <= i; ++j) {
            (dp[i + 1][j][0] += dp[i][j][0]) %= mod;
            (dp[i + 1][j][1] += dp[i][j][0]) %= mod;
            (dp[i + 1][j + 1][0] += dp[i][j][1]) %= mod;
        }
    }
    ep[0][0] = 1;
    for(int i = 0; i < K * 2; ++i) {
        int num = (N - i / 2 - 1) / K;
        for(int j = 0; j + (num + 1) / 2 <= N; ++j) { 
            for(int k = 0; k <= (num + 1) / 2; ++k) {
                (ep[i + 1][j + k] += (ep[i][j] * dp[num][k][0]) % mod) %= mod;
            }
        }
    }
    fac[0] = 1;
    for(int i = 1; i <= N; ++i) fac[i] = (fac[i - 1] * i) % mod;
    ll ans = fac[N];
    for(int i = 1; i <= N; ++i) {
        if(i % 2 == 1) {
            (ans += mod - (fac[N - i] * ep[K * 2][i]) % mod) %= mod;
        }
        else {
            (ans += (fac[N - i] * ep[K * 2][i]) % mod) %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 126208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int k,n;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin >> p[i];

  sort(p.begin(),p.end());

  int ans = 0;
  for(int i=0;i<k;i++){
    ans += p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
	int a, b, c;
	ios::sync_with_stdio;
	cin >> a >> b >> c;
	if (c >= a&&c <= b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int n;
string s, t;
string c = "mcxi";
int v[] = {1000, 100, 10, 1};

string enc(int x)
{
  char buf[50];
  sprintf(buf, "%dm%dc%dx%di", x/1000, x/100%10, x/10%10, x%10);
  string tmp = buf, ret;
  for(int i = 0; i < tmp.size(); i++){
    if(tmp[i] == '0') i++;
    else if(tmp[i] == '1');
    else ret += tmp[i];
  }
  return ret;
}

int dec(string s)
{
  int ret = 0;
  for(int i = 0 ;i < s.size(); i++){
    for(int j = 0; j < 4; j++){
      if(c[j] == s[i]){
        int m = 1;
        if(i != 0 && s[i-1] >= '2' && s[i-1] <= '9') m = s[i-1]-'0';
        ret += v[j] * m;
      }
    }
  }
  return ret;
}

int main(void)
{
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s >> t;
    //cout << dec(s) << " " << dec(t) << endl;
    cout << enc(dec(s)+dec(t)) << endl;
  }
  return 0;
}



Measured memory_bytes: 3248
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

int main(){ 
   int n;
   cin>>n;
   vector<int> a(n);
   int flag=1;
   rep(i,n){
      cin>>a[i];
      if(a[i]%2==0){
         if(a[i]%3!=0){
            if(a[i]%5!=0){
               flag=0;
            }
         }
      }
   }
   flag==1? cout<<"APPROVED":cout<<"DENIED";
      return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for w in range(W + 1):
        dp[i + 1][w] = dp[i][w]
        if w - wv[i][0] >= 0:
            dp[i + 1][w] = max(dp[i + 1][w], dp[i][w - wv[i][0]] + wv[i][1])

print(dp[N][W])


Measured memory_bytes: 120172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, l);
    Cins(int, l, a);
    
    vc<vc<ll>> dp(l+1, vc<ll>(4+1, 0));

    for(int i = l-1; i >= 0; i --){
        int ev = (a[i] == 0) ? 2 : (a[i] % 2 == 0) ? 0 : 1;
        int od = (a[i] % 2 == 0) ? 1 : 0;
        
        dp[i][0] = dp[i+1][0] + a[i];
        dp[i][1] = min(dp[i+1][1] + ev,   dp[i][0]);
        dp[i][2] = min(dp[i+1][2] + od,   dp[i][1]);
        dp[i][3] = min(dp[i+1][3] + ev,   dp[i][2]);
        dp[i][4] = min(dp[i+1][4] + a[i], dp[i][3]);
    }
    // For(i, l+1) Couts(dp[i]);
    
    Cout(dp[0][4]);
}




Measured memory_bytes: 15104
//
// Created by kuroneko on 2019-09-15.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;

#define INF 1000000000000009LL
#define MOD 1000000007LL

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight):src(src), dst(dst), weight(weight) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main() {
    ll N, K, Q; cin >> N >> K >> Q;
    vector<ll> a(Q), v(N);
    for (int i = 0; i < N; i++) v[i] = 0;
    for (int i = 0; i < Q; i++){
        ll a; cin >> a;
        a--;
        v[a]++;
    }

    for (int i = 0; i < N; i++) {
        if (K - Q + v[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;

}


Measured memory_bytes: 2176
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int d, n;
    int a;
    cin >> d >> n;
    if (d == 0) {
        a = 1;
    } else if (d == 1) {
        a = 100;
    } else {
        a = 10000;
    }
    if (n == 100) {
        cout << (a * 101) << endl;
    } else {
        cout << (a * n) << endl;
    }
}


Measured memory_bytes: 888
N = int(input())
w = input()
w_list = set([w])
e = w[-1]
for i in range(1,N):
    w = input()
    if e != w[0]:
        print("No")
        break
    if w in w_list:
        print("No")
        break
    e = w[-1]
    w_list.add(w)
else:
    print("Yes")

Measured memory_bytes: 3064
N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))

dp = [10 ** 10] * (N+1)
dp[:2] = 0, 0

for i in range(1, N+1):
    for j in range(1, K+1):
        if i + j > N:
            break
        dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j] - H[i]))

print(dp[N])

Measured memory_bytes: 52832
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B;
    cin >> N >> A >> B;
    if((B-A-1) % 2 == 0){
        print("Borys");
    }else{
        print("Alice");
    }


 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int a[1005],b[1005],dp[10005];
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    int m,n;
    cin>>m>>n;
	FOR(i,1,n)cin>>a[i]>>b[i];
	int ans=1e9;
	FOR(i,1,m)dp[i]=ans;
	FOR(i,1,n){
		for(int j=a[i];j<=m;j++)dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
	}
	FOR(i,1,n){
		for(int j=m;j>=max(0,m-a[i]);j--){
			ans=min(ans,dp[j]+b[i]);
		}
	}
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 256
#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		=  	1000000007;

int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, K;
string s, t;
// <------------- Implement Functions Here ----------> //



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

void MAIN() {
	char c;
	cin>>c;
	if(isupper(c)) cout<<"A";
	else cout<<"a";	
}


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


Measured memory_bytes: 3648
/*  -*- coding: utf-8 -*-
 *
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int x0 = 0, y0 = 0, x1 = w, y1 = h;
  //printf("(%d,%d)-(%d,%d)\n", x0, y0, x1, y1);
  for (int i = 0; i < n; i++) {
    int xi, yi, ai;
    cin >> xi >> yi >> ai;

    switch (ai) {
    case 1: x0 = max(x0, xi); break;
    case 2: x1 = min(x1, xi); break;
    case 3: y0 = max(y0, yi); break;
    case 4: y1 = min(y1, yi); break;
    }
    //printf("(%d,%d)-(%d,%d)\n", x0, y0, x1, y1);
  }

  int ar = (x1 > x0 && y1 > y0) ? (x1 - x0) * (y1 - y0) : 0;
  printf("%d\n", ar);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);

    if (a > b && a > c) {
        puts("A");
    } else if (b > a && b > c) {
        puts("B");
    } else {
        puts("C");
    }

    return 0;
}



Measured memory_bytes: 2032
#include<stdio.h>
int isPrime(int x){
  int i;
  if(x<2)return 0;
  else if(x==2)return 1;
  if(x%2==0)return 0;
  for(i=3;i*i<=x;i+=2){
    if(x%i==0)return 0;
  }return 1;
}

int main(){
  int n,x,i;
  int cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    if(isPrime(x))cnt++;
  }
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2032
import java.awt.geom.Point2D;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){		
		new AOJ0114();
	}
	
	class AOJ0114{
		public AOJ0114() {
			while(true){
				Bug bug = new Bug(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
				if(bug.all_zero())break;
				System.out.println(bug.movement());
			}
		}
		class Bug{
			int x,y,z;
			int kaisu;
			int a1,a2,a3,m1,m2,m3;
			public Bug(int a1,int m1,int a2,int m2,int a3,int m3) {
				this.x = 1;
				this.y = 1;
				this.z = 1;
				kaisu=0;
				this.a1 = a1;
				this.a2 = a2;
				this.a3 = a3;
				this.m1 = m1;
				this.m2 = m2;
				this.m3 = m3;
			}
			
			boolean all_zero(){
				return a1+a2+a3+m1+m2+m3==0;
			}
			
			long movement(){
				int a = move(a1,x,m1);
				int b = move(a2, y, m2);
				int c = move(a3, z, m3);
				return lcm(lcm(a,b), c);
			}
			
			long lcm(long a,long b){
				return a/gcd(a,b)*b;
			}
			long gcd(long a,long b){
				long r;
				while(a%b!=0){
					r=a%b;
					a=b;
					b=r;
				}
				return b;
			}
			int move(int a,int xyz,int m){
				int kaisu=0;
				while(true){
					xyz = (a*xyz)%m;
					kaisu++;
					if(xyz==1)return kaisu;
				}
			}
			
			
			int gcd(int a,int b){
				int r;
				int kaisu = 0;
				while(a%b!=0){
					kaisu++;
					r=a%b;
					a=b;
					b=r;
				}
				return kaisu;
			}
			
		}
	}


	class AOJ2503{
		int MAX = 0;
		public AOJ2503() {
			Scanner in = new Scanner(System.in);
			int n = in.nextInt();
			int m = in.nextInt();

			int[][] cost = new int[n][n];

			int[] dp = new int[n];
			for(int i=0;i<n*n;i++){
				cost[i/n][i%n]=MAX;
			}
			for(int i=0;i<m;i++){
				int a = in.nextInt();
				int b = in.nextInt();
				cost[a][b]=in.nextInt();
			}	
			//			TODO 一番大きいパスを0のポイントからn-1のポイントまでの

			for(int s=1;s<n;s++){
				for(int i=0;i<=s;i++){
					if(cost[i][s]==MAX)continue;
					dp[s]=Math.max(dp[s],dp[i]+cost[i][s]);
				}
			}
			for(int s=0;s<n;s++)for(int i=0;i<n;i++){
				if(cost[s][i]==MAX)continue;
				dp[i]=Math.max(dp[s]+cost[s][i],dp[i]);
			}
			for(int i=0;i<n;i++)System.out.print(dp[i]+" ");
			System.out.println();
			System.out.println(dp[n-1]);
		}
	}
}

Measured memory_bytes: 18580
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        var N = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Array.Sort(a);
        Array.Reverse(a);
        var alice = 0;
        var bob = 0;
        for (int i = 0; i < N; i++)
            if (i % 2 == 0) alice += a[i];
            else bob += a[i];
        return alice - bob;
    }
}

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

int main(){
  string a;
 int c,d,e;
  c=0;
  cin>>a;
  for(int i=0;i<3;i++){
     if(a[i]=='1'){
   c++;
     }
  }
      cout<<c<<endl;
}


Measured memory_bytes: 256
import sys
HAND=["null","one pair","two pair","three card","straight","full house","four card"]
for line in sys.stdin.readlines():
    cards=sorted(map(int,line.strip().split(",")))
    switch=len(set(cards))
    ma=max([cards.count(i) for i in cards])
    if switch==4:print HAND[1]
    elif switch==3:
        if ma==2:print HAND[2]
        else:print HAND[3]
    elif switch==2:
        if ma==4:print HAND[6]
        else:print HAND[5]
    else:
        if cards==[1,10,11,12,13] or [cards[i+1]-cards[i] for i in xrange(4)]==[1,1,1,1]:print HAND[4]
        else:print HAND[0]

Measured memory_bytes: 23000
#include <stdio.h>


int main(void){
	
int n,d,ans=0;
	
scanf("%d %d",&n,&d);

if(d==100)d++;
printf("%d",d);

if(!n) printf("\n");
else if(n==1)printf("00\n");
else printf("0000\n");
return 0;

}



Measured memory_bytes: 128
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        for _ in range(num): return []
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list,zip(*read_all))

#################

N,K = II()
ans = 0
for b in range(K+1,N+1):
    i = math.floor((N-K)/b)
    ans += i*(b-K) + min(N-(K+i*b)+1, b-K)

if K==0:
    ans -= N-K

print(ans)

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

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

/*
    BIT: Binary Indexed Tree (1-indexed)
*/
class BIT {
    private:
        ll N;
        vector<ll> bit;

    public:
        BIT(ll n, ll initial_value);
        void add(ll i, ll x);
        ll sum(ll i);
};

BIT::BIT(ll n, ll initial_value) {
    N = n;
    bit.resize(N + 1, initial_value);
}

// i番目 (1-indexed) の要素にxを加える
void BIT::add(ll i, ll x) {
    while (i <= N) {
        bit[i] += x;
        i += i & -i;
    }
}

// 区間[1, i] (1-indexed) の要素の和を求める
ll BIT::sum(ll i) {
    ll ans = 0;
    while (i > 0) {
        ans += bit[i];
        i -= i & -i;
    }
    return ans;
}

int main() {

  int N, Q;
  cin >> N >> Q;
  vector<int> C(N + 1);
  rep(i,N) cin >> C[i + 1];
  vector<int> L(Q), R(Q);
  rep(i,Q) cin >> L[i] >> R[i];
  vector<P> query(Q);
  rep(i,Q) {
    query[i].first = R[i];
    query[i].second = L[i];
  }

  vector<int> last(N + 1, -1);
  sort(query.begin(), query.end());
  int now_r = 1;

  BIT tree(N, 0);

  map<P, ll> ans; 

  rep(i,Q) {
    while (now_r <= query[i].first) {
      if (last[C[now_r]] > 0) tree.add(last[C[now_r]], -1);
      tree.add(now_r, 1);
      last[C[now_r]] = now_r;
      now_r++;
    }
    ans[query[i]] = tree.sum(query[i].first) - tree.sum(query[i].second - 1);
  }

  rep(i,Q) cout << ans[make_pair(R[i], L[i])] << endl;
      
  return 0;
}

Measured memory_bytes: 50644
/*
ぬいぐるみの整理 (Plush Toys)
<問題>
ある JOI 関係者は，おもちゃ屋で働いている．今日は，店内にあるぬいぐるみコーナーの整理をすることになった．
ぬいぐるみコーナーの棚には，N 個のぬいぐるみが左から右に一列に並べられている．
棚は仕切りにより N 個の区画に区切られており，1 つの区画に 1 個のぬいぐるみを置く．
このおもちゃ屋は合計 M 種類のぬいぐるみを売っており，それぞれ 1 から M までの番号が付けられている．
棚に並べられた N 個のぬいぐるみは，それぞれこの M 種類のうちのいずれかである．
また，それぞれの種類のぬいぐるみは，少なくとも 1 個は存在する．
見栄えを良くするため，同じ種類のぬいぐるみが全て連続して棚に置かれるように，ぬいぐるみを並べ替えたい．
次のような方法で，ぬいぐるみを並べ替えることにした．
・N個のぬいぐるみのうちいくつかを選び，棚から取り出す．取り出さなかったぬいぐるみの位置は動かさない．
・取り出したぬいぐるみを，好きな順に棚の空いている区画に戻していく．
並べ替えた後，同じ種類のぬいぐるみが全て連続して棚に置かれていなければならない． 
並べ替えるために取り出すぬいぐるみの個数の最小値を求めるプログラムを作成せよ．
<入力>
入力は 1 + N 行からなる．
1 行目には 2 個の整数 N, M (1 ≦ N ≦ 100000,
1 ≦ M ≦ 20) が空白を区切りとして書かれており，ぬいぐるみが N 個あり，種類が M 種類あることを表す．
続く N 行のそれぞれには，1 以上 M 以下の整数が書かれている．
N 行のうちの i 行目 (1 ≦ i ≦ N) に書かれた整数は，
棚の左から i 番目の区画に置かれたぬいぐるみの種類を表す．
各種類について，少なくとも 1 個のぬいぐるみが存在していることが保証される．
*/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int p[110000];
//sum[ぬいぐるみの種類][何番目にあるか]
int sum[20][110000];
int sz[20];
int dp[1<<20];
int main(void)
{
	int a,b;cin>>a>>b;
	for(int i=0;i<a;i++){
		//並べられているぬいぐるみの数
		cin>>p[i];
		//すべての番号を1小さくする
		p[i]--;
		//人形の種類のある位置に１にする。
		sum[p[i]][i+1]=1;
		//人形の種類の数
		sz[p[i]]++;
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++){
			sum[i][j+1]+=sum[i][j];
		}
	}
	for(int i=0;i<(1<<b);i++)
	{
		dp[i]=999999999;
	}
	dp[0]=0;
	for(int i=0;i<(1<<b);i++){
		int pos=0;
		for(int j=0;j<b;j++){
			if(i&(1<<j))pos+=sz[j];
		}
		for(int j=0;j<b;j++){
			if(i&(1<<j)){
				continue;
			}
			dp[i+(1<<j)]=min(dp[i+(1<<j)],dp[i]+sz[j]-sum[j][pos+sz[j]]+sum[j][pos]);
		}
	}
	cout<<dp[(1<<b)-1]<<endl;
	return 0;
}


Measured memory_bytes: 15492
# B - ROT N
# https://atcoder.jp/contests/abc146/tasks/abc146_b

N = int(input())
S = input()

tmp = ""

for s in S:
    unicode_point = ord(s) + N

    if unicode_point > 90:
        unicode_point = 64 + (unicode_point - 90)

    tmp += chr(unicode_point)

print(tmp)

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

int main(){
  cout << fixed << setprecision(10);
  int n; cin>>n;
  vector<vector<double>> xy(n,vector<double>(2));
  rep(i,n){
    cin>>xy[i][0]>>xy[i][1];
  }
  double ans=0;
  vector<vector<double>> kyori(n,vector<double>(n,0));
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      kyori[i][j]= sqrt((xy[i][0]-xy[j][0])*(xy[i][0]-xy[j][0])+(xy[i][1]-xy[j][1])*(xy[i][1]-xy[j][1]));
      ans += kyori[i][j]*2/n;
    }
  }

  cout<<ans<<endl;
   

}


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sortA(v);
    ll ans=0;
    rep(i,k) ans+=v[i];
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------


int main(){
  string a,b,c;

  cin >> a >> b >> c;

  string ans;
  string now = "a";
  while (true) {
    if (now.at(0) == 'a') {
      if (int(a.size()) == 0) {
        ans = 'A';
        break;
      }
      now = a.at(0);
      a.erase(0, 1);
    } else if (now.at(0) == 'b') {
      if ( int(b.size()) == 0) {
        ans = 'B';
        break;
      }
      now = b.at(0);
      b.erase(0, 1);
    } else if (now.at(0) == 'c') {
      if (int(c.size()) == 0) {
        ans = 'C';
        break;
      }
      now = c.at(0);
      c.erase(0, 1);
    }
  }

  cout << ans << "\n";
}


Measured memory_bytes: 256
from itertools import product

M, D = map(int, input().split())
m_day = [(m, d) for m, d in product(range(1, M+1), range(22, D+1)) if int(str(d)[0]) >= 2 and int(str(d)[1]) >= 2 and m == int(str(d)[0]) * int(str(d)[1])]
print(len(m_day))

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = Long.parseLong(sc.next());
        long r = Long.MAX_VALUE;
        for (long a = 1; a*a <= N; a++) {
            if (N % a == 0) {
                long b = N / a;
                long m = Math.max(String.valueOf(a).length(), String.valueOf(b).length());
                r = Math.min(r,m);
            }
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 23764
n = int(input())
v = list(map(int, input().split()))
v = sorted(v)
u = []
a = 1

u.append(1/2)
u.append(1/2)

for i in range(n-2):
    if n != 2:
        a = u.pop(-1)/2
        u.append(a)
        u.append(a)

u = sorted(u)

s = 0
for i in range(len(v)):
	s += v[i]*u[i]
         
print(s)

Measured memory_bytes: 3064
n=input()
k=int(input())
counter=0
nex=0
for i in range(len(n)):
  if n[i]=='1':
    counter+=1
  else:
    nex=n[i]
    break
if nex==0:
  nex='1'
if k>counter:
  print(nex)
else:
  print(1)

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

int main() {
    int N, count = 0;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());
    
    for (int i = 0; i < N - 2; i++) {
        for (int j = N - 1; j > 1; j--) {
            int k = j - 1;
            while ((i < k) && (L.at(j) < L.at(i) + L.at(k))) {
                count++;
                k--;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
def smaller(x, y):
	if x < y: return x
	return y

nine = []
six = []
a = 9
while a <= 100000:
	nine.append(a)
	a *= 9
a = 6
while a <= 100000:
	six.append(a)
	a *= 6

dp = [0]
for i in range(1, 100001):
	min = dp[i-1]+1
	for j in range(0, len(nine)):
		if i < nine[j]: break
		min = smaller(min, dp[i-nine[j]]+1)
	for j in range(0, len(six)):
		if i < six[j]: break
		min = smaller(min, dp[i-six[j]]+1)
	dp.append(min)
print dp[int(raw_input())]

Measured memory_bytes: 38452
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#define _USE_MATH_DEFINES

#include<math.h>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int n;
	vector<int> a, b;
	
	while (true)
	{
		int ta, tb;
		scanf("%d %d", &ta, &tb);

		if (ta == 0 && tb == 0)
		{
			break;
		}
		else
		{
			a.push_back(ta);
			b.push_back(tb);
		}
	}

	for (int i = 0; i != a.size(); i++)
	{
		for (int j = 0; j < a[i]; j++)
		{
			for (int k = 0; k < b[i]; k++)
			{
				if ((j + k) % 2 == 0)
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
const int mx=(1e6)+10;
int mp[mx+10];


int main()
{
    FastRead;
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }

    int cnt=0;
    for(int i=1;i<=mx;i++)
    {
        if(mp[i])
        {
            if(mp[i]==1)cnt++;
            for(int j=i;j<=mx;j+=i)
                mp[j]=0;
        }
    }
    cout<<cnt;

}


Measured memory_bytes: 7556
# https://atcoder.jp/contests/sumitrust2019/submissions/13016562を見た

n = int(input())
s = input()
ans = 0

pin = [str(i).zfill(3) for i in range(1000)]

for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1

print(ans)


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

int main() {
int k,a,b;
cin >> k;
cin >> a >> b;

bool c = false;
for(int i=a;i<=b;i++){
    if(i%k == 0) c = true;
}
if(c == true){
 cout << "OK" << endl;
}else{
 cout << "NG" << endl;
}

return 0;

}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	int n; cin >> n;
	if (n%1000 == 0) cout << 0 << endl;
	else cout << 1000 - (n%1000) << endl;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        ll N, M;
        cin >> N >> M;
        vllvll dp(M+1, vll(1<<N, inf));
        dp[0][0] = 0;

        rep(i, 0, M) {
                ll a, b;
                cin >> a >> b;
                vll cs;
                ll c;
                rep(j, 0, b) cin >> c, cs.push_back(c-1);
                ll total = 0;
                rep(j, 0, len(cs)) total ^= (1<<cs[j]);
                
                rep(bit, 0, 1<<N) {
                        chmin(dp[i+1][bit], dp[i][bit]);
                        chmin(dp[i+1][bit | total], dp[i][bit] + a);
                }
        
        }

        if (dp[M-1][(1<<N) - 1] == inf) cout << -1 << endl;
        else cout << dp[M-1][(1<<N) - 1] << endl;
}


Measured memory_bytes: 35472
from itertools import product
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
bit = [1,-1]
su_max = 0
for i in product(bit,repeat=3):
 # print(i)
  l_1 = []
  for a,b,c in l:
    t = a*(i[0]) + b*(i[1]) + c*(i[2])
  #  print(a,b,c,t)
    l_1.append(t)
  l_1 = sorted(l_1)[::-1]
  su_max = max(su_max, sum(l_1[:m]))
print(su_max)

Measured memory_bytes: 9136
N = int(input())
a = list(map(int, input().split(" ")))
b=a
b.sort()

flag = True
s =0
e =N-1
for i in range(N-1):
    if b[i] == b[i+1]:
        flag = False
        break
        



if flag:
    print("YES")

else:
    print("NO")

    
    



    

Measured memory_bytes: 26804
A = int(input())
T = list(map(int,input().split()))
D = int(input())
defo = []
for _ in range(D):
  defo = T
  a,p = map(int,input().split())
  q = T[a-1] -p
  s = sum(defo)
  s = s-q
  print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl

int main() {
  ll X, a;
  ci(X);
    a += (X / 500) * 1000;
    a += (X % 500) / 5 * 5;
  co(a);
}  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn=1e5+100;
int n,m;
struct node{
    int p,y,id;
}point[maxn];
int g[maxn],vis[maxn];
bool cmp(node a,node b){
    return a.y<b.y;
}
int rev(int num){
    int cnt=0;
    if(num==0) return 1;
    while(num){
        cnt++;
        num/=10;
    }
    return cnt;
}
vector<int>v[maxn];
int search(int id,int num){
    int l=0,r=v[id].size()-1;
    while(l<=r){
        int mid=(l+r)/2;
        if(num<v[id][mid]){
            r=mid-1;
        }else if(num>v[id][mid]){
            l=mid+1;
        }else{
            return mid+1;
        }
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&point[i].p,&point[i].y);
        point[i].id=i;
    }
    sort(point+1,point+1+m,cmp);
    for(int i=1;i<=m;i++){
        g[point[i].id]=i;
        v[point[i].p].push_back(point[i].y);
    }
    for(int i=1;i<=m;i++){
        int num=g[i];
       // int str2=search(num,point[num].y);
        int str1=point[num].p;
        int str2=search(str1,point[num].y);
        //int str2=vis[point[num].p];
        int len1=rev(str1);
        int len2=rev(str2);
        if(len1<6){
            for(int j=0;j<6-len1;j++) printf("0");
        }
        printf("%d",str1);
        if(len2<6){
            for(int j=0;j<6-len2;j++) printf("0");
        }
        printf("%d\n",str2);
    }
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();
#define MOD 1000000007

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
bool chmax(T &m, const T q)
{
    if (m < q)
    {
        m = q;
        return true;
    }
    else
        return false;
}
template <typename T>
bool chmin(T &m, const T q)
{
    if (m > q)
    {
        m = q;
        return true;
    }
    else
        return false;
}

void solve()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    // cin.ignore();

    vector<vector<int>> s(H, vector<int>(W));
    rep(i, H) rep(j, W) s[i][j] = S[i][j] - '0';

    int ans = (H - 1) * (W - 1);
    rep(a, 1 << (H - 1))
    {
        int ncut = __builtin_popcount(a);
        int ans_a = ncut;
        const int h = ncut + 1;

        vector<vector<int>> bigs(h, vector<int>(W, 0));
        int ii = 0;
        rep(i, H)
        {
            rep(j, W)
                bigs[ii][j] += s[i][j];
            if ((a >> i) & 1)
                ii++;
        }

        bool is_impossible = false;
        vector<int> bigk(h, 0);
        rep(j, W)
        {
            bool is_ok = true;
            rep(ii, h)
            {
                if (bigs[ii][j] > K)
                {
                    is_impossible = true;
                    break;
                }
                if (bigk[ii] + bigs[ii][j] > K)
                {
                    is_ok = false;
                    break;
                }
            }

            if (is_impossible)
            {
                continue;
                // cout << "impossible" << endl;
                // cout << endl;
                // cin.ignore();
            }

            if (!is_ok)
            {
                ans_a++;
                bigk.clear();
                bigk.resize(h, 0);
            }
            rep(ii, h) bigk[ii] += bigs[ii][j];

            // cout << endl;
            // cout << "bigs: " << endl;
            // rep(ii, h)
            // {
            //     rep(jj, W) cout << bigs[ii][jj];
            //     cout << endl;
            // }
            // rep(jj, W)
            // {
            //     cout << (jj != j ? ' ' : '!');
            // }
            // cout << endl;
            // cout << "ans_a: " << ans_a << endl;
            // cout << "bigk: " << endl;
            // rep(ii, h)
            // {
            //     cout << bigk[ii] << endl;
            // }
            // cin.ignore();
        }
        if (is_impossible)
            continue;

        chmin(ans, ans_a);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 384
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define int long long
    # define mo 1000000007
    using namespace std;
    #define goku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
     bool ch(int x)
     {
         for(int i=2;i*i<=x;i++)
         {
             //cout<<i<<" ";
             if(x%i==0)
             {
                 return false;
             }
         }
         return true;
     }
    signed main(){
        goku
    int x;
    cin>>x;
    while(1)
    {
        if(ch(x))
        {
            cout<<x;
            break;
        }
        x++;
    }
       return 0;
    }


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: usize);
    let mut p = 0;
    for i in 1.. {
        if i * (i - 1) / 2 == n {
            p = i;
            break;
        }
        if i * (i - 1) / 2 > n {
            break;
        }
    }
    if p == 0 {
        println!("No");
        return;
    }

    let mut groups = vec![];
    for i in 0..p {
        for j in (i + 1)..p {
            groups.push((i, j));
        }
    }

    assert_eq!(groups.len(), n);
    let mut ans = vec![vec![]; p];
    for (i, &(x, y)) in groups.iter().enumerate() {
        ans[x].push(i);
        ans[y].push(i);
    }

    println!("Yes");
    println!("{}", ans.len());
    for ans in ans.iter() {
        print!("{}", ans.len());
        for &ans in ans.iter() {
            print!(" {}", ans + 1);
        }
        println!();
    }
}


Measured memory_bytes: 9596