akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)

signed main(){

	lli n;
	lli m;
	cin>>n>>m;
	lli data[100100]={0};

	REP(i,0,m){
		lli a,b;
		cin>>a>>b;
		data[a]++;
		data[b]++;
	}

	REP(i,0,100100){

		if(data[i]%2!=0){
			cout<<"NO"<<endl;
			return 0;
		}
		
	}
	cout<<"YES"<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;

int main(){
    ll n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        ll a;
        cin>>a;
        n=n-a;
    }
    if(n<0){
        cout<<-1<<endl;
    }else{
        cout<<n<<endl;
    }
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int h = kbd.nextInt();
        int w = kbd.nextInt();
        if(!(h==0 && w==0)){
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
            if(c(i,j))System.out.print("#");
            else System.out.print(".");
            }
            System.out.println();
        }
        System.out.println();
        }
    }
    }
 
    static boolean c(int i, int j){
    boolean a = i%2==1;
    boolean b = j%2==1;
    if(a==true && b==true) return true;
    if(a==false && b==true) return false;
    if(a==true && b==false) return false;
    return true;
    }
}

Measured memory_bytes: 26720
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,ans="Yes";
  cin>>s;
  for(int i=0;i<s.size();i++){
      if(i%2==0&&s.at(i)=='L'){ans="No";break;}
      else if(i%2==1&&s.at(i)=='R'){ans="No";break;}
  }
  cout<<ans;
}


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

int main(){
    int n, m;
    cin >> n >> m;

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

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    if(x[n] >= y[0]){
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }

    return 0;

}


Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
                
#define int long long
#define ll long long 
bool FLAG = 0;
#define debug(x) if (FLAG) { 	cerr << #x << " = " << x << endl;}
#define debug_vec(x) if (FLAG) {cerr << #x << " = {"; for (auto to x) cout << to << ", "; cout << "}" << endl}
#define F first
#define S second                               
#define sqr(x) ((x) * (x))
#define make make_pair
#define pb push_back
#define sz(x) (int)(x.size()) 
#define all(x) x.begin (), x.end ()

using namespace std;
                        
typedef unsigned long long ull;
typedef long double ld;

const int MOD = 998244353, N = (int)1e6+ 222;
const int INF = (int)1e18;
const ld eps = (ld)1e-6;

int dx[] = {0, -1, 0, 1, 0};
int dy[] = {0, 0, 1, 0, -1};         
                 
int n, a[N], l[N], r[N];


inline void solve () {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	a[n + 1] = -INF;
	stack <int> s;
	for (int i = 1; i <= n + 1; ++i) {
		while (!s.empty() && a[s.top()] > a[i]) {
			r[s.top()] = i - 1;
			s.pop();
		}
		s.push(i);
	}
	s.pop();
	a[0] = -INF;
	for (int i = n; i >= 0; --i) {
		while (!s.empty() && a[s.top()] > a[i]) {
			l[s.top()] = i + 1;
			s.pop();
		}
		s.push(i);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans += (r[i] - i + 1) * (i - l[i] + 1) * a[i];		
	}
	cout << ans;
}	    

signed main () {
	#ifdef Maga
		freopen("input", "r", stdin);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 11396
#include <stdio.h>

int main(void)
{
	int i, j, k, h, w;
	int m[500][500];
	int area, hmin;
	char str[501];
	while (scanf("%d %d", &h, &w) != EOF)
	{
		if (h == 0)
			break;

		area = 0;
		for (i = 0; i < h; i++)
		{
			scanf("%s", str);
			for (j = 0; j < w; j++)
			{
				int c;
				if (str[j] == '*') c = 0;
				else
				{
					if (i == 0)
						c = 1;
					else
						c = m[i-1][j] + 1;
				}
				m[i][j] = c;
			}
		}

		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				hmin = 501;
				for (k = j; k < w && m[i][k] != 0; k++)
				{
					if (m[i][k] < hmin)
						hmin = m[i][k];
					if (area < hmin * (k - j + 1))
						area = hmin * (k - j + 1);
				}
			}
		}

		printf("%d\n", area);
	}

	return 0;
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
	int a, num[4]={};
	for(int i = 0; i < 6; ++i){
		cin>>a;
		num[a-1]++;
	}
	int cnt=0;
	for(int i=0; i<4; i++){
		if(num[i]%2==1){
			cnt++;
		}
	}
    if(cnt==0||cnt==2){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a[30],s,h=-999;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	h=a[0];
	s++;
	for(int i=1;i<n;i++)
	{
		if(h<=a[i])
		{
			h=a[i];
			s++;
		}
	}
	cout<<s<<endl;
}

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

for i in range(n):
    if a[0] >= a[1]:
        a[1] *= 2
    elif a[1] >= a[2]:
        a[2] *= 2
    
if a[0] < a[1] < a[2]:
    print("Yes")
else:
    print("No")   



Measured memory_bytes: 9156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) //cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    for(ll b = k+1; b <= n; b++){
        ll num = n/b;
        ans += num*(b-k);
        ll amari = n%b;
        ans += max(0LL,amari-k+1);
    }
    if(k==0)ans-=n;
    cout << ans << endl;
}

Measured memory_bytes: 504
n=int(input())
a=[0]*n
xy=[]
for i in range(n):
    a[i]=int(input())
    hoge=[]*a[i]
    for j in range(a[i]):
        hoge.append(tuple(int(i) for i in input().split()))
    xy.append(hoge)
 
ans=0
def check(j,pattarn):
    if j in pattarn:
        for x,y in xy[j]:
            if not y and (x-1 in pattarn):
                return 0
            if y and (x-1 not in pattarn):
                return 0
        return 1
 
for bit in range(1<<n):
    pattarn = []
    for j in range(n):
        if (bit & (1<<j)):
            pattarn.append(j)
 
    for j in range(n):
        if check(j,pattarn)==0:
            break
    else:
        ans=max(ans,len(pattarn))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#define LE(x) (2*(x))
#define RI(x) (2*(x)+1)
#define PA(x) ((x)/2)
using namespace std;
const int N_MAX = 500005;
int H[N_MAX];
int n;

/*void test(int flag){
    cout<<"///////////NOW TEST//////////"<<endl;
    for(int i=1;i<=n;i++){
        cout<<H[i]<<' ';
    }
    cout<<endl<<"///////////flag = "<<flag<<"//////////"<<endl;
    getchar();
}*/

void maxHeapify(int flag){
    if(flag>PA(n)){
        return;
    }
    int l = LE(flag);
    int r = RI(flag);
    if(r<=n){
        if(H[r]>H[l]){
            if(H[r]>H[flag]){
                H[r]^=H[flag];
                H[flag]^=H[r];
                H[r]^=H[flag];
                //test(flag);
                maxHeapify(r);
            }else{
                return;
            }
        }else{
            if(H[l]>H[flag]){
                H[l]^=H[flag];
                H[flag]^=H[l];
                H[l]^=H[flag];
                //test(flag);
                maxHeapify(l);
            }else{
                return;
            }
        }
    }else{
        if(H[l]>H[flag]){
                H[l]^=H[flag];
                H[flag]^=H[l];
                H[l]^=H[flag];
                //test(flag);
        }else{
            return;
        }
    }
}

void buildMaxHeap(){
    for(int i=PA(n); i>0; i--){
        maxHeapify(i);
    }
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>H[i];
    }
    buildMaxHeap();
    for(int i=1;i<=n;i++){
        cout<<' '<<H[i];
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 5080
import sys
n, x = map(int, input().split())
ans = 0
layer = [1 for _ in range(n+1)]
patty = [1 for _ in range(n+1)]
for i in range(1,n+1):
    layer[i] = 2*layer[i-1]+3
    patty[i] = 2*patty[i-1]+1
def eat(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif x <= 1+layer[n-1]:
        return eat(n-1, x-1)
    elif x == 2+layer[n-1]:
        return patty[n-1]+1
    elif x <= 2+2*layer[n-1]:
        return patty[n-1]+1+eat(n-1, x-2-layer[n-1])
    else:
        return 2*patty[n-1]+1
ans = eat(n, x)
print(ans)


Measured memory_bytes: 3064
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cins(s);

    int ans=1;
    for(size_t i=1; i<s.size(); i++)
        if(s[i]!=s[i-1])
            ans++;
    cout<<ans<<endl;

}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include <algorithm>
#include <functional>
using namespace std;

int main ()
{
    int n;
    cin >> n;
    vector<int> v(n/2);
    vector<int> w(n/2);
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            cin >> v[i / 2];
        }
        if (i % 2 == 1) {
            cin >> w[i / 2];
        }
    }
    sort(v.begin(),v.end());
    sort(w.begin(),w.end());
    v.push_back(-1);
    w.push_back(-1);
    int counteven = 0;
    int maxcounteven = 0;
    int beforeeven = -1;
    int secondcounteven = 0;
    int maxcountevenelement = -1;
    for (int i = 0; i < v.size(); ++i) {
        if (beforeeven != v[i]) {
            if (counteven > maxcounteven) {
                secondcounteven = maxcounteven;
                maxcounteven = counteven;
                maxcountevenelement = beforeeven;
            }
            else if (counteven > secondcounteven) {
                secondcounteven = counteven;
            }
            counteven = 1;
        }
        else {
            counteven++;
        }
        beforeeven = v[i];
    }
    int countodd = 0;
    int maxcountodd = 0;
    int beforeodd = -1;
    int secondcountodd = 0;
    int maxcountoddelement = -1;
    for (int i = 0; i < w.size(); ++i) {
        if (beforeodd != w[i]) {
            if (countodd > maxcountodd) {
                secondcountodd = maxcountodd;
                maxcountodd = countodd;
                maxcountoddelement = beforeodd;
            }
            else if (countodd > secondcountodd) {
                secondcountodd = countodd;
            }
            countodd = 1;
        }
        else {
            countodd++;
        }
        beforeodd = w[i];
    }
    int ans = -1;
    if (n == 2) {
        cout << 0;
        return 0;
    }
    if (maxcountoddelement != maxcountevenelement) {
        ans = n - maxcountodd - maxcounteven;
    }
    else {
        ans = min(n - maxcountodd - secondcounteven, n - maxcounteven -secondcountodd);
    }
    cout << ans;
    
    /*
    //<<codes for debug>>
    
    cout << endl << "maxcountodd:";
    cout << endl << maxcountodd;
    cout << endl << "maxcounteven:";
    cout << endl << maxcounteven << endl;
    cout << "maxcountevenelement:" << endl;
    cout << maxcountevenelement << endl;
    cout << "maxcountoddelement:" << endl;
    cout << maxcountoddelement << endl;
    cout << "secondcounteven:" << endl;
    cout << secondcounteven << endl;
    cout << "secondcountodd" << endl;
    cout << secondcountodd << endl;
    cout << "v" << endl;
    for (int i = 0; i < v.size(); ++i) {
        cout << v[i] << endl;
    }
    cout << "w" << endl;
    for (int i = 0; i < w.size(); ++i) {
        cout << w[i] << endl;
    }
    */
    
}

Measured memory_bytes: 828
bingo = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

check = [[ False ] * 3 for i in range(3)]

for i in range(n):
    number = b[i]
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == number:
                check[j][k] = True

check_t = [list(x) for x in zip(*check)]

for i in range(3):
    if sum(check[i]) == 3 or sum(check_t[i]) == 3:
        print("Yes")
        exit()

if check[0][0] == check[1][1] == check[2][2] == True or check[2][0] == check[1][1] == check[0][2] == 1:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
	int  A,B,C;
	cin >> A >> B >> C;
	if( B-A ==C-B )
	{
		cout << "YES" <<endl;
	}
	else
	{
		cout << "NO" <<endl;
	}
	//(char)でint型をchar型にできる
	//小文字のコードは大文字のコードより0x20(16進数の“20”)大きい
	// str.size() strの文字数が取得できる
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N;
vector<ll> A;
vector<ll> abs_A;
bool has_zero = false;
int num_minus = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  abs_A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    abs_A[i] = abs(A[i]);
    if (A[i] == 0) {
      has_zero = true;
    }
    if (A[i] < 0) {
      num_minus++;
    }
  }

  ll ans = 0;
  if (has_zero) {
    for (auto &e : abs_A) {
      ans += e;
    }
  } else {
    for (auto &e : abs_A) {
      ans += e;
    }
    if (num_minus % 2 != 0) {
      sort(abs_A.begin(), abs_A.end());
      ans -= (2 * abs_A[0]);
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define N 20
typedef long long LL;
const int mod = 1e9 + 7; int Pow2[N * N], from[N * N], to[N * N], cnt[1 << 16];
int f[2][1 << 16], n, m;
inline bool check(int s, int i) {return s & (1 << i - 1);}
inline int count(int s) {
    int res = 0, tmp = s;
    while (s) res++, s = (s - 1) & tmp;
    return res;
}
inline void calc(int i) {
    for (int s = 1; s < 1 << n;s++) if (check(s, i)) {
        int &sum = f[i - 1][s]; sum = Pow2[cnt[s]];
        for (int ss = s - 1;ss;ss = (ss - 1) & s) if (check(ss, i)) {
            int sgn = count(s - ss) & 1 ? mod - 1 : 1;
            sum = (sum + (LL)sgn * Pow2[cnt[s - ss]] % mod * f[i - 1][ss]) % mod;
        }
    }
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1;i <= m;i++) scanf("%d%d", &from[i], &to[i]);
    Pow2[0] = 1;
    for (int i = 1;i <= m;i++) Pow2[i] = Pow2[i - 1] * 2 % mod;
    for (int i = 0;i < 1 << n;i++)
        for (int j = 1;j <= m;j++)
            if (check(i, from[j]) && check(i, to[j]))
                cnt[i]++;
    // for (int i = 0;i < 1 << n;i++) cout << i << ' ' << cnt[i] << endl;
    calc(1), calc(2);
    int res = 0;
    for (int s = 1;s < 1 << n;s++) if (check(s, 1)) {
        int tmp = ((1 << n) - 1) - s;
        // cout << s << ' ' << tmp << endl;
        for (int ss = tmp;ss;ss = (ss - 1) & tmp) if (check(ss, 2)) {
            if (cnt[s] + cnt[ss] != cnt[s + ss]) continue;
            // cout << s << ' ' << ss << endl;
            res = (res + (LL)f[0][s] * f[1][ss] % mod * Pow2[cnt[tmp - ss]]) % mod;
        }
    }
    printf("%d\n", (Pow2[m] - res + mod) % mod);
    return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll A,B,T;
    cin >> A >> B >> T;
    cout << T/A*B << endl;
    return 0;
}


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

x = 0
for i in range(n):
  x += (-1)**i*a[i]

for i in range(n):
  if i == 0:
    print(x)
  else:
    x = 2*(a[i-1]-x//2)
    print(x)
   

Measured memory_bytes: 63984
buildings =  [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())

    buildings[b-1][f-1][r-1] += v
sep_count = len(buildings) - 1
for b in buildings:
    for f in b:
        print(" ",end="")
        print(*f)
    if sep_count != 0:
        print("#" * 20)
        sep_count -= 1



Measured memory_bytes: 5628
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	n := scanInt(sc)
	str := scanString(sc)

	bu := bytes.NewBufferString("")
	for i := 0; i < len(str); i++ {
		c := str[i] + byte(n)
		if c > 'Z' {
			c = c - 'Z' + 'A' - 1
		}
		bu.WriteByte(c)
	}
	fmt.Println(bu.String())
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int LL=(int)(s[0]-48)*10+(int)(s[1]-48); 
    int RR=(int)(s[2]-48)*10+(int)(s[3]-48); 
    
    if(1<=RR && RR<=12 && 1<=LL && LL<=12) cout << "AMBIGUOUS" ENDL;
    else if(RR>=0 && 1<=LL && LL<=12) cout << "MMYY" ENDL;
    else if(1<=RR && RR<=12 && LL>=0) cout << "YYMM" ENDL; 
    else cout << "NA" ENDL;    
    return 0;
}

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

int main(void)
{
    int n, m, x;
    scanf("%d %d %d", &n, &m, &x);
    bool a[n+1]={};
    for (size_t i = 0; i < m; i++)
    {
        int t;
        scanf("%d", &t);
        a[t] = true;
    }
    int l = 0, r = 0;
    for (size_t i = 1; i < x; i++)
    {
        if(a[i])
        {
            l++;
        }
    }
    for (size_t i = x+1; i < n+1; i++)
    {
        if (a[i])
        {
            r++;
        }
    }
    printf("%d\n", l < r ? l : r);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define FTEST int testcase;fin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define plii pair<ll,pii>
#define no {cout<<"no"<<endl;return;}
#define yes {cout<<"yes"<<endl;}
#define rep(i,N) for(int i=0;i<N;i++)
const int maxn=1e6;
const int mod=998244353;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll divs[maxn+1];
void count_d(){
    memset(divs,0,sizeof divs);
    for(int i=1;i<=maxn;i++){
        for(int j=i;j<=maxn;j+=i) divs[j]++;
    }
}
void solve(){

    int n;cin>>n;
    ll ans=0;
    count_d();
    for(int c=1;c<=n-1;c++){
        ans+=divs[n-c];
    }
    cout<<ans;
    return;
}

int main(){
    IO
    solve();

    return(0);
}



Measured memory_bytes: 11476
import java.util.Scanner;

class Main {

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

        int a=stdIn.nextInt();
        int b=stdIn.nextInt();
        int c=stdIn.nextInt();
        int d=stdIn.nextInt();

        do{
            c=c-b;
            if(c>0){
                a=a-d;
            }
        }while(a>0&&c>0);

        if(c>0){
            System.out.println("No");
            
        }
        else{
            System.out.println("Yes");
            
        }
        
        
    }

}

Measured memory_bytes: 35744
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/11  Problem: N18_f AGC010 C / Link: http://agc010.contest.atcoder.jp/tasks/agc010_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;
LL a[100005];
LL ans = 1;//okか
vector<vector<LL>>G;

LL f(LL u, LL p) {
	VL v;
	FOR(i, 0, SZ(G[u])) {
		if (G[u][i] != p)v.push_back(G[u][i]);
	}
	
	if (SZ(v) == 0)return a[u];//not ch

	LL sum = 0; LL maxv = -1;
	FOR(i, 0, SZ(v)) {
		LL t = f(v[i], u);
		sum += t;
		maxv = max(maxv, t);
	}
	if (sum < a[u]) { ans = 0; return 0; }//普通にしたが多い
	
	LL up = min(sum / 2, sum - maxv);
	LL res = sum - a[u];
	if (res > up) { ans = 0; return 0; }
	
	return sum - res * 2;
}

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

	cin >> N;
	FOR(i, 0, N)cin >> a[i];
	G = vector<vector<LL>>(N, vector<LL>());
	FOR(i, 0, N - 1) {
		LL a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if (N == 2) {
		cout << ((a[0]==a[1])?"YES":"NO") << endl;
		return 0;
	}
	LL root = -1;
	FOR(i, 0, N)if (SZ(G[i]) >= 2)root = i;
	LL res=f(root, -1);
	
	cout << ((ans&&res==0)?"YES":"NO") << "\n";

	return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;


// 階乗を求める
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

void solve() {
    int N;
    cin >> N;
    vector<int> v(N);
    vector<pair<int,int>> vp(N);
    REP(i,N) {
        int x,y;
        cin >> x >> y;
        vp[i] = make_pair(x,y);
    }
    REP(i,N) v[i] = i;
    double ans = 0;
    do {
        // d
        REP(i,N-1) {
            auto [x1,y1] = vp[v[i]];
            auto [x2,y2] = vp[v[i+1]];
            double d = sqrt((abs(x1-x2)*abs(x1-x2))+(abs(y1-y2)*abs(y1-y2)));
            ans += d;
        }
    }while (next_permutation(ALL(v)));
    cout << fixed << setprecision(12) << ans/double(facctorialMethod(N)) << endl;
}

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

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int f(int n) {
  if (n % 2)
    return 3 * n + 1;
  else
    return n / 2;
}

int main() {
  int s;
  set<int> a;
  cin >> s;
  a.insert(s);
  int count = 1;
  while (1) {
    count++;
    int sb = a.size();
    s = f(s);
    a.insert(s);
    int sa = a.size();
    if (sb == sa) break;
  }
  print(count);
  return 0;
}

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

int main(){
  string s,t;cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if(s<t){
    cout << "Yes" <<endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int a,b,c; cin>>a>>b>>c;
  if(a+b<c)
  cout<<"No"<<endl;
  else
  cout<<"Yes"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	bool operator<(const struct Info &arg) const{
		return sum_cost < arg.sum_cost;
	};
	int array[16];
	int state,sum_cost,used_num;
};

int N,M;
int POW[17];
int dp[65536];
int futon[16],demand[101];

void func(){

	futon[0] = 0;
	for(int i = 1; i <= N; i++)scanf("%d",&futon[i]);
	demand[0] = 0;
	for(int i = 1; i <= M; i++)scanf("%d",&demand[i]);

	sort(demand,demand+(M+1));

	N++;

	for(int i = 0; i < POW[N]; i++)dp[i] = BIG_NUM;

	Info first;
	first.state = 0;
	first.used_num = 0;
	first.sum_cost = 0;

	priority_queue<Info> Q;

	Q.push(first);

	int tmp_sum,next_state;

	while(!Q.empty()){

		if(Q.top().used_num == N){
			Q.pop();
		}else if(Q.top().sum_cost > dp[Q.top().state]){
			Q.pop();
		}else{

			for(int loop = 0; loop < N; loop++){
				if(Q.top().state & (1 << loop)){
					//Do noghint
				}else{
					Info next_info;
					for(int i = 0; i < Q.top().used_num; i++)next_info.array[i] = Q.top().array[i];
					next_info.array[Q.top().used_num] = futon[loop];

					if(Q.top().used_num > 0){
						next_info.array[Q.top().used_num] += next_info.array[Q.top().used_num-1];
					}
					int index = 0;
					tmp_sum = 0;
					for(int i = 1; i <= M; i++){
						while(index < Q.top().used_num && abs(demand[i]-next_info.array[index]) > abs(demand[i]-next_info.array[index+1]))index++;
						tmp_sum += abs(demand[i]-next_info.array[index]);
					}

					next_state = Q.top().state + POW[loop];

					if(dp[next_state] > tmp_sum){
						dp[next_state] = tmp_sum;
						next_info.state = next_state;
						next_info.sum_cost = tmp_sum;
						next_info.used_num = Q.top().used_num+1;
						Q.push(next_info);
					}
				}
			}
			Q.pop();
		}
	}

	printf("%d\n",dp[POW[N]-1]);
}


int main(){

	for(int i = 0; i < 17; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}
	return 0;

}

Measured memory_bytes: 11284
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define MAX 401

int dp[2][MAX],table[3] = {500,100,50};


int main(){

	for(int i = 0; i < 3; i++)table[i] /= 50;

	int num[3],X;
	scanf("%d %d %d %d",&num[0],&num[1],&num[2],&X);

	X /= 50;
	int tmp;

	int CURRENT = 0,NEXT = 1;

	dp[CURRENT][0] = 1;
	dp[NEXT][0] = 1;

	for(int i = 1; i <= X; i++){
		dp[CURRENT][i] = 0;
		dp[NEXT][i] = 0;
	}

	for(int coin = 0; coin < 3; coin++){
		for(int mult = 1; mult <= num[coin]; mult++){
			tmp = table[coin]*mult;

			if(tmp > X)break;

			for(int i = X; i-tmp >= 0; i--){
				dp[NEXT][i] += dp[CURRENT][i-tmp];
			}
		}
		for(int i = 0; i <= X; i++){
			dp[CURRENT][i] = dp[NEXT][i];
		}
	}

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

	return 0;
}


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

int dp[1000004][3]={0};
//int dp1[1000004]={0};
int func(int i,int arr[][3],int j,int n)
{
    int very_min=-2;
    if(i>n-1)
    {
        return 0;
    }
 if(dp[i][j]!=0)
        {
        return dp[i][j];
        }
    for(int k=0;k<=2;k++)
    {
        if(k!=j)
        {
        int ref=arr[i][k]+func(i+1,arr,k,n);
       if(ref>very_min)
       {
           very_min=ref;
       }
        }

    }
    dp[i][j]=very_min;
    return dp[i][j];
   // dp1[i]=very_min;
    //dp[i]=max(arr[i][0]+func(i+1,arr),arr[i][1]+func(i+1,arr),arr[i][2]+func(i+1,arr));
   // return dp[i][k];
}
int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
scanf("%d",&arr[i][j]);        }
    }
    func(0,arr,4,n);
    //int very_min=-2;

    cout<<dp[0][4];
    return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l,r,a[50],j;
  while(cin>>n>>l>>r&&n&&l&&r){
    int cnt=0;
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=l;i<=r;++i){
      for(j=0;j<n;++j){
        if(i%a[j]==0) break;
      }
      if(j<n){
        if((j+1)%2) ++cnt;
      }else{
        if(!(n%2)) ++cnt;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}



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

int main(){
	// sengen
	int x,n;
	// nyuryoku
	cin >> x >> n;
	if(n == 0){
		cout << x;
		return 0;
	}
	int p[n];
	for(int i=0;i<n;i++){
		cin >> p[i];
	}
	for(int i=0;i<=200;i++){
		int ans = x - i;
		for(int j=0;j<n;j++){
			if(ans == p[j]){
				break;
			}
			if(j == n-1){
				cout << ans;
				return 0;
			}
		}

		ans = x + i;
		for(int j=0;j<n;j++){
			if(ans == p[j]){
				break;
			}
			if(j == n-1){
				cout << ans;
				return 0;
			}
		}
	}
	// keisan

	// syutsuryoku
}

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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int32_t main()
{   
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    int f=0;
    while(n){
        f|=(n%10==7);
        n/=10;
    }
    if(f)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll f(ll n) {
  if(n%2==0) return n/2;
  return 3*n+1;
}

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

  ll n;
  cin >> n;
  vector<ll> h(n);
  REP(i, n) cin >> h[i];

  ll cnt = 0;
  FOR(i, 1, 101) {
    bool flag = false;
    REP(j, n) {
      if(h[j] >= i && !flag) {
        flag = true;
        cnt++;
      } else if(h[j] < i) {
        flag = false;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

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

using PP = pair<int, int>;

const int inf = 1.1e9;

int n, m;
int bs[100000];
int ds[100001];
int l[200000];
int r[200000];
vector<PP> G[100001];
bool used[100001];
bool ans[200000];

bool rec(int from, int pid) {
  if (used[from]) return false;
  used[from] = true;
  
  bool odd = ds[from];
  for (PP e : G[from]) {
    int to = e.first;
    int id = e.second;
    odd ^= rec(to, id);
  }
  
  if (pid != -1 && odd) {
    ans[pid] = true;
  }
  return odd;
}

bool sub(int from) {
  bool res = rec(from, -1);
  return !res;
}

bool solve() {
  for (int i = 0; i <= n; ++i) {
    ds[i] = (i == n ? 0 : bs[i]) ^ (i == 0 ? 0 : bs[i - 1]);
  }
  
  for (int j = 0; j < m; ++j) {
    G[l[j]].push_back(PP(r[j], j));
    G[r[j]].push_back(PP(l[j], j));
  }
  
  for (int i = 0; i <= n; ++i) {
    if (used[i]) continue;
    if (!sub(i)) return false;
  }
  return true;
}

void input() {
  cin >> n >> m;
  vector<PP> bombs;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    bombs.push_back(PP(a, b));
  }
  sort(bombs.begin(), bombs.end());
  
  for (int j = 0; j < m; ++j) {
    int c, d;
    cin >> c >> d;
    ++d;
    l[j] = lower_bound(bombs.begin(), bombs.end(), PP(c, -inf)) - bombs.begin();
    r[j] = lower_bound(bombs.begin(), bombs.end(), PP(d, -inf)) - bombs.begin();
  }
  
  for (int i = 0; i < n; ++i) {
    bs[i] = bombs[i].second;
  }
}

int main() {
  input();
  bool res = solve();
  if (res) {
    int cnt = count(ans, ans + m, true);
    cout << cnt << endl;
    for (int i = 0; i < m; ++i) {
      if (ans[i]) {
        cout << i + 1 << ' ';
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 15204
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

bool isprime(int n)
{
	if(n == 1) return false;
	if(n == 2) return true;
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0) return false;
	}
	return true;
}

int main()
{
	int n;
	cin >> n;
	vector<int> v;
	for(int i = 2; i <= 55555; i++){
		if(isprime(i) && i % 5 == 1) v.push_back(i);
	}
	for(int i = 0; i < n; i++){
		cout << v[i];
		if(i == n - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
list_a = []
list_a.append(list((map(int, input().split()))))
list_a.append(list((map(int, input().split()))))
for i in range (0,n):
    if i == 0:
        pass
    else:
        list_a[0][i] = list_a[0][i-1] + list_a[0][i]

for j in range(0,n):
    if j == 0:
        list_a[1][j] = list_a[0][j] + list_a[1][j]
    else:
        list_a[1][j] = max(list_a[0][j], list_a[1][j-1]) + list_a[1][j]

print(list_a[1][n-1])


Measured memory_bytes: 3064
n = int(input())

if n == 100000:
  ans = 90000+900+9
elif n >= 10000:
  ans = n-9999+900+9
elif n >= 1000:
  ans = 900+9
elif n >= 100:
  ans = n-99 + 9
elif n >= 10:
  ans = 9
else:
  ans = n

print(ans)

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

int main() {
    int n, c;
    while(cin >> n >> c, n) {
        vector<int> a(n, 0);
        vector<int> b(c, 0);
        for(int i=0; i<n; ++i) {
            for(int j=0; j<16; ++j) {
                int t; cin >> t;
                a[i] |= t << j;
            }
        }
        for(int i=0; i<c; ++i) {
            for(int j=0; j<16; ++j) {
                int t; cin >> t;
                b[i] |= t << j;
            }
        }
        vector<vector<int>> dp(n+1, vector<int>(1 << 16, -1));
        int res = 0;
        dp[0][0] = 0;
        for(int i=0; i<n; ++i) {
            for(int j=0; j<1<<16; ++j) {
                if(dp[i][j] == -1) {
                    continue;
                }
                int now = j | a[i];
                for(int k=0; k<c; ++k) {
                    int clear = now & b[k];
                    int cnt = __builtin_popcount(clear);
                    int next = now - clear;
                    dp[i+1][next] = max(dp[i+1][next], dp[i][j] + cnt);
                    res = max(res, dp[i+1][next]);
                }
            }
        }
        cout << res << endl;
    }
}


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

using namespace std;
const int mod = 1e9 + 7;
int n, a[101], k;
long long dp[101][100001];
int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 0; i <= k; i++){
        dp[0][i] = 1;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= k; j++){
            if(j - a[i] - 1 > -1){
                dp[i][j] = (dp[i - 1][j] - dp[i - 1][j - a[i] - 1]) % mod;
                if(dp[i][j] < 0){
                    dp[i][j] += mod;
                }
            }
            else{
                dp[i][j] = dp[i - 1][j];
            }
        }
        if(i != n){
            for(int j = 1; j <= k; j++){
                (dp[i][j] += dp[i][j - 1]) %= mod;
            }
        }
    }
    cout << dp[n][k] << '\n';
}


Measured memory_bytes: 79104
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

ll a[200010];
ll sum[200010];

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    sum[i+1] = sum[i] + a[i];
  }

  ll ans = 1e10;
  if(n < 3){
    ans = abs(a[0]-a[1]);
    cout << ans << endl;
    return 0;
  }
  FOR(i, 1, n-1){
    //cout << sum[i] << " vs " << sum[n] - sum[i] << endl;
    ans = min(ans, abs(sum[i]-(sum[n]-sum[i])));
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn=2e5+10;
int a[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    int sum=0;
    for(int i=1;i<=k;i++)
        sum+=a[i];
    cout<<sum<<'\n';



}


Measured memory_bytes: 3656
import math
N = int(input())
INF = float("inf")
for a in range(1, int(math.sqrt(N)) + 1):
    if N % a != 0:
        continue
    b = int(N / a)
    a = list(map(int, str(a)))
    b = list(map(int, str(b)))
    length = max(len(a), len(b))
    if INF > length:
        INF = length
print(INF)


Measured memory_bytes: 73568
import collections as cl
def check(y,x):
    if 0 <= x and x < w and 0 <= y and y < h :
        return True
    else:
        return False

def func():
    while q:
        y,x,count= q.popleft()
        if check(y,x) == False or s[y][x] == '#' or (y,x) in conf:
            continue
        else:
            q.append([y-1,x,count+1])
            q.append([y+1,x,count+1])
            q.append([y,x-1,count+1])
            q.append([y,x+1,count+1])
            ans.append(count)
            conf.add((y,x))
    return max(ans)
q = cl.deque()
conf = set()
h,w = map(int,input().split())
s = []
step_max = []
for i in range(h):
    s.append(list(map(str,input())))
ans = []
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            q.append([i,j,0])
            step_max.append(func())
            conf = set()
            ans = []
print(max(step_max))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int conta( string a, string b, int len ) {
    int res = 0;

    fo(i, len) if ( a[i] != b[i] ) res++;

    return res;
}


int main() {sws;

    string s, t;
    cin >> s >> t;

    int ns = s.length(), nt = t.length();

    int ans = INF;
    fo(i, ns - nt + 1) {
        ans = min(ans, conta(s.substr(i, nt), t, nt));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
from collections import deque

R=lambda: map(int, input().split())

n, m = R()
g = [[] for _ in range(n)]
for _ in range(m):
  u, v = R()
  g[u - 1].append(v - 1)
  g[v - 1].append(u - 1)

r = [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = deque([0])
while q:
  u = q.popleft()
  for v in g[u]:
    if not V[v]:
      V[v] = True
      r[v - 1] = u + 1
      q.append(v)

print(*(['No'],['Yes'] + r)[all(r)], sep='\n')


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

int main()
{
  int n,k;
  for(;cin>>n>>k,n;)
    {
      int card[n];
      int tmp=1;
      int nmax=0;
      for(int i=0;i<n;i++)
	{
	  cin>>card[i];
	  tmp*=card[i];
	  if(i>=k)
	    tmp/=card[i-k];
	  nmax=max(nmax,tmp);
	}
      int amax=0;
      for(int i=0;i<n-1;i++)
	for(int j=i+1;j<n;j++)
	  {
	    swap(card[i],card[j]);
	    tmp=1;
	    
	    for(int x=0;x<n;x++)
	      {
		tmp*=card[x];
		if(x>=k)
		  tmp/=card[x-k];
		amax=max(amax,tmp);
	      }
	    swap(card[i],card[j]);	    
	  }
      if(amax-nmax<0)
	cout<<"NO GAME"<<endl;
      else
	cout<<amax-nmax<<endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

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

using namespace std;

int n;
int a[100];

int err(int m){
	int s = 0;
	rep(i, n){
		int d = a[i] - m;
		s += d * d;
	}
	return s;
}

int main() {
	cin >> n;
	rep(i, n){
		cin >> a[i];
	}

	int s = 0;
	rep(i, n){
		s += a[i];
	}
	int p = s / n;
	int q = p + 1;
	cout << min(err(p), err(q)) << endl;
	return 0;
}

Measured memory_bytes: 256
// D - Not Divisible

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[200000];
unordered_map<int, int> cnt;
bool has_divisor[1000001];

void set_has_divisor(int a) {
	for (int i=2; a*i <= 1000000; i++) {
		has_divisor[a*i] = true;
	}
}

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

	for (int i=0; i<N; i++) {
		cin >> A[i];
		cnt[A[i]]++;
		if (cnt[A[i]] == 1) set_has_divisor(A[i]);
	}

	int ans = 0;

	for (int i=0; i<N; i++) {
		if (cnt[A[i]] >= 2) continue;
		if (has_divisor[A[i]] == false) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

int a,b;
char c[100][100];

int main(){
    cin>>b>>a;
    rep(i,100)rep(j,100){
        c[i][j]=(i<50?'#':'.');
    }
    a--;
    for(int i=51;a;i+=2)for(int j=0;j<100&&a;j+=2){
        c[i][j]='#';
        a--;
    }
    b--;
    for(int i=0;b;i+=2)for(int j=0;j<100&&b;j+=2){
        c[i][j]='.';
        b--;
    }
    cout<<"100 100\n";
    rep(i,100){
        rep(j,100)cout<<c[i][j];
        cout<<endl;
    }
}

Measured memory_bytes: 256