akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Replace Digits
// Contest : AtCoder - ACL Beginner Contest
// URL : https://atcoder.jp/contests/abl/tasks/abl_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
    T f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1, mod = 998244353;

int n, q;
int len[N << 2], tr[N << 2], lz[N << 2];
int h_111[N];

inline int qpow(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod;
		a = a * a % mod, b >>= 1;
	}
	return res;
}

inline int ls(int p) {return p << 1;}
inline int rs(int p) {return p << 1 | 1;}

inline void upd_sz(int p) {len[p] = len[ls(p)] + len[rs(p)];}
inline void pushup(int p) {tr[p] = (tr[ls(p)] * qpow(10, len[rs(p)]) % mod + tr[rs(p)]) % mod;}

inline void pushdown(int p)
{
	if (lz[p])
	{
		tr[ls(p)] = h_111[len[ls(p)]] * lz[p] % mod, lz[ls(p)] = lz[p];
		tr[rs(p)] = h_111[len[rs(p)]] * lz[p] % mod, lz[rs(p)] = lz[p];
		lz[p] = 0;
	}
}

void build(int l, int r, int p)
{
	if (l == r) {len[p] = tr[p] = 1; return;}
	int mid = (l + r) >> 1;
	build(l, mid, ls(p));
	build(mid + 1, r, rs(p));
	upd_sz(p); pushup(p);
}

void modify(int ql, int qr, int val, int l, int r, int p)
{
	if (ql <= l && r <= qr) {tr[p] = h_111[len[p]] * val % mod, lz[p] = val; return;}
	pushdown(p);
	int mid = (l + r) >> 1;
	if (ql <= mid) modify(ql, qr, val, l, mid, ls(p));
	if (qr > mid) modify(ql, qr, val, mid + 1, r, rs(p));
	pushup(p);
}

PII getans(int ql, int qr, int l, int r, int p)
{
	if (ql <= l && r <= qr) return make_pair(tr[p], len[p]);
	pushdown(p);
	int mid = (l + r) >> 1;
	PII gl, gr;
	if (ql <= mid && qr <= mid) return getans(ql, qr, l, mid, ls(p));
	else if (ql > mid && qr > mid) return getans(ql, qr, mid + 1, r, rs(p));
	else
	{
		gl = getans(ql, qr, l, mid, ls(p)), gr = getans(ql, qr, mid + 1, r, rs(p));
		return make_pair((gr.first + gl.first * qpow(10, gr.second) % mod) % mod, gl.second + gr.second);
	}
}

signed main()
{
    //File("");
    n = gi <int> (), q = gi <int> ();
    h_111[1] = 1;
    for (int i = 2; i <= n; i+=1) h_111[i] = (h_111[i - 1] * 10 + 1) % mod;
    build(1, n, 1);
    while (q--)
    {
    	int l = gi <int> (), r = gi <int> (), x = gi <int> ();
    	modify(l, r, x, 1, n, 1);
    	printf("%lld\n", getans(1, n, 1, n, 1).first);
    }
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

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

const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[maxn];
struct IT{
    ii s[maxn*4];
    void Build(int x , int l , int r , bool delta){
        if(l == r){
            s[x] = mp(a[l] , l);
            if((l & 1) != delta)s[x].first = 1e9;
            return;
        }
        int mid = l + r >> 1;
        Build(x*2,l,mid,delta);
        Build(x*2+1,mid+1,r,delta);
        s[x] = min(s[x * 2] , s[x * 2 + 1]);
    }
    ii Query(int x , int l , int r , int L ,int R){
        if(L > r || l > R){
            return mp(1e9,0);
        }
        if(L <= l && r <= R)return s[x];
        int mid = l + r >> 1;
        return min(Query(x*2,l,mid,L,R),Query(x*2+1,mid+1,r,L,R));
    }
}s[2];
int id[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w  ",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i];
        //cout << a[i] << endl;
        id[a[i]] = i;
    }
    s[0].Build(1,1,n,0);
    s[1].Build(1,1,n,1);
    //return 0;
    function<pair<ii,ii>(int,int)> Cal = [&](int l , int r){
        assert(!((r - l + 1) & 1));
        if(l > r)return mp(mp((int)1e9,(int)1e9),mp(l,r));
        auto tmp = s[(l & 1)].Query(1,1,n,l,r);
        return mp(mp(tmp.first,s[!(l & 1)].Query(1,1,n,tmp.second,r).first),mp(l,r));
    };
    priority_queue<pair<ii,ii>,vector<pair<ii,ii>>,greater<pair<ii,ii>>> pq;
    pq.push(Cal(1,n));
    for(int i = 1 ; i <= n / 2 ; ++i){
        auto u = pq.top().second;
        auto v = pq.top().first;
        pq.pop();
        cout << v.first << " " << v.second << " ";
        pq.push(Cal(u.first,id[v.first]-1));
        pq.push(Cal(id[v.first]+1,id[v.second]-1));
        pq.push(Cal(id[v.second]+1,u.second));
    }
}


Measured memory_bytes: 20080
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,c,sum=0,d=0;
  cin>>n;
  rep(i,n) cin>>c,sum+=c,d+=c*c;
  cout<<(sum*sum-d)/2;
}

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

class Cube{
	public:
  	int f[6];
  	Cube(){}
  	void roll_z(){roll(1,2,4,3);}//横にまわす。
  	void roll_y(){roll(0,2,5,3);}
  	void roll_x(){roll(0,1,5,4);}
  	void roll(int i,int j,int k,int l){
    int t=f[i];f[i]=f[j];f[j]=f[k];f[k]=f[l];f[l]=t;
    }
};

bool eq(Cube c1,Cube c2){
	for(int i=0;i<6;i++){
    	if(c1.f[i]!=c2.f[i]){
        	return false;
        }
      }
  	return true;
}



bool equal(Cube c1,Cube c2){
  	for(int i=0;i<6;i++){
    	for(int j=0;j<4;j++){
          if(eq(c1,c2)){
          	return true;
          }else{
          	c1.roll_z();
          }
        }
          if(i%2==0){
          	c1.roll_y();
          }else{
          	c1.roll_x();
          }
  }
       return false;
  }

int main(){
  Cube c[100];
  int n; cin>>n;
  bool hantei=true;
  for (int i=0;i<n;i++){
  	for (int j=0;j<6;j++){
      cin>>c[i].f[j];
    }
  }
  
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
  		if(equal(c[i],c[j])){
      	hantei=false;
  		}
    }
  }
 	 if(hantei){
  		cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }
  return 0;
}


Measured memory_bytes: 3124
#include <iostream>

int S[10000];
int T[500];

bool IsInclude(int key, int s_size)
{
    for (int i = 0; i < s_size; i++) {
        if (S[i] == key) {
            return true;
        }
    }
    return false;
}

int main(int argc, char *argv[])
{
    int n, q;

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

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

    int include_num = 0;
    for (int i = 0; i < q; i++) {
        if (IsInclude(T[i], n)) {
            include_num += 1;
        }
    }

    std::cout << include_num << std::endl;
}


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

int main(){
  int N;
  cin >> N;
  
  if (N < 10) {
    cout << "Yes";
    return 0;
  }
  
  for (int i = 2; i < 10; i++) {
    if (N % i == 0) {
      if (N / i < 10) {
        cout << "Yes";
        return 0;
      }
    }
  }
  
  cout << "No";
  
  return 0;
}


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

int judge(int c,int d) {
  if(d == 1) {
      return 1;
  }
  return 0;
}
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int e = judge(c,d);
  cout << e << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

int32_t main(){
  BOOST;
  int d,t,s;
  cin>>d>>t>>s;
  if (t*s>=d)cout<<"Yes";
  else cout<<"No";
  return 0; 
}


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

using namespace std;

int main() {
    long long int x, y, a, b, c, p[100001]={}, q[100001]={}, r[100001]={}, i, j, A, B, C, sum=0;
    scanf("%lld %lld %lld %lld %lld", &x, &y, &a, &b, &c);
    for(i=1;i<=a;i++)
        scanf("%lld", &p[i]);
    for(i=1;i<=b;i++)
        scanf("%lld", &q[i]);
    for(i=1;i<=c;i++)
        scanf("%lld", &r[i]);
    sort(p+1, p+(a+1));
    sort(q+1, q+(b+1));
    sort(r+1, r+(c+1));
    C=c;
    B=b-y+1;
    A=a-x+1;
    while(1)
        {
            if(((A>a)&&(B>b))||(C==0)||((r[C]<q[B])&&(r[C]<p[A]))||((A>a)&&(r[C]<q[B]))||((B>b)&&(r[C]<p[A])))
                break;
            if(A>a)
                {
                    B++;
                    C--;
                }
            else if(B>b)
                {
                    A++;
                    C--;
                }
            else
                {
                    if(p[A]>q[B])
                        {
                            B++;
                            C--;
                        }
                    else
                        {
                            A++;
                            C--;
                        }
                }
            
        }
    
    for(i=A;i<=a;i++)
        sum+=p[i];
    for(i=B;i<=b;i++)
        sum+=q[i];
    for(i=C+1;i<=c;i++)
        sum+=r[i];
    printf("%lld", sum);
    
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n;
long long W;
long long w[44],v[44];
const long long inf=1000000000000000001ll;
int target=20;
vector<pair<long long,long long> > res;
vector<pair<long long,long long> > res2;
void dfs(int i,long long ww,long long vv){
	if(i==target){if(ww<=W)res.push_back({ww,vv});return;}
	dfs(i+1,ww,vv);
	dfs(i+1,ww+w[i],vv+v[i]);
}
long long find(long long ww){
	pair<long long,long long> p=make_pair(ww,inf);
	int i=lower_bound(res2.begin(),res2.end(),p)-res2.begin()-1;
	if(i<0||i>=res2.size())return 0;
	return res2[i].second;
}
void dfs2(int i,long long ww,long long vv){
	if(i==target){if(ww<=W)res2.push_back({ww,vv});return;}
	dfs2(i+1,ww,vv);
	dfs2(i+1,ww+w[i],vv+v[i]);
}
int main(){
	cin>>n>>W;
	for(int i=0;i<n;i++)cin>>v[i]>>w[i];
	target=n/2;dfs(0,0,0);
	target=n;dfs2(n/2,0,0);
	sort(res2.begin(),res2.end());
	for(int i=res2.size()-2;i>=0;i--)
		while(i<(int)res2.size()-1&&res2[i+1].second<res2[i].second)res2.erase(res2.begin()+i+1);
	long long ans=0;	
	for(int i=0;i<res.size();i++)
		ans=max(ans,res[i].second+find(W-res[i].first));
	printf("%lld\n",ans);
	return 0;
}


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

int main()
{
	int N, cnt = 0;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}

	for (int i = 0; i < N - 1; i++)
	{
		int minj = i;
		for (int j = i; j < N; j++)
		{
			if (A.at(j) < A.at(minj))
			{
				minj = j;
			}
		}
		if (minj != i)
		{
			swap(A.at(i), A.at(minj));
			cnt++;
		}
	}
	for (int i = 0; i < N; i++)
	{
		if (i != N - 1)
			cout << A.at(i) << ' ';
		else
			cout << A.at(i) << endl;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3108
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  n,m = map(int,input().split())
  A = [input() for _ in range(n)]
  B = [input() for _ in range(m)]
  
  def fa(i,j):
    for a in range(m):
      for b in range(m):
        if A[i+a][j+b] != B[a][b]:
          return False
        else:
          continue
    return True
  
  for i in range(n - m +1):
    for j in range(n-m+1):
      if fa(i,j):
        print("Yes")
        exit()
  print('No')
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,A[110],X;

signed main(){
	cin>>N>>X;
	REP(i,N){
		cin>>A[i];
	}
	int t=0;
	int ans=0;
	REP(i,N){
		if(t<=X){
			ans++;
		}
		t+=A[i];
	}
	if(t<=X){
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for(int i = 0; i <n; i++)
        {
            A[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] m = new int[q];
        for(int i = 0; i <q; i++)
        {
            m[i] = sc.nextInt();
        }
        sc.close();
        boolean[][] dp = new boolean[22][2010];
        
        for(int i= 0;i < n;i++)
        {
            for(int j = 0; j < 2010; j++) 
            {
                dp[i][j] = false;
            }
        }
        dp[0][0] = true;

        for(int i= 0;i < n;i++)
        {
            for(int j = 0; j < 2010; j++) 
            {
                if(j - A[i] >= 0)
                {
                    dp[i+1][j] |= dp[i][j-A[i]];
                }
                dp[i+1][j] |= dp[i][j];
            }
        }
        for(int i = 0;i<q;i++)
        {
            if(dp[n][m[i]])
            {
                System.out.println("yes");
            }
            else{
                System.out.println("no");
            }
        }
        /*
        for(int i= 0;i < n+1;i++)
        {
            for(int j = 0; j < 20; j++) 
            {
                if(dp[i][j])System.out.print(1);
                else System.out.print(0);
            }
            System.out.println();
        }
        */
    

    }
}


Measured memory_bytes: 26840
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {

	long long N, K=0;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}

	sort(d.begin(), d.end());

	K = d[(N / 2)] - d[(N / 2) - 1];
	if (K < 0)
	{
		K = 0;
	}
		
	cout << K;

}

Measured memory_bytes: 640
/*  ex4_1
    L40S38  */
#include<stdio.h>
#include<math.h>
int main(void){
    int tree,d;
    //tree:リンゴの木の本数
    //d:iの木の監視員はx番の木(i-d<=x<=i+d})を監視
    scanf("%d %d",&tree,&d);
    int ans=tree/(2*d+1);//監視員は最大2*d+1本の木を監視
    int remain=tree%(2*d+1);
    if(remain>0){
        ans+=1;
        //r>0ならばa人では監視できない木を監視する監視員が必要
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s; 
  int sum=0;
  vector<char>vec(16);
  vector<char>vec_compare={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
  for(int i=0;i<16;i++) vec.at(i)=s[i];
  for(int i=0;i<16;i++){
    if(vec.at(i)!=vec_compare.at(i)) sum++;
    else sum+=0;
  }
  cout<<sum;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	static class Node {
		long x, y;

		Node(String line) {
			String[] tokens = line.split(" ");
			x = Long.parseLong(tokens[0]);
			y = Long.parseLong(tokens[1]);
		}

		Node(long x, long y) {
			this.x = x;
			this.y = y;
		}

		long getDist(Node other) {
			return Math.abs(other.x - x) + Math.abs(other.y - y);
		}
	}

	int N;
	Node[] nodes;
	long[] x, y;
	long xMax, xMin, yMax, yMin;

	long getMaxDistance(long[] X, long[] Y) {
		Node[] nodes = new Node[N];
		for (int i = 0; i < N; ++i) {
			nodes[i] = new Node(X[i], Y[i]);
		}
		Arrays.sort(nodes, new Comparator<Node>() {
			@Override
			public int compare(Node o1, Node o2) {
				if (o1.x + o1.y != o2.x + o2.y) {
					return Long.compare(o1.x + o1.y, o2.x + o2.y);
				} else {
					return Long.compare(o1.x, o2.x);
				}
			}
		});

		return nodes[N - 1].getDist(nodes[0]);
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		x = new long[N];
		y = new long[N];
		xMax = -1;
		yMax = -1;
		xMin = Long.MAX_VALUE / 2;
		yMin = Long.MAX_VALUE / 2;
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			x[i] = Long.parseLong(tokens[0]);
			y[i] = Long.parseLong(tokens[1]);
			xMin = Math.min(xMin, x[i]);
			xMax = Math.max(xMax, x[i]);
			yMin = Math.min(yMin, y[i]);
			yMax = Math.max(yMax, y[i]);
		}

		long maxDist = getMaxDistance(x, y);
		long[] invX = new long[N];
		for (int i = 0; i < N; ++i) {
			invX[i] = -1L * x[i] + xMax + 1L;
		}
		maxDist = Math.max(maxDist, getMaxDistance(invX, y));
		long[] invY = new long[N];
		for (int i = 0; i < N; ++i) {
			invY[i] = -1L * y[i] + yMax + 1L;
		}
		maxDist = Math.max(maxDist, getMaxDistance(x, invY));
		System.out.println(maxDist);
	}

	void calc() {
	}

	void showResult() {
	}
}

Measured memory_bytes: 63524
import Data.List;main=do{n<-readLn;k<-q n;q n>>=print.f k};m=sortOn;q n=m fst<$>mapM(\_->map read.words<$>getLine>>= \[a,b]->pure(a::Int,b))[1..n];f u[]=0;f u((c,d):v)=case m snd[(a,b)|(a,b)<-u,a<=c,b<=d]of{[]->f u v;r->1+f(filter(/=last r)u)v}

Measured memory_bytes: 1020
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back


/*´z
ZqÌÔðl¶¹¸ÉR[hüÍðßñÇ­³ªÁÄcalÖàÌøÌÔÏ¦ÄWA

*/

int cal(int l,int r,char cop){
  switch(cop){
  case '+':return l+r;
  case '-':return l-r;
  case '*':return l*r;
  }
}



main(){
  int a,b,c,d;
  vector<char> op;
  rep(i,9){
    if(i<3)op.PB('+');
    else if(i<6)op.PB('-');
    else if(i<9)op.PB('*');
  }
  while(cin>>a>>b>>c>>d,a|b|c|d){
    vector<int> num;
    num.PB(a),num.PB(b),num.PB(c),num.PB(d);

    sort(num.begin(),num.end());
    sort(op.begin(),op.end());

    do{
      do{
        a=cal(num[0],num[1],op[0]);
        b=cal(num[2],num[3],op[2]);
        a=cal(a,b,op[1]);
        if(a==10){
          printf("((%d %c %d) %c (%d %c %d))\n",num[0],op[0],num[1],op[1],num[2],op[2],num[3]);
          goto END;
        }

        a=cal(num[0],num[1],op[0]);
        a=cal(a,num[2],op[1]);
        a=cal(a,num[3],op[2]);
        if(a==10){
          printf("(((%d %c %d) %c %d) %c %d)\n",num[0],op[0],num[1],op[1],num[2],op[2],num[3]);
          goto END;
        }

        a=cal(num[1],num[2],op[1]);
        a=cal(num[0],a,op[0]);
        a=cal(a,num[3],op[2]);
        if(a==10){
          printf("((%d %c (%d %c %d)) %c %d)\n",num[0],op[0],num[1],op[1],num[2],op[2],num[3]);
          goto END;
        }

        a=cal(num[1],num[2],op[1]);
        a=cal(a,num[3],op[2]);
        a=cal(num[0],a,op[0]);
        if(a==10){
          printf("(%d %c ((%d %c %d) %c %d))\n",num[0],op[0],num[1],op[1],num[2],op[2],num[3]);
          goto END;
        }
        
        a=cal(num[2],num[3],op[2]);
        a=cal(num[1],a,op[1]);
        a=cal(num[0],a,op[0]);
        if(a==10){
          printf("(%d %c (%d %c (%d %c %d)))\n",num[0],op[0],num[1],op[1],num[2],op[2],num[3]);
          goto END;
        }
        
      }while(next_permutation(op.begin(),op.end()));
    }while(next_permutation(num.begin(),num.end()));
    puts("0");
    END:;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 200010
class Tan{
private:
    stack<ll> s;
    ll tot,res;
public:
    void Init(ll x){
	tot=x;
	res=0;
    }
    void Add(ll x,ll i){
	if(x>=tot){
	    for(;tot<x;tot*=4){
		if(s.size()==0){
		    res+=i;
		}
		else{
		    res+=i-s.top();
		    s.pop();
		}
	    }
	}
	else{
	    for(ll y=x*4;y<=tot;y*=4){
		s.push(i);
	    }
	}
	tot=x;
    }
    ll Calc(){
	return res;
    }
};
ll n,a[N],x[N],y[N];
int main(){
    cin>>n;
    lol(i,n)cin>>a[i];
    Tan ta;
    ta.Init(a[0]);x[0]=x[1]=0;
    for(int i=1;i<n;i++){
	ta.Add(a[i],i);
	x[i+1]=ta.Calc();
    }
    
    lol(i,n/2)swap(a[i],a[n-i-1]);
    
    Tan tb;
    tb.Init(a[0]);y[0]=y[1]=0;
    for(int i=1;i<n;i++){
	tb.Add(a[i],i);
	y[i+1]=tb.Calc();
    }
    
    //for(int i=0;i<=n;i++)cout<<x[i]<<" ";cout<<endl;
    //for(int i=0;i<=n;i++)cout<<y[n-i]<<" ";cout<<endl;
    
    ll ans=1e18;
    for(int i=0;i<=n;i++){
	ll res=x[i]+y[n-i];
	res=res*2+i;
	ans=min(ans,res);
    }
    if(ans==1e18)ans=-1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

const int Inf = 0x3f3f3f3f, MaxN = 200005;

typedef pair<int, int> Interval;
Interval p[MaxN];

priority_queue<int, vector<int>, greater<int>> Heap;

int main()
{
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	for (int i = 1; i <= N; i++)
		cin >> p[i].first >> p[i].second;
	sort(p + 1, p + N + 1, [](const Interval &a, const Interval &b) -> bool {
		return a.first == b.first ? a.second > b.second : a.first < b.first;
	});
	int now = 0;
	for (int i = 1; i <= N; i++)
	{
		if (p[i].first)
			break;
		now = i;
		Heap.push(p[1].second);
	}
	int Ans = 0;
	for (int i = 1; i <= M; i++)
	{
		for (; now < N && p[now + 1].first < i; Heap.push(p[++now].second))
			;
		if (now < N)
			++now;
		else
		{
			if (!Heap.empty() && Heap.top() <= i)
				Heap.pop();
			else
				continue;
		}
		if (++Ans == N)
			break;
	}
	cout << N - Ans << endl;
	return 0;
}

Measured memory_bytes: 2936
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

#define INF 999999999

using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
// input
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    bool flag = true;

    string YAKINIKU = "YAKI", ans;

    cin >> s;

    REP(i,4){
        if(s[i] != YAKINIKU[i])
            flag = false;
    }

    ans = (flag) ? "Yes":"No";
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

int n;
int a[200000];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);

    int ans=0;
    int itr=1;
    bool exist=false;
    for(int i=0;i<n;i++)
    {
        if(!exist&&a[i]==1) exist=true;
        if(a[i]!=itr)
        {
            ans++;
        }
        else itr++;
    }
    if(!exist) printf("-1\n");
    else printf("%d\n",ans);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

vector<int> zalgo(vector<int> s){
  vector<int> ret(s.size());
  int c=0;
  FOR(i,1,s.size()){
	if(i+ret[i-c]<c+ret[c]) ret[i]=ret[i-c];
	else{
	  int j=max(0ll,c+ret[c]-i);
	  while(i+j<s.size() && s[j]==s[i+j]) j++;
	  ret[i]=j;
	  c=i;
	}
  }
  ret[0]=s.size();
  return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n+1),b(n+1),c(n),d(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		cin>>b[i];
	}
	a[n]=a[0];
	b[n]=b[0];
	rep(i,n){
		c[i]=a[i]^a[i+1];
		d[i]=b[i]^b[i+1];
	}
	vector<int> cnt(3*n);
	rep(i,n){
		cnt[i]=d[i];
	}
	FOR(i,n,2*n){
		cnt[i]=c[i-n];
		cnt[i+n]=c[i-n];
	}
	cnt=zalgo(cnt);
	vector<int> ans;
	FOR(i,n,2*n){
		if(cnt[i]>=n){
			ans.push_back(i-n);
		}
	}
	for(auto k:ans){
		cout<<k<<' '<<(b[0]^a[k])<<endl;
	}
}

Measured memory_bytes: 10800
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<ll>num(n);
    for(int i=0;i<n;i++)cin>>num[i];
    vector<ll>zen;
    vector<ll>kou;
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
	zen.pb(num[i]+num[j]);
      }
      zen.pb(num[i]);
    }
    zen.pb(0);
    sort(zen.begin(),zen.end());
    ll ans=0;
    for(int i=0;i<zen.size();i++){
      ll left=0,right=zen.size()-1;
      ll mid;
      while(left!=right){
	mid=(left+right)/2;
	if(zen[mid]+zen[i]<=m)
	  left=mid+1;
	else if(zen[mid]+zen[i]>m)
	  right=mid;
	else
	  break;
	//	cout<<left<<" "<<right<<endl;
      }
      if(left>0&&zen[i]+zen[left-1]<=m)
	ans=max(ans,zen[i]+zen[left-1]);
      else if(zen[i]+zen[left]<=m)
	ans=max(ans,zen[i]+zen[left-1]);
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 10732
#include<cstdio>
#include<algorithm>

using namespace std;

int a[200000],b[200000],c[200000];
int dp[200000][3];

int main()
{
  int n=0;scanf("%d",&n);
  for(int i=1;i<=n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
  for(int i=1;i<=n;i++)
  {
    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
  }
  printf("%d",max(dp[n][0],max(dp[n][1],dp[n][2])));
}

Measured memory_bytes: 3584
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    _ <- B.getLine
    as <- V.fromList . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    let (v1, vs) = V.unstablePartition odd as
        v4 = V.filter (\x -> x `mod` 4 == 0) vs
    let b1 = V.length v1
        b4 = V.length v4
        b2 = V.length as - b1 - b4
    putStrLn $ if b2 == 0
                then if b1 <= b4 + 1 then "Yes" else "No"
                else if b1 <= b4     then "Yes" else "No"


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

#define fir first
#define sec second
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long LL;
typedef unsigned long long u64;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int read() {
	int x = 0, f = 1;char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = -1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}

const int MaxN = 101234;

int n, a[MaxN];

int main() {
	int i;
	n = read();
	for(i = 1; i <= n; i++) a[i] = read();
	LL l = 2, r = 3;
	if(a[n] ^ 2) return puts("-1"), 0;
	
	for(i = n; i > 1; i--) {
		LL z = a[i - 1];
		l = (l + z - 1) / z * z;
		r = r / z * z + (z - 1);
	}
	
	if(l > r) puts("-1");
	else cout << l << " " << r << endl;
	return 0;
}




Measured memory_bytes: 640
#include<stdio.h>
int main()
{
     int x;
     scanf("%d",&x);
     int a[82]={0};
     for(int i=1;i<=9;i++)
     {
         for(int j=i;j<=9;j++)
         {
             a[i*j]=1;
         }
     }
     if(x>81)
         printf("No\n");
     else
     {
         if(a[x]==1)
             printf("Yes\n");
         else
             printf("No\n");
     }
     return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

    ll x;
    cin>>x;

    ll a=0,b=0;
    ll A,B;
    int flag=0;
    for(ll i=0;i<1000;i++){
        if(flag==1)break;
        A=i*i*i*i*i;
        if(A>x){
            for(ll j=1;j<1000;j++){
                B=j*j*j*j*j;
                if(A==B+x){
                    a=i;
                    b=j;
                    flag=1;
                    break;
                }
            }
        }
        else if(A<x){
            for(ll j=-1;j>-1000;j--){
                B=j*j*j*j*j;
                if(A==B+x){
                    a=i;
                    b=j;
                    flag=1;
                    break;
                }
            }

        }
        else {
            a=i;
            b=0;
        }
    }

    cout<<a<<" "<<b<<endl;

    return 0;
}


Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  sort(all(A), greater<ll>());
  ll ans = 0;
  ans += A[0];
  rep(i, (n-2)/2) {
    ans += 2*A[i+1];
  }
  if(n%2) ans += A[n/2];
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

#define intt long long

int main() {

	int k;
	cin >> k;
	queue <intt> q;
	for (int i = 1; i <= 9; i ++) {
		q.push(1LL * i);
	}
	while (-- k) {
		intt x = q.front();
		q.pop();
		if (x % 10 != 0) {
			q.push(x * 10 + x % 10 - 1);
		}
		q.push(10 * x + x % 10);
		if (x % 10 != 9) {
			q.push(x * 10 + x % 10 + 1);
		}
	}
	cout << q.front() << '\n';
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2];
int i,j,k,l,t,n,m,tot;
void add(int x,int y){
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
int dfs(int x,int y){
	int l=0,t=h[x];
	while (t){
		if (go[t]!=y) l^=dfs(go[t],x)+1;
		t=nxt[t];
	}
	return l;
}
int main(){
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d",&j,&k);
		add(j,k);add(k,j);
	}
	if (dfs(1,0)) printf("Alice\n");else printf("Bob\n");
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  int sum = 0;
  int tmp;
  for (int i = 0; i < M; i++) {
    cin >> tmp;
    sum += tmp;
  }
  
  int ans = N - sum;
  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  
  return 0; 
  
}
  

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    int res = 0;
    string a, b, c;
    cin >> n >> a >> b >> c;
    rep (i, n) {
        if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) res += 2;
        else if (a[i] == b[i] && b[i] != c[i]) res++;
        else if (a[i] == c[i] && a[i] != b[i]) res++;
        else if (b[i] == c[i] && a[i] != b[i]) res++;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
		str=sc.nextLine();
		StringBuilder b = new StringBuilder();
		String[] s=str.split(" ");
		for(int i=(s.length-1);i>=0;i--){
			b.append(s[i]+" ");
		}
		b.deleteCharAt(b.lastIndexOf(" "));
		System.out.println(b);
	}
}

Measured memory_bytes: 26208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<char, bool> map = new Dictionary<char, bool>()
            {
                {'A',true }, {'B',false }, {'C',false }
            };

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                char pos1 = input[0], pos2 = input[2];

                bool temp = map[pos1];
                map[pos1] = map[pos2];
                map[pos2] = temp;
            }

            foreach (var m in map)
            {
                if (m.Value) Console.WriteLine(m.Key);
            }
        }
    }
}

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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 1000010, Mod = 1e9 + 7;
int fac[N], ifac[N];
int fpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1ll * a * a % Mod)
		if (b & 1) res = 1ll * res * a % Mod;
	return res;
}
int C(int n, int m) {
	if (n < m) return 0;
	return 1ll * fac[n] * ifac[n - m] % Mod * ifac[m] % Mod;
}
int n, m, k;
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	read(n), read(m), read(k);
	fac[0] = 1;
	for (int i = 1; i <= N - 10; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	ifac[N - 10] = fpow(fac[N - 10], Mod - 2);
	for (int i = N - 10; i >= 1; i--) ifac[i - 1] = 1ll * ifac[i] * i % Mod;
	LL ans = fpow(3, m + k), S = 1;
	for (int t = 1; t <= m + k; t++) {
		S = (2 * S % Mod - C(t - 1, m) + Mod) % Mod;
		if (t - k > 0) S = (S - C(t - 1, t - k - 1) + Mod) % Mod;
		ans = (ans + 1ll * fpow(3, m + k - t) * C(t + n - 1, n - 1) % Mod * S % Mod) % Mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8064
N, K = map(int, input().split())
S = " " + input() + " "

num101 = []
if("0" == S[1]):
    num101 = [0]
for i in range(1, N + 1):
    if(S[i - 1] != S[i]):
        st = i
    if(S[i] != S[i + 1]):
        num101.append(i - st + 1)
if("0" == S[-2]):
    num101.append(0)
#print("num101= {}".format(num101))

sum101 = [0]
for i in range(len(num101)):
    sum101.append(sum101[-1] + num101[i])
#print("sum101={}".format(sum101))

maxsum = 0
for i in range(0, len(sum101), 2):
    left = i
    right = min(i + 2 * K + 1, len(sum101) - 1)
    sumK = sum101[right] - sum101[left]
    maxsum = max(maxsum, sumK)
    if(right >= len(sum101) - 1):
        break

print(maxsum)


Measured memory_bytes: 8088
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
    ll n;
    cin>>n;
    map<ll,ll> m;
    rep(i,n){
        ll a;cin>>a;
        m[a]++;
    }
    ll ans=0;
    for(auto itr=m.begin();itr!=m.end();itr++){
        if(itr->second%2!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
    

    
    return 0;
}


Measured memory_bytes: 6528
h,w=map(int,input().split())
a=['']*h
for i in range(h):
    a[i]=input()

row=[False]*h
col=[False]*w

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            row[i]=True
            col[j]=True;

for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j],end="")
        print()


Measured memory_bytes: 4468
#include <stdio.h>
#include <string.h>

int main() {
	char S[11];
	int len, ok = 1, i, cnt = 0, C;

	scanf("%s", S);
	len = strlen(S);

	ok = (S[0] == 'A');

	if (ok == 1) {
		for (i = 2; i < len - 1; i++) {
			if (S[i] == 'C') {
				cnt++;
				C = i;
			}
		}
		ok = (cnt == 1);
	}

	if (ok == 1) {
		for (i = 1; i < len; i++) {
			if (i != C && S[i] - 'a' < 0) {
				ok = 0;
			}
		}
	}

	if (ok == 1) {
		printf("AC");
	}
	else {
		printf("WA");
	}

	return 0;
}

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

#define y1 hasjdnasd
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define pb push_back
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

#define ll long long
#define oo 1e18 + 7
#define int long long

const int N = 2e5 + 5;
int n , C;
int h[N] , dp[N];

struct line
{
    int a , b;
    void operator -= (line const &o)
    {
        a -= o.a;
        b -= o.b;
    }
};

deque < line > dq;

int CCW(line l1 , line l2 , line l3)
{
    l3 -= l2;
    l2 -= l1;
    return l2.a * l3.b - l2.b * l3.a;
}

int val(line l , int x)
{
    return l.a * x + l.b;
}

void addline(line l)
{
    while(dq.size() >= 2 && CCW(dq[dq.size() - 2] , dq[dq.size() - 1] , l) >= 0)
        dq.pop_back();
    dq.pb(l);
}

int get(int x)
{
    int l = 0 , r = dq.size() - 1 , mid = 0;
    while(l <= r)
    {
        mid = (l + r) / 2;
        if(mid != 0 && val(dq[mid - 1] , x) < val(dq[mid] , x)) r = mid - 1;
        else if(mid != dq.size() - 1 && val(dq[mid + 1] , x) < val(dq[mid] , x)) l = mid + 1;
        else break;
    }
    return val(dq[mid] , x);
}

main()
{
    //freopen("Z.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> C;
    FOR(i , 1 , n)
        cin >> h[i];
    line l;
    l.a = -2 * h[1];
    l.b = h[1] * h[1];
    addline(l);
    FOR(i , 2 , n)
    {
        dp[i] = h[i] * h[i] + get(h[i]) + C;
        l.a = -2 * h[i];
        l.b = dp[i] + h[i] * h[i];
        addline(l);
    }
    cout << dp[n];
}


Measured memory_bytes: 6656
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([set([])for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  ans+=len(l_lis[i]-mat[s])*len(r_lis[i])
  mat[s]=l_lis[i]
  
print(ans)

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

// v[i][j] := iCj
template <typename T>
std::vector<std::vector<T>> comb2(T n, T r)
{
    std::vector<std::vector<T>> v(n + 1, std::vector<T>(n + 1, 0));
    for (int i = 0; i < (int)v.size(); i++)
    {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < (int)v.size(); j++)
    {
        for (int k = 1; k < j; k++)
        {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
            v[j][k] %= MOD;
        }
    }
    return v;
}

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

    ll n, k;
    cin >> n >> k;
    auto comb = comb2(1010, 1010);
    vector<ll> fact(1010, 1);
    for (int i = 2; i <= 1000; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    cout << (comb[k][n] * fact[n]) % MOD << endl;
}



Measured memory_bytes: 6848
// D - Grid Repainting
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using VC = vector<char>;
using VVC = vector<VC>;
using PII = pair<int,int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int bfs(int H, int W, VVC &S){
	int dx[4]={0,-1,0,1}, dy[4]={-1,0,1,0};
	vvi dist(H+1, vi(W+1, -1));
	dist[1][1] = 0;
	S[1][1] = '_';
	queue<PII> q;
	q.push({1, 1});
	while(!q.empty()){
		int i,j; tie(i,j)= q.front(); q.pop();
		rpz(k, 4){
			int y = i + dy[k], x = j + dx[k];
			if(S[y][x] != '.') continue;
			dist[y][x] = dist[i][j] + 1;
			q.push({y, x});
			S[y][x] = '_';
			if(y==H && x==W) return dist[H][W];
		}
	}
	return dist[H][W];
}

int main(){
	int H,W; cin>>H>>W;
	VVC S(H+2,VC(W+2, '#'));
	int white = 0;
	rpz(i, H){
		string s; cin>>s;
		rpz(j, W){
			if(s[j] == '.') white++;
			S[i+1][j+1] = s[j];
		}
	}
	int dist = bfs(H, W, S);
	cout<< (dist<0? -1: white - dist - 1) <<endl;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n,d,x;
  cin>>n>>d>>x;
  int kabu[d+10][n+10]={};
  for(int i=0;i<d;i++)
    for(int j=0;j<n;j++)
      cin>>kabu[i][j];
  ll ans=0;

  for(int i=0;i<d-1;i++){
    int dp[n+10][x+10]={};
    bool dp2[n+10][x+10]={};
    dp2[0][0]=true;
    for(int j=1;j<=n;j++){
      for(int k=0;k<x;k++){
	if(dp2[j-1][k]){
	  dp[j][k]=max(dp[j-1][k],dp[j][k]);
	  dp2[j][k]=true;
	}
	if(dp2[j-1][k]){
	  int cnt=1;
	  while(k+cnt*kabu[i][j-1]<=x){
	    //	  cout<<j<<" "<<k<<endl;
	    dp[j][k+cnt*kabu[i][j-1]]=max(dp[j][k+cnt*kabu[i][j-1]],dp[j-1][k]+cnt*kabu[i+1][j-1]);
	    dp2[j][k+cnt*kabu[i][j-1]]=true;
	    cnt++;
	  }
	}
      }
    }
    int num=x;
    for(int j=0;j<=n;j++){
      for(int i=0;i<=num;i++){
	//	cout<<dp[j][i]<<" ";
	x=max(x,dp[j][i]+num-i);
      }
      //cout<<endl;
    }
    //cout<<endl;
     //cout<<endl;
    //cout<<x<<endl;
  }
  cout<<x<<endl;
  return 0;
}



Measured memory_bytes: 5712
#include <iostream>
#include <vector>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    bool operator<(const ModInt& b) const { return val < b.val; }
    bool operator<=(const ModInt& b) const { return val <= b.val; }
    bool operator>(const ModInt& b) const { return val > b.val; }
    bool operator>=(const ModInt& b) const { return val >= b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept {
        lint v;
        is >> v;
        x = v;
        return is;
    }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 998244353;
using mint = ModInt<MOD>;

void solve() {
    int n, s;
    std::cin >> n >> s;

    std::vector<mint> dp(s + 1, 0);
    dp[0] = 1;
    auto ndp = dp;

    while (n--) {
        int d;
        std::cin >> d;

        ndp = dp;
        for (auto& x : ndp) x *= 2;
        for (int i = 0; i + d <= s; ++i) {
            ndp[i + d] += dp[i];
        }

        std::swap(dp, ndp);
    }

    std::cout << dp[s] << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3664