akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> a;
int d,n,m;

int main()
{
	while(1){
	scanf("%d",&d);
	if(d == 0){
		break;
	}
	a.clear();
	scanf("%d%d",&n,&m);
	rep(i,n-1){
		int x;
		scanf("%d",&x);
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	a.push_back(d);
	ll ans = 0;
	rep(i,m){
		int x;
		scanf("%d",&x);
		vector<int>::iterator it = lower_bound(a.begin(),a.end(),x);
		if(*it == x){
			continue;
		}
		ans += min(x-*(it-1),*it-x);
	}
	printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3580
#C - こだわり者いろはちゃん

#input N K
N,K = list(map(int,input().split()))

#input D1 ~ Dk as set D
D = set(map(int,input().split()))

while True:
  #整数Nの桁に含まれる整数の集合 set digit_set
  digit_set = set(map(int,str(N)))
  #共通部分が空
  if len(D & digit_set) == 0 :
    break
  N += 1

print(N)


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

using namespace std;
int n,m;
long long d[101][100001];
struct things{
    long long a,b;
};
things a[101];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i].a>>a[i].b;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            d[i][j]=d[i-1][j];
            if(j<a[i].a)
                continue;
            d[i][j]=max(d[i][j],d[i-1][j-a[i].a]+a[i].b);
        }
    }
    cout<<d[n][m];
    return 0;
}


Measured memory_bytes: 78336
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        HashSet<Integer> hs = new HashSet<Integer>();
        hs.add(sc.nextInt());
        hs.add(sc.nextInt());
        hs.add(sc.nextInt());
        if(hs.size() == 2){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

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

int ice[14][14];
int num[10000];
int gx,gy;

int ans = 0;
int ccc = 0;
void dfs(int x,int y,int C,int px,int py){
  if( c[y][x] == '#' || c[y][x] == '*') return;
  if( C + abs(x-gx) + abs(y-gy) >= ans ) return;
  if( c[y][x] == 'G'){ans = C; return; }

  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( px == tx && ty == py ) continue;
    if( c[ty][tx] == '*' ) return;
  }
  char cur = c[y][x];
  c[y][x] = '*';
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( c[ty][tx] == 'X' ){
      int b = ice[ty][tx];
      if( num[b] > 0 ){
	num[b]--;
	dfs(tx,ty,C+1,x,y);
	num[b]++;
      }
    }else{
      dfs(tx,ty,C+1,x,y);
    }
  }
  c[y][x] = cur;
  return;
}
void grouping(int x,int y,int k){
  ice[y][x] = k;
  num[k]++;
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( c[ty][tx] == 'X' && ice[ty][tx] < 0 )grouping(tx,ty,k);
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  int W,H;
  while(cin >> W >> H && W){
    rep(i,14)rep(j,14) ice[i][j] = -1;
    rep(i,14)rep(j,14) 
      c[i][j] = '#';
    int sx , sy;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> c[i+1][j+1];
	if(c[i+1][j+1] == 'S'){
	  c[i+1][j+1] = '.';
	  sx = j+1 , sy = i+1;
	}else if(c[i+1][j+1] == 'G' ){
	  gx = j+1 , gy = i+1;
	}
      }
    }
    int k = 0;
    for(int i = 1 ; i <= H ; i++){
      for(int j = 1 ; j <= W ; j++){
	if( c[i][j] == 'X' && ice[i][j] < 0){
	  num[k] = 0;
	  grouping(j,i,k);
	  num[k] /= 2;
	  k++;
	}
      }
    }
    ans = 1e7;
    dfs(sx,sy,0,-1,-1);
    cout << ans << endl;
    
  }
}

Measured memory_bytes: 1200
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const ll INF=1000000000000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	int a[2][102];
	scanf("%d",&n);
	rep(i,2)rep(j,n)scanf("%d",&a[i][j]);
	
	int ret = 0;
	rep(i,n){
		int sum = 0;
		for(int j = 0 ; j <= i ; j ++)sum += a[0][j];
		for(int j = i ; j < n ; j ++)sum += a[1][j];
		ret = max(ret,sum);
	}
	
	printf("%d\n",ret);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){
  int m;
  cin >> m;
  if(m%1000%111 == 0 || (m - m%10)%111 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int n,sum=0,max=0;
char wtf;
int main(){
	scanf("%d ",&n);
		
	for(int i=1;i<=n;i++){
		scanf("%c",&wtf);
		if(wtf=='I'){
			sum=sum+1;

		}
		else if(wtf=='D'){
			sum=sum-1;

		}
		if(sum>max)
			max=sum;
	}
	printf("%d",max);
}

Measured memory_bytes: 128
a, b = map(int, input().split())
lst = [4, 6, 9, 11]
lst2 = [1, 3, 5, 7, 8, 10, 12]
if a==b==2:
  print('Yes')
elif a in lst and b in lst:
  print('Yes')
elif a in lst2 and b in lst2:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}

bool pairCompare(const pair<Int,Int>& firstElof, const pair<Int,Int>& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main() {
    int N;
    cin >> N;
    vector<pair<Int,Int>> XY = vector<pair<Int,Int>>(N);

    rep(i,N){
        Int a, b;
        cin >>a >> b;
        XY[i].first = a;
        XY[i].second = b;
    }
    vector<pair<Int,Int>> Xsorted  = XY;
    vector<pair<Int,Int>> Ysorted  = XY;

    sort(Xsorted.begin(), Xsorted.end());
    sort(Ysorted.begin(), Ysorted.end(), pairCompare);

    int xcostmin = 99999;

    map<string,int> xmp;
    int key_max =0;
    rep(i,N){
        rep(j,N){
            if(i==j) {
                continue;
            }
            Int p, q;
            p = Xsorted[i].first - Xsorted[j].first;
            q = Xsorted[i].second - Xsorted[j].second;
            string diff;
            diff = to_string(p)+","+to_string(q);
            xmp[diff]++;
        }
    }

    for(auto itr = xmp.begin(); itr != xmp.end(); itr++){
        key_max = max(key_max, xmp[itr->first]);
    }


    cout << N-key_max << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer n = sc.nextInt();
		int i = n % 10;

		if (i == 2 || i == 4 || i == 5 || i == 7 || i == 9) {
			System.out.println("hon");
		} else if (i == 0 || i == 1 || i == 6 || i == 8) {
			System.out.println("pon");
		} else {
			System.out.println("bon");
		}
	}
}

Measured memory_bytes: 35632
#include<iostream>
#include<algorithm>
using namespace std;
void kanpsack(int a[][2],int n,int w){
	long long int knap[n][w+1];
	for(int i=0;i<=w;i++){
		if(i<a[0][0])
		knap[0][i]=0;
		else
		knap[0][i]=(long long int)a[0][1];
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<=w;j++){
			if(j<a[i][0])
			knap[i][j]=knap[i-1][j];
			else
			knap[i][j]=max(knap[i-1][j],knap[i-1][j-a[i][0]]+(long long int)a[i][1]);
		}
	}
	cout<<knap[n-1][w]<<endl;
}
int main(){
	int n,w;cin>>n>>w;
	int a[n][2];
	for(int i=0;i<n;i++)
	cin>>a[i][0]>>a[i][1];
	kanpsack(a,n,w);
}

Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////
bool cmp(vector<ll> a, vector<ll> b) {
	rep(j, 4) {
		if (a[j] < b[j]) { return true; }
		if (a[j] > b[j]) { return false; }
	}
	return false;
}

ll com(ll a, ll b) {
	if (a < b) { return 0; }

	ll ret = 1;
	for (ll i = a; i >= a - b + 1; i--)ret *= i;
	
	return ret;
}

vector<ll> rotate(vector<ll> s, ll j) {
	vector<ll> ret(4);

	rep(i, 4) { ret[i] = s[(i + j) % 4]; }
	
	return ret;
}

vector<ll> normalize(vector<ll> s) {
	vector<ll> ret = s;

	rep(i, 4) { if (cmp(rotate(s, i), ret)) { ret = rotate(s, i); } }

	return ret;
}


int main() {
	ll N;
	cin >> N;

	mint dp[63][3] = {};

	dp[62][0] = 1;

	for (ll i = 61; i >= 0; i--) {
		rep(j, 3) {
			ll k = j * 2 + ((N >> i) & 1);
			//cout << i<<j<<k << endl;
			dp[i][min(k, 2)] += dp[i + 1][j];
			if (k > 0) { dp[i][min(k - 1, 2)] += dp[i + 1][j]; }
			if (k > 1) { dp[i][min(k - 2, 2)] += dp[i + 1][j]; }

		}

		//rep(j, 3) cout << i<<" "<<j<<" "<<dp[i][j] << endl;
	}

	mint ans = 0;
	rep(j, 3) ans += dp[0][j];

	cout << ans << endl;
	
}


Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  console.log(buildMaxHeap(arr).reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 140176
import math

n, k = map(int, input().split())
result = 0
for first_dice in range(1, n + 1):
    front_count = max(math.ceil(math.log(k / first_dice, 2)), 0)
    result += (1 / n) * (1 / 2) ** front_count

print(float(result))


Measured memory_bytes: 2940
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


dhl = [-1, 1]
dw = [(0, 1), (0, -1)]


def getNeighbor(h, w):
    # print(h, w)
    if h < H - 1 and vertical[h][w] == 0:
        yield (h + 1, w)
    if h > 0 and vertical[h - 1][w] == 0:
        yield (h - 1, w)
    if w > 0 and horizon[h][w - 1] == 0:
        yield (h, w - 1)
    if w < W - 1 and horizon[h][w] == 0:
        yield (h, w + 1)


def solve():
    mp = [[0] * W for _ in range(H)]
    Q = deque()
    Q.append((0, 0))
    while Q:
        # print(Q)
        nh, nw = Q.popleft()
        for h, w in getNeighbor(nh, nw):
            if mp[h][w] == 0:
                mp[h][w] = mp[nh][nw] + 1
                Q.append((h, w))

    return 0 if mp[H - 1][W - 1] == 0 else mp[H - 1][W - 1] + 1


ans = []
while True:
    W, H = inpl()
    if W == H == 0:
        break
    horizon = []
    vertical = []
    for _ in range(H - 1):
        horizon.append(inpl())
        vertical.append(inpl())
    horizon.append(inpl())
    ans.append(solve())

for a in ans:
    print(a)



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

int main(){
    string S;
    cin >> S;
    if(S == "ABC"){
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}


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

int main(){
    ll i,n;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
    }
    ll mx=arr[0],sum=0;
    for(i=1;i<n;i++){
        mx=max(mx,arr[i]);
        if(arr[i]<mx)sum+=(mx-arr[i]);
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 5188
N, M = map(int,input().split())
C = [[] for i in range(N)]
for i in range(M):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  C[a].append(b)
  C[b].append(a)
visited = [0]*N
ans = 0
def dfs(x):
  global ans
  visited[x] = 1  
  if all(visited):
    ans += 1
    return
  for i in C[x]:
    if visited[i] == 0:
      dfs(i)
      visited[i] = 0
  return
dfs(0)
print(ans)

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

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  int n=0;
  for(int i=1;i<=a;i++){
    if(a%i==0 && b%i==0){
      n++;
    }
  }
  n-=k-1;
  int y=0;
  for(int i=1;i<=a;i++){
    if(a%i==0 && b%i==0){
      y++;
      if(y==n) cout<<i<<endl;
    }
  }
      
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w, k; cin >> h >> w >> k;
  vector<string> s(h); REP(i, h) cin >> s[i];
  int ans = INF;
  REP(i, 1 << (h - 1)) {
    int m = __builtin_popcount(i) + 1;
    vector<int> mem(h);
    int now = 0;
    REP(j, h) {
      mem[j] = now;
      if (i >> j & 1) ++now;
    }
    int cnt = m - 1;
    vector<int> group(m, 0);
    bool ok = true;
    REP(x, w) {
      REP(y, h) group[mem[y]] += s[y][x] == '1';
      bool cut = false;
      REP(j, m) cut |= group[j] > k;
      if (cut) {
        ++cnt;
        fill(ALL(group), 0);
        REP(y, h) group[mem[y]] += s[y][x] == '1';
        REP(j, m) ok &= group[j] <= k;
      }
    }
    if (ok) chmin(ans, cnt);
  }
  cout << ans << '\n';
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  string Alfabet = "abcdefghijklmnopqrstuvwxyz";
  int length = (int)(S.size());
  int s[26] = {};
  bool flag = false;

  for(int i=0; i<length; ++i)
    ++s[S[i]-'a'];

  for(int i=0; i<26; ++i) {
    if(s[i]==0 && flag == false) {
      cout << Alfabet[i] << endl;
      flag = true;
    }
  }

  if(!flag) cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define reset(N) memset(N,0,sizeof(N))
#define clear(N) while(N.size()>0) N.pop()
#define f(a,v,b) for(int a=v;a<b;a++)
#define cb(N) __builtin_popcount(N)
#define cbl(N) __builtin_popcountl(N)
#define cbll(N) __builtin_popcountll(N)
using namespace std;
int n,k;
int h[100001];
int dp[100001];
void solve(){
	cin>>n;
	f(i,0,n){
		cin>>h[i];
	}
	dp[1]=dp[0]+abs(h[0]-h[1]);
	f(i,2,n){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
#define double long long
using namespace std;
signed main() {
	int H, N;
	cin >> H >> N;
	int ans = 0;
	bool X = false;

	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		ans += A[i];
		if (ans >= H) {
			X = true;
		}
	}
	if (X == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 4060
import std.stdio, std.string, std.conv, std.algorithm, std.range;

enum po = cast(ulong)1_000_000_007;

int[] factorize(int n) {
    auto c = 2;
    auto res = new int[0];
    while (c <= n) {
        if (n % c == 0) {
            res ~= c;
            n /= c;
            continue;
        }
        c++;
    }
    if (n > 1) res ~= n;
    return res;
};

void main() {
    auto N = readln.chomp.to!int;
    auto primes = new int[0];
    if (N == 1) {
        writeln(1);
        return;
    }
    foreach (i; 2..N+1) {
        primes ~= factorize(i);
    }
    primes.sort().group.map!(a => cast(ulong)(a[1]+1)).reduce!((a,b) => a * b % po).writeln;
}

Measured memory_bytes: 256
N=int(input())
suits=["S","H","C","D"]
cards=[]
for _ in range(N):
    s,n=input().split()
    if s=="S":
        cards.append(int(n))
    elif s=="H":
        cards.append(13+int(n))
    elif s=="C":
        cards.append(26+int(n))
    else:
        cards.append(39+int(n))
        
for i in range(1,53):
    if i not in cards:
        print(suits[(i-1)//13],(i-1)%13+1)
        


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

typedef long long ll;

ll N, A, B;
vector<ll> H;

bool check(ll k) {
  ll x = 0;
  for (ll h : H) x += (max(h - B * k, 0ll) + (A - B) - 1) / (A - B);
  return x <= k;
}
int main() {
  cin >> N >> A >> B;
  H.resize(N);
  for (ll i = 0; i < N; ++i) cin >> H[i];
  ll ng = 0, ok = 1e9;
  while (ok - ng >= 2) {
    ll mid = (ok + ng) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	char s[10];
	scanf("%s",s);
	int i,a=0,b=0;
	for(i=0;s[i]!='\0';i++){
		if('A'<=s[i]&&s[i]<='Z'){a++;}
		if(s[i]=='C'){b+=1<i&&s[i+1]!='\0';}
	}
	printf(s[0]=='A'&&a==2&&b==1?"AC":"WA");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514];
int ans[114514];
signed main(){
	ic(n) ic(k)
	rep(0,i,n)cin>>a[i];
	ans[0]=0;
	int sum=0;
	rep(1,i,n)ans[i]=mod;
	rep(1,i,n){
		rep(0,j,min(k,i)+1){
		sum=ans[i-j]+abs(a[i]-a[i-j]);
		if(sum<ans[i])ans[i]=sum;
		sum=0;
		}	
	}	
	c(ans[n-1])
}                               	                                         

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int k = sc.nextInt();

            int max = Math.max(Math.max(a, b), c);
            int ans = max;
            for (int i = 0; i < k; i++) {
                ans *= 2;
            }

            ans += (a + b + c) - max;

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 21716
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <cmath>
#include <utility>
#include <vector>
using namespace std;
using W = double;
using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;
using Poly = vector<P>;
#define X real()
#define Y imag()
const W EPS = (1e-10);

vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second;
  W t = (ra*ra-rb*rb+d*d)/2/d, h = sqrt(ra*ra-t*t);
  P m = t/abs(cb-ca)*(cb-ca)+ca;
  vector<P> cp(2,m);
  P n = (ca-cb)*P(0,1);
  n *= h/abs(n);
  cp[0] -= n;
  cp[1] += n;
  return cp;
}

bool is_cross(const C &A, const C &B){
  W d = abs(A.first-B.first);
  return A.second+B.second >= d and abs(A.second-B.second) <= d;
}

int main(){
  int N;
  while(cin >> N, N){
    vector<W> V(N);
    vector<P> S;
    for(int i = 0; i < N; ++i){
      W x, y;
      cin >> x >> y >> V[i];
      S.emplace_back(x,y);
    }
    W ng = 0, ok = 1e9;
    for(int tmp = 0; tmp < 100; ++tmp){
      W t = (ok+ng)/2;
      vector<P> cps = S;
      for(int i = 0; i < N; ++i){
        for(int j = 0; j < i; ++j){
          C ci = C(S[i],V[i]*t), cj = C(S[j],V[j]*t);
          if(not is_cross(ci,cj))
            continue;
          vector<P> c = cpcc(ci,cj);
          cps.push_back(c[0]);
          cps.push_back(c[1]);
        }
      }
      bool g = false;
      for(auto p : cps){
        bool f = true;
        for(int i = 0; i < N; ++i){
          if(abs(p-S[i]) <= V[i]*t+EPS)
            continue;
          f = false;
          break;
        }
        if(not f) continue;
        g = true;
        break;
      }
      if(g){
        ok = t;
      }else{
        ng = t;
      }
    }
    printf("%.12f\n",(ok+ng)/2);
  }
}



Measured memory_bytes: 3336
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	vector<char>al(26);
	al = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
	vector<char>AL(26);
	AL = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
	vector<char>NUM(10);
	rep(i, N) {
		if (i == K - 1) {
			rep(j, 26) {
				if (S[i] == AL[j]) {
					cout << al[j];
				}
			}
		}
		else {
			cout << S[i];
		}
	}
	cout << endl;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll h,w;cin>>h>>w;
  char s[h][w];rep(i,0,h)rep(j,0,w)cin>>s[i][j];
  ll check[h][w];CLR(check,false);
  bool b[h][w];CLR(b,false);

  ll ma=h+w-1;
  ll inf=1000000;

  ll dx[2]={1,0};
  ll dy[2]={0,1};

  rep(i,0,h){
    rep(j,0,w){
      if(s[i][j]=='#'&&!check[i][j]){
        if(i==h-1&&j==w-1){b[i][j]=true;check[i][j]=true;}
        else if(i==h-1){
          rep(jc,j,w){
            if(check[i][jc])break;
            bool k=false;
            if(IN(0,w,jc+1)&&s[i][jc+1]=='#')k=true;
            check[i][jc]=true;
            if(!k){
              b[i][jc]=true;
              break;
            }
          }
        }
        else if(j==w-1){
          rep(ic,i,h){
            if(check[ic][j])break;
            bool k=false;
            if(IN(0,h,ic+1)&&s[ic+1][j]=='#')k=true;
            check[ic][j]=true;
            if(!k){
              b[ic][j]=true;
              break;
            }
          }

        }
        else{
          ll d=w;
          // out(i<<":"<<j);
          rep(ic,i,h){
          if(s[ic][j]=='.')break;
          rep(jc,j,d){
          // rep(jc,j,w){
            if(check[ic][jc]||s[ic][jc]=='.')break;
            bool jk=false;
            // ll k=-1;
            if(IN(0,d,jc+1)){
              if(s[ic][jc+1]=='.')jk=true;
            }else jk=true;

            bool ik=false;
            if(IN(0,h,ic+1)){
              if(s[ic+1][jc]=='.')ik=true;
            }else ik=true;

            if(s[ic][jc]=='#')check[ic][jc]=true;
            if(jk){chmin(d,jc+1);}
            if(jk&&ik){b[ic][jc]=true;break;}

          }
        }
        }
      }
    }
  }

  ll ans[h][w];CLR(ans,0);
  if(b[0][0])ans[0][0]=1;
  else {
    if(check[0][0])ans[0][0]=1;
    else ans[0][0]=0;
  }

  rep(i,1,h){
    bool e=false;
    if(check[i][0])e=true;

    ans[i][0]=ans[i-1][0];

    if(s[i-1][0]=='.'){
      if(e)ans[i][0]++;
    }
    else{
      if(b[i-1][0]){
        if(e)ans[i][0]++;
      }
    }
  }
  rep(j,1,w){
    bool e=false;
    if(check[0][j])e=true;

    ans[0][j]=ans[0][j-1];

    if(s[0][j-1]=='.'){
      if(e)ans[0][j]++;
    }
    else{
      if(b[0][j-1]){
        if(e)ans[0][j]++;
      }
    }
  }

  rep(i,1,h){
    rep(j,1,w){
      if(check[i][j]){
        ll a=ans[i-1][j],b=ans[i][j-1];

        if(!check[i-1][j])a++;
        if(!check[i][j-1])b++;

        ans[i][j]+=min(a,b);

      }
      else ans[i][j]+=min(ans[i-1][j],ans[i][j-1]);
    }
  }
  out(ans[h-1][w-1]);




  return 0;
}


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

pair <pair<string, int>, int> p[110];
char in[120];

int main(){
    int a; cin >> a;
    for(int i = 0; i < a; i++){
       int t; cin >> in >> t;
       string tmp = in;
       p[i] = make_pair(make_pair(in,-t),i);
    }
    
    sort(p, p+a);
    for(int i= 0; i < a; i++) cout << p[i].second + 1 << endl;
}

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

using namespace std;

int main() {
    while (true) {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        cout << min(x, y) << " " << max(x, y) << '\n';
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
int main(void)
{
  int test = 1;
  int i,j,k,l;
  int n;
  int min = INT_MAX;
  int rep = INT_MIN;
  static int a[200005];
  scanf("%d",&n);
  rep(i,n) {
    scanf("%d",&a[i]);
    if(a[i] - min > rep) rep = a[i] - min;
    if(min > a[i]) min = a[i];
  }
  printf("%d\n",rep);
  return 0;
}

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

__int128 lmodpower(__int128 a, __int128 r, __int128 mod){ //a^r
    __int128 x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

__int128 lmodinv(__int128 a, __int128 mod){
    return lmodpower(a, mod-2, mod);
}

vector<__int128> eval(vector<__int128> &A, __int128 x, int depth, int K, int c, __int128 mod) {
    if (depth == K) {
        if (c < (int)A.size()) return {A[c]};
        else return {0};
    }
    __int128 xx = x*x%mod;
    vector<__int128> even = eval(A, xx, depth+1, K, c, mod);
    vector<__int128> odd = eval(A, xx, depth+1, K, c + (1<<depth), mod);
    vector<__int128> res(1<<(K-depth));
    __int128 y = 1;
    for (int i = 0; i < (1<<(K-depth-1)); i++) {
        __int128 f1 = even[i], f2 = y*odd[i]%mod;
        res[i] = f1+f2;
        if (res[i] >= mod) res[i] -= mod;
        int im = i+(1<<(K-depth-1));
        res[im] = f1-f2;
        if (res[im] < mod) res[im] += mod;
        y = y*x%mod;
    }
    return res;
}


vector<ll> FFT(vector<__int128> &A, vector<__int128> &B) {
    int d = A.size()+B.size()-1;
    int K = 1;
    while ((1<<K) < d) K++;
    __int128 lmod = 59785854321;
    lmod <<= 24;
    lmod += 1;
    __int128 proot = lmodpower(7, (__int128)59785854321<<(24-K), lmod);
    __int128 m = lmodinv(1<<K, lmod);
    
    vector<__int128> eval_a = eval(A, proot, 0, K, 0, lmod);
    vector<__int128> eval_b = eval(B, proot, 0, K, 0, lmod);
    vector<__int128> mul(1<<K, 0);
    for (int i = 0; i < (1<<K); i++) {
        mul[i] = eval_a[i]*eval_b[i]%lmod;
    }

    vector<__int128> lres = eval(mul, lmodinv(proot, lmod), 0, K, 0, lmod);
    for (int i = 0; i < (1<<K); i++) {
        lres[i] = lres[i] * m % lmod;
    }
    
    vector<ll> res(1<<K);
    ll mask = (1LL<<62)-1;
    for (int i = 0; i < (1<<K); i++) res[i] = (ll)(lres[i]&mask);
    return res;
}

int main() {
    int N;
    cin >> N;
    ll mod = 200003;
    vector<int> A(N, 0), B(mod, 0);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        B[A[i]]++;
    }
    
    ll g = 1;
    vector<__int128> cnt(mod, 0);
    for (int i = 0; i < mod-1; i++) {
        cnt[i] = B[g];
        g *= 2;
        g %= mod;
    }
    
    vector<ll> fft = FFT(cnt, cnt);
    g = 1;
    ll ans = 0;
    for (int i = 0; i < N; i++) ans -= ((ll)A[i]*A[i])%mod;
    for (int i = 0; i < (int)fft.size(); i++) {
        ans += fft[i]*g;
        g *= 2;
        g %= mod;
    }
    ans /= 2;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 57116
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        cin = new Scanner();
        long[] xyzk = cin.ArrayLong(4);
        long[][] abc = new long[3][];
        
        for(int a = 0; a < abc.Length; a++)
        {
            abc[a]= cin.ArrayLong((int)xyzk[a]);
        }
        List<long> ab = new List<long>();
        for(int a = 0; a < xyzk[0]; a++)
        {
            for(int b = 0; b < xyzk[1]; b++)
            {
                ab.Add(abc[0][a]+abc[1][b]);
            }
        }
        Array.Sort(abc[2]);
        Array.Reverse(abc[2]);
        ab.Sort();
        ab.Reverse();
        List<long> abc2 = new List<long>();
        for (int a = 0; a < xyzk[2]; a++)
        {
            for (int b = 0; b < Math.Min((int)Math.Ceiling((double)xyzk[3]/(a+1)), ab.Capacity); b++)
            {
                abc2.Add(ab[b] + abc[2][a]);
            }
        }
        abc2.Sort();
        abc2.Reverse();
        for(int a = 0; a < xyzk[3]; a++)
        {
            Console.WriteLine(abc2[a]);
        }
        
        Console.ReadLine();

    }
}
























class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 29792
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt)
    val b = readLine()!!.split(" ").map(String::toInt)
    val c = readLine()!!.split(" ").map(String::toInt)

    var ans = b.sum()
    for(i in 0..n-2){
        if(a[i] + 1 == a[i+1]){
            ans += c[a[i] - 1]
        }
    }

    println(ans)
}

Measured memory_bytes: 37776
// A Dynamic Programming based 
// solution for 0-1 Knapsack problem 
#include <stdio.h> 
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
// A utility function that returns 
// maximum of two integers 


// Returns the maximum value that 
// can be put in a knapsack of capacity W 
ll knapSack(ll W, ll wt[], ll val[], ll n) 
{ 
	ll i, w; 
	ll K[n + 1][W + 1]; 

	// Build table K[][] in bottom up manner 
	for (i = 0; i <= n; i++) { 
		for (w = 0; w <= W; w++) { 
			if (i == 0 || w == 0) 
				K[i][w] = 0; 
			else if (wt[i - 1] <= w) 
				K[i][w] = max( 
					val[i - 1] + K[i - 1][w - wt[i - 1]], 
					K[i - 1][w]); 
			else
				K[i][w] = K[i - 1][w]; 
		} 
	} 

	return K[n][W]; 
} 

int main() 
{ 
    ll n,W;
    cin>>n>>W;
    ll wt[n],val[n];
    for(ll i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
    }
	cout<<knapSack(W, wt, val, n); 
	return 0; 
} 


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll s = 0;
    forn(n) {
        cin >> v[i];
        s ^= v[i];
    }
    forn(n) {
        cout << (s ^ v[i]) << ' ';
    }
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 4772
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int L = scanner.nextInt();
		ArrayList<String> S = new ArrayList<String>();
		for(int i = 0; i <= N; i++) {
			S.add(scanner.nextLine());
		}
		scanner.close();

		Collections.sort(S);

		for(String str: S) {
			System.out.print(str);
		}

		System.out.println();

	}

}


Measured memory_bytes: 36200
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
if n==1 or d[0]!=0:
    ans=0
d=sorted(d)
for j in range(0,n-1):
        if d[j+1]-d[j]>1:
            ans=0
            break
        
if d[0]!=0 or d[1]==0:
    ans=0
else:
    for i in range(1,n-1):
        if d[i]==d[i+1]:
            a+=1
        else:
            ans=ans*(b**a)
            b=a
            a=1
ans=ans*(b**a)
ans=ans%998244353
print(ans)

Measured memory_bytes: 53676
#include "bits/stdc++.h"

using namespace std;


int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        
        int ans=a%b;
        if(ans==0)cout<<b<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
# Knapsack 1
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]
for n in range(N):
    for w in range(W + 1):
        if wv[n][0] <= w:
            dp[n+1][w] = max(dp[n][w], dp[n][w - wv[n][0]] + wv[n][1])
        else:
            dp[n+1][w] = dp[n][w]
print(dp[N][W])

Measured memory_bytes: 172868
def main():
    N = int(input())
    S = input()
    max_count = 0
    for i in range(N-1):
        Aset = set(list(S[:i+1]))
        Bset = set(list(S[i+1:]))
        max_count = max(max_count, len(Aset & Bset))
    return max_count



if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
 long long a[10001],n,m,i;
 long long s=0;
 cin>>n>>m;
 for (i=1;i<=m;i++)
 {
     cin>>a[i];
     s+=a[i];
 }
 if(s>n) cout<<-1;
 else cout<<n-s;
 return 0;
}


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

void solve(long long N, std::vector<long long> s){
    ll sum = 0;
    for(ll i=0; i< N; i++ ) sum+= s[i];
    vector<vll> dp(N+1, vll(sum+1, 0));
    for(ll i=0; i<=N; i++){
        dp[i][0] = 1;
    }
    for(ll i=0; i< N; i++){
        for(ll j=1; j<= sum; j++){
            if(dp[i][j])
                dp[i+1][j] = 1;
            if(j-s[i]>=0 && dp[i][j-s[i]])
                dp[i+1][j] = 1;
        }
    }

    for(ll j=sum; j>=0; j--){
        if(dp[N][j] && j%10 != 0) {
            cout << j << endl;
            return;
        }
    }
    cout << 0 << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> s(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&s[i]);
    }
    solve(N, std::move(s));
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



int main() {
  ll n;
  cin >> n ;



  vector<ll> u(n - 1, 0);
  vector<ll> v(n - 1, 0);
  vector<ll> w(n - 1, 0);

  for (int i = 0; i < n - 1; i++) {
    cin >> u[i] >> v[i] >> w[i];
    u[i]--;
    v[i]--;
  }

  ll ans = 0;

  // vector<vector<ll>> nmap(n);
  vector<vector<pair<ll,bool>>> nmap(n);
  // vector<vector<bool>> distmap(n,vector<bool>(n,LINF));//偶数ならtrue


  for (int i = 0; i < n - 1; i++) {
    nmap[u[i]].push_back( make_pair( v[i], (w[i]%2 == 0)) );
    nmap[v[i]].push_back(  make_pair( u[i], (w[i]%2 == 0))  );
  }




  ll startnode = 0;

  for (int i = 0; i < n; i++) {
    if (nmap[i].size() == 1){
      startnode = i;
      break;
    }
  }


  cerr << startnode <<endl;
  // for(auto v:nmap[startnode]){
  //   cerr << v <<endl;
  // }



  vector<bool> root_dist(n,false);
  vector<bool> reachmap(n,false);



  vector<ll> searchNode;
  searchNode.push_back(startnode);
  root_dist[startnode] = true;
  reachmap[startnode] = true;
 


  while(searchNode.size() > 0){
    ll from_node = searchNode[searchNode.size()-1];

    searchNode.pop_back();
    for(auto v:nmap[from_node]){
      if (reachmap[v.first] == true)continue;

      // if (distmap[from_node][v]  == true  ){
      if (v.second){
        root_dist[v.first] = root_dist[from_node];
      }else{
        root_dist[v.first] = !root_dist[from_node];
      }
      searchNode.push_back(v.first);
      reachmap[v.first] = true;
    }

  }

  // cerr << endl;
  // for (int i = 0; i < n; i++) {
  //   cerr << root_dist[i] <<endl;
  // }



  for (int i = 0; i < n; i++) {

      if (root_dist[i]== true){
        cout << 0 <<endl;
      }else{
        cout << 1 <<endl;
      }
  }


  // cout << ans << endl;

}







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


int main() {
  string s;
  cin >> s;
  bool ch=true;
  
  rep(i,s.size()-1){
    if(s.at(i)==s.at(i+1)){
      cout<<i+1<<" "<<i+2<<endl;
      ch=false;
      break;
    }
  }
 if(ch){
   rep(i,s.size()-2){
     if(s.at(i)!=s.at(i+1)&&s.at(i)==s.at(i+2)){
      cout<<i+1<<" "<<i+3<<endl;
      ch=false;
      break;
    }
  }
 }
  if(ch){
   cout<<-1<<" "<<-1<<endl;
 }
 
}



Measured memory_bytes: 512
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
    var x = parseInt(chunk.trim(), 10);
    var s = x%60;
    var m = Math.floor((x/60)%60);
    var h = Math.floor(x/60/60);
    console.log(h + ':' + m + ':' + s);
});

Measured memory_bytes: 15472
import numpy as np
N = int(input())
H = np.array(list(map(int, input().split())))

tmp_1 = H[np.where(H==H.max())[0].min():]
ans_1 = min(tmp_1) > max(H)-2

tmp2 = H[1:] - H[:-1]

ans_2 = all(tmp2 > -2)

print("Yes") if ans_1 & ans_2 else print("No")

Measured memory_bytes: 23132
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    string s[51];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }
    string al = "abcdefghijklmnopqrstuvwxyz";
    
    ll minv[30];
    Fill(minv,(ll)1e9);
    for (int i = 0; i < n; i++) {
        ll each[30];
        Fill(each,0);
        for (int j = 0; j < s[i].length(); j++) {
            each[s[i][j]-'a']++;
        }
        for (int j = 0; j < 30; j++) {
            minv[j] = min(minv[j],each[j]);
        }
    }
    for (int j = 0; j < 30; j++) {
        for (int i = 0;i < minv[j]; i++) {
            std::cout << al[j];
        }
    }
    std::cout  << std::endl;
}


Measured memory_bytes: 256
//四つ子素数の大きさを配列に入れたらTime Limit Exceededでした.
//直しても直してもTime Limit Exceeded___ドツボです
//エラストテネスの篩を忘れていましたorz
// Respect2Dさんのコメントを見て気づきました。


import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);

    static int[] prime = new int[10000001];
    // 0:未判定
    // 1:素数
    // -1:素数ではない

    public static void main(String[] args){

	prepare();

	while(true){
	    int n = kbd.nextInt();
	    if(n==0) break;
	    solve(n);
	}
    }

    static void prepare(){
	prime[0] = prime[1] = -1;
	int i=2;
	for(; i<prime.length; i++){
	    if(prime[i] == 0){
		prime[i] = 1;
		for(int j=i+i; j<prime.length; j+=i) prime[j]=-1;
	    }
	}
    }

    static void solve(int n){

	while(!(prime[n]==1 && prime[n-2]==1 && prime[n-6]==1 && prime[n-8]==1)){
	    n--;
	}
	System.out.println(n);
    }

    /*
    static boolean prime(int a){
	int k = (int)Math.sqrt(a);
	for(int l=2; l<=k; l++){
	    if(a%l == 0) return false;
	}
	return true;
    }
    */
}

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

int main(){
  int A[101][101], r, c;

  cin >> r >> c;
  for(int i = 0; i < r; i++) 
    for (int j = 0; j < c; j++) cin >> A[i][j];

  for(int i = 0; i <= r; i++) A[i][c] = 0;
  for(int j = 0; j <= c; j++) A[r][j] = 0;

  for(int i = 0; i < r; i++){
    for(int j = 0; j < c; j++){
      A[i][c] += A[i][j];
      A[r][j] += A[i][j];
      A[r][c] += A[i][j];
    }
  }

  for(int i = 0; i <= r; i++){
    for(int j = 0; j <= c; j++){
      if(j) cout << " "; 
      cout << A[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <climits>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int dp[101000],h[100010],n,k;
int main(void){
    cin >> n >> k;
    for(int i = 0;i < n;i++) cin >> h[i];
    for(int i = 0;i < 100010;i++){
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(int i = 0;i < n;i++){
        for(int j = 1;j <= k;j++){
            chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");               
    else if(b>=0)puts("Zero");             
    else if((a&1)^(b&1))puts("Positive");  
    else puts("Negative");
    return 0;
}

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

int main() {
	int N;
	string S;
	int count;
	int ans=0;
	
	cin>>N;
	cin>>S;
	
	for(count=0;count<N-2;count++){
		if(((S.at(count)=='A')&(S.at(count+1)=='B'))&(S.at(count+2)=='C')){
			ans=ans+1;
		}
	}
	
	cout <<ans<<endl;
	return 0;
	
}





Measured memory_bytes: 256
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))

max = 0
i = 0
while i < n-1:
  if max < a[i+1] - a[i]:
    max = a[i+1] - a[i]
  i+=1

if max < (a[0] + k) - a[n-1]:
  max = (a[0] + k) - a[n-1]

print(k-max)

Measured memory_bytes: 26444