akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
A = inputIL()

a = [[] for i in range(31)]

for x in A:
  n = math.floor(math.log(x)/math.log(2))
  a[n].append(x)

for i in range(31)[::-1]:
  if M>=len(a[i]):
    if i>0:
      M -= len(a[i])
      disc = [x//2 for x in a[i]]
      a[i] = []
      a[i-1] += disc
      a[i-1].sort()
    else:
      print(0)
      exit()
  else:
    if i>0:
      disc = [x//2 for x in a[i][len(a[i])-M:len(a[i])]] 
      a[i-1] += disc
      a[i] = a[i][:len(a[i])-M]
      break
    else:
      print(len(a[0])-M)
      exit()

print(sum(sum(item) for item in a))

Measured memory_bytes: 88416
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N+1; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int count=0,flag,a,b,c,n,r1,r2,x,m,k;
  cin>>n;
  vint bukatu(n+1,0);
  UnionFind tree(n);
  cin>>m>>k;
 
   for(int i=0;i<k;i++){
    count++;
    cin>>flag;
    if(flag==1){
      cin>>a>>b;
      r1=tree.root(a);
      r2=tree.root(b);
      if(bukatu[r1]!=0 && bukatu[r2]==0){
	bukatu[r2]=bukatu[r1];
      }
      else if(bukatu[r1]==0 && bukatu[r2]!=0){
	bukatu[r1]=bukatu[r2];
      }
      else if(bukatu[r1]!=bukatu[r2]){
	cout<<count<<'\n';
	return(0);
      }
      tree.unite(a,b);
    }
    if(flag==2){
      cin>>c>>x;
      r1=tree.root(c);
      if(bukatu[r1]==0){
	bukatu[r1]=x;
      }
      else if(bukatu[r1]!=x){
	cout<<count<<'\n';
	return(0);
      }
    }
   }
  cout<<0<<'\n';
  return(0);
}



Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

int main () {
    int n;
    while (cin >> n) {
        map<int, int> cnt;
        rep(i, n) {
            int x;
            cin >> x;
            ++cnt[x];
        }

        int ans = 0;
        for (auto &e : cnt) {
            int x, c;
            tie(x, c) = e;
            if (c < x) ans += c;
            else ans += min(c, c - x);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4736
#include <cstdio>
#include <cstring>

const int MAXN = 1e5 + 10;

int len;
char s[MAXN];

int main() {
    scanf("%s", s + 1);
    for (char* c = &s[1]; *c; ++c)
        if ((c - s) & 1)
            putchar(*c);
    putchar('\n');

    return 0;
}


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

int main () {
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    int res = 0, t = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == t) t++;
        else res++;
    }

    if (res == n) res = -1;
    cout << res << endl;

    return 0;    
}



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

using namespace std;
typedef long long ll;

ll A[100];
ll N,K;

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) A[i] = 0;
    for(int i=0;i<K;i++){
        ll d;
        cin >> d;
        for(int j=0;j<d;j++){
            ll a;
            cin >> a;
            A[a-1]++;
        }
    }
    ll c = 0;
    for(int i=0;i<N;i++){
        if(A[i] == 0) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3636
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    query: [(usize1, usize1); m],
  }
  let mut pop = vec![0; n];
  for &(a, b) in &query {
    pop[a] += 1;
    pop[b] += 1;
  }

  if pop.iter().all(|&x| x % 2 == 0) {
    puts!("YES\n");
  } else {
    puts!("NO\n");
  }
}


Measured memory_bytes: 8444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n, m, max, conflict, array[];
		
		while(!(string = reader.readLine()).equals("0 0")){
			n = Integer.valueOf(string.split(" ")[0]);
			m = Integer.valueOf(string.split(" ")[1]);
			
			array = new int[n];
			for(int i = 0; i < n; i++) array[i] = Integer.valueOf(reader.readLine());
			
			max = 0;
			for(int i = 0; i < m; i++) max += array[i];
			
			conflict = max;
			for(int i = 0; i < n - m - 1; i++){
				conflict += array[i + m] - array[i];
				if(max < conflict) max = conflict;
			}
			
			System.out.println(max);
		}
		reader.readLine();
	}
}

Measured memory_bytes: 36992
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <array>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

template<typename T>
void p(T elem) {cout << elem << endl;}
template<typename T>
void ps(vector<T>& arr) { for(T e: arr) p(e); }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

int main(void) {
    int num;
    cin >> num;
    map<string, int> cnt_map;
    for(int i = 0; i < num; i++) {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        cnt_map[str]++;
    }

    int64_t ans = 0;
    for(auto p: cnt_map) {
        debug("%d\n", p.second);
        int64_t res = (int64_t)p.second*(p.second-1)/2;
        ans += res;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11244
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
ll read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
const int N=1e5+5;
struct node
{
  ll x,y;	
}z[2*N];
bool cmp(const node a,const node b)
{   if(a.y!=b.y)
	return a.y<b.y;
	return a.x<b.x;
}
int main()
{
  ll n=rr,sum=0,end=0;
  for(int i=0;i<n;i++)
  {
  	ll x=rr,y=rr;
  	sum+=x;
  	end=max(end,y);
  	z[i].x=x;
  	z[i].y=y;
  }
  if(end<sum)
  {
  	printf("No\n");
  	return 0;
  }
  sort(z,z+n,cmp);
  ll time=0;
  for(int i=0;i<n;i++)
  {
  	 
  	 if(time+z[i].x<=z[i].y)
  	 time+=z[i].x;
  	 else
  	 {
  	 		printf("No\n");
  	return 0;
	   }
  }
  printf("Yes\n");
}




Measured memory_bytes: 3328
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    int l = -1;
    int r = 2 * n;
    int middle;
    int male_mod = -1;
    rep(i, 20) {
        middle = ( l + r ) / 2;
        cout << middle % n << endl;
        string s;
        cin >> s;
        if ( s == "Vacant" ) break;
        if ( i == 0 ) {
            if ( s == "Male" ) male_mod = 0;
            else               male_mod = 1;
            l = middle;
        }
        else {
            if ( middle % 2 == male_mod && s == "Female" || 
                 middle % 2 != male_mod && s == "Male"   ) {
                r = middle;
            }
            else {
                l = middle;
            }
        }
    } 
    return 0;
}


Measured memory_bytes: 852
H,W = map(int,input().split())

SS = []
for i in range(H):
    SS.append(list(input()))
    
def seekindices(h,w,H,W):
    cand = []
    for x in [-1,0,1]:
        for y in [-1,0,1]:
            if abs(x) == 1:
                if h + x >= 0 and h + x < H:
                    cand.append([h+x,w])
            elif abs(y) == 1:
                if w + y >=0 and w + y < W:
                    cand.append([h,w+y])
    return(cand)

ans = 'Yes'

for h in range(H):
    for w in range(W):
        if SS[h][w] == "#":
            seeks = seekindices(h,w,H,W)
            bochi = 0
            for s in seeks:
                i,j = s[:]
                if SS[i][j] == "#":
                    bochi = 1
            if bochi == 0:
                ans = 'No'
            
print(ans)
    


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>l(N + 1);
	vector<int>r(N + 1);

	for (int i = 1; i <= N; i++) {
		cin >> l[i] >> r[i];
	}
	int sum = 0;

	for (int i = 1; i <= N; i++) {
		sum += r[i] - l[i] + 1;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
using namespace std;
typedef long long ll;
int n,X,Y;
int fac[maxn],inv[maxn];
vector <pair<int,int> > r[maxn];
vector <pair<int,int> > p;
vector <int> v[maxn],tmp;
void add(int x,int y){
	v[x].push_back(y);v[y].push_back(x);
}
int cnt,vis[maxn],c[maxn],ge[maxn],zh[maxn];
void dfs(int x){
	cnt++;vis[x]=1;ge[c[x]]++;tmp.push_back(c[x]);
	for(int i=0;i<(int)v[x].size();i++){
		if(!vis[v[x][i]]){
			dfs(v[x][i]);
		}
	}
}
int cal(int x,int y){
	return 1ll*fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
void jia(int x){
	for(int i=1;i<=n;i++){
		if(c[i]==c[x])continue;
		if(zh[i]+zh[x]<=Y)add(i,x);
	}
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&X,&Y);
	inv[0]=1;fac[0]=1;inv[1]=1;fac[1]=1;
	for(int i=2;i<=n;i++){
		fac[i]=1ll*fac[i-1]*i%MOD;
		inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
	}
	for(int i=2;i<=n;i++){
		inv[i]=1ll*inv[i-1]*inv[i]%MOD;
	}
	for(int i=1;i<=n;i++){
		int C,w;scanf("%d%d",&C,&w);
		c[i]=C;zh[i]=w;
		r[C].push_back(make_pair(w,i));
	}
	for(int i=1;i<=n;i++){
		if(r[i].size()==0)continue;
		sort(r[i].begin(),r[i].end());
		p.push_back(r[i][0]);
		for(int j=1;j<(int)r[i].size();j++){
			if(r[i][j].first+r[i][0].first<=X){
				add(r[i][j].second,r[i][0].second);
			}
		}
	}
	sort(p.begin(),p.end());
	if(p.size())jia(p[0].second);
	if(p.size()>1)jia(p[1].second);
	int res=1;
			dfs(p[0].second);
			for(int j=0;j<(int)tmp.size();j++){
				if(ge[tmp[j]]==0)continue;
				res=1ll*res*cal(cnt,ge[tmp[j]])%MOD;
				cnt-=ge[tmp[j]];
				ge[tmp[j]]=0;
			}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 28568
#include<bits/stdc++.h>
#define lowbit(i) ((i)&(-i))
#define lson(i) ((i)<<1)
#define rson(i) ((i)<<1|1)
#define ft first
#define se second
#define MAXN 100007
using namespace std;

typedef long long ll;typedef unsigned long long ul;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef queue<int> qii;typedef queue<pii> qpi;

const int inf=2e9+7;

struct edge{
	ll x,y,val;
	edge(int _x,int _y,int _val){x=_x,y=_y,val=_val;}
};

vector<edge> v;

struct node{
	int x,y,num;
}dot1[MAXN],dot2[MAXN];

bool cmp1(node x,node y){
	return x.x<y.x;
}

bool cmp2(node x,node y){
	return x.y<y.y;
}

bool comp(edge x,edge y){
	return x.val<y.val;
}

int n,fa[MAXN];
ll res;

int find(int x){
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}

void merge(int x,int y){
	int fx=find(x),fy=find(y);
	if(fx!=fy)
		fa[fx]=fy;
}

int main()
{
// 	freopen("","r",stdin);
// 	freopen("","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&dot1[i].x,&dot1[i].y);
		dot2[i].x=dot1[i].x;dot2[i].y=dot1[i].y;
		dot2[i].num=dot1[i].num=i;
	}
	
	//建边(删除无用边) 
	sort(dot1+1,dot1+n+1,cmp1);
	sort(dot2+1,dot2+n+1,cmp2);
	/*
	for(int i=1;i<=n;i++){
		printf("num %d:(%d,%d)\n",i,dot1[i].x,dot1[i].y);
	}
	*/
	for(int i=2;i<=n;i++){
		v.push_back( edge(dot1[i-1].num,dot1[i].num,dot1[i].x-dot1[i-1].x) );
		v.push_back( edge(dot2[i-1].num,dot2[i].num,dot2[i].y-dot2[i-1].y) );
	}
	sort(v.begin(),v.end(),comp);
	
	//初始化 
	for(int i=1;i<=n;i++)
		fa[i]=i;
    /*
	for(int i=0;i<v.size();i++){
		printf("(%d,%d) dis=%d\n",v[i].x,v[i].y,v[i].val);
	}
	*/
	//Kruscal
	for(int i=0;i<v.size();i++){
		if(find(v[i].x)!=find(v[i].y)){
			merge(v[i].x,v[i].y);
			res+=v[i].val;
		}
	}
	printf("%lld\n",res);
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    cin >> N;
    vector<ll> A,B;
    A.pb(0);
    B.pb(0);
    for (int i = 1; i <= N; i++) {
        ll a; cin >> a;
        A.pb(A[i-1]+a);
    }
    for (int i = 1; i <= N; i++) {
        ll b; cin >> b;
        B.pb(B[i-1]+b);
    }
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = max(ans,A[i]+B[N]-B[i-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    pe=[0]*N
    ac=[False]*N
    for i in range(M):
        if S[i]=="AC":
            ac[p[i]-1]=True
        if S[i]=="WA" and ac[p[i]-1]==False:
            pe[p[i]-1]+=1

    a=0
    for i in range(N):
        if ac[i]==False: pe[i]=0
        else: a+=1

    print(a, sum(pe))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    solve(N, M, p, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14872
<?php

$n = trim(fgets(STDIN));

$total = 0;
for($i = 0; $i < $n; $i++){
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    if($b == "BTC"){
        $total += $a * 380000;
    }else{
        $total += $a;
    }
}
echo $total;

Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int m, n, k;
    cin >> m >> n >> k;
    set<pii> sw;
    set<int> yoko[n+1], tate[m+1];
    for(int i = 0; i < k; i++){
        int x, y;
        cin >> x >> y;
        sw.insert({x, y});
    }
    set<pii> s = sw;
    s.insert({1, 1});
    s.insert({m, n});
    map<pii,int> id;
    vector<pii> v;
    int siz = 0;
    for(pii p : s){
        id[p] = siz++;
        v.push_back(p);
        int x = p.first, y = p.second;
        yoko[y].insert(x);
        tate[x].insert(y);
    }
    vector<vector<ll>> dp(2, vector<ll>(siz, 1ll<<60));
    dp[0][0] = 0;
    priority_queue<pair<ll,pii>> pq;
    pq.push({-0, {0, 0}});
    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        ll cost = -p.first;
        int pos = p.second.first, stat = p.second.second;
        int x = v[pos].first, y = v[pos].second;
        if(sw.count({x,y})>0 && dp[1-stat][pos] > dp[stat][pos]+1){
            dp[1-stat][pos] = dp[stat][pos]+1;
            pq.push({-dp[1-stat][pos], {pos, 1-stat}});
        }
        if(stat == 1){
            auto it = yoko[y].lower_bound(x);
            if(it != yoko[y].begin()){
                it--;
                ll nc = x-(*it);
                int npos = id[{*it,y}];
                if(dp[stat][npos] > dp[stat][pos]+nc){
                   dp[stat][npos] = dp[stat][pos]+nc;
                   pq.push({-dp[stat][npos], {npos, stat}});
                }
                it++;
            }
            it++;
            if(it != yoko[y].end()){
                ll nc = (*it)-x;
                int npos = id[{*it,y}];
                if(dp[stat][npos] > dp[stat][pos]+nc){
                   dp[stat][npos] = dp[stat][pos]+nc;
                   pq.push({-dp[stat][npos], {npos, stat}});
                }
            }
        }else if(stat == 0){
            auto it = tate[x].lower_bound(y);
            if(it != tate[x].begin()){
                it--;
                ll nc = y-(*it);
                int npos = id[{x, *it}];
                if(dp[stat][npos] > dp[stat][pos]+nc){
                   dp[stat][npos] = dp[stat][pos]+nc;
                   pq.push({-dp[stat][npos], {npos, stat}});
                }
                it++;
            }
            it++;
            if(it != tate[x].end()){
                ll nc = (*it)-y;
                int npos = id[{x, *it}];
                if(dp[stat][npos] > dp[stat][pos]+nc){
                   dp[stat][npos] = dp[stat][pos]+nc;
                   pq.push({-dp[stat][npos], {npos, stat}});
                }
            }
        }
    }
    ll ret = min(dp[0][siz-1], dp[1][siz-1]);
    if(ret == 1ll<<60)  ret = -1;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 68936
#include<cstdio>
#include<algorithm>
#define MAXN 10006
using namespace std;
long long n,a[MAXN],b[MAXN],sum1,sum2;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&b[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>b[i]) sum1+=a[i]-b[i];
		else sum2+=(b[i]-a[i])/2;
	}
	if(sum1<=sum2) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
INF = 10 ** 10
dp = Array.new(n, INF)
n.times do |idx|
  next dp[idx] = 0 if idx.zero?

  1.upto(k) do |aidx|
    break if aidx > idx
    dp[idx] = dp[idx-aidx] + (h[idx] - h[idx-aidx]).abs if dp[idx] > dp[idx-aidx] + (h[idx] - h[idx-aidx]).abs
  end
end
puts dp[n-1]


Measured memory_bytes: 8844
#include<stdio.h>


int main()
{
 int i,j,a,b,c ;
 float x,y,d ;
 char s[34534] ;
 scanf("%d",&a) ;
 b=a%10 ;
 if(b==2||b==4||b==5||b==7||b==9)
    printf("hon") ;
 else if(b==0||b==1||b==6||b==8)
    printf("pon") ;
 else
    printf("bon") ;
 return 0 ;
}


Measured memory_bytes: 1732
n, k = map(int, input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X % n)
    

i = Base_10_to_n(n, k)
print(len(str(i)))

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

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

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

  int box[N + 1];
  for (int i = 1; i <= N; i++)
  {
    box[i] = 0;
  }

  int box_cnt = 0;
  for (int i = N; i >= 1; i--)
  {
    int sum = 0;
    for (int j = 2 * i; j <= N; j += i)
    {
      sum += box[j];
    }
    if (sum % 2 == a[i])
      box[i] = 0;
    else
    {
      box[i] = 1;
      box_cnt++;
    }
  }
  cout << box_cnt << endl;

  if (box_cnt == 0)
    return 0;

  for (int i = 1; i <= N; i++)
  {
    if (box[i] == 1)
    {
      cout << i;
      if (--box_cnt > 0)
        cout << ' ';
    }
  }
  cout << endl;
}

Measured memory_bytes: 2432
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split()])

vector = []
for mi in range(m):
    vector.append(int(input()))



for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]


    print(sum)

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n ;
  cin >> n ;
  vll a(n) ;
  vll b(n) ;
  vll c(n) ;
  REP(i,n){
    cin >> a[i] ;
  }
  REP(i,n){
    cin >> b[i] ;
  }
  REP(i,n){
    cin >> c[i] ;
  }
  sort(ALL(a)) ;
  sort(ALL(b)) ;
  sort(ALL(c)) ;
  
  vll bb(n) ;
  
  auto itr = lower_bound(ALL(a),b[0]) ;
  ll dis ;
  if(itr==a.begin()){
    bb[0] = 0 ;
  }
  else if(itr==a.end()){
    bb[0] = n ;
  }
  else{
    dis = distance(a.begin(),itr) ;
    bb[0] = dis ;
  }
  
  REP(i,n-1){
    itr = lower_bound(ALL(a),b[i+1]) ;
    if(itr==a.begin()){
      bb[i+1] = bb[i] ;
    }
    else if(itr==a.end()){
      bb[i+1] = bb[i] + n ;
    }
    else{
      dis = distance(a.begin(),itr) ;
      bb[i+1] = bb[i] + dis ;
    }
  }
  
  vll ans(n) ;
  
  itr = lower_bound(ALL(b),c[0]) ;
  if(itr==b.begin()){
    ans[0] = 0 ;
  }
  else if(itr==b.end()){
    ans[0] = bb[n-1] ;
  }
  else{
    dis = distance(b.begin(),itr) ;
    ans[0] = bb[dis-1] ;
  }
  
  REP(i,n-1){
    itr = lower_bound(ALL(b),c[i+1]) ;
    if(itr==b.begin()){
      ans[i+1] = ans[i] ;
    }
    else if(itr==b.end()){
      ans[i+1] = ans[i] + bb[n-1] ;
    }
    else{
      dis = distance(b.begin(),itr) ;
      ans[i+1] = ans[i] + bb[dis-1] ;
    }
  }
  /*
  REP(i,n){
    cout << bb[i] <<" " ;
  }
  cout <<endl ;
  
  REP(i,n){
    cout << ans[i] << " " ;
  }
  cout <<endl ;
  */
   
    
  
    
    
  cout << ans[n-1] << endl ;
  
  
  
  return 0 ;
}



Measured memory_bytes: 4224
#include<iostream>

using namespace std;
using ll = long long;

int N;
int a[10000];
int b[10000];
ll K;
int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        K -= a[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> b[i];
        K += b[i];
    }
    ll cnt1 = K;
    ll cnt2 = K;

    for (int i = 0; i < N; ++i) {
        //cout << a[i] << ", " << b[i] << endl;
        if (a[i] == b[i]) continue;
        if (a[i] > b[i]) {
            cnt1 -= a[i] - b[i];
        } else {
            cnt2 -= (b[i] - a[i] + 1) / 2;
            if ((b[i] - a[i]) % 2 != 0) cnt1--;
        }
        //cout << "2 -- rest: " << cnt2 << " 1 -- rest:" << cnt1 << endl;
    }

    if (cnt1 >= 0 && cnt2 >= 0 && cnt1 == cnt2 * 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 888
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef pair <ii,int> iii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int vis[N], tab[N], n, m, i, a, b, result;
VI graf[N];
set<int> s, s2;
set<int>::iterator it, it2;

void dfs(int w) {
	vis[w] = 1;
	s.insert(w);
	for (int i=0;i<graf[w].size();i++) if (!vis[graf[w][i]]) dfs(graf[w][i]);
}

int main() {
scanf("%d %d", &n, &m);
for (i=1;i<=n;i++) {
	scanf("%d", &tab[i]);
	graf[i].clear();
	vis[i] = 0;
}
for (i=0;i<m;i++) {
	scanf("%d %d", &a, &b);
	graf[a].pb(b);
	graf[b].pb(a);
}
result = 0;
for (i=1;i<=n;i++) if (!vis[i]) {
	s.clear();
	dfs(i);
	s2.clear();
	for (it = s.begin();it!=s.end();it++) s2.insert(tab[*it]);
	it = s.begin();
	it2 = s2.begin();
	while (it != s.end() && it2 != s2.end()) {
		if (*it == *it2) {
			result++;
			it++;
			it2++;
		} else if (*it < *it2) it++; else it2++;
	}
}
printf("%d\n", result);
return 0;
}



Measured memory_bytes: 17920
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n,l,i;
    cin>>n>>l;
    string x="";
    vector <string> a(n);
    for(i=0;i<n;++i)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(i=0;i<n;++i)
        x+=a[i];
    cout<<x;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS = 1e-12;
const double INF = 1e12;

int dp[4][101][101];//dp[上上:0 右右:1 上右:2 右上:3][交差点の座標]
int main(){
	int w,h;
	while(cin>>w>>h){
		if(w==0&&h==0)break;
		CLR(dp);
		dp[0][0][1]=dp[1][1][0]=1;
		
		FOR(i,1,w+1){//上j 右i
			FOR(j,1,h+1){
				dp[0][i][j]=(dp[0][i][j-1]+dp[3][i][j-1])%100000;
				dp[1][i][j]=(dp[1][i-1][j]+dp[2][i-1][j])%100000;
				dp[2][i][j]=dp[0][i-1][j]%100000;
				dp[3][i][j]=dp[1][i][j-1]%100000;
			}
		}
		long res=0;
		REP(i,4)res+=dp[i][w][h];
		cout<<res%100000<<endl;
	}
	return 0;
}

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


int main()
{
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    if(k <= x/d) { cout << x - k*d << endl; return 0;}

    ll lim = x/d;
    if((k + lim) & 1) cout << (lim+1)*d - x << endl;
    else cout << x - lim*d << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] xs = new int[3];
			int[] ys = new int[3];
			for (int i = 0; i < 3; i++) {
				int a = scanner.next().charAt(0) - 'A';
				xs[i] = a % 3;
				ys[i] = a / 3;
			}
			double[][][] dp = new double[2][3][3];
			int u = 0;
			dp[u][xs[0]][ys[0]] = 1;
			for (int i = 0; i < n; i++) {
				for (int x = 0; x < 3; x++) {
					for (int y = 0; y < 3; y++) {
						if(dp[u][x][y]==0)
							continue;
						for (int[] m : move) {
							int nx = x + m[0];
							int ny = y + m[1];
							if (nx == xs[2] && ny == ys[2] || nx < 0 || 2 < nx
									|| ny < 0 || 2 < ny)
								dp[1 - u][x][y] += dp[u][x][y] / 4;
							else
								dp[1 - u][nx][ny] += dp[u][x][y] / 4;
						}
						dp[u][x][y] = 0;
					}
				}
				u = 1 - u;
			}
			System.out.printf("%.8f\n", dp[u][xs[1]][ys[1]]);
		}
	}

	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

}

Measured memory_bytes: 20512
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int cnt[64] = {};
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[300010];
    rep(i, N) cin >> A[i];
    int ans = 0;
    rep(i, N) {
        rep(j, 62) {
            if(A[i] & (1LL << j)) cnt[j]++;
        }
    }
    rep(i, N) {
        rep(j, 62) {
            if(!(A[i] & (1LL << j))) continue;
            int k = (1LL << j) % mod;
            cnt[j]--;
            int remain = (N - 1) - cnt[j];
            //cout << j << " " << remain << endl;
            ans = (ans + k * remain) % mod;
            cnt[j]++;
        }
    }
    //rep(j, 61) if(cnt[j] > 0) cout << j << " " << cnt[j] << endl;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(){
    string str;
    cin>>str;
    int t=0;
    for(int i=0;i<str.size();i++){
        if(str[i]=='o') t++;
    }
    long long ans=700+(t*100);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back

using namespace std;

const int  mod = 1e9 + 7;
const int e = 2e5 + 69;
const int base = 311;

ll a[e];

int main()
{
   int n, x, y;
   cin >> n >> x >> y;
   vector<ll>a(n, 0);
   for(int i=1; i<n; i++)
   {
       for(int j=i+1; j<=n; j++)
       {
           if(i != j)
           {
               int dist = 1e9;
               dist = min(dist, abs(j - i));
               dist = min(dist, abs(j - x) + abs(i - y) + 1);
               dist = min(dist, abs(j - y) + abs(i - x) + 1);
               a[dist] ++;
           }
       }
   }
   for(int i=1; i<n; i++)
   {
       cout << a[i] <<"\n";
   }
}


Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init (n + 2) @@ fun i -> if i = 0 || i > n then 0 else Scanf.scanf " %d" (+) 0
let s = Array.fold_left (fun (s, p) a -> s + abs (p - a), a) (0, 0) a_s |> fst
let f i = s - abs (a_s.(i - 1) - a_s.(i)) - abs (a_s.(i) - a_s.(i + 1)) + abs (a_s.(i - 1) - a_s.(i + 1))
let _ = for i = 1 to n do Printf.printf "%d\n" @@ f i done

Measured memory_bytes: 6272
from collections import deque

N = int(input())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    to[a - 1].append((b - 1, c))
    to[b - 1].append((a - 1, c))
Q, K = map(int, input().split())
XY = []
for _ in range(Q):
    x, y = map(int, input().split())
    XY.append((x - 1, y - 1))

ds = [0] * N
q = deque()
q.append((K - 1, 0, -1))
while len(q):
    a, d, par = q.pop()
    ds[a] = d
    for b, c in to[a]:
        if b != par:
            q.append((b, d + c, a))

for x, y in XY:
    print(ds[x] + ds[y])


Measured memory_bytes: 61488
N,M,Q = map(int,input().split())
ABCD = []
for q in range(Q):
    ABCD.append([int(i) for i in input().split()])
from itertools import combinations_with_replacement as comb
M_list = [i for i in range(1,M+1)]
ans = 0
for c in comb(M_list,N):
    temp = 0
    for abcd in ABCD:
        if c[abcd[1]-1] - c[abcd[0]-1] == abcd[2]:
            temp += abcd[3]
    ans = max(temp,ans)
print(ans)


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define MAXN 100015
using namespace std;
typedef long long ll;
long long n,m;
char S[MAXN],T[MAXN];
map<int,char>str;
ll gcd(long long M,long long N)
{
    ll Rem;
    while(N > 0)
    {
        Rem = M % N;
        M = N;
        N = Rem;
    }
    return M;
}
bool check(ll x)
{
    if(S[1]!=T[1])
    {
        return 0;
    }
    str[1]=S[1];
    int l1=x/n;
    for(int i=2;i<=n;i++)
    {
        str[(i-1)*l1+1]=S[i];
    }
    int l2=x/m;
    for(int i=2;i<=m;i++)
    {
        if(str[(i-1)*l2+1]&&str[(i-1)*l2+1]!=T[i])
        {
            return 0;
        }
        str[(i-1)*l2+1]=T[i];
    }
    return 1;
}
int main()
{
    scanf("%lld %lld",&n,&m);
    scanf("%s",S+1);
    scanf("%s",T+1);
    if(check(n*m/gcd(n,m)))
    {
        printf("%lld",n*m/gcd(n,m));
    }
    else
    {
        printf("-1");
    }
}


Measured memory_bytes: 8192
N = int(input())
temp = input()
temp = temp.split(" ")
arr = []
prod=1
for i in range(N):
    arr.append(int(temp[i]))
arr.sort()
flag=0    
for i in range(N):
    prod = prod*arr[i]
    if prod>1000000000000000000:
        flag=1
        break
if flag==0:
    print(prod)
else:
    print(-1)

Measured memory_bytes: 22092
n = 50000
sn = n**0.5 + 1
is_prime = [false, false] + [true] * (n - 1)

(2..sn).each do |i|
  next unless is_prime[i]
  (i*i).step(n, i).each do |j|
    is_prime[j] = false
  end
end

pl = (2..n).map.select{ |i| is_prime[i] }

while gets do
  s = $_.to_i
  break if s == 0
  count = 0

  tmp = pl.dup
  l = tmp.shift
  h = tmp.pop
  until tmp.empty? do
    if (l + h) == s
      count += 1
      l = tmp.shift
    elsif (l + h) > s
      h = tmp.pop
    else
      l = tmp.shift
    end
  end

  if l*2 == s or h*2 == s or (l + h) == s
    count += 1
  end
  puts count
end

Measured memory_bytes: 7396
#include<stdio.h>
#include<algorithm>
#include<queue>
const int MAX=1100;
using namespace std;
typedef pair<int,int> pii;
typedef long long lld;
char fin[MAX][MAX];
int n,m,a,b,cnt_a,cnt_b,ben_a,ben_b;
void myprint(){
    for(int i=0;i<n;i++) printf("%s\n",fin[i]);
}
int main(){
    scanf("%d%d%d%d",&n,&m,&a,&b);
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) fin[i][j]='.';
    if(n%2) ben_a=m/2;
    if(m%2) ben_b=n/2;
    for(int i=0;i<n-1;i+=2) for(int j=0;j<m-1;j+=2){
        if(cnt_a+ben_a<a){
            cnt_a++,fin[i][j]='<',fin[i][j+1]='>';
            if(cnt_a<a) cnt_a++,fin[i+1][j]='<',fin[i+1][j+1]='>';
        }
        else if(cnt_b+ben_b<b){
            cnt_b++,fin[i][j]='^',fin[i+1][j]='v';
            if(cnt_b<b) cnt_b++,fin[i][j+1]='^',fin[i+1][j+1]='v';
        }
    }
    if(n%2){
        for(int j=0;j<m-1;j+=2) if(cnt_a<a) cnt_a++,fin[n-1][j]='<',fin[n-1][j+1]='>';
    }
    if(m%2){
        for(int i=0;i<n-1;i+=2) if(cnt_b<b) cnt_b++,fin[i][m-1]='^',fin[i+1][m-1]='v';
    }
    if(cnt_a==a&&cnt_b==b){
        printf("YES\n");
        myprint();
    }
    else{
        if(n%2&&m%2&&n>2&&m>2){
            for(int i=0;i<n;i++) for(int j=0;j<m;j++) fin[i][j]='.';
            ben_a=m/2-1,ben_b=n/2-1;
            fin[n-3][m-3]='<',fin[n-3][m-2]='>';
            fin[n-3][m-1]='^',fin[n-2][m-1]='v';
            fin[n-1][m-2]='<',fin[n-1][m-1]='>';
            fin[n-2][m-3]='^',fin[n-1][m-3]='v';
            cnt_a=2,cnt_b=2;
            for(int i=0;i<n-1;i+=2) for(int j=0;j<m-1;j+=2) if(fin[i][j]=='.'){
                if(cnt_a+ben_a<a){
                    cnt_a++,fin[i][j]='<',fin[i][j+1]='>';
                    if(cnt_a<a) cnt_a++,fin[i+1][j]='<',fin[i+1][j+1]='>';
                }
                else if(cnt_b+ben_b<b){
                    cnt_b++,fin[i][j]='^',fin[i+1][j]='v';
                    if(cnt_b<b) cnt_b++,fin[i][j+1]='^',fin[i+1][j+1]='v';
                }
            }
            if(n%2){
                for(int j=0;j<m-3;j+=2) if(cnt_a<a) cnt_a++,fin[n-1][j]='<',fin[n-1][j+1]='>';
            }
            if(m%2){
                for(int i=0;i<n-3;i+=2) if(cnt_b<b) cnt_b++,fin[i][m-1]='^',fin[i+1][m-1]='v';
            }
            if(cnt_a==a&&cnt_b==b){
                printf("YES\n");
                myprint();
            }
            else printf("NO\n");
        }
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


// 2整数の最大公約数を求める関数
ll gcd(ll x, ll y) {
  if(y == 0) return x;
  else return gcd(y, x % y);
}

// 2整数の最小公倍数を求める関数
ll lcm(ll x, ll y) {
  return y / gcd(x, y) * x;
}

// 3個以上の整数の最大公約数を求める関数
ll gcdary(ll a[], ll n) {
  if(n == 1) return (a[0]);
  else if(n == 2) return (gcd(a[0], a[1]));
  else return (gcd(a[0], gcdary(&a[1], n - 1)));
}

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

  int n;
  cin>>n;
  ll t[n];
  rep(i,n) cin>>t[i];
  sort(t, t + n);
  ll now = t[0];
  rep(i,n) {
    now = lcm(now, t[i]);
  }
  cout << now << endl;


  return 0;
}


Measured memory_bytes: 256
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <functional>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define sz(a) (int)(a.size())
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	auto divs = [&](int v) {
		vi ans;
		for (int d = 1; d * d <= v; d++) if (v % d == 0) ans.pb(d), ans.pb(v / d);
		SORT(ans); ans.erase(unique(all(ans)), ans.end());
		return ans;
	};
	int n; cin >> n;
	int ans = sz(divs(n - 1)) - 1;
	vi p = divs(n);
	for (auto x : p) if(x != 1){
		int m = n;
		while (m % x == 0) m /= x;
		if (m % x == 1) ans++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3704
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,X = map(int, readline().split())
    CA = [[int(i) for i in readline().split()] for _ in range(N)]
    
    ans = 10**15
    for i in range(2**N):
        m = [0] * M
        c = 0
        flag = True
        for j in range(N):
            if (i >> j) & 1:
                c += CA[j][0]
                for k in range(1,M+1):
                    m[k-1] += CA[j][k]
        for a in m:
            if a < X:
                flag = False
                break
        if flag:
            ans = min(ans, c)

    print(ans if ans < 10**15 else -1)


if __name__ == "__main__":
    main()


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

int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n),b(n,0);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int j = 0; j < k; j++) {
        b.assign(n,0);
        for(int i = 0; i < n; i++) {
            b[max(0,i-a[i])]++;
            if(i+a[i]+1<n) b[i+a[i]+1]--;
        }
        bool end_chk=true;
        for(int i = 0; i < n; i++) {
            if(i>0) b[i]+=b[i-1];
            if(b[i]!=n) end_chk=false;
            a[i]=b[i];
        }
        if(end_chk) break;
    }
    for(int i = 0; i < n; i++) {
        cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4832