akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  int n, m;
  cin >> n >> m;
  int start = 0;
  REP(i, n){
    int k;
    cin >> k;
    start = (start << 1) | k;
  }
  int goal1 = 0, goal2 = 0;
  int t = 0;
  REP(i, m){
    int k;
    cin >> k;
    REP(j, k){
      goal1 = (goal1 << 1) | t;
      goal2 = (goal2 << 1) | (~t & 1);
    }
    t = ~t & 1;
  }

  vb G(1 << (n + 1));
  G[start] = true;
  queue<int> que;
  que.push(start);
  que.push(-1);
  int step = 0;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    if(p == goal1 || p == goal2) {
      cout << step << endl;
      break;
    }

    if(p == -1) {
      step++;
      que.push(p);
      continue;
    }

    REP(i, n - 1){
      int trade = 3 << i;
      int disable = p & trade;
      int next = p ^ trade;
      if (disable == 0 || disable == trade) continue;
      if(next >= (1 << n)) continue;
      if(G[next]) continue;
      G[next] = true;
      que.push(next);
    }
  }
}

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

int main(){
    ll K,N;
    cin>>K>>N;
    vl A(N);
    vl B(N);
    F0R(i,N){
        cin>>A[i];
    }
    ll ans=0;
    F0R(i,N){
        if(i<N-1){
            B[i]=abs((A[(i+1)]-A[i]));
            ans=max(ans,B[i]);
        }else{
            B[i]=abs((A[(i)%N]-K))+abs((A[(i+1)%N]));
            ans=max(ans,B[i]);
        }
    }
    cout<<K-ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
tax_8, tax_10 = map(int, input().split())

k = int(tax_8 / 0.08)
kk = int((tax_8+1) / 0.08)
kkk = int(tax_10 / 0.1)
kkkk = int((tax_10+1) / 0.1)

for i in range(min(k, kkk), max(kk, kkkk)):
    if int(i * 0.08) is tax_8 and int(i * 0.1) is tax_10:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 3064
from math import factorial
def C(n,r):
  if n>=r:
    return factorial(n) // factorial(r) // factorial(n - r)
  else:
    return 0
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
c=[0]*N
for i in range(1,N+1):
  c[i-1]=C(B[i],2)
  
ans=sum(c)
for i in range(N):
  if B[A[i]]>2:
    print(ans-c[A[i]-1]+c[A[i]-1]*(B[A[i]]-2)//B[A[i]])
  else:
    print(ans-c[A[i]-1])

Measured memory_bytes: 26772
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S, T; cin >> S >> T;
  int L = S.size();
  for (int i = 0; i < L; ++i) {
    bool ok = true;
    for (int j = 0; j < L; ++j) {
      if (S[j] != T[(i + j) % L]) {
        ok = false;
        break;
      }
    }

    if (ok) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3584
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: u32
    }
    for i in 1..10 {
        for j in 1..10 {
            if i * j == n {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
from collections import Counter
N = int(input())
ds = list(map(int, input().split()))
c = Counter(ds)
cs = c.most_common()

if N >= 24 or cs[0][1] >= 3 or 0 in c:
  print("0")
  exit()

l = len(cs)
k = 0
s = (1 << 0) + (1 << 24)
while k < l and cs[k][1] == 2:
  s += (1 << cs[k][0]) + (1 << (24 - cs[k][0]))
  k += 1

def process(s, i):
  if i == l:
    return min(map(len, bin(s)[2:].split("1")[1:-1])) + 1
  return max(
    process(s + (1 << cs[i][0]), i+1),
    process(s + (1 << (24 - cs[i][0])), i+1),
  )

print(process(s, k))

Measured memory_bytes: 3444
def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    # s = input().rstrip()
    a, b = [int(x) for x in input().rstrip().split(" ")]

    ans = 0
    for num in range(a, b+1):
        s = str(num)
        if(s[0] == s[4] and s[1] == s[3]):
            ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()


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

#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;
ll a[200000], b[200000], n, ans;;
vector < int > g[200000];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    ll s = 0;
    for (int i = n; i >= 1; i--){
        a[i] += s;
        if (a[i] % b[i] == 0) continue;
        ll k = b[i] - a[i] % b[i];
        s += k;
    }
    cout << s;
}


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

int get(int);

int main(){
    int i, n, num[10], order;
    long sum=0, resum=0;
    char s[10];
    scanf("%s", s);
    for (i=0; i<10; i++){
        if (s[i] == '\0') break;
    }
    n = i;
    
    for (i=0; i<n; i++){
        num[i] = atol(&s[i])/(long)pow(10, n-i-1);
    }
    
    for (i=0; i<n; i++){
        for (order=0; order<n-i; order++){
            sum += num[i]*pow(10, order)*pow(2, i)*pow(2, get(n-i-order-2));
            //printf("%d %d: %ld\n", num[i], order, sum-resum);
            resum = sum;
        }
    }
    
    printf ("%ld\n", sum);
    
    
    //printf("%d\n", (atoi(&s[0])-atoi(&s[1]))/(int)pow(10, 4));
    //printf("%d\n", (atoi(&s[1])-atoi(&s[2]))/(int)pow(10, 3));
    
    return 0;
}

int get(int a){
    return (a>=0)? a : 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

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

  int ball[n+1];
  ball[0] = -1;
  REP(i,n){
    ball[i] = -1;
  }

  for(int i=n;i>0;i--){
    int t = n - n%i;
    int count = 0;
    while(t>i){
      count += ball[t];
      t -= i;
    }
    count %= 2;
    if(count!=a[i]){
      ball[i] = 1;
    }else{
      ball[i] = 0;
    }
  }

int ans = 0;
vector<int> v;
  REP(i,n){
    if(ball[i+1]==1){
      ans++;
      v.pb(i+1);
    }
  }
  cout<<ans<<endl;
  REP(i,v.size()){
    cout<<v[i]<<endl;
  }

 

  return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int unsigned long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;

void solve()
  {
   int n,k;
   cin>>n>>k;
   int cnt = 0;
   loop(i,0,n)
    {
      int x;
      cin>>x;
      cnt += (x>=k);
    }
    cout<<cnt;
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

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

#define INF 2000000000

long long int dp[5050][5050],dp_max[5050][5050];
int dp_size[5050];
int p[5050];
long long int c[5050];


int main(){

    int N,K;

    cin >> N >> K;

    for(int i = 1;i <= N;i++){
        cin >> p[i];
    }
    for(int i = 1;i <= N;i++){
        cin >> c[i];
    }

    for(int i = 0;i <= N;i++){
        for(int j = 0;j <= N;j++){
            dp_max[i][j] = -10000000000000000;
        }
    }

    for(int i = 1;i <= N;i++){

        int now = i;
        int count = 1;
        while(true){
            dp[i][count] = dp[i][count-1] + c[p[now]];
            dp_max[i][count] = max(dp_max[i][count-1],dp[i][count]);
            now = p[now];
            if(now == i){
                dp_size[i] = count;
                break;
            }
            count++;
        }

    }
    long long int ans = -10000000000000000;
    for(int i = 1;i <= N;i++){
        if(K <= dp_size[i]){
            ans = max(ans,dp_max[i][K]);
        }else{
            if(dp[i][dp_size[i]] < 0){
                ans = max(ans,dp_max[i][dp_size[i]]);
            }else{
                long long int tmp_ans;
                if(K % dp_size[i] == 0){
                    tmp_ans = dp[i][dp_size[i]] * (K / dp_size[i]);
                    tmp_ans = max(tmp_ans,dp[i][dp_size[i]] * (K / dp_size[i] - 1) + dp_max[i][dp_size[i]]);
                    
                }else{
                    tmp_ans = dp[i][dp_size[i]] * (K / dp_size[i]) + dp_max[i][K % dp_size[i]];
                    tmp_ans = max(tmp_ans,dp[i][dp_size[i]] * (K / dp_size[i]-1) + dp_max[i][dp_size[i]]);
                    
                }
                ans = max(ans,tmp_ans);
            }
        }
    }

    cout << ans << endl;

/*
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= dp_size[i];j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }

    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= dp_size[i];j++){
            cout << dp_max[i][j] << " ";
        }
        cout << endl;
    }

*/
    return 0;
}

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

namespace _20191021
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sInput = Console.ReadLine().Split(' ');
            int a = int.Parse(sInput[0]);
            int b = int.Parse(sInput[1]);

            int[] ans = { a + b, a - b, a * b };
            Array.Sort(ans);
            Array.Reverse(ans);

            Console.WriteLine(ans[0]);

        }
    }
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

vector<ll> imos(200'010, 0);

ll calc(list<char> buf) {
	int idx = 0;
	for (auto itr = buf.begin(); itr != buf.end(); ++itr) {
		if (*itr == 'A')imos[idx] = 1;
		else imos[idx] = 0;
		idx++;
	}
	REP(i, (int)buf.size() - 1) {
		imos[i + 1] += imos[i];
	}

	idx = 0;
	ll res = 0;
	for (auto itr = buf.begin(); itr != buf.end(); ++itr) {
		if (*itr == 'D')res += imos[idx];
		idx++;
	}
	return res;
}

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

	ll res = 0;
	ll cnt = 0;

	//list<char> li;
	REP(i, s.size()) {
		if (s[i] == 'A')cnt++;
		else if (s[i] == 'C')cnt = 0;
		else {
			if (i == s.size() - 1)cnt = 0;
			else {
				if (s[i + 1] == 'C') {
					res += cnt;
					i++;
				}
				else {
					cnt = 0;
				}
			}
		}
	}
	/*
	ll res = 0;
	list<char> buf;
	while (!li.empty()) {
		while (!li.empty() && (li.front() == 'A' || li.front() == 'D')) {
			buf.push_back(li.front());
			li.pop_front();
		}
		while (!li.empty() && (li.front() == 'B' || li.front() == 'C'))li.pop_front();
		res += calc(buf);
		buf.clear();
	}
	*/
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2180
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    now_a_i=a[i]
    now_b_i=b[i]
    if now_a_i>=now_b_i:
        a[i]=now_a_i-now_b_i
        b[i]=0
        ans+=now_b_i
    else:
        a[i]=0
        b[i]=now_b_i-now_a_i
        ans+=now_a_i
        now_a_i_1=a[i+1]
        now_b_i=b[i]
        if now_a_i_1>=now_b_i:
            a[i+1]=now_a_i_1-now_b_i
            b[i]=0
            ans+=now_b_i
        else:
            a[i+1]=0
            b[i]=now_b_i-now_a_i_1
            ans+=now_a_i_1
print(ans)

Measured memory_bytes: 24344
N = int(input())
l = []

for i in range(N):
    X = int(input())
    l.append(X)

l1 = sorted(l)
l2 = sorted(l, reverse=True)

if N%2 == 0:
    result = 0
    for i in range(N//2):
        if i == N//2-1:
            result = result + l2[i] - l1[i]
        else:
            result = result + 2 * l2[i] - 2 * l1[i]
    print(result)
else:
    result1 = 0
    for i in range(N//2):
        result1 += 2 * l2[i]
    for i in range(N//2 - 1):
        result1 -= 2 * l1[i]
    result1 = result1 - l1[N//2 - 1] - l1[N//2]

    result2 = 0
    for i in range(N//2 - 1):
        result2 += 2 * l2[i]
    for i in range(N//2):
        result2 -= 2 * l1[i]
    result2 = result2 + l1[N//2] + l1[N//2 + 1]
    print(max(result1, result2))


Measured memory_bytes: 9040
import bisect
a,b,q=map(int,input().split(' '))
INF=10**19
s=[-INF]+[int(input()) for i in range(a)]+[INF]
t=[-INF]+[int(input()) for i in range(b)]+[INF]
s.sort()
t.sort()
for i in range(q):
    x=int(input())
    b,d=bisect.bisect(s,x),bisect.bisect(t,x)
    mi=INF
    for j in [s[b-1],s[b]]:
        for k in [t[d-1],t[d]]:
            mi=min(mi,abs(j-x)+abs(j-k),abs(k-x)+abs(j-k))
    print(mi)
    


Measured memory_bytes: 12800
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  char s[20];
  scanf("%s", s);
  
  int p = 0;
  if(s[0] == 'A') p++;
  
  int q = 0; int r = 0; int n = strlen(s);
  for(int i = 2; i < n - 1; i++){
    if(s[i] == 'C') q++;
  }
  
  for(int i = 1; i < n; i++){
    for(int j = 0; j < 26; j++){
      if(s[i] == 'A' + j && j != 2) r++;
    }
  }
  
  
  if(p == 1 && q == 1 && r == 0) printf("AC\n");
  else printf("WA\n");
  
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	char a = s.charAt(0);
	int x = (int) a;
	if (x>=65&&x<=90) System.out.println("A");
	else System.out.println("a");
	sc.close();}}

Measured memory_bytes: 35756
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
int N, M;
int k[11];
int s[11][11];
int p[11];

void solve() {

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
		}
	}
	for (int i = 0; i < M; i++) {
		cin >> p[i];
	}
	ll ans = 0LL;
	for (int i = 0; i < (1 << N); i++) {
		bool f = true;
		for (int j = 0; j < M; j++) {
			int cnt = 0;
			for (int l = 0; l < k[j]; l++) {
				if ((i >> (s[j][l] - 1)) & 1) cnt++;
			}
			if (cnt % 2 != p[j]) {
				f = false;
				break;
			};
		}
		if (!f) continue;
		ans++;
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,q,ans,a[52],b[52],c[52],d[52],f[52];
inline void dfs(re int x){
	if(x>n){
		re int sum=0;
		for(re int i=1;i<=q;++i){
			if(f[b[i]]-f[a[i]]==c[i])sum+=d[i];
		}
		ans=max(ans,sum);
		return;
	}
	for(re int i=f[x-1];i<=m;++i){
		f[x]=i;
		dfs(x+1);
	}
}
signed main(){
	n=read(),m=read(),q=read();
	for(re int i=1;i<=q;++i){
		a[i]=read();
		b[i]=read();
		c[i]=read();
		d[i]=read();
	}
	f[0]=1;
	dfs(1);
	printf("%d",ans);
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;

bool compare(pii a, pii b) { return a.first > b.first; }
int main() {
  int n;
  cin >> n;
  vector<pii> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = 0;
  }

  sort(a.begin(), a.end(), compare);

  for (int i = 0; i < n; i++) {
    a[i].second = (i == 0 ? 1 : 2);
  }

  int count = 0;

  ll ans = 0;
  int i = 0;

  while (1) {
    ans += a[i].first * a[i].second;
    count += a[i].second;

    if (count == n - 1) {
      break;
    }
    if (count == n) {
      ans -= a[i].first;
      break;
    }
    i++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4788
#include<stdio.h>
void f(int y,int x,char d[120][120],char w){
  if(d[y][x]-w)return ;
  d[y][x]=0;
  f(y+1,x,d,w);
  f(y-1,x,d,w);
  f(y,x+1,d,w);
  f(y,x-1,d,w);
}
int main(){
  int h,w,i,j,c;
  while(scanf("%d %d",&h,&w),h){
    char d[120][120]={0};
    for(i=c=0;i<h;i++)scanf("%s",d[i+1]+1);
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	if(d[i][j]==0)continue;
	c++;
	f(i,j,d,d[i][j]);
      }
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t a,b,k;
    cin >> a >> b>> k;
        if(a>=k){
            //高橋君のをk枚食べればいいだけ
            //cout << "p1" <<endl;
            a = a -k;
        }
        else if(a < k && a+b>=k){
            //cout << "p2" <<endl;
            //高橋君を食べつくした後残りの青木君を食べる
            k = k-a;
            a = 0;
            b = b -k;
        }
        else{
            //cout << "p3" <<endl;
            //両方食べつくす   
            a=0;
            b=0;
        }
    cout << a <<" "<<b <<endl;
}

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

int main()
{
	int n;
	std::cin >> n;
	int ans = 0;
	std::vector<std::vector<std::pair<int, int> > > tst;
	for (int i = 0; i < n; i++)
	{
		int a;
		std::cin >> a;
		std::pair<int, int> XY;
		std::vector<std::pair<int, int> > P;		
		for (int j = 0; j < a; j++)
		{
			int x;
			int y;
			std::cin >> x >> y;
			x--;
			XY.first = x;
			XY.second = y;
			P.push_back(XY);
		}
		tst.push_back(P);
	}
	for (int bit = 0; bit < (1 << n); bit++)
	{
		int pre_ans = 0;
		bool flag = true;
		for (int i = 0; i < n; i++)
		{
			if (!(bit & (1 << i)))
				continue;
			for (int k = 0; k < tst.at(i).size(); k++)
			{
				int x = tst.at(i).at(k).first;
				int y = tst.at(i).at(k).second;
				if (y == 1 && !(bit & (1 << x)))
					flag = false;
				if ( y == 0 && (bit & (1 << x)))
					flag = false;
			}
		}
		if (flag)
		{
			for (int i = 0 ; i < n; i++)
			{
				if (bit & (1 << i))
					++pre_ans;
			}
		}
		if (pre_ans > ans)
			ans = pre_ans;
	}
	std::cout << ans << '\n';
}


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

mx = lst[0]
if n == 1:
  print(0)
else:
  s =0
  for i in range(1,n):
    if lst[i] < mx:
      s += mx -lst[i]
    if lst[i] > mx:  
      mx = lst[i]
      
  print(s)    

Measured memory_bytes: 32244
#include<bits/stdc++.h>
using namespace std;
 
using lnt = long long;
using Real = long double;
 
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)
 
#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
 
constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;
 
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}
 
using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	lnt N, X, T; cin >> N >> X >> T;
	lnt kai = (N+X-1) / X;
	cout << T * kai << ln;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))

ans = 0
l = r = 0
total = A[0]
xor = A[0]

while True:
    if xor == total:
        ans += r - l + 1
        r += 1
        if r == N:
            break
        total += A[r]
        xor ^= A[r]
    else:
        total -= A[l]
        xor ^= A[l]
        l += 1

print(ans)

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

const int DAT_SiZE = (1<<18)-1;
int N = 1<<17;
long long data[DAT_SiZE];

void add(int a,int b,int x,int k,int l,int r){
  if(a <= l && r <= b){
    data[k] += x;
  }
  else if(l < b && a < r){
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
}

long long get(int a,int k,int l,int r){
  if(l == a && a+1 == r) return data[k];
  else if(l <= a && a < r){
    return data[k]+get(a,k*2+1,l,(l+r)/2)+get(a,k*2+2,(l+r)/2,r);
  }
  return 0;
}

int i,j,n,m;
string str;

int main(){
  cin >> n >> m;
  vector<int> a(n);
  for(i = 0;i < n;i++) cin >> a[i];
  long long ans = 0,zero = 0;
  for(i = 1;i < n;i++){
    if(a[i]>a[i-1]){
      j = a[i]-a[i-1];
      add(a[i-1]+1,a[i],1,0,0,N);
      add(a[i],a[i]+1,-j+1,0,0,N);
    }
    else{
      j = m-a[i-1]+a[i];
      add(a[i-1]+1,m+1,1,0,0,N);
      add(0,a[i],1,0,0,N);
      add(a[i],a[i]+1,-j+1,0,0,N);
      zero += m-a[i-1];
    }
    ans += j;
  }
  vector<long long> sm(m);
  sm[0] = get(1,0,0,N);
  long long maxi = sm[0];
  for(i = 1;i < m;i++){
    sm[i] = get(i+1,0,0,N)+sm[i-1];
    if(maxi < sm[i]) maxi = sm[i];
  }
  cout << ans-zero-maxi << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);


int main() {
    class union_find{
            vector<long> parent, tree_size;
        public:
            union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
                for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
            }
            ll find(ll x){
                while(parent[x] != x)x = parent[x] = parent[parent[x]];
                return x;
            }
            void merge(ll a, ll b){
                a = find(a);
                b = find(b);
    	    if(a==b) return;
                if(tree_size[a] < tree_size[b])swap(a, b);
                tree_size[a] += tree_size[b];
                parent[b] = a;
                return;
            }
    	bool same(ll a, ll b){
    	    a = find(a);
    	    b = find(b);
    	    return a == b;
    	}
        };
    //uf.mergeのように使う
    //ufはMAX_N+1でとるか、代入時に0-indexedにする
    cin>>N>>Q;
    union_find uf(N);
    rep(i, Q){
        int t, u, v;
        scanf("%d%d%d", &t, &u, &v);
        if(t == 0){
            uf.merge(u, v);
        }else{
            printf("%d\n", uf.same(u, v));
        }
    }
}


Measured memory_bytes: 6444
from pprint import pprint
import itertools


n,m,q = map(int, input().split())

ql = [list(map(int,input().split())) for _ in range(q)]



a_lists = list(itertools.combinations_with_replacement(range(m), n))

#print(a_lists)

dmax = 0

for a_mini in a_lists:
    dtemp = 0
    for ql_mini in ql:
        if a_mini[ql_mini[1]-1] - a_mini[ql_mini[0]-1] == ql_mini[2]:
            dtemp += ql_mini[3]
        else:
            pass
    if dtemp >= dmax:
        dmax = dtemp

print(dmax)

Measured memory_bytes: 91768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

int main(){
    int N;
    cin >> N;  
    int ans = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	ll n; cin>>n;
	ll ans= n*(n-1)/2;
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)

	pas := make([]interface{}, n)
	for i := range a {
		pas[i] = &a[i]
	}
	fmt.Scan(pas...)

	for i, e := range a {
		fmt.Print(e)
		if i != n-1 {
			fmt.Print(" ")
		} else {
			fmt.Println()
		}
	}

	for i := 1; i < n; i++ {
		v := a[i]
		j := i - 1
		for j >= 0 && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v

		for i, e := range a {
			fmt.Print(e)
			if i != n-1 {
				fmt.Print(" ")
			} else {
				fmt.Println()
			}
		}
	}
}



Measured memory_bytes: 1212
from collections import deque
import sys


N, D, A = map(int, input().split())
M = [tuple(map(int, x.split())) for x in sys.stdin.readlines()]
M.sort()

q = deque()
qt = deque()

ans = 0
dmg = 0
for x, h in M:
    if len(q) == 0:
        bomb = (h + A - 1) // A
        q.append((x + 2 * D, bomb))
        dmg += bomb * A
        ans += bomb
    else:
        while len(q) > 0:
            d, bomb = q.popleft()
            if d < x:
                dmg -= bomb * A
            else:
                q.appendleft((d, bomb))
                break
        if h > dmg:
            bomb = ((h - dmg) + A - 1) // A
            q.append((x + 2 * D, bomb))
            dmg += bomb * A
            ans += bomb

print(ans)


Measured memory_bytes: 46184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace CF2016B_A
{
    class Program
    {
        static string a = "CODEFESTIVAL2016";
        static int ans;
        static void Main(string[] args)
        {
            var t = ReadLine();
            for (int i = 0; i < 16; i++)
            {
                if (a[i] != t[i])
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}


Measured memory_bytes: 2648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

int
main(void)
{
        int r;
        int D;
        int x;

        scanf("%d %d %d", &r, &D, &x);

        for (int i = 1; i <= 10; i++) {
                printf("%d\n", r * x - D);
                x = r * x - D;
        }

        return 0;
}


Measured memory_bytes: 128
k = int(input())

t = 7
t %= k

for i in range(k+1):
    if t == 0:
        print(i+1)
        break
    #常に余りを用いる　⇒　10**7桁の演算
    t = (t*10 + 7)%k
else:print(-1)

"""
else:
for(while)文を
break文で抜ける（真）　⇒　実行しない
forのイテラブルを使い切る、whileが偽になる　⇒　実行する
"""

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

int isprime(int m){
if (m<2) {return 0;}
if(m==2)return 1;
if(m%2==0)return 0;
for (int i =3 ; i*i <= m; i=i+2) {
	if(m%i==0){return 0;}
}
return 1;
}


int main() {
int n,m,l,ans=0;
	cin>>n;
	for (int i = 0; i < n; ++i) {
	cin>>m;
	if(isprime(m)){ans+=1;}
}
cout<<ans<<endl;
}

Measured memory_bytes: 3056
k,s = list(map(int, input().split()))
cnt=0
minX=max(s-2*k, 0)
maxX=min(s, k)
for x in range(minX, maxX+1):
    rest=s-x
    if k>=rest:
        cnt+=rest+1
    else:
        cnt+=2*k-rest+1
    
print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);

	if(a<=b && b<=c)
	{
		printf("%d %d %d\n",a, b, c);
	}
	else
	{
		if(a<=c && c<=b)
		{
			printf("%d %d %d\n", a, c, b);
		}
		else
		{
			if (b<=a && a<=c)
			{
				printf("%d %d %d\n", b, a, c);
			}
			else
			{
				if (b<=c && c<=a)
				{
					printf("%d %d %d\n", b, c, a);
				}
				else
				{
					if (c<=a && a<=b)
					{
						printf("%d %d %d\n", c, a, b);
					}
					else
					{
						if (c <= b && b <= a)
						{
							printf("%d %d %d\n", c, b, a);
						}
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2756
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using LL = long long;
const int INF = 1e9;

int main(void) {
    int X;
    cin >> X;
    bool is_prime[200000+1];
    for (int i = 0; i <= 200000; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= 200000; i++) {
        if (is_prime[i]) {
            for (int j = 2 * i; j <= 200000; j += i) is_prime[j] = false;
        }
    }
    for (int x = X;; x++) {
        if (is_prime[x]) {
            cout << x << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) {
        cin>>a[i];
        if (a[i] == 0) {
            cout << 0 << '\n';
            return 0;
        }
    }

    ll ans = 1;
    rep(i,n) {
        if (ans > LINF/a[i]) {
            cout << -1 << '\n';
            return 0;
        }
        ans *= a[i];
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4036
//karna padega 
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n;
		cout << n*n*n;

	
	}
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
  
  int n,m;cin>>n>>m;
  long long int count=0;
  for(int i=0;i<m;i++)
  {
    int x;cin>>x;
    count+=x;
  }
  if(count>n)
    cout<<-1<<endl;
  else
    cout<<n-count<<endl;
  return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] S = sc.next().toCharArray();
        int length = S.length;
    
    
        for (int i = 0; i < length; i++) {
            int n = (S[i] - 'A' + N) % 26;
            S[i] = (char) (n + 'A');
        }
    
        System.out.println((new String(S)));
    }
}

Measured memory_bytes: 21972
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

cnt = 0
for i in range(n):
  if a_list[i] <= b_list[i]:
    cnt += a_list[i]
    b_list[i] -= a_list[i]
    a_list[i] = 0
    if a_list[i+1] <= b_list[i]:
      cnt += a_list[i+1]
      a_list[i+1] = 0
    else:
      cnt += b_list[i]
      a_list[i+1] -= b_list[i]
  else:
    cnt += b_list[i]
    a_list[i] -= b_list[i]
    b_list[i] = 0
    
print(cnt)

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

int main(){
  char s[3];cin>>s;
  int cnt=0;
  rep(i,3)
    if(s[i]=='1'){
      cnt++;
    };
  cout<<cnt<<endl;
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
    int x,maxi=-1;cin>>x;
    vi vec;
    for(int i=0; i<x; ++i)
    {
    	int n;cin>>n;
    	vec.pb(n);
    	if(n>maxi)
    		maxi=n;
    }
    sort(all(vec));
    int cnt=0;
    for(int i=1; i<=maxi; ++i)
    {
    	int n = lb(all(vec),i)-vec.begin();
    	if(n==x-n)
    		++cnt;
    }
    cout<<cnt<<"\n";

}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    vector<int>a,b,c;
    int x,i,j;
    cin>>n>>k;
  //  cout<<"sss"<<" ";
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x<0)a.push_back(-1*x);
        else b.push_back(x);
       // cout<<"ss";
    }
   // cout<<"ss";
    if(a.size()!=0)sort(a.begin(),a.end());
    int ans=1000000009;
    int flag,temp;
   // cout<<a.size();
    for(i=0;i<a.size()&&i<k;i++)
    {
        temp=k-i-2;
        if((b.size()>=temp+1)&&temp>0)
        {
            flag=2*a[i]+b[temp];
            if(flag<ans)ans=flag;
        }
    }
    if(a.size()>=k)
    {
        if(a[k-1]<ans)ans=a[k-1];
    }
  //  cout<<"sww";
    for(i=0;i<b.size()&&i<k;i++)
    {
        temp=k-i-2;
        if((a.size()>=temp+1)&&temp>0)
        {
            flag=2*b[i]+a[temp];
         //   cout<<flag<<" ";
            if(flag<ans)ans=flag;
        }
    }
    if(b.size()>=k)
    {
        if(b[k-1]<ans)ans=b[k-1];
    }
    cout<<ans;

}

Measured memory_bytes: 1020
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,N1,*H,*P,i,max=0,count=0;
  scanf("%d",&N);
  H = (int*)malloc(N*sizeof(int));
  P = (int*)malloc(N*sizeof(int));
  for(i=0;i<N;i++)
    scanf("%d",&H[i]);
  N1 = N-1;
  for(i=0;i<N1;i++)
    if(H[i]>=H[i+1])
      P[i] = 1;
    else
      P[i] = 0;
  P[N1] = 0;
  for(i=0;i<N1;i++){
    if(P[i]==0){
      count = 0;
      continue;
    }
    count++;
    if(count>max)
      max = count;
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 896
import heapq
n, m = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)
#print(A)

for i in range(m):
    val = heapq.heappop(A)
    val = -(-val // 2)
    heapq.heappush(A, val)

print(-sum(A))

Measured memory_bytes: 72216
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int n;
  S(n);
  vi v;
  rep(i,0,2*n) {
    int x;
    S(x);
    v.push_back(x);
  }
  sort(all(v));
  int ans = 0;
  rep(i,0,2*n) {
    if(i & 1) continue;
    ans += v[i];
  }
  P(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
#define fo(i,s,e_ex) for(i=s;i<e_ex;i++)
#define MOD 1000000007//998244353

ll arr[105],dp[105][100005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll i,j,n,k;
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>arr[i];
	fo(i,0,k+1) dp[0][i]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<=k;j++){
			ll mn=j-arr[i]-1;
			dp[i][j]=dp[i-1][j];
			if(mn>=0) dp[i][j]-=dp[i-1][mn];
			dp[i][j]=(dp[i][j]+MOD)%MOD;
		}
		if(i==n){
			cout<<dp[n][k]<<endl;
			return 0;
		}
		for(j=1;j<=k;j++) {
			dp[i][j]+=dp[i][j-1];
			dp[i][j]%=MOD;
		}
	}
	return 0;
}


Measured memory_bytes: 82464
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

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

  int32_t N, M;
  cin >> N >> M;
  int32_t num_state = (1 << N);
  vector<vector<int>> dp(M+1, vector<int>(num_state, INT_MAX >> 1));
  dp[0][0] = 0;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = 0; j < b; j++) {
      int c;
      cin >> c;
      int update = 1 << (c - 1);
      for (int mask = 0; mask < num_state; mask++) {
        if (((mask >> (c-1)) & 1) == 1) continue;
        dp[i+1][mask + update] = min(dp[i+1][mask], a + dp[i][mask]); 
        //cout << "update: " << c << "," << update << "," << mask << "," << dp[i+1][mask+update] << endl;
        //dp[i+1][mask + update] = min(dp[i+1][mask + update], dp[i+1][mask]);
      }
    }
    for (int mask = 0; mask < num_state; mask++) {
      dp[i+1][mask] = min(dp[i][mask], dp[i+1][mask]);
    }
  }

  if (dp[M][num_state - 1] >= (INT_MAX >> 1)) cout << -1 << endl;
  else cout << dp[M][num_state - 1] << endl;
  return 0;
}

Measured memory_bytes: 16384
#!/usr/bin/env pypy3


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    n, m = get_ints()

    divs = []

    div = 1
    while div * div <= m:
        if m % div == 0:
            divs.append(div)
            if div * div < m:
                divs.append(m // div)
        div += 1
        
    divs.sort()
    ratios = [m // div for div in divs]

    i = 0
    while i + 1 < len(divs) and ratios[i + 1] >= n:
        i += 1
    print(divs[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
n = int(input())
s = []

if n%2 == 0:
	s.append(0)
else:
	s.append(1)
i = 1
nn = n - s[i-1]
while nn != 0:
	if nn%(2**(i+1)) == 0:
		s.append(0)
	else:
		s.append(1)
	nn -= s[i]*(-2)**i
	i += 1
s.reverse()
print("".join(map(str, s)))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define modulo 1000000007
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

	int n = s.size();
	vector<int> num(n,0);
	vector<int> nL,nR;
	for(int i=0; i<n; i++){
		if(s[i]=='L') nL.push_back(i);
		else nR.push_back(i);
	}

	int plus;
	for(int i=0; i<n; i++){
		if(s[i]=='L') plus = -1;
		else plus = 1;

		int n1;
		if(s[i]=='L'){
			for(int j=nR.size()-1; j>=0; j--){
				if(nR[j] < i){
					n1 = nR[j]-i;
					break;
				}
			}
		}
		if(s[i]=='R'){
			for(int j=0; j<nL.size(); j++){
				if(nL[j] > i){
					n1 = nL[j]-i;
					break;
				}
			}
		}

		if(n1%2==0) num[i+n1] ++;
		else num[i+n1-plus] ++;
	}

	for(int i=0; i<n; i++) cout << num[i] << endl;
	return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <string>
#include <array>
using namespace std;

int main() {
  string S,T;
  cin >> S >> T;
  array<int,26> Rs,Rt;
  for (int i=0; i<26; i++) {
    Rs[i] = -1;
    Rt[i] = -1;
  }
  for (int i=0; i<S.size(); i++) {
    if (Rs[S[i]-97]>=0) {if (Rs[S[i]-97]!=T[i]) {cout << "No" << endl;return 0;}}
    if (Rt[T[i]-97]>=0) {if (Rt[T[i]-97]!=S[i]) {cout << "No" << endl;return 0;}}
    if (Rs[S[i]-97]<0) Rs[S[i]-97] = T[i];
    if (Rt[T[i]-97]<0) Rt[T[i]-97] = S[i];
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef pair<ll,ll> P;
int main(){
    string s; cin >> s;
    int ans = 0;
    int num = stoi(s);
    rep(i,s.size()){
        ans += (int)(s[i]-'0');
    }
    if(num%ans==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def cnt(a):
    if a&1:
        return 0
    else:
        return 1 + cnt(a//2)

def solve():
    n = f()[0]
    a = f()

    ans = 0
    for i in a:
        ans += cnt(i)
    
    print(ans)



solve()


Measured memory_bytes: 4148
N, K = map(int, input().split())
S = list(input())

l = []
bef = ""
start = 0
ans = 0

for i, s in enumerate(S):
    if bef=="":
        start = i
    elif bef!=s:
        cnt = 0
        l.append(i-start)
        start = i
    bef = s
l.append(i-start+1)

size = len(l)
ans = 0
for i in range(min(2*K+1, size)):
    ans += l[i]
ans -= 1
for i in range(min(2*K+1, size), size):
    ans += l[i]-1
print(ans)

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

vector<int>v[200005];
bool vis[200005];
queue<int>q;

int main()
{
    int n,m,i,j,a,b,ans=1,c=0;

    cin>>n>>m;

    for(i=0;i<m;i++){
        scanf("%d %d",&a,&b);

        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(i=1;i<=n;i++){
        if(!vis[i]){
            q.push(i);
            c=1;
        }
        while(!q.empty()){
            a=q.front();
            q.pop();
            vis[a]=1;

            for(j=0;j<v[a].size();j++){
                if(!vis[v[a][j]]){
                    c++;
                    q.push(v[a][j]);
                    vis[v[a][j]]=1;
                }
            }
        }
        ans=max(ans,c);
    }
    cout<<ans<<"\n";

    return 0;
}






Measured memory_bytes: 15144
import numpy as np
N,M,X=map(int,input().split())
C=[[0 for i in range(M)] for j in range(N)]
for i in range(N):
    C[i] = list(map(int, input().split()))
D=np.array(C)
E=[0]*2**N

for i in range(2**N):
  c=format(i,'012b')
  for j in range(N):
    d=int(c[12-N+j])
    E[i]+=D[j]*int(d)

if min(E[-1][1:M+1])<X:
  print(-1);exit()
    
Max=E[-1][0]+1
Min=Max
for i in range(2**N):
  if min(E[i][1:M+1])>=X:
    if Min>E[i][0]:Min=E[i][0]
    continue
  else:E[i][0]=Max
print(Min)
exit()

Measured memory_bytes: 28168