akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define EPS 1e-7

int main(){
  ll h,w;
  cin>>h>>w;
  char s[51][51];
  rep(i,h){
    rep(j,w){
      cin>>s[i][j];
    }
  }

  vector<pair<int,int>> P;

  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#'){
      if(!((i-1>=0&&s[i-1][j]=='#') || (i+1<h&&s[i+1][j]=='#') || (j-1>=0&&s[i][j-1]=='#') || (j+1<w&&s[i][j+1]=='#'))){
        cout<<"No"<<endl;
        pair<int,int> p = make_pair(i,j);
        P.push_back(p);
        return 0;
      }
      }
    }
  }

  rep(i,P.size()){
    /* cout<<P[i].first<<","<<P[i].second<<endl; */
  }
  cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
	int n=0;
	int data[100000]={};
	int now=0;
	int res=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> data[i];
	}
	while(true){
		int temp=data[now]-1;
		data[now]=-1;
		now=temp;
		res++;
		//cout << "res=" << res << "now=" << now << endl;
		if(now==1){
			break;
		}else if(now==-1){
			res=-1;
			break;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();

		System.out.println(Math.min(p+q,Math.min(p+r, q+r)));
	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22996
#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<int,int> 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;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n,m,ans(0);
    cin >> n >> m;
    /*int a[n+2][m+2];
    memset(a,0,sizeof(a));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            for(int k = -1; k <= 1; k++)
            {
                for(int l = -1; l <= 1; l++)
                {
                    a[i+k][j+l]^=1;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cout << a[i][j];
            if(a[i][j]==1)ans++;
        }
        cout << endl;
    }*/
    if(n>1)ans = n-2;
    else ans = 1;
    if(m>1)ans*=(m-2);
    else ans*=1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector> 
using namespace std;
int main() {
  int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        int sum = c;
        for (int j = 0; j < m; j++) {
            int a_j;
            cin >> a_j;
            sum += a_j * b[j];
        }
        if (sum > 0) {
            count++;
        }
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 256
import sys 
s = sys.stdin.readline().strip()
c_find = False                                                                                                                                                                                                                        
f_find = False
for c in s:
    if c_find:
        if c == 'F':
            print 'Yes'
            exit(0)
    else:
        if c == 'C':
            c_find = True
print 'No'

Measured memory_bytes: 2568
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

class rep {
	const usize f, l;

public:
	class itr {
		friend rep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	rep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
class revrep {
	const usize f, l;

public:
	class itr {
		friend revrep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	revrep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<usize> a(100000, 0), b(100000, 0);
	for (const auto i : rep(0, n / 2)) {
		u32 x, y;
		::std::cin >> x >> y;
		++a[x - 1];
		++b[y - 1];
	}
	usize am = ::std::max_element(a.begin(), a.end()) - a.begin();
	usize bm = ::std::max_element(b.begin(), b.end()) - b.begin();
	if (am != bm) {
		::std::cout << n - a[am] - b[bm] << ::std::endl;
	}
	else {
		const usize a0 = a[am];
		const usize b0 = b[bm];
		a[am] = 0;
		b[bm] = 0;
		am = ::std::max_element(a.begin(), a.end()) - a.begin();
		bm = ::std::max_element(b.begin(), b.end()) - b.begin();
		const usize a1 = a[am];
		const usize b1 = b[bm];
		::std::cout << n - ::std::max(a0 + b1, a1 + b0) << ::std::endl;
	}
	return 0;
}


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

int main(){
    int k,n;
    cin >> k >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int b = k-(a[n-1]-a[0]);
    for(int i=0; i<n-1; i++){
        b = max(b,a[i+1]-a[i]);
    }
    cout << k-b << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力受け取り, 入次数も管理する
int n,k;
    cin >> n >>k;
int resu=0;
for(int i=0;i<n;i++){
int te;
cin >> te;
if(te>=k)resu++;
}



cout << resu;




   
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val a = readLine()?.toInt() ?: return
    val b = readLine()?.toInt() ?: return
    val c = readLine()?.toInt() ?: return
    val d = readLine()?.toInt() ?: return
    val e = readLine()?.toInt() ?: return

    val wait = listOf(a, b, c, d, e).sortedBy {
        -((it % 10 - 10) % 10)
    }.reduce { acc, i ->
        acc - ((acc % 10 - 10) % 10) + i
    }

    println(wait.toString())
}

Measured memory_bytes: 35904
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    string s;
    cin >> s;
    int num = s.length() - 2;

    cout << s[0] << num << s[s.size() - 1] << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> t(N), x(N), y(N);
    for (int i = 0; i < N; i++) cin >> t[i] >> x[i] >> y[i];

    int pret = 0, prex = 0, prey = 0;
    bool ans = true;
    for (int i = 0; i < N; i++) {
        int dt = t[i] - pret;
        int dx = abs(x[i] - prex);
        int dy = abs(y[i] - prey);
        if (dt < dx + dy || dt % 2 != (dx + dy) % 2) {
            ans = false;
            break;
        }
        pret = t[i], prex = x[i], prey = y[i];
    }

    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int cmp(const void* p, const void* q) {
	return *(int*)p - *(int*)q;
}

int lcd(int p, int q) {
	int upper, lower, r;

	if (p >= q) upper = p, lower = q;
	else upper = q, lower = p;
	r = upper % lower;
	if (r)return lcd(lower, r);
	else return lower;
}

int main(void) {
	int n, X;
	int x;
	int sa[100000];
	int ans;

	scanf("%d %d", &n, &X);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (x >= X) sa[i] = x - X;
		else sa[i] = -(x - X);
	}
	qsort(sa, n, sizeof(int), cmp);

	ans = sa[0];
	for (int i = 1; i < n ; i++) 
		ans = lcd(ans, sa[i]);
	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 892
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
h = Hash.new(0)

a.each do |num|
  h[num] += 1
end

hen = nil
h.sort_by{|k,v| -k}.each do |k,v|
  if hen.nil? && v >= 2
    hen = k
    v -= 2
  end
  if hen && v >= 2
    puts hen * k
    exit
  end
end

puts 0


Measured memory_bytes: 23928
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  //N,Lを入力
  int N,L;
  scanf("%d%d",&N,&L);

  //りんごの味を配列にする
  int i,app[N];
  for(i=0;i<N;i++)
    app[i]=L+i;

  //味の絶対値が最も小さいりんごを求め>る
  int tmp,bite=300,bitenum;
  for(i=0;i<N;i++){
    tmp = app[i];
    if(tmp<0)
      tmp = -tmp;
    if(tmp<bite){
      bite = tmp;
      bitenum = i;
    }
  }

  //パイの味を求める
  int pie=0;
  for(i=0;i<N;i++)
    pie += app[i];
  pie -= app[bitenum];

  //出力して終了
  printf("%d\n",pie);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int co(const void *a, const void *b) {
  return *(long long int *)b - *(long long int *)a;
}
int main(){
  long long int n,i,x[100010],tmp[3];
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&x[i]);
  }
  qsort(x,n,sizeof(long long int),co);
  tmp[0]=x[0];
  int l=0;
  for(i=1;i<n;i++){
    if(tmp[l]==x[i])l++;
    else tmp[l]=x[i];
    if(l==2)break;
  }
  if(l==2)printf("%lld\n",tmp[0]*tmp[1]);
  else puts("0");
  return 0;
}


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 2e5 + 2;
int n, m;
int l[N][26], r[N][26];
char s[N];
int L[26], R[26];
struct node
{
    char c, sig;
}q[N];
bool canmove(int pos)
{
    return pos > 0 && pos <= n;
}
void move(int pos, int v)
{
    for (int i = 0; i < 26; i ++){
        if (L[i] == pos)
            L[i] += v;
        if (R[i] == pos)
            R[i] += v;
    }
}
int check(int pos)
{
    for (int i = 1 ; i <= m; i ++)
        if (s[pos] == q[i].c){
            if (q[i].sig == 'L') pos -= 1;
            else
                pos += 1;
            if (pos == 0)return -1;
            if (pos > n) return 1;
        }
    return 0;
}
int main()
{
    scanf("%d %d", &n, &m);
    scanf("%s", s + 1);
    for (int i = 1; i <= n ; i++) {
        s[i] -= 'A';
        for (int j = 0; j < 26; j ++)
            l[i][j] = l[i - 1][j];
        l[i][s[i]] = i;
    }
    for (int i = 0; i < 26;  i++)
        r[n + 1][i] = n + 1;
    for (int i = n; i >= 1; i --){
        for (int j = 0; j < 26; j ++)
            r[i][j] = r[i + 1][j];
        r[i][s[i]] = i;
    }
    for (int i = 1; i <= m ; i++)
        scanf(" %c %c", &q[i].c, &q[i].sig), q[i].c -= 'A';
    int L = 1 , R = n, mid, LL = n + 1, sig, RR = 0;
    while (L <= R)
    {
        mid = (L + R) / 2;
        sig = check(mid);
        if (!sig)
            LL = min(LL, mid), R = mid - 1;
        else
            if (sig < 0)
                L = mid + 1;
            else
                R = mid - 1;
    }
    L = 1 , R = n;
    while (L <= R)
    {
        mid = (L + R) / 2;
        sig = check(mid);
        if (!sig)
            RR = max(RR, mid), L = mid + 1;
        else
        if (sig < 0)
            L = mid + 1;
        else
            R = mid - 1;
    }

    printf("%d\n", max(0, RR - LL + 1));
    return 0;
}

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int> > v(m);

    int k;
    for(int i = 0; i < m; ++i){
        cin >> k;
        for(int j = 0; j < k; ++j){
            int s;
            cin >> s;
            v[i].push_back(s);
            v[i].back()--;
        }
    }

    vector<int> p(m);

    for(int i = 0; i < m; ++i) cin >> p[i];

    int ans = 0;

    for(int i = 0; i < (1 << n); ++i){
        bool check = true;

        for(int j = 0; j < m; ++j){
            int count = 0;

            for(int id : v[j]){
                if(i >> id & 1){
                    count++;
                }
            }

            count %= 2;

            if(count != p[j]){
                check = false;
            }
        }

        if(check){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 300005
using namespace std;
int n;
char c[maxn];
int s1[maxn],s2[maxn];
int m=0x3f3f3f3f;
int main(){
	cin>>n;
	cin>>c+1;
	for(int i=1;i<=n;i++){
		s1[i]=s1[i-1]+(c[i]=='E');
		s2[i]=s2[i-1]+(c[i]=='W');
	}
	
	for(int i=1;i<=n;i++)
	m=min(m,s2[i-1]+s1[n]-s1[i]);
	
	cout<<m<<endl;
}
		

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5 + 100;
int a,b;
void nhap()
{
    cin >> a >> b;
}

void solve()
{
    for (int c = 1; c <= 3; c++) {
        if (a * b * c % 2 == 1) {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    N, K = map(int, input().strip().split())
    S = input().strip()
    before = S[0]
    count = 0
    score = N
    for s in S[1:]:
        if before == "R" and s == "L":
            count += 1
        before = s
    if S[0] == "L":
        score = N - 1 - 2*max(count-K, 0)
        if S[-1] == "R":
            if count - K < 0:
                pass
            else:
                score -= 1
    else:
        score = N - 2*max(count-K, 0)
        if count - K <= 0:
            score -= 1
        else:
            if S[-1] == "R":
                score -= 1
    print(score)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include <bits/stdc++.h> 
    //#define M_PI 3.14159265358979323846



using namespace std;
#define M 1000000007
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();++it)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define sz(a) (int)a.size()
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define ssortB(arr)   stable_sort(arr.begin(),arr.end(),greater<ll >());
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define fi first
#define se second
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define mp make_pair
#define endl "\n" 
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
//#define check(ds,a) (ds.find(a)!=ds.end()?1:0)

int main(){
    int n,x,t;cin>>n>>x>>t;
    int a=(x+n-1)/x;
    cout<<a*t<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <map>
using namespace std;

const int MAXN = 100100;

int n;
vector<int> a;
vector<int> v[MAXN];
vector<bool> u;

long long dfs(int x) {
	u[x] = true;

	bool leaf = true;
	long long from_down = 0;
	long long mx = -1;
	for (int i = 0; i < (int)v[x].size(); ++i) {
		if (!u[v[x][i]]) {
			long long val = dfs(v[x][i]);
			mx = max(mx, val);
			from_down += val;
			leaf = false;
		}
	}

	if (leaf) {
		return a[x];
	} else {
		long long l = from_down - a[x];
		if (l < 0) {
			cout << "NO" << endl;
			exit(0);
		}
		if (a[x] < l) {
			cout << "NO" << endl;
			exit(0);
		}
		long long d = (a[x] - l);

		if (l + d != a[x]) {
			cout << "NO" << endl;
			exit(0);
		}

		if (2 * l + d != from_down) {
			cout << "NO" << endl;
			exit(0);
		}

		if ((from_down - mx) < l) {
			cout << "NO" << endl;
			exit(0);
		}
		return d;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	for (int i = 0; i + 1 < n; ++i) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		v[x].push_back(y);
		v[y].push_back(x);
	}

	if (n == 2) {
		if (a[0] == a[1]) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
		return 0;
	}

	int root = -1;
	for (int i = 0; i < n && root == -1; ++i) {
		if (v[i].size() > 1) {
			root = i;
			break;
		}
	}

	u.assign(n, false);
	if (dfs(root)) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 11520
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

#include <climits>

using namespace std;

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

	bool flag = false;
	for(int i = 0; i <= (n / 4); i++) {
		for (int j = 0; j <= (n / 7); j++) {
			int total = 4 * i + 7 * j;
			if (total == n) {
				flag = true;
				break;
			}
		}

	}

	if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;

	return 0;

}

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

#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))


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

int main() {
    string S;
    cin >> S;

    if (S == "Sunny") {
        printf("Cloudy\n");
    } else if (S == "Cloudy") {
        printf("Rainy\n");
    } else if (S == "Rainy") {
        printf("Sunny\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string O = in<string>(),E = in<string>();
    REP(i,E.size()){
        cout << O[i];
        cout << E[i];
    }
    if(E.size() < O.size())cout << O[E.size()];
    cout << "\n";
}

Measured memory_bytes: 256
// Last Change:       11/29/2018 18:45:55.
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <list>
#include <memory>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  char a[100][100];
  int hhh[100], www[100];
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    hhh[i] = 0;
  }
  for (int i = 0; i < W; i++) {
    www[i] = 0;
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        hhh[i]++;
        www[j]++;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    if (hhh[i]) {
      for (int j = 0; j < W; j++) {
        if (www[j]) {
          cout << a[i][j];
        }
      }
      cout << "\n";
    }
  }
  cout << flush;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 500001
#define NIL 2000000001
void maxHeapify(int);
void buildMaxHeap();
int heap[N],n;
main(){
  int i, j, k;
  for(i=0;i<N;i++){
    heap[i]=NIL;
  }
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&heap[i]);
  }
  buildMaxHeap();
  for(i=1;i<=n;i++){
    printf(" %d",heap[i]);
  }   
  printf("\n");
  return 0;
}
  
  
void maxHeapify(int i){
  int l,r,largest,a;
    l = 2*i;
   
    r = 2*i+1;
    
  if(l<=n && heap[l] > heap[i]) largest = l;
  else largest = i;
    
  if(r<=n && heap[r] > heap[largest])  largest = r;
    
  if(largest!=i){
    a=heap[largest];
    heap[largest]=heap[i];
    heap[i]=a;
    maxHeapify(largest);
  }
}
void buildMaxHeap(){
  int i;
  for(i=n/2;i>=1;i--){
    maxHeapify(i); 
  }
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using Edge = pair<ll,ll>;
using Graph =vector<vector<int>>;

int main() {
  int N,M;
  cin>>N>>M;
  cout<<N*M<<endl;
}


Measured memory_bytes: 3640
import sys
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(int(input()))
if n==1:
    if 1 in l:
        print(0)
    else:
        print(1)
    sys.exit()
ans1=0
ans2=0
c=0
if 1 in l:
    c+=1
    if 2 in l:
        print(0)
        sys.exit()
    else:
        ans2=1
else:
    ans1=1
    if 2 in l:
        c+=1
    else:
        ans2=2
ans=[0,ans1,ans2]
S=2
while S<n:
    S+=1
    if c>=len(l):
        ans.append((ans[-1]+ans[-2])%1000000007)
    elif S==l[c]:
        c+=1
        ans.append(0)
    else:
        ans.append((ans[-1]+ans[-2])%1000000007)
print(ans[-1])

Measured memory_bytes: 7416
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {
  REP(i, v.size()) print(v[i]);
}
template <typename T> inline void print(const vector<T>& v, string s = " ") {
  REP(i, v.size()) {
    if (i != 0) cout << s;
    cout << v[i];
  }
  cout << '\n';
}
// clang-format on
/* }}} */

signed main() {
  int n = in();
  int cnt = 0;
  REP(_, n) {
    string s;
    cin >> s;
    if (s == "A") {
      cnt++;
    } else {
      cnt--;
    }
    if (cnt < 0) {
      print("NO");
      return 0;
    }
  }
  print(cnt == 0 ? "YES" : "NO");

  return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <string>

int main() {
	std::string s;

	std::getline(std::cin, s);

	for (char &c : s) {
		if (std::islower(c)) {
			c = std::toupper(c);
		} else if (std::isupper(c)) {
			c = std::tolower(c);
		}
	}
	
	std::cout << s << '\n';

	return 0;
}


Measured memory_bytes: 3156
// ABC176C - 

#include <bits/stdc++.h>
using namespace std;

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

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

	ull ans = 0;
	ull max = A[0];
	for (int i = 1; i < N; i++) {
		if (A[i] < max) {
			ans += (max - A[i]);
		} else {
			max = A[i];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4044
#include <stdio.h>
#include<math.h>

int main(void)
{
	double x1,y1;
	double x2,y2;
	double ans;
	double X,Y,Z;

	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

	X = (x2 - x1)*(x2 - x1);
	Y = (y2 - y1)*(y2 - y1);
	Z = X + Y;
	ans = sqrt(Z);

	printf("%f\n", ans);

	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[51];

int main()
{
	int N, absmax = 1;

	cin >> N;
	repc(i, 1, N) cin >> a[i];

	repc(i, 2, N) {
		if (abs(a[absmax]) < abs(a[i])) absmax = i;
	}

	if (a[absmax] > 0) {
		cout << N * 2 << endl;
		repc(i, 1, N) {
			if (i == 1) {
				cout << absmax << ' ' << i << endl;
				cout << absmax << ' ' << i << endl;
			}
			else {
				cout << i - 1 << ' ' << i << endl;
				cout << i - 1 << ' ' << i << endl;
			}
		}
	}
	else if (a[absmax] < 0) {
		cout << N * 2 << endl;
		rrepc(i, N, 1) {
			if (i == N) {
				cout << absmax << ' ' << i << endl;
				cout << absmax << ' ' << i << endl;
			}
			else {
				cout << i + 1 << ' ' << i << endl;
				cout << i + 1 << ' ' << i << endl;
			}
		}
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}


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





int N, W;
int v[100], w[100];
//-----------------------------------------------------------------
int dp[101][10001]; // dp[i][j] := i???????????§??????????????????????¨????j?????¨????????????????????§???
int main() {
	cin >> N >> W;
	rep(i, 0, N) cin >> v[i] >> w[i];

	// ?????????
	rep(i, 0, 101) rep(j, 0, 10001) dp[i][j] = -1;
	dp[0][0] = 0; // 0??????(?????????)??§?????????????¨????0?????¨?????????????????????????????????

	rep(i, 0, N) rep(j, 0, W + 1) if (0 <= dp[i][j]) {
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); // i????????????????????????
		if (j + w[i] <= W) { // i?????????????????????????????????????¨????W????¶????????????????
			dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
		}
	}

	// dp[N][0] ??? dp[N][W]??????????????§????????????
	int ans = -1;
	rep(j, 0, W + 1) ans = max(ans, dp[N][j]);
	cout << ans << endl;
}

Measured memory_bytes: 7052
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;

void answer(ll v) {
	for (const auto neighbor : graph[v]) {
		//探索したことあるなら親
		if (visited[neighbor] == 0) {
			query[neighbor] += query[v];
			ans[neighbor] += query[neighbor];
			visited[neighbor] = 1;
			answer(neighbor);
		}
	}
}

//138D
int main(void) {
	ll n;
	cin >> n;
	graph = vector<vector<ll>>(n, vector<ll>());
	query = vector<ll>(n, 0);
	ans = vector<ll>(n, 0);
	visited = vector<ll>(n, 0);
	ll q;
	cin >> q;
	rep(i, 0, n-1) {
		ll a, b;
		cin >> a >> b;
		graph[a - 1].push_back(b - 1);
		graph[b - 1].push_back(a - 1);
	}
	rep(i, 0, q) {
		ll p, x;
		cin >> p >> x;
		query[p - 1] += x;
	}
	ans[0] = query[0];
	visited[0] = 1;
	answer(0);
	
	rep(i, 0, n) {
		cout << ans[i];
		if (i != n - 1) cout << " ";
		else cout << endl;
	}
}

Measured memory_bytes: 24320
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int N = 0;
  int L[100];
  int maxNum = 0;
  int lengthSum = 0;
  
  cin >> N;
  if(N == 0) {
    cout << "N error" << endl;
  }
  
  //L[]を取得
  for(int ii = 0;ii < N; ii++) {
    cin >> L[ii];
  }
  
  for(int ii = 0; ii < N; ii++) {
    if(L[ii] > maxNum) {
      maxNum = L[ii];
    }
    
    lengthSum = lengthSum + L[ii];
    
  }
  
  if(maxNum >= (lengthSum - maxNum) ) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var s = Read();
            var n = s.Length;

            long d = 1;
            var count = new long[2019];
            count[0] = 1;
            long ans = 0;
            long t = 0;
            for (int i = 1; i <= n; i++)
            {
                t = (d * s[n - i].ToLong() + t).ToLong() % 2019;
                ans += count[t];
                count[t]++;
                d = d * 10 % 2019;
            }

            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToLong(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 21716
#include <cstdio>
#include <cmath>

int main (){
  double x1, y1, x2, y2;
  double distance;

  scanf ( "%lf %lf %lf %lf", &x1, &y1, &x2, &y2 );

  distance = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

  printf("%lf\n", distance);

}

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

using namespace std;

int dp[1000][8]; // 100 = J, 010 = O, 001 = I

bool check(int a, char c) // ??¬???????????\????????????
{
    int shift;

    if (c == 'J') shift = 2;
    if (c == 'O') shift = 1;
    if (c == 'I') shift = 0;

    return (a >> shift) & 1;
}

int main()
{
    int n; cin >> n;
    char sche[1001]; cin >> sche;

    for (int i = 1; i <= 7; ++i) if (i >> 2 & 1) dp[0][i] = check(i, sche[0]);

    for (int i = 1; i < n; ++i) {
        for (int j = 1; j <= 7; ++j) { // i ??\???
            if (!check(j, sche[i])) continue;
            for (int k = 1; k <= 7; ++k) { // i - 1 ??\???
                if ((j & k) && dp[i - 1][k]) {
                    dp[i][j] += dp[i - 1][k];
                    dp[i][j] %= 10007;
                }
            }
        }
    }

    int ans = 0;

    for (int i = 1; i <= 7; ++i) ans += dp[n - 1][i];

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

Measured memory_bytes: 1180
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
h,w=map(int,input().split())
nx,ny=map(int,input().split())
gx,gy=map(int,input().split())
maze=[input()for i in range(h)]
from heapq import heapify, heappop, heappush
seen=set()
gx-=1;gy-=1
SIZE=h*w
hq=[(nx-1)*w+ny-1]
while hq:
    d=heappop(hq)
    c,d=divmod(d,SIZE)
    x,y=divmod(d,w)
    if w*x +y in seen:continue
    seen.add(w*x +y)
    if x==gx and y==gy:print(c);exit()
    if x and w*(x-1)+y not in seen and maze[x-1 ][y]!=35:
        heappush(hq,(c*SIZE+w*(x-1)+y))
    if y and w*x+y-1 not in seen and maze[x][y-1]!=35:
        heappush(hq,(c*SIZE+w*x+y-1))
    if x+1<h  and w*(x+1)+y not in seen and maze[x+1][y]!=35:
        heappush(hq,(c*SIZE+w*(x+1)+y))
    if y+1<w  and w*x+y+1 not in seen and maze[x][y+1]!=35:
        heappush(hq,(c*SIZE+w*x+y+1))
    for i in range(max(0,x-2),min(h,x+3)):
        for j in range(max(0,y-2),min(w,y+3)):
            if i==x and j==y:continue
            if maze[i][j]==46 and w*i + j not in seen:
                heappush(hq,(c+1)*SIZE+w*i+j)

print(-1)


Measured memory_bytes: 151740
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(a==0) cout << 1 << endl;
    if(b==0) cout << 2 << endl;
    if(c==0) cout << 3 << endl;
    if(d==0) cout << 4 << endl;
    if(e==0) cout << 5 << endl;
}


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

#include <atcoder/all>

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

using namespace std;
using namespace atcoder;

const int MAX = 300005;
int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i, n) cin >> a[i];
    segtree<int, op, e> dp(MAX);

    rep(i, n) {
        int x = a[i];
        int l = x - k, r = x + k + 1;
        int now = dp.prod(max(l, 0), min(r, MAX)) + 1;
        dp.set(x, now);
    }

    cout << dp.prod(0, MAX) << endl;
    return 0;
}


Measured memory_bytes: 9576
import itertools
N,M,Q = map(int,input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1,M+1),N):
  value = 0
  for i in range(Q):
    if A[b[i]-1] - A[a[i]-1] == c[i]:
      value += d[i]
  ans = max(ans,value)
print(ans)

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

int cnt = 0;

void insertionSort(int A[], int n, int g){
    int v, j;
    for(int i = 0; i < n; i++){
        v = A[i];
        j = i - g;
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void ShellSort(int A[], int n){
    list<int> G_list;
    int k = 1;
    int m = 1;
    G_list.push_front(k);
    
    while(1){
        k = 3 * k + 1;
        if(k > n) break;
        m++;
        G_list.push_front(k);
    }
    
    std::list<int>::iterator itr;
    int G[m];
    int g = 0;
    for(itr = G_list.begin(); itr != G_list.end(); itr++){
        G[g] = *itr;
        g++;
    }
    
    for(int i = 0; i < m; i++){
        insertionSort(A, n, G[i]);
    }
    
    //出力
    cout << m << endl;
    for(int i = 0; i < m; i++){
        if(i == 0){
            cout << G[i];
        }else{
            cout << " " << G[i];
        }
    }
    
    cout << endl;
    cout << cnt << endl;
    
    for(int i = 0; i < n; i++){
        cout << A[i] << endl;
    }
}

int main(void){
    int n;
    cin >> n;
    
    int A[n];
    
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    
    ShellSort(A, n);
    
    
}


Measured memory_bytes: 6992
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;


int main(){
	string s;
	cin>>s;
	int change=0;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]!=s[i+1]){
			change++;
		}
	}
	cout<<change<<endl;
}

Measured memory_bytes: 512
N = int(input())
*A, = map(int,input().split())
 
P = [0]*N
for i,a in enumerate(A):
    P[a-1] = i
 
class UnionFind:
    def __init__(self,N):
        self.Parent = [-1]*N
        self.Min = [-1]*N
        self.Max = [-1]*N
    def get_Parent(self,n):
        if self.Parent[n] == -1:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def get_min(self,n):
        p = self.get_Parent(n)
        return self.Min[p]
    def get_max(self,n):
        p = self.get_Parent(n)
        return self.Max[p]
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y: 
            self.Min[x] = min(self.Min[x],self.Min[y])
            self.Max[x] = max(self.Max[x],self.Max[y])
            self.Parent[y] = x
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)
    def create(self,n):
        if self.Min[n] == -1:
            self.Min[n] = n
            self.Max[n] = n
 
T = UnionFind(N)
ans = 0
for i in range(N-1,-1,-1):
    p = P[i]
    T.create(p)
    if p-1>=0 and T.get_min(p-1)!=-1:
        T.merge(p,p-1)
    if p+1<N and T.get_min(p+1)!=-1:
        T.merge(p,p+1)
    ans += (i+1)*(p-T.get_min(p)+1)*(T.get_max(p)-p+1)
print(ans)

Measured memory_bytes: 24744
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,c;cin>>a>>b>>c;
  cout<<min({a+b,b+c,c+a})<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
int n,m,a[N];
vector<int> e[N];
//题意:n点,m边,q个操作 vi,di,ci 每次将与v距离d以内的点涂成c,问q次操作后n个定点颜色?
//n,m,q<=1e5,d<=10 首先 操作i,j,i<j 若操作i有部分被j包含,则被包含部分无效
//逆向考虑,从编号大的操作开始,记忆化操作fun(u,d),如果fun(u,d)被执行,编号小的fun(u,d)就不用再执行了
//fun(u,d)=fun(u,d-1)+fun(v,d-1)(v是u的邻点) 时间复杂都O(Q+M*d) 
int vis[N];
int f[N][15];
struct node{
	int v,d,c;
}q[N];
void fun(int u,int d,int c)
{
	if(f[u][d]!=-1)
		return;
	if(!a[u])
	a[u]=c;
	if(d==0)//边界 
	{
		return;
	}
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i];
		fun(v,d-1,c);
	}
	f[u][d]=1;
}
int main()
{
	while(cin>>n>>m)
	{
	
		int u,v;
		for(int i=1;i<=n;i++)
			e[i].clear();
		memset(a,0,sizeof(a));
		memset(f,-1,sizeof(f));
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&u,&v);
			e[u].push_back(v);
			e[v].push_back(u);
		}
		int Q;
		cin>>Q;
		for(int i=0;i<Q;i++)
			scanf("%d%d%d",&q[i].v,&q[i].d,&q[i].c);
		for(int i=Q-1;i>=0;i--)
		{
			fun(q[i].v,q[i].d,q[i].c);
		}
		for(int i=1;i<=n;i++)
			cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 23544
#include<iostream>
#include<deque>
#include<algorithm>
#define INF 1<<28
using namespace std;

struct P{
  int x, y, c;
  P(int x, int y, int c):x(x),y(y),c(c){}
};

int w, h;
char s[999][999];
int sx, sy;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

int bfs(){

  deque < P > que;
  int ans = INF;
  bool flag[999][999] = {};

  que.push_front(P(sx, sy, 0));
  flag[sy][sx] = true;
 
  while(!que.empty()){
    P p = que.front(); que.pop_front();
    int nx = p.x, ny = p.y;

    for(int i=0;i<4;i++){
      int x = nx + dx[i], y = ny + dy[i];

      if(flag[y][x]) continue;
      if(!y || !x || y == h+1 || x == w+1){
	ans = min(p.c, ans);
	continue;
      }
      
      if(s[ny][nx] != '#' && s[y][x] == '#') que.push_back(P(x,y,p.c+1));
      else que.push_front(P(x,y,p.c));
    }
    flag[ny][nx] = true;
  }
  return ans;
}

int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    for(int i=0;i<999;i++){
      for(int j=0;j<999;j++){
	s[i][j] = '.';
	if(i > h || j > w || !i || !j) continue;
	cin >> s[i][j];
	if(s[i][j] == '&') sx = j, sy = i;
      }
    }

    cout << bfs() << endl;

  }
}

Measured memory_bytes: 3292
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  x=w+1
  s=[c>>3for _ in range(h)for c in input()]
  dp=[10001]*h*x
  dp[0]=5-s[0]
  for i in range(1,w):
    dp[i]=dp[i-1]+(s[i-1]^s[i])
  for i in range(x,h*x,x):
    dp[i]=dp[i-x]+(s[i-x]^s[i])
    for j in range(1,w):
      k=i+j
      t=dp[k-1]+(s[k-1]^s[k])
      u=dp[k-x]+(s[k-x]^s[k])
      if t>u:t=u
      dp[k]=t
  print(dp[-2]+1>>1)
main()

Measured memory_bytes: 3188
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))

Measured memory_bytes: 113372
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>

int main(){

  int N, M;
  scanf("%d %d", &N, &M);
  std::priority_queue<long long> A;
  long long temp;
  for (int i=0; i<N; i++){
    scanf("%lld",&temp);
    A.push(temp);
  }

  for (int i=0; i<M; i++){
    temp = A.top();
    A.pop();
    A.push((long long)temp/2);
  }
  long long ans = 0;
  for (int i=0; i<N; i++){
    ans += A.top();
    A.pop();
  }
  
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>
int main (){
int i,j,k,a[10001],sum=0,b;
  scanf ("%d",&k);
  for (i=0;i<k;i++){
  scanf ("%d",&a[i]);
  for (j=0;j<1000;j++){
  if (a[i]%2==1){
  break;
  }
    a[i]=a[i]/2;
  }
  sum=sum+j;
  }
  printf ("%d",sum);
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

int main() {
	int n;
	cin >> n;
	VS v(n);
	REP(i, n) { cin >> v[i]; }

	set<string> m;
	char first = v[0][0];

	REPC(str, v) {
		//cout << str << endl;
		if (m.find(str) == m.end() && str[0] == first) {
			m.emplace(str);
			first = *(--str.end());
		} else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main(){
  int N,l[1100],r[1100],i;
  cin >> N;
  for(i=0;i<N;i++) cin >> l[i] >>r[i];
  int count=0;
  for(i=0;i<N;i++) count=count+(r[i]-l[i]+1);
  cout << count ;

}


Measured memory_bytes: 256
X,Y = gets.split.map(&:to_i)

if Y-2*X >= 0 and (Y-2*X) % 2 == 0
  K = (Y-2*X)/2
  T = X-K
  if T >= 0
    puts 'Yes'
  else
    puts 'No'
  end
else
  puts 'No'
end


Measured memory_bytes: 14428