akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N,x; cin>>N>>x;
  ll a[N]; CINA(a,N);
  ll r = 0;
  REP(i,N-1){
    ll dif = a[i] + a[i+1] - x;
    if(dif>0){
      if(a[i+1]>dif){
        a[i+1] -= dif;
      }else{
        a[i] -= (dif-a[i+1]);
        a[i+1] = 0;
      }
      r += dif;
    }
  }
  //REP(i,N){cout<<a[i]<<"\n";}
  cout << r;
}

Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    int x = 0, y = 0, t = 0;
    for (int i = 0; i < n; i++)
    {
        int d;
        scanf("%d", &d);
        int a, b;
        scanf("%d%d", &a, &b);
        int dist = abs(a - x) + abs(b - y);
        if (dist > d - t || dist % 2 != (d - t) % 2)
        {
            puts("No");
            return 0;
        }
        t = d;
        x = a, y = b;
    }
    puts("Yes");
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int[] cus = new int[N];
        for (int i = 0; i < N; i++) {
            cus[i] = sc.nextInt();
        }
        Arrays.sort(cus);
        int ride = 0;
        int count = 0;
        int border = 0;
        boolean isFirst = true;
        for (int i = 0; i < cus.length; i++) {
            ride++;
            int c = cus[i];
            if (isFirst) {
                border = c;
                isFirst = false;
            } 
            if (i == cus.length-1) {
                count++;
                break;
            }
            if (ride == C) {
                count++;
                ride = 0;
                isFirst = true;
                continue;
            }
            if (K < cus[i+1]-border) {
                count++;
                ride = 0;
                isFirst = true;
            }
        }
        System.out.println(count);
    }    
}


Measured memory_bytes: 59360
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code
	int n;
	cin  >> n;
	int b = n*n, c = b*n;
	cout << c+b+n; 
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;

int main ()
{
    string y,m,d;
    while (cin >> y >> m >> d) {
        string str;
        int i = 0;
        while (4 - y.size() > i++) str += '0'; str += y; i=0;
        while (2 - m.size() > i++) str += '0'; str += m; i=0;
        while (2 - d.size() > i++) str += '0'; str += d; i=0;
        if (str < "18680908") cout << "pre-meiji" << endl;
        else if (str < "19120730") cout << "meiji " << atoi(y.c_str()) - 1867 << " " << m << " " << d << endl;
        else if (str < "19261225") cout << "taisho " << atoi(y.c_str()) - 1911 << " " << m << " " << d << endl ;
        else if (str < "19890108") cout << "showa " << atoi(y.c_str()) - 1925 << " " << m << " " << d << endl;
        else cout << "heisei " << atoi(y.c_str()) - 1988 << " " << m << " " << d << endl;
    }

    return 0;
}

Measured memory_bytes: 1204
//b.c B-Can you solve this?
#include<stdio.h>
#include<stdbool.h>

typedef struct{
    int a[21];
    bool flag;
    int ans;
}com;

int main(void){
    int n,m,c;
    scanf("%d %d %d",&n,&m,&c);
    int b[m];
    for(int i=0;i<m;++i){
        scanf("%d",&b[i]);
    }

    com buf[n];
    for(int i=0;i<n;++i){
        buf[i].ans = 0;
        for(int j=0;j<m;++j){
            scanf("%d",&buf[i].a[j]);
            buf[i].ans += buf[i].a[j] * b[j];
        }
        buf[i].ans += c;
        if(buf[i].ans>0){
            buf[i].flag = true;
        }else{
            buf[i].flag = false;
        }
    }

    int num = 0;
    for(int i=0;i<n;++i){
        if(buf[i].flag==true){
            num++;
        }
    }

    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }

void _main() {
  int Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;

  int min_s = min({Q*4, H*2, S});
  ll ans = 1ll * min_s * N;
  if (N%2 == 0) {
    chmin(ans, 1ll * D*N/2);
  } else {
    chmin(ans, 1ll * D*(N/2) + min_s);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  cout<<'A'<<s2[0]<<'C'<<endl;
  
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli k,sum=0,cnt;
    string s,t;
    lli i,j=0;
    cin>>t>>k;
    s=t;
    cnt=0;
    rep(i,1,s.size()){
        if(s[i-1]==s[i]){
            s[i]='0';
            cnt++;
        }
    }
    if(s[0]!=s[s.size()-1]){
        sum=cnt*k;
    }
    else{
        s=t;
        sum=cnt;
        cnt=1;
        s[0]='1';
        rep(i,1,s.size()){
            if(s[i-1]==s[i]){
                s[i]='0';
                cnt++;
            }
        }
        if(t[0]==s[s.size()-1]){
            sum+=cnt*(k-1);
        }
        else{
            lli bef=sum;
            sum+=cnt;
            sum=sum*(k/2);
            if(k%2==1){
                sum+=bef;
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,k;
    int num,cnt =0;

    cin >> a >> b >> k;
    
    for(int i = min(a,b);i >= 1;i--)
    {
        if(a%i == 0 && b%i == 0)
        {
            --k;
            if(k == 0)
            {
                cout << i<< endl;
            }
        }
    }
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, k) = input!(usize, usize);
    let (s,) = input!(String);
    
    let mut divided: Vec<u64> = vec![];

    let mut continued = 0;

    let mut current_div = '2';

    {
        if s.chars().next().unwrap() == '0' {
            divided.push(0);
        }
    }

    for c in s.chars() {
        if c == current_div {
            continued += 1;
        } else {
            if continued != 0 {
                divided.push(continued);
            }
            continued = 1;
            current_div = c;
        }
    }

    divided.push(continued);

    if current_div == '0' {
        divided.push(0);
    }

    let first_right = std::cmp::min(divided.len(), 2 * k + 1);
    
    let mut current_total: u64 = divided[0..first_right].iter().sum();
    let mut max = current_total;
    // println!("{}", current_total);
    // println!("   {}", divided.len() - (2 * k + 1));

    if divided.len() > 2 * k {
        for i in 2..(divided.len() - 2 * k) {
            if i % 2 == 1 {
                continue;
            }
            let left = i;
            let right = left + 2 * k;

            max = std::cmp::max(max, current_total);
            current_total = current_total + divided[right] + divided[right - 1] - divided[left - 1] - divided[left - 2];
            // println!("{} {} : {}", left, right, current_total);
        }
    }
    
    max = std::cmp::max(max, current_total);

    println!("{}", max);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <climits>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const int mod = 1000000007;

ll dp[100100];

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    rep(i, n-1) {
        //cout << "i: " << i << " dp[i]: " << dp[i] << endl;
        dp[i+1] = LLONG_MAX;
        rep(j, k) {
            if (i-j >= 0) dp[i+1] = min(dp[i+1], dp[i-j] + abs(h[i+1]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


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

string a;

int main(){
	cin >> a;
	int sum0=0;
	int sum1=0;
	for(int i=0; i<a.length(); ++i){
		if(a[i] == '0'){
			++sum0;
		}else{
			++sum1;
		}
	}
	if(sum0 < sum1){
		cout << 2*sum0;
	}else{
		cout << 2*sum1;
	}
	
	return 0;
	
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
  int i, j;
  int n;
  int a[200000], b[200000] = {0};
  
  scanf("%d", &n);
  for(i = 1; i < n; i++){
    scanf("%d", &a[i]);
    b[a[i] - 1]++;
  }
  for(i = 0; i < n; i++){
    printf("%d\n", b[i]);
  }
  
  return 0;
}

Measured memory_bytes: 3292
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int k = Integer.parseInt(in[1]);

        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < k; i++) {
            int d = Integer.parseInt(br.readLine());
            in = br.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                set.add(Integer.parseInt(in[j]));
            }
        }

        br.close();

        bw.write(String.valueOf(n - set.size()));

        bw.flush();

    }
}

Measured memory_bytes: 33756
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto&& V : v)
#define all(x) (x).begin(), (x).end()
using lint = long long;
const int INF = 1 << 29;
const double EPS = 1e-9;
using namespace std;

int main(void) {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int maxi = max({a, b, c});
  int left = a + b + c - maxi;
  rep(i, k) {
    maxi *= 2;
  }
  cout << left + maxi << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/


void sw(ll *a, ll *b){
    if(*a%2){
        int tmp = *a;
        *a = *b;
        *b = tmp;
    }
}

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

    ll H, W;
    cin >> H >> W;

    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }

    if(!(H%2&&W%2)){
        sw(&H, &W);
        cout << (H/2) * W << endl;
    }else{
        cout << H * (W - 1) / 2 + (H + 1) / 2 << endl;
        
    }
}

Measured memory_bytes: 256
using System;

namespace ConsoleApplicationSample
{
    class Program
    {
        static void Main(string[] args)
        {
            //[0,]1棟 [, 0]~[, 9]1階
            //[1,]2棟 [,10]~[,19]2階
            //[2,]3棟 [,20]~[,29]3階
            //[3,]4棟 
            int[,] room = new int[4, 30];
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                int b, f, r, v;
                string[] str = Console.ReadLine().Split(' ');
                b = int.Parse(str[0]);
                f = int.Parse(str[1]);
                r = int.Parse(str[2]);
                v = int.Parse(str[3]);
                room[b-1,(f-1)*10 + r-1] += v;
            }

            Output(room);
        }

        private static void Output(int[,] room)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 30; j++)
                {
                    Console.Write(" {0}", room[i, j]);
                    if (j % 10 == 9)
                    {
                        Console.Write("\n");
                    }
                }
                if (3 != i)
                {
                    Console.WriteLine("####################");
                }
            }
        }

    }

}

Measured memory_bytes: 19984
#pragma comment(linker, "/stack:200000000")
 #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > s;
void find(vector<int>a,int k)
{
    for(int i=0;i<10;i++)
    {
        vector<int>temp=a;
        temp.push_back(i);
        if(k<4)
            find(temp,k+1);
        else
        {
            s.push_back(a);
            break;
        }    
    }
}
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif
    

// -------------------------------------Code starts here--------------------------------------------------------------------- 

    vector<int>tt;
    find(tt,1);
    int n;
    cin>>n;
    string str;
    cin>>str;
    int cnt=0;
    for(auto i:s)
    {
        int ind=0;
        for(int j=0;j<n;j++)
        {
            if(i[ind]==str[j]-'0')
            {
                ind++;
                if(ind==3)
                break;
            }
        }
        if(ind==3)
        {
            cnt++;
        }
    }
    cout<<cnt;
// -------------------------------------Code ends here------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
     clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    double X, T; cin >> X >> T;
    cout << X / T << endstr;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		long n = Long.parseLong(scanner.nextLine());
		long a = 0;
		long b = 0;
		long ans = Long.MAX_VALUE;

		scanner.close();

		for(int i = 1; i <= Math.sqrt(n); i++) {

			if(n % i == 0) {
				a   = i;
				b   = n / i;
				ans = Math.min(ans, a + b - 2);

			}

		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            int[] counts = new int[5];
            for (int i = 0; i < N; i++) {
                counts[A[i] % 4 == 0 ? 4 : A[i] % 2 == 0 ? 2 : 1]++;
            }

            if (counts[1] <= counts[4]) {
                System.out.println("Yes");
                return;
            }
            if (counts[1] >= counts[4] + 2) {
                System.out.println("No");
                return;
            }
            System.out.println(counts[2] == 0 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 49344
h, w = map(int, input().split())
retu = [0 for i in range(w)]
gyou = [0 for i in range(h)]
lst = []
for i in range(h):
    ai = input()
    kuro = 0
    for j in range(w):
        if ai[j] == '#':
            kuro = 1
            retu[j] = 1
    if kuro == 1:
        gyou[i] = 1
    lst.append(ai)

ans = []
for i in range(h):
    if gyou[i] == 0: continue
    temp = ''
    for j in range(w):
        if retu[j] == 1:
            temp += lst[i][j]
    ans.append(temp)

for temp in ans:
    print(temp)

Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,A,x=0;cin>>N;
  vector<long long int>S(N+1);
  cin>>S.at(0);
  for(int i=1;i<N;i++){
    cin>>A;S.at(i)=S.at(i-1)+A;
  }
  N++;S.at(N-1)=0;
  sort(S.begin(),S.end());
  long long int j=-1;
  for(int i=0;i<N;i++){
    if(i==N-1||S.at(i+1)!=S.at(i)){
      long long int n=i-j;
      x+=n*(n-1)/2;
      j=i;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner
var out *bufio.Writer

func main() {
	sc = bufio.NewScanner(os.Stdin)
	//bytes, _ := ioutil.ReadFile("./stdin.txt")
	//sc = bufio.NewScanner(strings.NewReader(string(bytes)))
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1<<20)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()

	dic := []string{}
	f(&dic, 0, n, make([]byte, n), 'a', 'a', map[string]bool{})
	sort.Sort(sort.StringSlice(dic))

	for _, str := range dic {
		fmt.Fprintln(out, str)
	}
}

func f(list *[]string, i, n int, s []byte, c, mc byte, v map[string]bool) {
	s[i] = c
	if i == n-1 {
		str := string(append([]byte{}, s...))
		if _, ok := v[str]; !ok {
			*list = append(*list, str)
			v[str] = true
		}
		return
	}
	if c > mc {
		mc = c
	}

	for j := i + 1; j < n; j++ {
		for k := byte('a'); k <= mc+1; k++ {
			f(list, j, n, s, k, mc, v)
		}
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func intMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 21252
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

int aa[2];

void solve(){
	li a=aa[0],b=aa[1];
	if(a<b)swap(a,b);
	while(a%b!=0){
		int tmp=a%b;
		a=b;
		b=tmp;
	}
	cout<<b<<" "<<aa[0]*(aa[1]/b)<<endl;
}

int main(){
	while(cin>>aa[0]){
		cin>>aa[1];
		solve();
	}
	
	return 0;
}

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

typedef long long ll;

int main() {
    ll n, k; cin >> n >> k;

    if(n < k) {
        cout << 1ll * min((n % k), abs((n%k) - k));
    }else{
        if(n%k == 0) {
            cout << 0;
        }else{
            cout << 1ll*abs((n % k) - k);
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N,n=0;

    scanf("%d",&N);

    if(N==100000){
        n=90909;
    }else if(N>=10000){
        n=N-9999+909;
    }else if(N>=1000){
        n=909;
    }else if(N>=100){
        n=N-99+9;
    }else if(N>=10){
        n=9;
    }else{
        n=N;
    }

    printf("%d\n",n);
}

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

int main(){
    int n;
    cin >> n;
    deque<int> dq;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        if((i&1)==0)dq.push_back(a);
        else dq.push_front(a);
    }
    for(int i=0;i<n;++i){
        if((n&1) != 0){
            cout << dq.back(); dq.pop_back();
        }else{
            cout << dq.front(); dq.pop_front();
        }
        if(i == n-1)cout << endl;
        else cout << " ";
    }

    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(k);
  for(int i = 0; i < n; i++){
    a[(i + 1) % k]++;
  }
  ll ans = 0;
  for(int i = 0; i < k; i++) {
    if(i * 2 % k == 0){
      ans += pow(a[i], 3);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a;
    cin >> a;
    string ans;
    while (a > 0) {
        a--;
        ans.push_back((char)(a % 26 + 'a'));
        a /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x,y;
    cin>>x>>y;
    if(y>=2*x && y<=4*x && (y&1)==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

int main()
{
    int k;
    string s;

    cin >> k >> s;

    if (s.length() > k)
    {
        for (int i = 0; i < k; i++)
        {
            cout << s.at(i);
        }
        cout << "..." << endl;
    }
    else
    {
        for (int i = 0; i < s.length(); i++)
        {
            cout << s.at(i);
        }
        cout << endl;
    }
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for(int i = 0; i < n - 1; i++){
    int tmp;
    cin >> tmp;
    a[tmp - 1]++;
  }
  for(int i = 0; i < n; i++){
    cout << a[i] << '\n';
  }
    return 0;
}

Measured memory_bytes: 4048
def parse_node(l, r, S):
    left, right = 0, 0
    cnt = 0
    for i in range(l, r + 1):
        if S[i] == '(':
            cnt += 1
        elif S[i] == ')':
            cnt -= 1
        elif cnt == 0 and S[i] == "[":
            left = i
        elif cnt == 0 and S[i] == "]":
            right = i
    return left, right


def parser(l1, r1, l2, r2):
    n1_l, n1_r = parse_node(l1, r1, S1)
    n2_l, n2_r = parse_node(l2, r2, S2)
    # print(n1_l, n1_r, n2_l, n2_r)
    node = "[{}]".format(int(S1[n1_l + 1:n1_r]) + int(S2[n2_l + 1:n2_r]))
    left_node = "({})".format("" if min(n1_l - l1, n2_l - l2) <= 2 else parser(l1 + 1, n1_l - 2, l2 + 1, n2_l - 2))
    right_node = "({})".format("" if min(r1 - n1_r, r2 - n2_r) <= 2 else parser(n1_r + 2, r1 - 1, n2_r + 2, r2 - 1))
    return left_node + node + right_node



S1, S2 = input(), input()
print(parser(0, len(S1) - 1, 0, len(S2) - 1))

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100050

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//


//
int main(){
	int N,M;cin>>N>>M;
	V DP(N+1,0);
	REP(i,M){
		int a;cin>>a;
		DP[a] = -1;
	}


	DP[0] = 1;
	DP[1] = (DP[1]!=-1?1:-1);
	REPS(i,2,N+1){
		if(DP[i] == -1)continue;
		DP[i] = ((ll)(DP[i-1]>=0?DP[i-1]:0) + (DP[i-2]>=0?DP[i-2]:0) ) % MOD;
	}

	cout << DP[N] << endl;

	return 0;
}




Measured memory_bytes: 640
//さすが解説は天才的ですねー
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

const int IMAX = 10000001;
int ifac[IMAX + 1];

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


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

	ll facN = 1;
	rep1(i, N) facN = facN * i % mod;
	ifac[N] = modpow(facN, mod - 2);
	for (int i = N; i > 0; i--) ifac[i - 1] = (ll)ifac[i] * i % mod;

	ll kotae = modpow(3, N);

	ll hiku = 0;
	int k = 1;
	rep(i, N / 2) {
		hiku += (ll)ifac[i] * ifac[N - i] % mod * k % mod;
		k = k * 2 % mod;
	}
	hiku = hiku % mod * facN * 2 % mod;
	printf("%lld", (kotae - hiku + mod) % mod);

	Would you please return 0;
}

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

int N,M,Q,m=0;
vector<int> A(10,1),a(50),b(50),c(50),d(50);


void dfs(int n,int k){
  A.at(n)=k;
  if(n==N-1){
    int x=0;
    for(int i=0;i<Q;i++){
      if(A.at(b.at(i)-1)-A.at(a.at(i)-1)==c.at(i)){
        x+=d.at(i);
      }
    }
    m=max(x,m);
    return;
  }
  for(int i=k;i<=M;i++){
    dfs(n+1,i);
  }
  return;
}
    


int main(){
  
  cin >> N >> M >> Q;
  for(int i=0;i<Q;i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }
  dfs(0,1);
  cout << m << endl;
  
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define UNIQUE(v) do{ (v).erase( unique(begin(v), end(v)), end(v) ); } while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	ios_base::sync_with_stdio(false);
	int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
	A--; B--; C--; D--;
	string S; cin >> S;
	S += "#####";
	bool canswap = false;
	repr(i, B, D) {
		if (S[i] == '#' && S[i + 1] == '#') goto NO;
		if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') canswap = true;
	}

	if (!canswap && D < C) goto NO;

	repr(i, A, C - 1) {
		if (S[i] == '#' && S[i + 1] == '#') goto NO;
	}

	cout << "Yes" << endl;
	return 0;

	NO:
	cout << "No" << endl;
	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n, m, q;
    cin>>n>>m>>q;
    if(n == 0) break;
    vector<bitset<36>> s(q+1);
    vector<bitset<1000>> b(q+1);
    s[0] = bitset<36>(0);
    b[0] = bitset<1000>(0);
    for(int i=1;i<=q;++i) {
      string tmps, tmpq;
      cin >> tmps >> tmpq;
      reverse(ALL(tmps));
      reverse(ALL(tmpq));
      s[i] = bitset<36>(tmps);
      b[i] = bitset<1000>(tmpq);
    }

    vector<pair<bitset<36>, bitset<1000>>> a(q+2);
    for(int i=0;i<q;++i) {
      a[i] = make_pair(s[i+1], b[i] ^ b[i+1]);
    }
    a[q] = make_pair(bitset<36>(0), bitset<1000>(0));
    string tmps = "", tmpq = "";
    for(int i=0;i<n;++i) {
      tmps += '1';
    }
    for(int i=0;i<m;++i) {
      tmpq += '1';
    }
    a[q+1] = make_pair(bitset<36>(tmps), bitset<1000>(tmpq));


    vector<bitset<1000>> cor(n, ~bitset<1000>(0));
    for(int i=0;i<n;++i) {
      for(int j=0;j<q+2;++j) {
        if(a[j].first[i]) {
          cor[i] &= a[j].second;
        } else {
          cor[i] &= ~a[j].second;
        }
      }
    }

    vector<char> pos(m, '*');

    for(int i=0;i<m;++i) {
      for(int j=0;j<n;++j) {
        if(cor[j][i] == 1 && pos[i] == '*') {
          pos[i] = (0 <= j && j <= 9) ? j + '0' : j - 10 + 'A';
        } else if(cor[j][i] == 1) {
          pos[i] = '?';
        }
      }
    }

    for(int i=0;i<m;++i) {
      cout << pos[i];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3156
import numpy as np

N=int(input())
c=np.array(list(input()))
n=np.count_nonzero(c == 'R')
i=0
j=N-1
cnt=0
if N==n:
    print(cnt)
    exit(0)
while 1:
    while c[i]!='W' and i<n:
        i+=1
    while c[j]!='R' and j>n-1:
        j-=1
    if i>=n or j<n:
        print(cnt)
        exit(0)
    temp=c[i]
    c[i]=c[j]
    c[j]=temp
    cnt+=1

print(cnt)

Measured memory_bytes: 29072
/**
 * author: Behradm
 * Created: 2020.08.29 13:50:28
 * In The Name of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, t, s;
  cin >> d >> t >> s;
  double q = d / (double) s;
  if (q <= t)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 3648
/*
 * “The difference between a master and a novice - is that the master has failed
 * more times, than the novice has tried.”
 */
#include <bits/stdc++.h>
#define pvar(x) clog << "[" << #x << ":" << x << "]\n"
using namespace std;
using ll = long long int;
using tiii = tuple<int,int,int>;
const int inf = 1e6 + 1;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int main() {
  int h,w,ix, iy, dtx, dty;
  cin >> h >> w >> ix >> iy >> dtx >> dty;
  char v[h+1][w+1];
  int dist[h+1][w+1];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      scanf(" %c",&v[i][j]);
      dist[i][j] = inf;
    }
  }
  set<tiii> q;
  dist[ix][iy] = 0;
  q.insert({dist[ix][iy],ix,iy});
  while (!q.empty()) {
    int d, cx, cy;
    auto it = q.begin();
    tie(d,cx,cy) = (*it);
    q.erase(it);
    for (int i = 0; i < 4; i++) {
      int x = cx + dx[i], y = cy + dy[i];
      if (x <= 0 || x > h || y <= 0 || y > w || v[x][y] == '#') continue;
      if (dist[x][y] > d) {//Relax edge
        dist[x][y] = d;
        q.insert({dist[x][y],x,y});
      }
    }
		
    for (int p = cx-2; p <= cx+2; p++) {
      for (int l = cy-2; l <= cy+2; l++) {
        if (p <= 0 || p > h || l <= 0 || l > w || v[p][l] == '#') continue;
        if (dist[p][l] > d + 1) {
          dist[p][l] = d + 1;
          q.insert({dist[p][l],p,l});
        }
      }
    }
  }
  if (dist[dtx][dty] == inf)
    printf("-1\n");
  else
    printf("%d\n",dist[dtx][dty]);
}


Measured memory_bytes: 9264
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<pr, ut> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=7+1e+9;
 
int main() {
	int K, T;
	int a[128];
	pr cakes[128];
	cin >> K >> T;
	REP(i,T){
		cin >> a[i];
		cakes[i] = pr(a[i], i);
	}
	if(T == 1){
		cout << cakes[0].F - 1 << endl;
		return 0;
	}
	sort(cakes, cakes + T, greater<pr>());
	int prev = -1, ans = 0;
	REP(i,K){
		if(prev == cakes[0].S){
			if(cakes[1].F == 0){
				ans = cakes[0].F;
				break;
			}
			else{
				cakes[1].F -= 1;
				prev = cakes[1].S;
			}
		}
		else{
			cakes[0].F -= 1;
			prev = cakes[0].S;
		}
		sort(cakes, cakes + T, greater<pr>());
	}
	cout << ans << endl;
    return 0;	
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll c = 1;
    while(c*(c+1)/2 < N) ++c;
    REP(i,1,c+1) {
        if(i == c*(c+1)/2 - N) continue;
        PR(i);
    }

    return 0;
}

/*



*/

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

int main(){
  int n,m;
  cin>>n>>m;
  char grid[50][50];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>grid[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(grid[i][j]=='#'){
        if(grid[i][j+1]!='#'&&grid[i][j-1]!='#'&&grid[i+1][j]!='#'&&grid[i-1][j]!='#'){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
n = int(input())
data = {}
for i in range(n):
    b, f, r, v = map(int, input().split())
    if (b,f,r) in data:
        data[(b,f,r)] = data[(b,f,r)] + v
    else:
        data[(b,f,r)] = v
for b in range(1,5):
    for f in range(1,4):
        for r in range(1,11):
            if (b,f,r) in data:
               print(" "+str(data[(b,f,r)]),end="")
            else:
                print(" 0",end="")
        print("")
    if b < 4:
        print("#"*20)


Measured memory_bytes: 5628
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i = 0; i< n; i++){
        scanf("%d",&a[i]);
    }
    int min = a[0];
    int max = a[0];
    for(int i = 1; i < n; i++){
        if(a[i] < min){
            min = a[i];
        }
        if(a[i] > max){
            max = a[i];
        }
    }
    printf("%d\n",max - min);

    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
bool debug;
#define all(x) (x).begin(), (x).end()
#define ll long long

#define db(x) if(debug)cout << " " << (x) <<" "
#define dbn(x) if(debug)cout << "\n" << (#x) << " is " << (x) << endl
#define endl "\n"
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
// fill(all(vec), 1);
//vec.resize(unique(all(vec))-vec.begin())
const int N = 3e6;
std::vector<ll> e[N], ans(N);
queue<ll> vb,vw;


void dfs1(ll v, ll p, ll c)
{
	if(c)
		vb.push(v);
	else
		vw.push(v);
    for(auto i : e[v])
        if(i != p)
            dfs1(i, v, c ^ 1);

}

void solve()
{
    ll n, x, y, z, i;
    cin >> n;
    rep(i, n - 1)
    {
        cin >> x >> y;
        e[x].pb(y);
        e[y].pb(x);
    }
    dfs1(1, -1, 0);
    if(vb.size()<vw.size()) swap(vb,vw);
	for(int i=1;i<=n;i++)
	{
		if(i%3==1)
		{
			int v=vb.front();vb.pop();
			ans[v]=i;
		}
	}
	if(vb.size()<vw.size()) swap(vb,vw);
	for(int i=1;i<=n;i++)
	{
		if(i%3==2)
		{
			int v=vb.front();vb.pop();
			ans[v]=i;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(i%3==0)
		{
			int v;
			if(!vb.empty()) {v=vb.front();vb.pop();}
			else {v=vw.front();vw.pop();}
			ans[v]=i;
		}
	}
    rep1(i,n)
    cout<<ans[i]<<" ";

}



int main()
{
 

    if(debug)
    {
#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
#endif
    }

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;


    while(t--)
    {
        solve();
        // cout << endl;
    }


}

Measured memory_bytes: 110592