akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] first = br.readLine().split(" ", 2);
		int h = Integer.parseInt(first[0]);
		int w = Integer.parseInt(first[1]);
		boolean[][] field = new boolean[h][w];
		ArrayDeque<Integer> deq = new ArrayDeque<>();
		for (int i = 0; i < h; i++) {
		    char[] arr = br.readLine().toCharArray();
		    for (int j = 0; j < w; j++) {
		        field[i][j] = (arr[j] == '#');
		        if (field[i][j]) {
		            deq.add(i * w + j);
		        }
		    }
		}
		ArrayDeque<Integer> next = new ArrayDeque<>();
		int count = 0;
		while (deq.size() > 0) {
		    count++;
		    while(deq.size() > 0) {
		        int i = deq.poll();
		        int y = i / w;
		        int x = i % w;
		        if (y > 0 && !field[y - 1][x]) {
		            next.add((y - 1) * w + x);
		            field[y - 1][x] = true;
		        }
		        if (y < h - 1 && !field[y + 1][x]) {
		            next.add((y + 1) * w + x);
		            field[y + 1][x] = true;
		        }
		        if (x > 0 && !field[y][x - 1]) {
		            next.add(y * w + x - 1);
		            field[y][x - 1] = true;
		        }
		        if (x < w - 1 && !field[y][x + 1]) {
		            next.add(y * w + x + 1);
		            field[y][x + 1] = true;
		        }
		    }
		    ArrayDeque<Integer> tmp = next;
		    next = deq;
		    deq = tmp;
		}
		System.out.println(count - 1);
    }
}



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

char t[20], s[20];
int main() {
	int n; scanf("%d", &n);
	unordered_set<string>se;
	rep(i, n) {
		scanf("%s%s", t, s);
		if (!strcmp(t, "insert"))se.insert(s);
		else
			puts(se.find(s) != se.end() ? "yes" : "no");
	}
}

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

using namespace std;
int n, a[100001];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    int mid = ((a[n] + 1) / 2), pos = 0;
    for(int i = 1; i < n; i++){
        if(abs(pos - mid) > abs(a[i] - mid)){
            pos = a[i];
        }
    }
    cout << a[n] << " " << pos;
}


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

int main()
{
  int N, a = 0;
  vector<int> A(20), B(20), C(20);
  cin >> N;

  for (int i = 0; i < N; ++i) cin >> A[i];
  for (int i = 0; i < N; ++i) cin >> B[i];
  for (int i = 0; i < N - 1; ++i) cin >> C[i];

  for (int i = 0; i < N; ++i) {
    a += B[A[i] - 1];
    if (i > 0 && A[i - 1] + 1 == A[i]) {
      a += C[A[i - 1] - 1];
    }
  }

  cout << a << endl;
}


Measured memory_bytes: 256
K = int(input())

MAX = 10**16 + 1000
N = 2
for n in range(2,51):
    SUM = n*(n-1)+K
    if 0--SUM//n > MAX:
        continue
    else:
        N = n
        break

plus = K//N
amari = K%N
A = [N-1 + plus]*N

for k in range(amari):
    for i in range(N):    
        if i==k:
            A[i] += N
        else:
            A[i] -= 1

    
print(N)
print(*A)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W;
  cin>>H>>W;
  int N;
  cin>>N;
  if(H>W){
    if(N%H==0){
      cout<<N/H<<endl;
    }
    else {
      cout<<N/H+1<<endl;
    }
  }
  else {
    if(N%W==0){
      cout<<N/W<<endl;
    }
    else cout<<N/W+1<<endl;
  }
}



Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
    int r,c;
    cin>>r>>c;
    int yokowa[r]={},tatewa[c]={},goukei=0;
    int a[r+1][c+1];
    int d,j,i,k,l,m,n,o,p,q,s;
    for(j=0;j<r;j++){
       for(i=0;i<c;i++){
          cin>>d;
          a[j][i]=d;
       }
    }
    for(k=0;k<r;k++){
       for(l=0;l<c;l++){
          yokowa[k]+=a[k][l];
       }
    }
    for(m=0;m<c;m++){
       for(n=0;n<r;n++){
          tatewa[m]+=a[n][m];
       }
    }
    for(o=0;o<c;o++){
       goukei+=tatewa[o];
    }
    for(p=0;p<r;p++){
       for(q=0;q<c;q++){
          cout<<a[p][q]<<" ";
       }
       cout<<yokowa[p]<<endl;
    }
    for(s=0;s<c;s++){
       cout<<tatewa[s]<<" ";
    }
    cout<<goukei<<endl;
}


Measured memory_bytes: 3124
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */


int main(){
   int n;
   cin >> n;
   vector<Bint> t(n), a(n);
   rep(i, n)cin >> t[i] >> a[i];
   ll res = 0;

   rep(i, n){
      if(i == 0)continue;
      Bint lb = 0, rb = 1000000000000000000;
      while(rb - lb > 1){
         Bint mid = (rb + lb) / 2;
         if(t[i - 1] <= t[i] * mid && a[i - 1] <= a[i] * mid){
            rb = mid;
         }
         else lb = mid;
      }
      t[i] *= rb;
      a[i] *= rb;
   }
   cout << t[n - 1] + a[n - 1] << endl;
   //rep(i, n)cout << t[i] << " " << a[i] << endl;
}


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

int main(){
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for (auto i = 0; i < h; i++) cin >> s[i];

    bool flg = true, tmp[4];
    for (auto i = 0; i < h; i++) {
        for (auto j = 0; j < w; j++) {
            if(s[i][j] == '#') {
                for (bool & k : tmp) k = true;
                if(i - 1 >= 0) {
                    if(s[i - 1][j] != '#') tmp[0] = false;
                } else tmp[0] = false;
                if(i + 1 < h) {
                    if(s[i + 1][j] != '#') tmp[1] = false;
                } else tmp[1] = false;
                if(j - 1 >= 0) {
                    if(s[i][j - 1] != '#') tmp[2] = false;
                } else tmp[2] = false;
                if(j + 1 < w) {
                    if(s[i][j + 1] != '#') tmp[3] = false;
                } else tmp[3] = false;
                if(tmp[0] or tmp[1] or tmp[2] or tmp[3]) flg = true;
                else {
                    flg = false;
                    break;
                }
            }
        }
        if(!flg) break;
    }
    cout << ((flg) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    while (1) {
        int n;
        cin >> n;
        if (!n) return 0;

        vector<int> power(n);
        map<string, int> mp;
        vector<vector<string>> nearby(n);
        for (int i = 0; i < n; ++i) {
            string s;
            int c;
            cin >> s >> power[i] >> c;
            mp[s] = i;
            nearby[i].resize(c);
            for (int j = 0; j < c; ++j)
                cin >> nearby[i][j];
        }
        vector<long long> isnearby(n, 0LL);
        for (int i = 0; i < n; ++i)
            for (auto& j : nearby[i])
                isnearby[i] |= 1LL << mp[j];

        for (int i = 0; i < n; ++i)
            if ((isnearby[0] >> i) & 1)
                power[i] = -1000000;

        int n1 = n / 2;
        int n2 = n - n1;
        vector<int> dp1(1 << n1, 0);
        vector<long long> inb1(1 << n1, 0);
        for (int i = 1; i < (1 << n1); ++i) {
            int ma = 0;
            for (int j = 0; j < n1; ++j) {
                if ((i >> j) & 1) {
                    inb1[i] |= isnearby[j];
                    dp1[i] += power[j];
                    ma = max(ma, dp1[i ^ (1 << j)]);
                }
            }
            if (i & inb1[i])
                dp1[i] = ma;
        }
        vector<int> dp2(1 << n2, 0);
        vector<long long> inb2(1 << n2, 0);
        for (int i = 1; i < (1 << n2); ++i) {
            int ma = 0;
            for (int j = 0; j < n2; ++j) {
                if ((i >> j) & 1) {
                    inb2[i] |= isnearby[n1 + j];
                    dp2[i] += power[n1 + j];
                    ma = max(ma, dp2[i ^ (1 << j)]);
                }
            }
            if (i & (inb2[i] >> n1))
                dp2[i] = ma;
        }
        int ans = 0;
        int msk = (1 << n2) - 1;
        for (int i = 1; i < (1 << n1); i += 2)
            ans = max(ans, dp1[i] + dp2[(inb1[i] >> n1) ^ msk]);

        cout << ans << "\n";
    }
}

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

long long s,x2,x3,y2,y3;

int main(){
    cin>>s;
    y2=1;
    y3=1000000000;
    x2=(s+999999999)/1000000000;
    x3=x2*1000000000-s;
    cout<<0<<' '<<0<<' '<<x2<<' '<<y2<<' '<<x3<<' '<<y3;
}

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

using namespace std;
int main(){

  int k;
  int s;
  cin >> k>>s;
  int x=0;
  int y=0;
  int z=0;
  int sum=0;
  long ans=0;
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
      z=y+x;
      if(s-z <=k and s-z >=0){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

const int LMAX=3010;
int dp[LMAX+1][LMAX+1],from[LMAX+1][LMAX+1];
string LCS(string &a,string &b){
	int m=a.size(),n=b.size();
	int dp[LMAX+1][LMAX+1],from[LMAX+1][LMAX+1];	rep(i,m+1)dp[i][0]=0,from[i][0]=-1;
	rep(i,n+1)dp[0][i]=0,from[0][i]=-1;
	rep(i,m)rep(j,n){
		if(a[i]==b[j]){
			dp[i+1][j+1]=dp[i][j]+1;
			from[i+1][j+1]=2;
		}else{
			if(dp[i][j+1]<dp[i+1][j]){
				dp[i+1][j+1]=dp[i+1][j];
				from[i+1][j+1]=1;
			}else{
				dp[i+1][j+1]=dp[i][j+1];
				from[i+1][j+1]=0;
			}
		}
	}
	int idx=dp[m][n];
	string out(idx,'!');
	for(int i=m,j=n;~from[i][j];){
		switch(from[i][j]){
			case 0:i--;break;
			case 1:j--;break;
			case 2:i--;j--;idx--;out[idx]=a[i];break;
		}
	}
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s,t;
	cin>>s>>t;
	cout<<LCS(s,t)<<endl;
}






Measured memory_bytes: 141952
#include<stdio.h>

int main(void)
{
    int N,X,T;

    scanf("%d %d %d",&N,&X,&T);

    int cnt=0;
    for(int i=0;N>0;i++)
    {
        N-=X;
        cnt++;
    }
    printf("%d",cnt*T);
}

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

int main() {
  int x;
  cin >> x;
  if(400 <= x && x <= 599) {
    cout << 8 << endl;
  } else if(600 <= x && x <= 799) {
    cout << 7 << endl;
  } else if(800 <= x && x <= 999) {
    cout << 6 << endl;
  } else if(1000 <= x && x <= 1199) {
    cout << 5 << endl;
  } else if(1200 <= x && x <= 1399) {
    cout << 4 << endl;
  } else if(1400 <= x && x <= 1599) {
    cout << 3 << endl;
  } else if(1600 <= x && x <= 1799) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3628
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Floor Function
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int a;
  ll b, n;
  scanf("%d%lld%lld", &a, &b, &n);

  // Let x = By+z (0<=z<B),
  // floor(Ax/B)-A*floor(x/B) = floor(A(By+z)/B)-A*floor((By+z)/B)
  // = floor(Ay+Az/B)-A*floor(y+z/B) = Ay+floor(Az/B)-Ay-A*floor(z/B)
  // = floor(Az/B)

  ll z = (n < b) ? n : b - 1;
  printf("%lld\n", a * z / b);
  return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define CFS cin.tie(nullptr);ios::sync_with_stdio(false);
#define CST(x) cout<<fixed<<setprecision(x);
using namespace std;
constexpr int IINF = numeric_limits<int>::max();
constexpr long LINF = numeric_limits<long>::max();
constexpr int MOD = (int) 1e9 + 7;
// constexpr int MOD = 998244353;

struct Tower {
    int i;
    int h;
    vector<int> adj;
};

int main(){
    int n, m;
    cin >> n >> m;
    map<int, int> mh;
    for (size_t i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        mh[i + 1] = h;
    }
    using pii = pair<int, int>;
    map<int, vector<int>> roads;
    for (size_t i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        roads[a].push_back(b);
        roads[b].push_back(a);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (roads[i].size() == 0) {
            ans++;
            continue;
        }
        bool flag = true;
        for (const auto x : roads[i]) {
            if (mh[x] >= mh[i]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 18908
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize
    }
    println!("{}", (n - 2) * 180);
}


Measured memory_bytes: 4352
from math import factorial

def divisors(n):
    e = int(n**0.5+1)
    k = int(0)
    div=[0]*e
    divs =[]
    for i in range(1,e):
        if n%i == 0:
            div[k] = i
            k +=1

    i = int(0)
    while div[i]!=0 : i +=1
    end=int(i)

    del div[end:]
    divs = div
    for i in reversed(div):
        a = int(n//i)
        if not a in divs:
            div.append(a)

    return(div)

N, M = map(int, input().split())
L = divisors(M)
maxans = int(M//N)

anst = int(0)
for i in L:
    if i > maxans:
        break
    else:anst = i

ans = anst
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;



void solve(){
	int a,b;
	cin>>a>>b;
	if(a>8 || b>8)cout<<":(";
	else cout<<"Yay!";

}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
void bubble(int *ar, int len) {
	int i, j,temp,cou=0, boolea = 1 ;

	for (i = len - 1; boolea; i--)
	{
		boolea = 0;
		for (j = 0; j < i;j++)
		{
			if (*(ar + j + 1) < *(ar + j))
			{
				temp = *(ar + j + 1);
				*(ar + j + 1) = *(ar + j);
				*(ar + j) = temp;
				cou++;
				boolea = 1;
			}
		}
	}
	for (i = 0; i < len-1; i++)
	{
		printf("%d ", *(ar + i));
	}
	printf("%d\n%d\n", *(ar + i),cou);

}

int main() {
	int N;
	int ar[100];
	int i;
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%d", &ar[i]);
	}
	bubble(ar, N);
	return 0;
}

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int N;
    vector<string> vec_s;
    vector<int> vec_t;
    string X;
    cin >> N;
    vec_s.resize(N);
    vec_t.resize(N);
    for (int i=0; i < N; i++) cin >> vec_s[i] >> vec_t[i];
    cin >> X;

    // resolve;
    int idx=0;
    for (auto s: vec_s) {
        if (s == X) break;
        idx++; 
    }

    // output
    auto beg = next(vec_t.begin(), idx+1);
    cout << accumulate(beg, vec_t.end(), 0) << endl;

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (int i = 0; i < g; ++i) {
    if (S[stepS * i] != T[stepT * i]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << (long long) N / g * M << '\n';
  return 0;
}

Measured memory_bytes: 640
#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<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

vt GCD(vt a, vt b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	ll a, b, c, d, e;
	cin >> a >> b >> c >> d;
	e = c * d / GCD(c, d);
	a -= 1;
	ll s = b - a;
	ll p = b / c - a / c;
	ll q = b / d - a / d;
	ll r = b / e - a / e;
	cout << s - (p + q - r);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
 
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;
 
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;
 
typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int MAXN = 1e3;
const int MOD = 1e9 + 7;

char grid[MAXN + 1][MAXN + 1];
int dp[MAXN + 1][MAXN + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/dp_h.txt", "r", stdin);
	
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++)
			cin >> grid[i][j];
	}
	
	dp[0][1] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(grid[i][j] == '#') continue;
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
		}
	}
	cout << dp[n][m] << '\n';
	
	return 0;
}

Measured memory_bytes: 5120
S=list(input())
X=""
for i in range(len(S)):
    if i%2==0:
        if S[i]=="L":
            X="No"
        else:
            continue
    else:
        if S[i]=="R":
            X="No"
        else:
            continue

if X=="No"   :
    print("No")

else:
    print("Yes")


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

int n;
int f[100][5][2];
int p[100][11];

int main() {
	bool good = false;

	cin >> n;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 5; ++j) {
			for (int k = 0; k < 2; ++k) {
				cin >> f[i][j][k];
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= 10; ++j) {
			cin >> p[i][j];
		}
	}

	int result = 0;
	for (int ii = 1; ii < 1024; ++ii) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			int count = 0;
			for (int j = 0; j < 5; ++j) {
				for (int k = 0; k < 2; ++k) {
					if (((1 & (ii >> j * 2 + k)) && 1 == f[i][j][k])) {
						count++;
					}
				}
			}
			sum += p[i][count];
		}

		if (ii == 1) result = sum;

		result = (result < sum) ? sum : result;
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int main(){
	ll n;
	cin>>n;
	ll a[200];
	ll i,j;
	ll s=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(i%2==0)
			if(a[i]%2==1)
				s++; 
	}
	cout<<s<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  int n,m;
  string s;
  cin>>n>>s;

  if(n%2==1){
    cout<<"No"<<endl;
  }
  else{
    m=n/2;
    for(int i=0;i<m;i++){
      if(s[i]!=s[i+m]){
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
      int d, x;
  cin >> n >> k;
  set<int>st;
  for(int i = 1; i <= n; ++i)st.insert(i);
  for(int i = 0; i < k; ++i) {

    cin >> d;
    for(int dd = 0; dd < d; ++dd){
      cin >> x;
      auto it = st.find(x);
      if(it != st.end())st.erase(it);
    }
  }
  cout << (int)st.size() << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tc = 1;
  // cin >> tc;
  for(int i = 1; i <= tc; ++i) {
    // cout << "Case #" << i <<": ";
    solve();
  }
  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int N;
  cin >> N;
  vector<i64> b(N + 1);
  for(int i = 1;i <= N;i++) cin >> b[i];
  vector<i64> ans;
  while(b.size() != 1) {
    for(int i = b.size() - 1;i >= 0;i--) {
      if(i == 0) { cout << -1 <<endl; return 0;}
      if(b[i] == i) {
        ans.push_back(i);
        b.erase(begin(b) + i);
        break;
      }
    }
  }
  reverse(all(ans));
  for(auto x: ans) {
    cout << x << endl;
  }
}


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

int main() {
    int n ;
    cin >> n ;
    vector<int>  a (n);
    int mx ; 
    rep(i, n){
        cin >> a[i] ;
    }
    vector<int> b = a ; 
    sort(b.begin(), b.end()) ;
    int n1 = b[n - 1] ;
    int n2 = b[n - 2] ;
    rep(i, n){
        if(a[i] == n1){
            cout << n2 << endl ;
        }
        else {
            cout << n1 << endl ; 
        }
    }
}

Measured memory_bytes: 4716
#include <iostream>
#include <set>

using namespace std;

set<string>S;

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++) {
		string s;
		cin>>s;
		S.insert(s);
	}
	cout<<S.size();
	return 0;
}

Measured memory_bytes: 19228
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long N;
bool check(long K)
{
	if(K==1)return false;
	long t=N;
	while(t%K==0)t/=K;
	return t%K==1;
}
main()
{
	cin>>N;
	vector<long>ans;
	for(long i=1;i*i<=N;i++)
	{
		if(N%i==0)
		{
			if(check(i))ans.push_back(i);
			if(check(N/i))ans.push_back(N/i);
		}
	}
	for(long i=1;i*i<=N-1;i++)
	{
		if((N-1)%i==0)
		{
			if(check(i))ans.push_back(i);
			if(check((N-1)/i))ans.push_back((N-1)/i);
		}
	}
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	cout<<ans.size()<<endl;
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

/* [L,R) */
range_list(L, R, []) :- L >= R, !.
range_list(L, R, [L|Xs]) :- L2 is L + 1, range_list(L2, R, Xs).

main :-
    get_number(K, X),
    L is X - (K - 1),
    R is X + (K - 1) + 1,
    range_list(L, R, Xs),
    put_numbers(Xs).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8236
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
 
int main() {
    int H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    H1 = H1*60;
    H2 = H2*60;
    if ((((H2+M2)-(H1+M1)) - K) <= 0){
        cout << "0" << endl;
    } else {
        cout << (((H2+M2)-(H1+M1)) - K) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3612
bingo_length = 3

grid = []
for i in range(bingo_length):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))

flag = False
for i in range(bingo_length):
  if grid[i][0] in b and grid[i][1] in b and grid[i][2] in b:
    flag = True
    break
for i in range(bingo_length):
  if grid[0][i] in b and grid[1][i] in b and grid[2][i] in b:
    flag = True
    break
if grid[0][0] in b and grid[1][1] in b and grid[2][2] in b:
  flag = True
if grid[0][2] in b and grid[1][1] in b and grid[2][0] in b:
  flag = True
if flag == True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vb vector<bool>
#define vi vector<ll>
#define vs vector<string>
#define vvi vector<vi>
#define vii vector<pair<ll, ll>>
#define pii pair<ll, ll>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define INF 1000*1000*1000
//#define mod (INF + 7)
#define mod1 (mod-1)
#define endl '\n'
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    if(n%k == 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll r,g,b;
int main() {
	ll n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		if(s[i]=='G')g++;
		if(s[i]=='B')b++;
	}
	//cout<<r<<' '<<g<<' '<<b<<endl;
	ll ans=r*g*b;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ll k=2*j-i;
			if(k>=n)break;
			if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i])ans--;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int num = scn.nextInt();
        for(int i = 1; i <= num; i++){
            if(i % 3 == 0){
                System.out.printf(" %d",i);
            }
            else{
                int n = i;
                while(n != 0){
                    if(n % 10 == 3){
                        System.out.printf(" %d",i);
                        break;
                    }
                    n /= 10;
                }
            }
        }
        System.out.printf("\n");
    }
}


Measured memory_bytes: 40996
#include <iostream>
#define BurstStream ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int cnt(int n)
{
    int s = 0;
    while (n != 0)
    {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int main()
{
    BurstStream
    int n, a, b;
    while (cin >> n >> a >> b)
    {
        int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            int s = cnt(i);
            if (a <= s && s <= b) sum += i;
        }
        cout << sum << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  uint32_t N;
  cin >> N;
  vector<uint32_t> A(N), B(N);
  for (uint32_t i = 0; i < N; ++i) cin >> A[i];

  copy(A.begin(), A.end(), B.begin());
  sort(B.begin(), B.end(), greater<uint32_t>());

  for (uint32_t i = 0; i < N; ++i) {
    if (A[i] < B[0]) {
      cout << B[0] << endl;
    } else {
      cout << B[1] << endl;
    }
  }
  return 0;
}


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

int main(){
  string s;
  cin>>s;
  if((s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])||
     (s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1])||
     (s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1])){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
n,m,x=map(int,input().split())
lis=[list(map(int,(input().split()))) for i in range(n)]

c=float('inf')
p=0
for i in range(2**(n+1)):
    al=[0]*m
    cost=0
    for j in range(n):
        if (i>>j)&1:
            for k in range(1,m+1):
                al[k-1]+=lis[j][k]
            cost+=lis[j][0]
    if min(al)>=x:
        c=min(c,cost)
        p=1
print(c) if p==1 else print(-1)


Measured memory_bytes: 74368
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<float> A(N);
    rep(i, N) cin >> A[i];

    float sum = 0;
    rep(i, N) {
        sum += 1.0 / A[i];
    }

    cout << 1.0 / sum << endl;

    return 0;
}

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

int main() {
  int n,k;cin>>n>>k;
  int p[n];
  for (int i=0; i<n; i++) cin >> p[i];
  sort(p, p+n);
  int ans = 0;
  for (int i=0; i<k; i++) ans += p[i];
  cout << ans << endl;

  return 0;
}


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

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

 typedef long long ll;
 const long long INF = 1LL << 60;



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

    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h.at(i);

    vector<long long> dp(n);
    for(int i = 0; i < n; i++) dp.at(i) = INF;
    dp.at(0) = 0;
    dp.at(1) = abs(h.at(1) - h.at(0));

    for(int i = 2; i < n; i++)
    {
        chmin(dp.at(i), (ll)(dp.at(i-1) + abs(h.at(i) - h.at(i-1))));
        chmin(dp.at(i), (ll)(dp.at(i-2) + abs(h.at(i) - h.at(i-2))));
    }

    cout << dp.at(n-1) << endl;

    return 0;
 }

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct __scanner__{ bool e; operator bool(){ return e; } } IN = { false };
inline __scanner__& operator>>(__scanner__& in,int &n)
{ in.e = scanf("%d",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,ll &n)
{ in.e = scanf("%lld",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,double &n)
{ in.e = scanf("%lf",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,char &n)
{ in.e = scanf(" %c",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,string &n) // BUFFER SIZE!
{ static char buf[1000000]; in.e = scanf(" %s",buf)==1; n = buf; return in; } 

int main(){
  int n, m, k;
  while (cin >> n >> m >> k) {
    bool ok = false;
    REP(i,n+1) REP(j,m+1) {
      ok = ok || (i * m + j * n - i * j * 2) == k;
    }
    cout << (ok ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <math.h>
#include <stdio.h>
#define eps 1e-9

using namespace std;

int n;
double x[55], y[55];
double distPP(double x, double y, double x2, double y2)
{
	return sqrt((x-x2)*(x-x2) + (y-y2)*(y-y2));
}

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	
	if(n % 2){
		cout << "NA" << endl;
		return 0;
	}
	
	double mx = (x[0]+x[n/2])/2, my = (y[0]+y[n/2])/2;
	for(int i = 0; i < n; i++){
		if(distPP(mx, my, (x[i]+x[(n/2+i)%n])/2, (y[i]+y[(n/2+i)%n])/2) > eps){
			cout << "NA" << endl;
			return 0;
		}
	}
	printf("%.11f %.11f\n", mx, my);
	
	return 0;
}


Measured memory_bytes: 3280
(declaim (optimize (speed 3) (debug 0) (safety 0)))
(format t "~A~%"
    (max (let ((n (read))
               (s (string (read)))
               (x 0))
           (loop for c across s
                 do (setq x (if (char= c #\I) (1+ x) (1- x)))
                 maximize x))
         0))

Measured memory_bytes: 12520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int func(int a, int b, int c){
  if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1) return 0;
  if(a == b && b == c) return -1;
  int cnt = 0;
  while(true){
    if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1) break;
    int aa = b / 2 + c / 2;
    int bb = a / 2 + c / 2;
    int cc = a / 2 + b / 2;
    a = aa, b = bb, c = cc;
    cnt++;
  }
  return cnt;
}


int main(){
  int a,b,c; cin >> a >> b >> c;
  int ans = func(a,b,c);
  cout << ans << endl;
  return 0;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

ll X, Y, A, B, C;
ll p[100010], q[100010], r[100010];

signed main(){
    cin >> X >> Y >> A >> B >> C;
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];
    sort(p, p + A, greater<ll>());
    sort(q, q + B, greater<ll>());
    sort(r, r + C, greater<ll>());
    ll ans = accumulate(p, p + X, 0LL) + accumulate(q, q + Y, 0LL);
    ll i = X - 1, j = Y - 1, k = 0 ;
    while(k < C && min(p[i], q[j]) < r[k]){
        if(p[i] < q[j]){
            ans += r[k] - p[i];
            p[i] = r[k];
            i = max(0LL, i - 1); k++;
        }else{
            ans += r[k] - q[j];
            q[j] = r[k];
            j = max(0LL, j - 1); k++;
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 2560
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, A = MAP()
x = LIST()

big = []
small = []
cnt = 0

for y in x:
	if y == A:
		cnt += 1
	elif y < A:
		small.append(A-y)
	else:
		big.append(y-A)

big_possible = [0]*2501
small_possible = [0]*2501
big_possible[0] = 1
small_possible[0] = 1

for a in big:
	for i in range(2500-a, -1, -1):
		if big_possible[i]:
			big_possible[i+a] += big_possible[i]

for b in small:
	for i in range(2500-b, -1, -1):
		if small_possible[i]:
			small_possible[i+b] += small_possible[i]

ans = 1
for i in range(1, 2501):
	ans += small_possible[i]*big_possible[i]


ans *= 2**cnt
print(ans-1)


Measured memory_bytes: 10036
#include<bits/stdc++.h>
using namespace std;
const long long int inf=1LL<<60;
int solve(int h,int n,int wt[],int val[])
{
    vector<long long int>dp(h+2,inf);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<h;j++)
        {
            int k=j+wt[i];
            if(k>h)k=h+1;
            dp[k]=min(dp[k],dp[j]+val[i]);
        }
    }
    return min(dp[h],dp[h+1]);
}
int main()
{
	int h,n;
    cin>>h>>n;
    int wt[n],val[n];
    for(int i=0;i<n;i++)
        cin>>wt[i]>>val[i];
    cout<<solve(h,n,wt,val)<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b, c, x;
	string s;
	cin >> a >> b;
	s = to_string(a) + to_string(b);
	c = stoi(s);
	x = sqrt(c);
	if (x * x == c) cout << "Yes\n";
	else cout << "No\n";


	return 0;
}


Measured memory_bytes: 256
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll M = 300 + 10;
const ll N = 40 * 10 + 10;

ll a[N] , dp[N][N], prefix[N];

int main()	
{
	faster();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		prefix[i + 1] = prefix[i] + a[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if(i == j)
				dp[i][j] = 0;
			else
				dp[i][j] = inf;
		}
	}
	for (int len = 2; len <= n; len++)
	{
		for (int i = 0; i <= n - len; i++)
		{
			int j = i + len - 1;
			for (int k = i; k < j; k++)
			{
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + prefix[j + 1] - prefix[i]);
			}
		}
	}
	cout << dp[0][n - 1] << endl;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, m, tmp, inf = 1e9;
    cin >> n >> m;
    n = pow(2, n);

    vll a(m, 0), b(m, 0), c(m, 0);
    REP(i,m){
        cin >> a[i] >> b[i];
        REP(j, b[i]){
            cin >> tmp;
            c[i] += pow(2, tmp-1);
        }
    }

    vll dp(n, inf);

    REP(i,m){
        REP(j,n){
            if(c[i] == j){
                if(a[i] < dp[j]) dp[j] = a[i];
            }
            if(dp[c[i]|j] > a[i]+dp[j]){
                dp[c[i]|j] = a[i]+dp[j];
            }
        }
    }

    if(dp[n-1]==inf) cout << -1 << endl;
    else cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  int cnt=0,row[H],col[W];
  char c[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>c[i][j];
      row[i]=0;
      col[j]=0;
    }
  }
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(c[i][j]=='.') cnt++;
    }
    if(cnt==W) row[i]=1;
    cnt=0;
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(c[i][j]=='.') cnt++;
    }
    if(cnt==H) col[j]=1;
    cnt=0;
  }
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(row[i]==1||col[j]==1) continue;
      else cout<<c[i][j];
    }
    if(row[i]==0)cout<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
typedef long long ll;
inline int rd(){
    int x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
const int N=200002;
int n;
int a[N];
std::map<ll,int> m;
ll ans;
int main(){
	n=rd();
	for(int i=1;i<=n;i++)a[i]=rd();
	for(int i=n;i>=1;i--){
		if(a[i]>=n)continue;
		ans+=m[i+a[i]];
		m[i-a[i]]++;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 20884
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
f = b-a
g = c-a
h = d-a
i = e-a
j = c-b
l = d-b
m = e-b
n = d-c
o = e-c
p = e-d
if f<=k and g<=k and h<=k and i<=k and j<=k and l<=k and m<=k and n<=k and o<=k and p<=k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064