akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    cin >> A;

    int ans = A[0][0] + accumulate(ALL(A[1]), 0);
    int pre = ans;
    FOR(i, 1, N) {
        ans = max(ans, pre - A[1][i - 1] + A[0][i]);
        pre = pre - A[1][i - 1] + A[0][i];
    }

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

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

int main(){
  int64_t N;
  cin>>N;
  int64_t i=1,j=N;
  for(int64_t x=1;x*x<=N;x++){
    if(N%x==0){
      i=x;
      j=N/x;
    }
  }
  printf("%ld",i+j-2);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n), b(n);
    REP(i,n) a[i] = in();
    REP(i,n) b[i] = in();

    int ans = 0;
    REP(x,29){
        int t = 1 << x;
        VI bb(b);
        REP(i,n) bb[i] &= 2 * t - 1;
        sort(ALL(bb));
        ll tot = 0;
        // cout << x << endl;
        // for (int x : bb) cout << x << " ";
        // cout << endl;
        REP(i,n){
            int aa = a[i] & (2 * t - 1);
            tot += lower_bound(ALL(bb), 2 * t - aa) - lower_bound(ALL(bb), t - aa);
            tot += lower_bound(ALL(bb), 4 * t - aa) - lower_bound(ALL(bb), 3 * t - aa);
            // cout << tot << endl;
        }
        if (tot % 2) ans += t;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline-------------------------------------------
    N = int(input())
    A = [int(input()) for i in range(N)]
    p = -float("inf")
    keepnumber = 0
    for i in range(N):
        if p <= A[i]:
            p = A[i]
            keepnumber = i
    for i in range(N):
        if i == keepnumber:
            print(max(A[:i]+A[i+1:]) if i != N else print(max(A[:N-1])))
        else:
            print(p)       
if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Measured memory_bytes: 17732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  string str;
  str="No";
  cin>>a>>b>>c;
  if(a==b){
    if(a!=c){
      str="Yes";
    }
  }
  if(a==c){
    if(a!=b){
      str="Yes";
    }
  }
  if(c==b){
    if(a!=c){
      str="Yes";
    }
  }
  cout<<str;
}

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

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

using namespace std;

int main(){
  int A, B, C, D, ans; cin >> A >> B >> C >> D;
  ans=max(A*B, C*D);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        int tmp = 1;
        while(tmp < b){
            ans++;
            tmp += a-1;
        }
        System.out.println(ans);
        sc.close();

    }

}


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

int main() {
  long n,x,y,p,l;
  cin >> n >> x >> y;
  if(n == 1){
    long a;
    cin >> a;
    cout << abs(y-a) << endl;
    return 0;
  }
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    if(i == n-2) p = a;
    if(i == n-1) l = a;
  }
  cout << max(abs(y-l),abs(p-l)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

static int MAX = 100;
static int INFTY = (1<<21);

int main(){
  int n,i,j;
  int M[MAX][MAX];
  int m,k,l,a;
  int min;
  int d[MAX];
  int vis[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&l,&m);
    for(j=0;j<m;j++){
      scanf("%d %d",&a,&k);
      M[l][a]=k;
    }
  }

  for(i=0;i<n;i++) {
    d[i]=INFTY;
    vis[i]=0;
  }

  d[0] = 0;

  while(1){
    min=INFTY;
    l=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&!vis[i]){
	l=i;
	min=d[i];
      }
    }
    if(l==-1) break;
    vis[l]=1;
    for(a=0;a<n;a++){
      if(!vis[a]&&M[l][a]!=INFTY){
	if(d[a]>d[l]+M[l][a]){
	  d[a]=d[l]+M[l][a];
	}
      }
    }
  }

  for(i=0;i<n;i++){
    if(d[i]==INFTY){
      printf("%d %d\n",i,-1);
    }else{
      printf("%d %d\n",i,d[i]);
    }
  }
  return 0;
}
  



Measured memory_bytes: 2056
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



int main() {
	vector<vector<int>> m(3, vector<int>(3));
	rep(i, 3) {
		rep(j, 3) {
			cin >> m[i][j];
		}
	}
	bool flag = true;
	int a = m[0][1] - m[0][0], b = m[0][2] - m[0][1];
	int c = m[1][0] - m[0][0], d = m[2][0] - m[1][0];
	rep(i, 3) {
		if (m[i][1] - m[i][0] != a || m[i][2] - m[i][1] != b) flag = false;
	}
	rep(i, 3) {
		if (m[1][i] - m[0][i] != c || m[2][i] - m[1][i] != d) flag = false;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

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

  map<string, lint> mp;
  while(N--) {
    string s;
    cin >> s;
    mp[s]++;
  }

  for(auto s : {"AC", "WA", "TLE", "RE"}) {
    cout << s << " x " << mp[s] << endl;
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}
int main()
{
    // 全ての位置との距離の最大公約数を求める
    int n;
    ll X;
    cin >> n >> X;
    ll a;

    n += 1;
    deque<ll> x(n);
    deque<ll> del(n - 1);
    x[0] = X;

    rep(i, 1, n)
    {
        cin >> x[i];
    }
    sort(x.begin(), x.end());

    rep(i, 0, n - 1)
    {
        del[i] = (abs(x[i + 1] - x[i]));
    }

    if (n - 1 == 1)
    {
        a = del[0];
    }
    else
    {
        a = gcd(del[0], del[1]);
        rep(i, 1, del.size())
        {
            a = gcd(a, del[i]);
            // cout << a << endl;
        }
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 1920
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int>a(n, 0);
	int cnt = 0;
	rep(i, 0, n) {
		if (s[i] == 'E')cnt++;
	}
	int mi =cnt;
	if (s[0] == 'E')cnt--;
	rep(i, 0, n-1) {
		if (s[i] == s[i + 1]) {
			if (s[i] == 'E')cnt--;
			else cnt++;
			mi = min(mi, cnt);
		}
	}
	cout << mi;
	return 0;
}





Measured memory_bytes: 1796
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
int n,a[100050];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int l=1;
	int r=n;
	double x,y;
	if(n%2==0) x=a[n]/2;
	else x=(a[n]+1)/2;
	int mid;
	while(l<=r){
		if(r-l==1){
			if(x-a[l]<=a[r]-x){
				mid=l;
				break;
			}
			else{
				mid=r;
				break;
			}
		}
		mid=(l+r)/2;
		if(a[mid]>x){
			r=mid;
		}
		else if(a[mid]<x){
			l=mid;
		}
		else if(a[mid]==x){
			break;
		}
	}
	if(n==2) printf("%d %d\n",a[2],a[1]);
	else printf("%d %d\n",a[n],a[mid]);
}

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

int main()
{
    string a,b;
    cin>>a>>b;
    if(a.length()>b.length())
    {
        cout<<"GREATER"<<endl;
    }
    else if(a.length()<b.length())
    {
        cout<<"LESS"<<endl;
    }
    else
    {
        if(a.compare(b)==0)
        cout<<"EQUAL"<<endl;
        else if(a.compare(b)>0)
        {
            cout<<"GREATER"<<endl;
        }
        else
            cout<<"LESS"<<endl;
    }
    return 0;
}


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

int N;

int solve(int a,int b,int c){
  if( !a ) return 0;
  int ret = 0;
  a--; ret += c+1;
  while( a ){
    a--; ret++;
    swap( a, b );
  }
  if( b ) ret++;
  return ret;  
}

int main(){
  cin >> N;
  int a,b,c;
  a = b = c = 0;
  for(int i=0;i<N;i++){
    int d; cin >> d;
    if( d % 3 == 0 ) c++;
    else if( d % 3 == 1 ) a++;
    else b++;
  }
  int res = 0;
  if( c ) res = 1;  
  cout << max( res, max( solve( a, b, c ), solve( b, a, c ) ) ) << endl;
  
}

Measured memory_bytes: 3092
from operator import itemgetter
from collections import deque
import sys

# スペース区切りの整数入力
n,d,a = map(int, input().split())

#指定数分の2つの整数を順番に受けてリストに入力
e = []
for i in range(n):
    e.append([int(x) for x in input().split()])
e.sort(key=itemgetter(0))

atk_times_sum = 0
atk_que = deque()
atk_acm_p = 0

for i in range(n):
    while len(atk_que) > 0:
        if atk_que[0][0] < e[i][0]:
            atk_u,atk_p = atk_que.popleft()
            atk_acm_p -= atk_p
        else:
            break
    e[i][1] -= atk_acm_p
    if e[i][1] <= 0:
        continue
    atk_u = e[i][0] + d*2
    if e[i][1] % a == 0:
        atk_times = e[i][1] // a
    else:
        atk_times = e[i][1] // a + 1
    e[i][1] = 0 
    atk_times_sum += atk_times
    atk_p = a * atk_times
    atk_acm_p += atk_p
    atk_que.append([atk_u,atk_p])

print(atk_times_sum)

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

typedef long long ll;

const int N = 1010;
int m[N][N];
vector<int> E[500000];
int n, t, cur, p;
int id = 1;
int res[500000];
int ret = 1;
int C[500000];
bool ok = true;

bool dfs(int x) {
    res[x] = 1;
    C[x] = 1;
    for (int i : E[x]) {
        if (C[i] == 1) return false;
        if (C[i] == 2) {
            res[x] = max(res[x], res[i] + 1);
            continue;
        }
        if (!dfs(i)) return false;
        res[x] = max(res[x], res[i] + 1);
    }
    C[x] = 2;
    ret = max(ret, res[x]);
    return true;
}

inline static int getid(int x, int y) {
    if (x > y)
        swap(x, y);
    if (m[x][y] == 0) {
        m[x][y] = id++;
    }
    return m[x][y];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            cin >> t;
            --t;
            cur = getid(i, t);
            if (j > 0) {
                E[cur].push_back(p);
            }
            p = cur;
        }
    }
    for (int i = 1; i < id; ++i) {
        if (C[i] == 0) {
            if (!dfs(i)) {
                ok = false;
                break;
            }
        }
    }
    if (ok)
        cout << ret << endl;
    else
        cout << -1 << endl;

    return 0;
}



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

using namespace std;

int i;
long long n;
deque <int> ans;

int main(){
	scanf("%lld", &n);
	
	n++;
	
	long long now = 1;
	int cnt = -1;
	
	while(now <= n){
		now *= 2;
		cnt++;
	}
	
	int nxt = 0;
	
	for(i = cnt - 1; i >= 0; i--){
		nxt++;
		ans.push_back(nxt);
		if(n & (1LL << i)){
			nxt++;
			ans.push_front(nxt);
		}
	}
	
	for(i = 1; i <= nxt; i++)
	ans.push_back(i);
	
	printf("%d\n", ans.size());
	
	for(i = 0; i < ans.size(); i++){
		if(i == 0)
		printf("%d", ans[i]);
		else
		printf(" %d", ans[i]);
	}
	
	printf("\n");
}


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

int main(){
  int h, w;
  std::cin >> h >> w;
  string s;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      std::cin >> s;
      if(s == "snuke"){
        std::cout << (char)(j + 'A') << i + 1 << std::endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const MAX: usize = 1000000;
const INF: i64 = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let mut t = Vec::new();
    for i in (1..).take_while(|i| i * (i+1) * (i+2) / 6 <= MAX) {
        t.push(i * (i+1) * (i+2) / 6);
    }
    let mut dp1 = vec![INF; MAX+1];
    dp1[0] = 0;
    for i in 0..MAX+1 {
        for &ti in &t {
            if i >= ti {
                dp1[i] = min(dp1[i], dp1[i - ti] + 1);
            }
        }
    }
    let mut dp2 = vec![INF; MAX+1];
    dp2[0] = 0;
    for i in 1..MAX+1 {
        for &ti in &t {
            if ti % 2 == 0 { continue; }
            if i >= ti {
                dp2[i] = min(dp2[i], dp2[i - ti] + 1);
            }
        }
    }
    loop {
        let N: usize = sc.get();
        if N == 0 {
            break;
        }
        println!("{} {}", dp1[N], dp2[N]);
    }
}



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


const int INF = 1e6;
int N, T;
vector<int> c, t;


void input() {
    cin >> N >> T;
    c = t = vector<int>(N);
    rep(i, N) cin >> c[i] >> t[i];
}


int main() {
    input();
    int ans = INF;
    rep(i, N) {
        if (t[i] <= T) ans = min(ans, c[i]);
    }
    if (ans == INF) cout << "TLE" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

field = [["@"] * (w + 2)] + [list("@"+input()+"@") for _ in range(h)] + [["@"] * (w + 2)]
direction = [(0, -1), (0, 1), (1, 0), (-1, 0)]

flip = {".": "#", "#": "."}

def count_up(i, j):
    que = [(i, j)]
    cnt = {".": 0, "#": 0}
    while que:
        i, j = que.pop()
        now = field[i][j]
        field[i][j] = "@"
        fliped_chip = flip.get(now)
        if fliped_chip is not None:
            cnt[now] += 1
        for d in direction:
            dx, dy = d
            nx, ny = j + dx, i + dy
            next_chip = field[ny][nx]
            if next_chip == fliped_chip:
                que.append((ny, nx))
    return cnt

cnt = [[0] * w for _ in range(h)]
result = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        dot_sharp = count_up(i, j)
        result += (dot_sharp["."] * dot_sharp["#"])
print(result)
#
#
# print("\n".join(map("".join, field)))
#
#


Measured memory_bytes: 20816
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(true) {
            int h = scanner.nextInt();
            int w = scanner.nextInt();
            if (h == 0 && w == 0) {
                break;
            }
            for(int row = 0; row < h; row++){
                for(int col = 0; col < w; col++){
                    if(row == 0 || row == h-1 || col == 0 || col == w-1){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        scanner.close();
    }
}



Measured memory_bytes: 36280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=1e5+10;
int n,m,a[MAXN];
ll t[MAXN],sum[MAXN];
struct opt
{
	int b,c;
	bool operator < (const opt &rhs) const
	{
		return c>rhs.c;
	}
}q[MAXN];
ll ans=0;
int head,tail;
int bs(int x)
{
	int L=head,R=tail,res=-1;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(a[mid]<x)
			L=mid+1,res=mid;
		else
			R=mid-1;
	}
	return res;
}
int main()
{
	n=read();
	m=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)
		sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=m;++i)
	{
		q[i].b=read();
		q[i].c=read();
	}
	sort(q+1,q+1+m);
	head=1,tail=n;
	for(int i=1;i<=m;++i)
	{
		int pos=bs(q[i].c);
		if(pos==-1)
			continue;
		int tmp=min(q[i].b,pos-head+1);
		ans+=1LL*tmp*q[i].c;
		head=head+tmp;
	}
	while(head<=tail)
	{
		ans+=a[head];
		++head;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL << 50;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
 
struct edge{
    int from, to; ll cost;
};

int main(){
    int n;
    cin >> n;
    int a[100001];
    REP(i, 100001) a[i] = 0;
    int ans = 0;
    REP(i, n){
        int tmp;
        cin >> tmp;
        if(tmp >= 100001){
            ans++;
        }else{
            a[tmp]++;
        }
    }
    REP(i, 100001){
        if(i <= a[i]){
            ans += a[i] - i;
        }else{
            ans += a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    S = deque(input())
    T = deque(input())
    same = False
    for _ in range(len(S)):
        if S == T:
            same = True
            break
        c = S.popleft()
        S.append(c)
    if same: print("Yes")
    else: print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 65076
#include <iostream>
#include <string>
#include <utility>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <tuple>
using namespace std;
using ll=long long;
ll gcd(ll a,ll b){return (b==0?a:gcd(b,a%b));}
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,n) for(int i=a;i<n;i++)
constexpr ll INF=1000000011;

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

    cout << n*800 - n/15*200 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <map>

using namespace std;

typedef unsigned long long ull;

struct Work {
    ull take;
    ull deadline;
    bool finished;
};

//std::vector<Work> allWorks;
std::map<ull, ull> deadlineToTime;

bool canFinish(ull curTime, ull N, ull finishedCount)
{
    if (finishedCount == N) {
        return true;
    }

    ull remainMaxTimeTask = 0;
    for (auto &ab : deadlineToTime) {
    //for (ull i=0; i<N; i++) {
        //auto& work = allWorks[i];
        //if (work.finished) {
        //    continue;
        //}
        auto tookTime = ab.second;
        auto deadline = ab.first;

        //remainMaxTimeTask = std::max(remainMaxTimeTask, work.take);
        //if (curTime + work.take > work.deadline) {
        //    // This task will be never finished
        //    return false;
        //}
        //work.finished = true;
        //if (canFinish(curTime + work.take, N, finishedCount+1)) {
        //    return true;
        //}
        //work.finished = false;
        curTime += tookTime;

        if (curTime > deadline) {
            return false;
        }
    }

    return true;
}

int main()
{
    ull N;
    cin >> N;
    //allWorks.resize(N);

    for (ull i=0; i<N; i++) {
        ull A, B;
        cin >> A >> B;
        deadlineToTime[B] += A;
        //cin >> allWorks[i].take >> allWorks[i].deadline;
        //allWorks[i].finished = false;
    }
    //std::sort(allWorks.begin(), allWorks.end(), [](const Work &lhs, const Work &rhs) {
    //    return lhs.take > rhs.take;
    //});

    auto ret = canFinish(0, N, 0);
    cout << (ret ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 12800
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        int ret = 0;
        for (int i = 1; i <= n; i++) {
            ret += (n - 1) / i;
        }
        System.out.println(ret);
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 32648
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = sc.nextInt();
        }
        int max = h[0];
        for(int i = 1; i<n; i++) {
            if(max-h[i]>=2) {
                System.out.println("No");
                return;
            }
            max = Math.max(max, h[i]);
        }
        System.out.println("Yes");

    }
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    ll n; cin >> n;
    vector<ll> a(n); REP(i, n) cin >> a[i];
    sort(ALL(a));
    
    ll ans1 = a[n-1];
    
    ll ans2;
    ll mx = inf;
    REP(i, n-1) {
        if (mx >= abs(ans1 / 2 - a[i])) {
            ans2 = a[i];
            mx = abs(ans1 / 2 - a[i]);
        }
    }
    cout << ans1 << " " << ans2 << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll H,W;
    cin >> H >> W;
    auto A = InputVec2dStr(H,W);
    ll count = 0;
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            if(A[yi][xi] == '#'){
                count++;
            }
        }
    }
    if(count == (H + W - 1)){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Goods = Tuple!(long, "w", long, "v");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto a = aryread();
    long abs_min = INF, abssum, minuscnt;
    foreach (e; a)
    {
        abssum += abs(e);
        abs_min = min(abs(e), abs_min);
        if (e <= 0)
            minuscnt++;
    }
    if (minuscnt % 2)
        writeln(abssum - 2 * abs_min);
    else
        writeln(abssum);
}


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

int main()
{
    int N;
    cin >> N;
    int digit = to_string(N).size(); //桁数

    int arr[3] = {3, 5, 7};
    int ans = 0;
    for(int d=3; d<= digit; d++){
        int patterns = 1;
        for(int i=0; i<d; i++) patterns *= 3;

        for(int _trits=0; _trits < patterns; _trits++){
            int trits = _trits;
            bitset<3> use;
            int sum = 0;
            for(int i=0; i < d; i++){
                sum = sum*10 + arr[trits % 3];
                use[trits % 3] = true;
                trits /= 3;
            }
            if(use.all() && sum <= N) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define endl '\n'
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;



int32_t main(){
    vaibhavv06;
	int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int pre[n+1];
    pre[0]=0;
    for(int i=1;i<=n;i++) pre[i]=pre[i-1]+arr[i-1];

    int dp[n][n]={0};
    for(int i=n-1;i>=0;i--){
        for(int j=i;j<n;j++){
            if(i==j) dp[i][j]=0;
            else{
                dp[i][j]=INT64_MAX;
                for(int k=i;k<=j;k++){
                    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+pre[j+1]-pre[i]);
                }
            }
        }
    }
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<n;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 1536
#include <stdio.h>
#define N 100000
#define Q 50000

int binarySearch(int);

int S[N], n;

int main()
{
  int i, C=0, result, q, T[Q];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
 
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    result=binarySearch(T[i]);
    if(result==1) C++;
  }
 printf("%d\n",C);

  return 0;
}

int binarySearch(int key)
{
  int left=0, right=n, mid;

  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key) return 1; 
    else if(key<S[mid])  right=mid;
    else  left=mid+1;
  }
  return 0;
}




 
  
  


Measured memory_bytes: 2364
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

LL N,A,B,C,D;
map<LL,LL> mp;
LL dfs(LL N){
    if(N==1) return D;
    if(N==0) return 0;
    if(mp.find(N) != mp.end()){
        return mp[N];
    }
    LL res = LINF;
    __int128 st = LINF;
    __int128 tmp = __int128(N) * __int128(D);
    if(st > tmp){
        res = N * D;
    }
    
    // 2
    if(N%2 == 0){
        chmin(res,dfs(N/2) + A);
    }else{
        chmin(res,dfs((N+1)/2) + A + D);
        chmin(res,dfs((N-1)/2) + A + D);
    }

    if(N%3 == 0){
        chmin(res,dfs(N/3) + B);
    }else{
        LL rem = N % 3;
        chmin(res,dfs((N-rem)/3) + B + D*rem);
        chmin(res,dfs((N+3-rem)/3) + B + D*(3-rem));
    }

    if(N%5 == 0){
        chmin(res,dfs(N/5) + C);
    }else{
        LL rem = N % 5;
        chmin(res,dfs((N-rem)/5) + C + D*rem);
        chmin(res,dfs((N+5-rem)/5) + C + D*(5-rem));
    }


    return mp[N] = res;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int T; cin >> T;
    REP(_,T){
        //LL N,A,B,C,D; 
        cin >>N>>A>>B>>C>>D;
        mp.clear();
        LL ans = dfs(N);
        cout << ans << endl;
    }

}

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

int main() {
	int i , x , flag=0 , s;
	cin >> s;
    while(s!=0)
    {
    	x=s%10;
    	s/=10;
    	if(x==7)
    	{
    		flag=1;
    		break;
    	}
    }
	if(flag==1)
	cout << "Yes";
	else
	cout << "No";
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 55;

int n, m, c, ans = 0;
int b[N];
int a[N][N];

int32_t main()
{
	IOS;
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		int cur = c;
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			cur += a[i][j] * b[j];
		}
		ans += (cur > 0);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int cnt = 0;
    int a;
    scanf("%d", &a);
    int b[a];
    //printf("%d", i);
    //printf("数値を入力してね\n");
    for(int i = 0;i < a; i++){
        scanf("%d",&b[i]);
    }
    
    for(int i = 0;i < a; i++){
        //printf("%d", b[i]);
        if((i+1)%2==1&&(b[i]%2)==1)
            cnt++;
    }
     
    printf("%d", cnt);
    return 0;
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<int, int>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  vector<string> s(h); for (int i = 0; i < h; i++) cin >> s[i];
  
  VVI d(h, VI(w, -1));
  queue<P> q;
  d[0][0] = 0;
  q.push(P(0, 0));
  while (not q.empty()) {
    int x = q.front().first, y = q.front().second; q.pop();
    VI dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 or nx >= h or ny < 0 or ny >= w or d[nx][ny] != -1 or s[nx][ny] != '.') continue;
      d[nx][ny] = d[x][y] + 1;
      q.push(P(nx, ny));
    }
  }

  int white = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      white += s[i][j] == '.';
    }
  }

  if (d[h - 1][w - 1] == -1) {
    cout << -1 << '\n';
  } else {
    cout << white - d[h - 1][w - 1] - 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
n, p = map(int, input().split()); a = list(map(int, input().split()))
s = t = u = 0; b = [1]
for i in range(n):
    if a[i]%2 == 0: s += 1
    else: t += 1
for i in range(1, n+1):
    b.append(b[-1]*i)
if p == 0:
    for i in range(0, t//2*2+1, 2):
        u += b[t]//b[i]//b[t-i]
else:
    for i in range(1, (t+1)//2*2, 2):
        u += b[t]//b[i]//b[t-i]
print(2**s*u)

Measured memory_bytes: 9120
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#define SIZE 4005
#define INF 1000000000

using namespace std;

int dp[SIZE][SIZE];
int col[SIZE],A[SIZE];
char str[5];
int bc[SIZE][SIZE];//0
int wc[SIZE][SIZE];//1

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<2*n;i++)
	{
		scanf("%s %d",&str,&A[i]);
		A[i]--;
		if(str[0]=='B') col[i]=0;
		else col[i]=1;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<2*n;j++)
		{
			if(col[j]==0&&A[j]==i) break;
			if(col[j]==1)
			{
				bc[i][A[j]]++;
			}
		}
		for(int j=n-2;j>=0;j--) bc[i][j]+=bc[i][j+1];
		for(int j=0;j<2*n;j++)
		{
			if(col[j]==1&&A[j]==i) break;
			if(col[j]==0)
			{
				wc[i][A[j]]++;
			}
		}
		for(int j=n-2;j>=0;j--) wc[i][j]+=wc[i][j+1];
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i<n)
			{
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+bc[i][j]);
			}
			if(j<n)
			{
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]+wc[j][i]);
			}
			//printf("%d %d : %d\n",i,j,dp[i][j]);
		}
	}
	int ret=dp[n][n];
	for(int i=0;i<2*n;i++)
	{
		for(int j=i+1;j<2*n;j++)
		{
			if(A[i]>A[j]&&col[i]==col[j])
			{
				ret++;
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}


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

int main(){
	int n;
	ll d;
	cin >> n >> d;
	vector<double> x(n);
	vector<double> y(n);
	rep(i,n){
		cin >> x[i];
		cin >> y[i];
	}
	double distance;
	int counts = 0;
	double a = 0.5;
	rep(i,n){
		distance = pow((x[i]*x[i] + y[i]*y[i]), a);
		if(distance <= d) counts++;
	}
	/*map<P,int> cnt;
	rep(i,n){
		pair<int, int> p;
		cin >> p.first;
		cin >> p.second;
		cnt[p]++;
	}
	double distance = 0;
	int counts =0;
	for(auto p : cnt){
		auto k = p.first.first;
		auto v = p.first.second;
	    distance = sqrt(k*k + v*v);
	    if(distance <= d) counts++;
	}*/
	cout << counts << endl;
}

Measured memory_bytes: 6504
import itertools

n=int(input())
a=tuple(map(int,input().split()))
if n==1:
    print(a[0])
else:
    b=tuple(sorted(a))
    A=list(itertools.permutations(b))
    count=len(A)-1

    if A.index(a)==count:
        print(' '.join(map(str,A[count-1])))
        print(' '.join(map(str,a)))
    elif A.index(a)==0:
        print(' '.join(map(str,b)))
        print(' '.join(map(str,A[1])))
    else:
        print(' '.join(map(str,A[A.index(a)-1])))
        print(' '.join(map(str,a)))
        print(' '.join(map(str,A[A.index(a)+1])))



Measured memory_bytes: 52360
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''
p = 10 ** 9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''


#a = list(map(int, input().split()))

aa,bb,m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ms = []
for i in range(m):
    ms.append(list(map(int, input().split())))


ans = 10**19
for i in range(m):
    now = a[ms[i][0]-1] + b[ms[i][1]-1] - ms[i][2]
    if(ans > now):
        ans = now
   
mina = min(a)
minb = min(b)
if(mina+minb < ans):
    ans = mina+minb
print(ans)

Measured memory_bytes: 106364
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int x,y,a,b,c; cin>>x>>y>>a>>b>>c;
    vi p(a),q(b);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    sort(all(p),greater<int>()); sort(all(q),greater<int>());
    pri_que<int> pq;
    rep(i,c){
        int t; cin>>t;
        pq.push(t);
    }
    rep(i,x)pq.push(p[i]);
    rep(i,y)pq.push(q[i]);

    int res=0;
    rep(i,x+y){
        res+=pq.top(); pq.pop();
    }
    cout<<res<<endl;


}

Measured memory_bytes: 9008