akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s;
    cin >> s;
    int min_a = 10000000;
    int max_z = -1;
    for (int i=0; i<=s.size(); i++) {
        if (s[i] == 'A') {
            min_a = min(min_a, i);
        } else if (s[i] == 'Z') {
            max_z = max(max_z, i);
        }
    }
    cout << max_z - min_a + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> p;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;
struct edge{
    int to;
    int cost;
};
int n,k;
vector<ll> fac,inv,finv;
void initCOM(){
    fac=inv=finv=vector<ll>(1e6+1);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<=1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main(){
    initCOM();
    cin>>n>>k;
    int m=min(n-1,k);
    ll ans=0;
    for(int h=0;h<=m;++h){
        ans+=COM(n,h)*COM(n-1,h)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key)
{
  NodePointer n;
  /*for(n=nil;n->next != nil;n=n->next)
    {
      //printf("a\n");
      if(n->next->key == key)return n;
    }
    return NULL;*/
  n=nil->next;
  while(n!=nil&&n->key!=key)
    n=n->next;
    return n;
}

void init(){
  nil = (struct node *)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 0;
  while(1){
    if ( cur == nil ) break;
    if ( isf++ > 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(NodePointer t)
{
  if(t!=nil)
    {
      //NodePointer delnode;
      /*delnode=t->next;
	t->next=delnode->next;
	free(delnode);*/
      t->prev->next=t->next;
      t->next->prev=t->prev;
      free(t);
    }
}

void deleteFirst(){
  NodePointer t = nil->next;
  deleteNode(t);
}

void deleteLast(){
  /* NodePointer n;
  //for(n=nil;n->next != nil;n=n->next);
  // n=nil->prev;
  n=nil->next;
  while(n->next!=nil)
    {
      
      n=n->next;
      printf("%d\n",n->key);
      }
      //printf("%d",nil->next->key);*/
  deleteNode(nil->prev);
}

void delete(int key)
{
  NodePointer n,delnode;
  if((n=listSearch(key)) != NULL)
    {     
      deleteNode(n);
    }
}


void insert(int key){
  NodePointer x;
  x = (struct node *)malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6)
	{
	  if ( com[6] == 'F' )
	    {
	      deleteFirst();
	    }
	  else if ( com[6] == 'L' )
	    {
	      deleteLast();
	    }
	} else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 32980
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num) - 1
    return cnt

while True:
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        exit()
    tmp = count(mid)
    if right - left <= 1:
        mid = right
        break
    elif tmp > K:
        left = mid
    else:
        right = mid

right = mid

while True:
    tmp = count(mid)
    if right - left <= 1:
        print(right)
        break
    elif tmp == K:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        break

Measured memory_bytes: 31016
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var x = readLine()!!.split(" ").map(String::toLong)
    var dic :MutableMap<Long,Long> = mutableMapOf()
    var cnt = 0L
    x.map{
            if(dic[it] == null) dic[it] = 0
            dic[it] = dic[it]!! + 1
            }
    dic.toList().sortedBy{it.first}.reversed().map{
        var (k,v) = it
        if(k>v) cnt += v
        else cnt += v-k
    }
    println(cnt)
}


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

int main(void){
    long long N,K,count=0,aplus,bplus;
    long long mod = (int) pow(10,9)+7;
    cin >> N >> K;
    long long A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    aplus = (K*(K+1)/2)%mod;
    bplus = (K*(K-1)/2)%mod;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i<j){
                if(A[i] > A[j]) count += aplus;
                if (count > mod) count-=mod;
            }else  if(i>j){
                if(A[i] > A[j]) count += bplus;
                if(count > mod ) count-=mod;
            }
        }
    }

    cout << count%mod << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */
int main() {
    int N, K; cin >> N >> K;
    int x[N];
    rep(i, N) {
        cin >> x[i];
    }
    int ans = INF;
    for(int i = 0;i < N - K + 1;++i) {
        if(x[i + K - 1] >= 0 == x[i] >= 0) {
            ans = min(ans, ((x[i] >= 0) ? x[i + K - 1] : abs(x[i])));
        }else {
            ans = min(ans, 2 * min(abs(x[i]), x[i + K - 1]) + max(abs(x[i]), x[i + K - 1]));
        }
    }
    cout << ans << endl;
}


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

int N;
int d[100000];

int main() {
    cin >> N;
    rep(i, N) cin >> d[i];

    sort(d, d + N);

    int end = d[N / 2];
    int start = d[(N / 2) - 1] + 1;

    // printf("%d %d\n", start, end);

    cout << end - start + 1 << endl;
}

Measured memory_bytes: 640
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {
    let ret;
    from_line!(a: i32, b: i32, c: i32);
    if a < b && b < c {
        ret = "Yes";
    }
    else {
        ret = "No";
    }
    println!("{}", ret);
}



Measured memory_bytes: 5020
#include <cstdio>
#include <algorithm>

using namespace std;

int v[100010];

int main ()
{
  //  freopen ("file.in", "r", stdin);

    int n;
    scanf ("%d", &n);

    for (int i = 1; i <= n; ++i)
        scanf ("%d", &v[i]);

    long long a = 2, b = 2;
    for (int i = n; i; --i)
    {
        if (a % v[i]) a = 1LL * (1LL * a / v[i] + 1LL) * v[i];
        b = 1LL * (1LL * b / v[i] + 1LL) * v[i] - 1LL;

        if (a > b)
        {
            printf ("-1\n");
            return 0;
        }
    }

    printf ("%lld %lld\n", a, b);

    return 0;
}


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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
int main(){
  ll n, m;
  cin >> n >> m;

  vector<ll> a(m), b(m);
  for(int i=0; i<m; i++) cin >> a[i] >> b[i];

  UnionFind uf(n);
  for(int i=0; i<m; i++){
    uf.unite(a[i]-1, b[i]-1);
  }

  // vector<bool> is_root(n, false);
  // for(int i=0; i<n; i++){
  //   ll x = uf.find(i);
  //   if(x == -1) is_root[i] = true;
  //   else is_root[x] = true;
  // }

  // ll cnt = 0;
  // for(int i=0; i<n; i++) if(is_root[i]) cnt++;

  ll cnt = 0;
  for(int i=0; i<n; i++) if(uf.d[i] < 0) cnt++; 
  ll ans = cnt-1;
  cout << ans << endl;

  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 5372
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;

const int MOD = 1000000007;

void add(int &a, int b) { a += b; if(MOD <= a) a -= MOD; }

int dp[2][1<<21];
vector<int> KV[22];

bitset<21> A[21];

int N;

int main() {
	cin >> N;
	for(int i = 0; i < N; i++) for(int j = 0, c; j < N; j++) {
		cin >> c;
		A[i][j] = !!c;
	}

	for(int key = 0; key < (1<<N); key++) {
		int c = 0;
		for(int i = 0; i < N; i++)
			if(key & (1<<i)) c++;
		KV[c].eb(key);
	}

	dp[0][0] = 1;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) if(A[i][j])
			for(int key : KV[i]) if(!(key & (1<<j)))
				add(dp[1][key | (1<<j)], dp[0][key]);
		memcpy(dp[0], dp[1], (1<<N) * sizeof(int));
		memset(dp[1], 0, (1<<N) * sizeof(int));
	}

	cout << dp[0][(1<<N)-1] << endl;
	return 0;
}

Measured memory_bytes: 26044
ken_shi_list = input().split()
ken_num = int(ken_shi_list[0])
shi_num = int(ken_shi_list[1])
 
shi_list = []
nen_list = [[] for i in range(ken_num) ]
 
for i in range(shi_num):
    shi_list.append(input().split())
    nen_list[int(shi_list[i][0])-1].append( int(shi_list[i][1]) )
 
 
checker = {}
for i in range(ken_num):
   nen_list[i].sort()
   for j in range(len(nen_list[i])):
        checker[nen_list[i][j]] = j+1


for i in range(shi_num):
    ken = int(shi_list[i][0])
    nen = int(shi_list[i][1])
    print( str(ken).zfill(6) + str(checker[nen]).zfill(6) )

Measured memory_bytes: 57204
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int got(int n,int x){
	return n/(1<<x);
}

int main(){
	
	ll n;
	cin>>n;
	ll cnt = 0,cnt1=  0;
	if(n&1){
		cout<<0<<endl;
		return 0;
	}
	n/=2;
	while(n){
		n /= 5;
		cnt += n;
	}

	cout<<cnt<<endl;
	

	return 0;
}

Measured memory_bytes: 3584
import fractions
A, B, C, D = map(int, input().split())

#C, Dの最小公倍数
lcm = C * D // fractions.gcd(C, D)

ans = B - A + 1
ans -= B // C - (A - 1) // C
ans -= B // D - (A - 1) // D
ans += B // lcm - (A - 1) // lcm
print(ans)


Measured memory_bytes: 64620
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    int n;
    int now=0;
    int high=0;
    int maxi=0;

    cin>>n;
    vector<int> h(n+1);
    FOR(i,1,n){
        cin>>h[i];
    }
    high=h[1];
    FOR(i,2,n){
        if(high>=h[i]){
            high=h[i];
            now++;
        }else{
            maxi=max(maxi,now);
            high=h[i];
            now=0;
        }
    }
    maxi=max(maxi,now);
    cout<<maxi<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    final static int NIL = -1;
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        TNode root = new TNode(NIL);
        for(int i = 0; i < n; i++) {
            String cmd = input.next();
            if (cmd.equals("insert")) {
                int key = Integer.parseInt(input.next());
                TNode z = new TNode(key);
                root = insert(root, z);
            } else if (cmd.equals("find")) {
                int key = Integer.parseInt(input.next());
                System.out.println(find(root, key)? "yes":"no");
            } if (cmd.equals("print")) {
                inOrder(root);
                System.out.println();
                preOrder(root);
                System.out.println();
            }
        }
    }
    public static TNode insert(TNode root, TNode z) {
        TNode y = new TNode(NIL); // 前一个节点
        TNode x = root; // 当前节点

        z.left = new TNode(NIL);
        z.right = new TNode(NIL);

        while( x.key != NIL ){ // 当前节点不为空
            y = x; // y 指向当前节点
            if( z.key < x.key ) {
                x = x.left;
            } else {
                x = x.right;
            }
        }

        z.parent = y;
        if( y.key == NIL ){
            root = z;
        } else {
            if( z.key < y.key ) {
                y.left = z;
            } else {
                y.right = z;
            }
        }
        return root;
    }
    public static boolean find(TNode root, int key) {
        TNode x = root;
        while( x.key != NIL) {
            if (key == x.key) {
                return true;
            } else if(key < x.key) {
                x = x.left;
            } else {
                x = x.right;
            }
        }
        return false;
    }
    public static void preOrder(TNode node) {
        if(node.key == NIL) {
            return;
        }
        System.out.print(" " + node.key);
        preOrder(node.left);
        preOrder(node.right);
    }
    public static void inOrder(TNode node) {
        if(node.key == NIL) {
            return;
        }
        inOrder(node.left);
        System.out.print(" " + node.key);
        inOrder(node.right);
    }
}

class TNode {
    int key;
    TNode left, right ,parent;
    TNode(int key) {
        this.key = key;
    }
}



Measured memory_bytes: 208768
def insertionSort(A, N):
    for i in range(1, N):
        print(" ".join([str(a) for a in A]))
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
    print(" ".join([str(a) for a in A]))    
    

N = int(input().rstrip())
A = [int(a) for a in input().rstrip().split(" ")]
insertionSort(A, N)


Measured memory_bytes: 5612
#include<iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    if (temp % 2 != 0) continue;
    if ((temp % 3 != 0) && (temp % 5 != 0)){
      cout << "DENIED";
      return 0;
    }
  }
  cout << "APPROVED";
  return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n; cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto &e: mp) {
        if (e.second > mx) mx = e.second;
    }
    vector<string> v;
    for (auto &e: mp) {
        if (e.second == mx) v.push_back(e.first);
    }
    sort(v.begin(), v.end());
    for (auto e: v) {
        cout << e << endl;
    }
    return 0;
}

Measured memory_bytes: 25584
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n>>m;
	   cout << (n-2*m<0?0:n-2*m) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> P;
const int mod = 1000000007;

int sum[100010];

signed main(){

    int n;
    cin >> n;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        sum[a]++;
        sum[b+1]--;
    }
    rep(i, 100009)sum[i+1] += sum[i];
    int ans = 0;
    rep(i, n+2)if(sum[i] >= i - 1)ans = max(ans, i - 1);
    cout << ans << endl;
}


Measured memory_bytes: 3908
H,W = map(int,input().split())
N = int(input())
A = []
for i, a in enumerate(map(int,input().split())):
  A.append([a,i+1])
A.sort(reverse= True)
grids = [[-1 for _ in range(W)] for _ in range(H)]

pos = [0,0]
for a,i in A:
  cnt = 0
  while cnt != a:
    grids[pos[1]][pos[0]] = i
    cnt += 1
    if pos[1]%2==0:
      if pos[0] != W-1: pos[0] +=1
      else: pos = [W-1,pos[1]+1]
    else:
      if pos[0] != 0: pos[0] -=1
      else: pos = [0,pos[1]+1]

[print(*row) for row in grids]

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

int main() {
  int N;
  cin>>N;
  int64_t a=0;
  for(int i=0;i<N;i++){
    int64_t b;
    cin>>b;
    a=a|b;
  }
  
  int Z=0;
  while(!(a&(1<<Z))){
    Z++;
  }
  cout<<Z<<endl;
  
}

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

int n,res=0,f[100005];

int main()
{
    cin>>n;
    int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        f[x]++;
    }
    for(int i=1;i<=1e5;i++)
        res=max(res,f[i-1]+f[i]+f[i+1]);
    cout<<res;
}


Measured memory_bytes: 640
S = input()
N = len(S)
max = 0
for i in range(N):
    if N-i<=max:
        break
    flag = 0
    for j in range(N-i):
        for k in range(j+1):
            if S[i+k]!='A' and S[i+k]!='T' and S[i+k]!='G' and S[i+k]!='C':
                flag = 1
                break
        if flag==0:
            if max < j+1:
                max = j+1
print(max)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double r = scan.nextDouble();
		double PI = Math.PI;
		scan.close();

		if (0 < r && r < 10000) {
			double res1 = r * r * PI;
			double res2 = 2 * r * PI;

			System.out.printf("%.6f",res1);
			System.out.print(" ");
			System.out.printf("%.6f",res2);
		}

	}

}

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

int main() 
{
  int k;
  cin>>k;
  ll sum=0;
  for(int a=1;a<=k;a++)
  {
    for(int b=1;b<=k;b++)
    {
      for(int c=1;c<=k;c++)
      {
        sum+=__gcd(a,__gcd(b,c));
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    vector<long long> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i);
    }

    long long ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += min(a * (x.at(i + 1) - x.at(i)), b);
    }

    cout << ans << endl;
}   

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

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

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_1_B
*/
int main() {
    int x, y; cin >> x >> y;
    cout << gcd(x, y) << endl;
}



Measured memory_bytes: 3084
#define _CRT_SECURE_NO_WARNINGS


#define	Rd(s) scanf("%d", &s)
#define	Rs(s) scanf("%s", &s)
#define	Rf(s) scanf("%f", &s)

#define RTNd(n, s, i) for (int i = 0;(i<n) ? scanf("%d", &s), true : false;i++)
#define RTNf(n, s, i) for (int i = 0;(i<n) ? scanf("%lf", &s), true : false;i++)

#define RTEs(s) while (fgets(s, sizeof(s), stdin) != NULL)
#define RTEc(s) while ((s = scanf("%c")) != EOF)

#define Pd(s) printf("%d", s);
#define Pf(s) printf("%f", s);

#define Pn printf("\n");

#define SORTV(v) sort(v.begin(), v.end())
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long lli;
using namespace std;

int main() {
	int c[100];
	int K, T;
	int max,bef,els;

	scanf("%d %d", &K, &T);
	for (int i = 0;i < T;i++) {
		scanf("%d", &c[i]);
	}
	bef = 0;
	for (int i = 0;i < K;i++) {
		max = 0;
		els = 0;
		for (int j = 0;j < T;j++) {
			if (c[j] > 0)els ++ ;
			if (c[max] < c[j]) {
				if (j != bef)max = j;
			}
		}
		c[max]--;
		bef = max;
		if (els == 1)break;
	}
	int ans=0;
	for (int i = 0;i < T;i++)ans += c[i];
	printf("%d\n", ans);

}
//改行注意




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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll sum = 0;
    REP(i, N){
    	sum ^= A[i];
    }

    ll X = 0;
    vector<ll> B(N, 0);
    REP(i, 60){
    	ll val = (sum>>i & 1);
    	if(val){
    		X += (1ll<<i);
    	}else{
    		REP(j, N){
    			ll bi = ((A[j]>>i) & 1);
    			B[j] += (bi<<i);
    		}
    	}
    }

    int r = 0;
    for(int i=60;i>=0;i--){
    	int j = r;
    	for(;j<N;j++){
    		if(B[j]>>i&1){
    			swap(B[r], B[j]);
    			break;
    		}
    	}
    	if(j==N) continue;
    	REP(k, N){
    		if(k == r) continue;
    		if(B[k]>>i&1) B[k] ^= B[r];
    	}
    	r++;
    }

    ll Y = 0;
    REP(i, N){
    	Y = max(Y, Y^B[i]);
    }

    cout << X + 2*Y << endl;

    return 0;
}

Measured memory_bytes: 1920
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, x = sc.nextInt()
  val a = Array.fill(n)(sc.nextInt())
  var ans = 0L
  for (i <- 1 until n) {
    if (a(i-1) + a(i) > x) {
      if (x >= a(i-1)) {
        ans += a(i-1) + a(i) - x
        a(i) -= a(i-1) + a(i) - x
      } else {
        ans += a(i)
        a(i) = 0
        ans += a(i-1) + a(i) - x
        a(i-1) -= a(i-1) + a(i) - x
      }
    }
  }
  println(ans)
}

Measured memory_bytes: 59448
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(int i=0; i<9; i++){
			String s=sc.next();
			int a=sc.nextInt();
			int b=sc.nextInt();
			println(s+" "+(a+b)+" "+(a*200+b*300));
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

class UnionFind {
public:
	vector<int> Parent;
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	int root(int A) {
		if (Parent[A] < 0) {
			return A;
		}
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
		if (size(A) < size(B)) {
			swap(A, B);
		}

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}

};

int main()
{
	int n, q;
	cin >> n >> q;
	UnionFind uni(n);
	for (int i = 0; i < q; i++) {
		int p;
		int a;
		int b;
		cin >> p >> a >> b;
		if (p == 0) {
			uni.connect(a, b);
		}
		else {
			if (uni.root(a) == uni.root(b)) {
				cout << "1" << endl;
			}
			else {
				cout << "0" << endl;
			}
		}
	}

	
	return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    ll arr[n+1][3],dp[n+1][3]={};
    for(ll i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
      cin>>arr[i][j];
    }
    dp[1][0]=arr[1][0];dp[1][1]=arr[1][1];dp[1][2]=arr[1][2];
    dp[0][0]=0;dp[0][1]=0;dp[0][2]=0;
    for(ll i=2;i<=n;i++)
    {
      dp[i][0]=arr[i][0]+max(max(dp[i-1][1],dp[i-1][2]),dp[i-2][0]);
      dp[i][1]=arr[i][1]+max(max(dp[i-1][2],dp[i-1][0]),dp[i-2][1]);
      dp[i][2]=arr[i][2]+max(max(dp[i-1][0],dp[i-1][1]),dp[i-2][2]);
    }

     cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
      return 0;
}


Measured memory_bytes: 8312
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i = 0; i < ty - sy; i++){
    cout << 'U';
  }
  for(int i = 0; i < tx - sx; i++){
    cout << 'R';
  }
  for(int i = 0; i < ty - sy; i++){
    cout << 'D';
  }
  for(int i = 0; i < tx - sx; i++){
    cout << 'L';
  }

  cout << 'L';

  for(int i = 0; i < ty+1 - sy; i++){
    cout << 'U';
  }
  for(int i = 0; i < tx - sx+1; i++){
    cout << 'R';
  }
  cout << "DR";
  for(int i = 0; i < ty+1 - sy; i++){
    cout << 'D';
  }
  for(int i = 0; i < tx - sx+1; i++){
    cout << 'L';
  }
  cout << 'U' << endl;

}

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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    int n, m;
    cin >> n >> m;
    lint tmp, tmp2;
    vector<lint> h(n);
    vector<vector<int>> ab(n);
    rep(i, n) cin >> h[i];
    rep(i, m) {
        cin >> tmp >> tmp2;
        tmp--; tmp2--;
        ab[tmp].pb(tmp2);
        ab[tmp2].pb(tmp);
    }
    
    int cnt = n;
    rep(i, n) {
        rep(j, ab[i].size()) {
            if(h[i] <= h[ab[i][j]]) {
                cnt--;
                break;
            }
        }
    }
    
    cout << cnt;
    
    return 0;
}


Measured memory_bytes: 9240
#include<iostream>
#include<cstdio>
#define NIL -1
#define MAX 25
using namespace std;

struct Tree{ int parent, left , right;};
Tree T[MAX];

void Pre(int x){
    if( x == NIL) return;
    printf(" %d", x);
    Pre(T[x].left);
    Pre(T[x].right);
}

void In(int x){
    if(x == NIL) return;
    In(T[x].left);
    printf(" %d", x);
    In(T[x].right);
}

void Post(int x){
    if(x == NIL) return;
    Post(T[x].left);
    Post(T[x].right);
    printf(" %d",x);
}

int main(){
    int n, id, left, right;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        T[i].parent = T[i].left = T[i].right = NIL;
    }
    
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id, &left, &right);
        T[id].left = left;
        T[id].right = right;
        if(left != NIL) T[left].parent = id;
        if(right != NIL) T[right].parent = id;
    }
    
    int root;
    for(int i = 0; i < n; i++){
        if(T[i].parent == NIL) root = i;
    }
    
    printf("Preorder\n");
    Pre(root);
    printf("\n");
    printf("Inorder\n");
    In(root);
    printf("\n");
    printf("Postorder\n");
    Post(root);
    printf("\n");
    
    return 0;
    
}


Measured memory_bytes: 3200
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
#define N 200001
int n,k;
int main(){
    while (scanf("%d %d",&n,&k)!=EOF){
        if (n%k)
            printf("1\n");
        else
            printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() {
			while(st==null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
					
				}
				catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int n = ob.nextInt(),k=ob.nextInt();
		long ways=k;
		n--;
		while(n>0) {
			ways*=k-1;
			n--;
		}
		System.out.println(ways);
		
	}

}


Measured memory_bytes: 23120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B;
    char op;
    cin >>A>>op>>B;

    if(op=='+'){
        cout<<A+B<<endl;
    }else{
        cout<<A-B<<endl;
    }
    



    return 0;
    

}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const LOG = 19;
int const MAX = (1 << LOG) + 41;

int n;
int a[MAX];
pii d[LOG][MAX];
int ans[MAX];

bool bit(int m, int i) {
	return (1 & (m >> i));
}

void relax(pii &p) {
	if (p.first == -1) {
		swap(p.first, p.second);
	} else if (p.second != -1) {
		if (a[p.first] < a[p.second]) { 
			swap(p.first, p.second);
		}
	}
}

bool better(int x, int y) {
	if (x == -1) return false;
	if (y == -1) return true;
	return a[x] > a[y];	
}

pii merge(pii a, pii b) {
	err("merging %d %d %d %d\n", a.first, a.second, b.first, b.second);
	relax(a);
	relax(b);
	if (better(b.first, a.second)) {
		swap(a.second, b.first);
		relax(a);
		relax(b);
	}
	if (better(b.first, a.second)) {
		swap(a.second, b.first);
		relax(a);
		relax(b);
	}
	err("result %d %d\n", a.first, a.second);
	return a;
}

void solve() {
	int k = (1 << n) - 1;
	fi(0, k) {
		d[0][i] = mp(i, -1);
	}
	fo(1, LOG - 1) {
		fi(0, k) {
			d[o][i] = d[o - 1][i];
			if (bit(i, o - 1)) {
				d[o][i] = merge(d[o][i], d[o - 1][ ( (1 << (o - 1)) ^ i)]);
			}
		}
	}

	fi(1, k) {
		ans[i] = a[d[LOG - 1][i].first] + a[d[LOG - 1][i].second];
		if (i) ans[i] = max(ans[i], ans[i - 1]);
		//
		err("mask = %d a = %d b = %d\n", i, d[LOG - 1][i].first, d[LOG - 1][i].second);
		//
	}

	fi(1, k) {
		printf("%d\n", ans[i]);
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d", &n);
  fi(0, (1 << n) - 1) {
  	scanf("%d", &a[i]);
  }
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 83968
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define N 2010
#define mo 1000000007
#define ll long long
using namespace std;
int n,K,f[N][N][2],ans;
int mi(int x)
{
	ll a=1;
	fo(i,1,x) a=a*2%mo;
	return a;
}
int main()
{
	scanf("%d%d",&n,&K);
	f[n+1][0][1]=1;
	fd(i,n+1,2)
	{
		fd(j,n,0) (f[i][j][0]+=f[i][j+1][0])%=mo;
		fo(j,0,n)
		{
			fo(k,0,1)
			{
				(f[i-1][j+1][1]+=f[i][j][k])%=mo;
				(f[i-1][j][0]+=f[i][j][k])%=mo;
			}
		}
	}
	ans=(ll)f[1][n-K][0]*mi(n-K-1)%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1

int n;
int m;
vector<vector<int>> ab(100, vector<int>(100));
vector<int> is_visit(100, NIL);

void bfs(int s){
    queue<int> q;
    q.push(s);
    int u;
    while(!q.empty()){
        u=q.front();
        is_visit[u]=1;
        q.pop();
        for(int v=0; v<n; v++){
            if(ab[u][v]==1 && is_visit[v]==NIL){
                q.push(v);
            }
        }
    }
}

int main(){
    vector<int> a;
    vector<int> b;
    int tmp_a;
    int tmp_b;
    int ans=0;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> tmp_a >> tmp_b;
        tmp_a--;
        tmp_b--;
        a.push_back(tmp_a);
        b.push_back(tmp_b);
        ab[tmp_a][tmp_b]=1;
        ab[tmp_b][tmp_a]=1;
    }

    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            is_visit[j]=NIL;
        }
        ab[a[i]][b[i]]=0;
        ab[b[i]][a[i]]=0;
        bfs(0);
        bool ok=true;
        for(int k=0; k<n; k++){
            if(is_visit[k]==NIL){
                ok=false;
                break;
            }
        }
        if(ok==false){
            ans++;
        }
        ab[a[i]][b[i]]=1;
        ab[b[i]][a[i]]=1;        
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque, defaultdict
import sys
input=sys.stdin.readline


def solve():
    H, W, K = map(int, input().split())
    y1, x1, y2, x2 = map(int, input().split())
    l = [[1 if s=="@" else 0 for s in input()] for _ in range(H)]
    INF = 10**12

    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1

    ddy = [0, 0, -1, 1]
    ddx = [-1, 1, 0, 0]

    dist = defaultdict(lambda :INF)
    dist[(y1, x1)] = 0
    q = deque([(y1, x1)])

    while q:
        y, x = q.popleft()
        for dy, dx in zip(ddy, ddx):
            for j in range(1, K+1):
                if not (0<=y+dy*j<H and 0<=x+dx*j<W):
                    break
                if l[y+dy*j][x+dx*j]:
                    break

                if dist[(y+dy*j, x+dx*j)] > dist[(y, x)] + 1:
                    dist[(y+dy*j, x+dx*j)] = dist[(y, x)] + 1
                    q.append((y+dy*j, x+dx*j))
                elif dist[(y+dy*j, x+dx*j)] == dist[(y, x)] + 1:
                    continue
                else:
                    break


    ans = dist[(y2, x2)]
    print(ans if ans!=INF else -1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 211268
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> g = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a % 2 == 0) g.add(a);
        }

        String result = "APPROVED";
        for (int b : g) {
            if (b % 3 != 0 && b % 5 != 0) {
                result = "DENIED";
                break;
            }
        }

        System.out.println(result);
    }
}

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

static int cmp_int (const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main (void) {
    int i, j, k, scaned;
    int n;
    scaned = scanf("%d", &n);
    if ( scaned != 1 ) {
        fprintf(stderr, "invalid input\n");
        return EXIT_FAILURE;
    }
    int l[n];
    for ( i=0; i<n; i++ ) {
        scaned = scanf("%d", &l[i]);
        if ( scaned != 1 ) {
            fprintf(stderr, "invalid input\n");
            return EXIT_FAILURE;
        }
    }

    qsort(l, n, sizeof(int), cmp_int);

    long long ans=0;
    for ( i=0; i<n-2; i++ ) {
        for ( j=i+1; j<n-1; j++ ) {
            for ( k=j+1; k<n; k++ ) {
                if ( l[k] < l[i]+l[j] )
                    ans++;
                else
                    break;
            }
        }
    }

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}


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

int main(){
    bool isPrime[n_size];
    isPrime[0]=false; isPrime[1]=false;

    for(unsigned i=2;i<n_size;i++)
        isPrime[i] = true;

    for(unsigned i=2;i*i<n_size;i++){
        if(isPrime[i]){
            for(unsigned j=(i*i);j<n_size;j+=i)
                isPrime[j] = false;
        }
    }

    unsigned n_prime[n_size];

    unsigned cnt = 0;
    for(unsigned i=0;i<n_size;i++){
        if(isPrime[i])
            cnt++;
        n_prime[i] = cnt;
    }

    unsigned n;
    while(cin>>n){
        cout << n_prime[n] << endl;
    }

    return 0;
}


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

int main() {
	// your code goes here
	int n ,i, j;
	string s, t;
	cin>>n;
	cin>>s;
	cin>>t;
	for(i=0; i<n; ++i) {
		if(s[i]==t[0]) {
			//cout<<i<<endl;
			int k=i;
			for(j=0; k<n; ++k, ++j)
				if(s[k]!=t[j])	break;
			if(k==n) {
				cout<<n+i;
				return 0;
			}
		}
	}
	cout<<2*n;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    ll n=s.size();
    for(ll i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(ll i=0;i<n-2;i++){
        if(s[i]==s[i+2]&&s[i]!=s[i+1]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
ll inf = 1000000000;
ll b[105];
int main() {
	ll n;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> b[i];
	}
	ll ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if (b[i] < b[i + 1]) {
			ans += b[i];
		}
		else {
			ans += b[i + 1];
		}
	}
	cout << ans + b[0] + b[n - 2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#define Re register int

double f[305][305][305];
int N,A[4];

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	var=w?-x:x;
}
double dp(int a,int b,int c)
{
	if (f[a][b][c]>=0) return f[a][b][c];
	if (!a&&!b&&!c) return 0;
	f[a][b][c]=1.0*N/(a+b+c);
	if (a) f[a][b][c]+=a*dp(a-1,b,c)/(a+b+c);
	if (b) f[a][b][c]+=b*dp(a+1,b-1,c)/(a+b+c);
	if (c) f[a][b][c]+=c*dp(a,b+1,c-1)/(a+b+c);
	return f[a][b][c];
}
int main(int argc, char const *argv[])
{
	read(N); memset(f,-1,sizeof(f));
	for (Re i=1,x; i<=N; ++i) read(x),++A[x];
	printf("%.10lf\n",dp(A[1],A[2],A[3]));
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

typedef long long ll;

int main()
{
    long long N;
    scanf("%lld", &N);
    long long T;
    scanf("%lld", &T);

    long long sum = 0;

    std::vector<long long> t(N);
    cin >> t[0];
    for (int i = 1; i < N; i++)
    {
        scanf("%lld", &t[i]);
        if (t[i] - t[i - 1] >= T)
        {
            sum += T;
        }
        else
        {
            sum += t[i] - t[i - 1];
        }
    }
    sum += T;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>


int main(int argc, char* argv[])
{
    long a, b;
    scanf("%ld %ld", &a, &b);

    if(a%2==0 || b%2==0) {
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }

    return 0;
}





Measured memory_bytes: 128