akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll l[2005][2005];
ll r[2005][2005];
ll u[2005][2005];
ll d[2005][2005];
string s[2005];

int main(){
    ll h,w;
    cin >> h >> w;
    for(ll i=0;i<h;i++){
        cin >> s[i];
    }
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            if(s[i][j]=='#') l[i][j]=0;
            else if(s[i][j]=='.'&&j==0) l[i][j]++;
            else l[i][j]=l[i][j-1]+1;
        }
        for(ll j=w-1;j>=0;j--){
            if(s[i][j]=='#') r[i][j]=0;
            else if(s[i][j]=='.'&&j==w-1) r[i][j]++;
            else r[i][j]=r[i][j+1]+1;
        }        
    }
    for(ll i=0;i<w;i++){
        for(ll j=0;j<h;j++){
            if(s[j][i]=='#') d[j][i]=0;
            else if(s[j][i]=='.'&&j==0) d[j][i]++;
            else d[j][i]=d[j-1][i]+1;
        }
        for(ll j=h-1;j>=0;j--){
            if(s[j][i]=='#') u[j][i]=0;
            else if(s[j][i]=='.'&&j==h-1) u[j][i]++;
            else u[j][i]=u[j+1][i]+1;
        }
    }
    ll res=0;
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            res=max(res,r[i][j]+l[i][j]+u[i][j]+d[i][j]-3);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 136508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m, l;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m >> l;
	if(n+m+l <= 21){
		print("win")
	}
	else{
		print("bust")
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.*;
import java.lang.*;

public class Main {
	char[][] maze;
	int[][] shadow;
	public void recur(int r, int c, int steps) {
		if (r<0 ||c<0 ||r>=maze.length || c>=maze[0].length) return;
		if (maze[r][c] == '#') {
			return;
		}
		if (shadow[r][c]<= steps) return;
		
		shadow[r][c] = steps;
		recur(r+1, c, steps+1);
		recur(r-1, c, steps+1);
		recur(r, c+1, steps+1);
		recur(r, c-1, steps+1);
	}
	public void run() throws Exception {
		FastScanner sc = new FastScanner();
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		maze = new char[r][c];
		shadow = new int[r][c];
		for (int i = 0; i<r; i++) {
			maze[i] = sc.next().toCharArray();
			Arrays.fill(shadow[i], Integer.MAX_VALUE);
		}
		int steps = 0;
		for (int i = 0; i<r; i++) {
			for (int j = 0;j<c; j++) {
				recur(i,j,0);
				for (int x = 0; x<r; x++) {
					for (int y = 0; y<c; y++) {
						if (shadow[x][y] == Integer.MAX_VALUE) {
							continue;
						}
						steps = Math.max(steps, shadow[x][y]);
					}
				}
				for (int x = 0; x<r; x++) {
				//	System.out.println(Arrays.toString(shadow[x]));
					Arrays.fill(shadow[x], Integer.MAX_VALUE);
				}
			}
		}
		System.out.println(steps);
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

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

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

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

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

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
}

Measured memory_bytes: 22912
#include<iostream>
#include<string>
#include<map>
using namespace std;
string s1,s2,ans="";
int dp[3003][3003];

   
void cal_ans(int i, int j)
{
   if(i<=0||j<=0)
   {
     return;
   }
   
   if(s1[i-1]==s2[j-1])
   {ans=s1[i-1]+ans;
    cal_ans(i-1,j-1);

   }
   else if(dp[i-1][j]>=dp[i][j-1])
   {
     cal_ans(i-1,j);
   }
   else
   {
     
     cal_ans(i,j-1);
   }
   
  

}



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

  

  
  cin>>s1>>s2;
  int n1=s1.size();
  int n2=s2.size();

  
  for(int i=0;i<=n1;i++)
  {
    for(int j=0;j<=n2;j++)
    {
         if(i==0||j==0)
           dp[i][j]=0;
         else if(s1[i-1]==s2[j-1])
         {
               dp[i][j]=1+dp[i-1][j-1];
         } 
         else
         {
           dp[i][j]=std::max(dp[i][j-1],dp[i-1][j]);
         }
         
    }
  }
 
  cal_ans(n1,n2);
  cout<<ans<<endl;


return 0;



}

Measured memory_bytes: 39296
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>

using namespace std;

long long MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<long long> d(n, 0);

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


    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i; j < n; j++)
        {
            if (i == j) {
                continue;
            }
            sum += (d[i] * d[j]);
        }
    }

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

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

int main(){
    int a,b;
    cin >> a >> b;
    string A,B;
    rep(i,b) A += to_string(a);
    rep(i,a) B += to_string(b);
    cout << min(A,B) << endl;  
    return 0;
}

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

int main(){
	int N,X;
	cin>>N>>X;
	
	int L[N];
	for(int i=0;i<N;i++){
		cin>>L[i];
	}
	
	int num=0;
	int D[N]={};
	for(int i=0;i<=N;i++){
		if(i==0)
			D[i]=0;
		else 
			D[i]=D[i-1]+L[i-1];
		
		//cout<<D[i]<<endl;
		
		if(D[i]<=X)
			num++;
	}
	
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int s[366][26];
int main() {

	int d;
	cin >> d;
	int c[26];
	int i, j, j2;
	for (i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (i = 0; i < d; i++) {
		for (j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}
	int last[26];
	for (i = 0; i < 26; i++) {
		last[i] = 0;
	}
	int jmax, jindex, jindex2;
	for (i = 1; i <= d; i++) {

		jmax = 0;
		jindex = -1;
		jindex2 = -1;
		/*for (j = 0; j < 26; j++) {
			if (c[j] *(i - last[j]) > jmax) {
				jmax = c[j] *(i - last[j]);
				jindex = j;
			}
			else if (c[j] *(i - last[j]) == jmax) {
				if (s[i - 1][j] > s[i - 1][jindex]) {
					jindex = j;
				}
			}
		}*/
		for (j = 0; j < 26; j++) {
			for (j2 = 0; j2 < 26; j2++) {
				if (j != j2) {
					if (s[i - 1][j] + 10 * c[j] * (i - last[j]) + s[i][j2] + 10 * c[j2] * (i + 1 - last[j2]) > jmax) {
						jmax = s[i - 1][j] + 10 * c[j] * (i - last[j]) + s[i][j2] + 10 * c[j2] * (i + 1 - last[j2]);
						jindex = j;
						jindex2 = j2;
					}
				}
				else {
					if (s[i - 1][j] + 10 * c[j] * (i - last[j]) + s[i][j2] + 10 * c[j2] > jmax) {
						jmax = s[i - 1][j] + 10 * c[j] * (i - last[j]) + s[i][j2] + 10 * c[j2];
						jindex = j;
						jindex2 = j2;
					}
				}
			}
		}
		/*for (j = 0; j < 26; j++) {
			if (s[i - 1][j] + 15 * c[j] * (i - last[j]) >= jmax) {
				jmax = s[i - 1][j] + 15 * c[j] * (i - last[j]);
				jindex = j;
			}
		}*/
		last[jindex] = i;
		cout << jindex + 1 << endl;
		


	}
	return 0;


}

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

// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    vector<double> p(N); rep(i,N)cin>>p[i];
    vector<vector<double>> dp(N+1,vector<double>(N+1,0));
    dp[0][0] = 1;
    // rep1(i,N){
    //     for(int j = 1; j <= i; j++){
    //         dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1.0-p[i]);//j==iのとき不都合
    //     }
    // }
    rep(i,N){
        for(int j = 0; j <= i; ++j){
            dp[i+1][j+1] += dp[i][j]*p[i];
            dp[i+1][j] += dp[i][j]*(1-p[i]);
        }
    }
    double res = 0;
    for(int i = N/2+1; i <= N; i++){
        res += dp[N][i];
    }
    cout<<setprecision(10)<<res<<endl;
}

Measured memory_bytes: 73700
N = int(input())

p = [0] * N
m = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    p[i] = x + y
    m[i] = x - y

pm = max(p) - min(p)
mm = max(m) - min(m)

print(max(pm, mm))

Measured memory_bytes: 24704
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FasterScanner in = new FasterScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FasterScanner in, PrintWriter out) {
            final int n = in.nextInt();

            long ans = 0;
            for (int i = 0; i < n; i++) {
                ans += in.nextLong() - 1;
            }

            out.println(ans);
        }

    }

    static class FasterScanner {
        private InputStream in;
        private byte[] buffer;
        private int bufPointer;
        private int bufLength;

        public FasterScanner(InputStream in) {
            this.in = in;
            buffer = new byte[1024];
        }

        private boolean hasNextByte() {
            if (bufPointer < bufLength) return true;
            bufPointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (bufLength > 0);
        }

        private int readByte() {
            if (hasNextByte()) return buffer[bufPointer++];
            return -1;
        }

        private static boolean isPrintableChar(int c) {
            return (c >= 33 && c <= 126);
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[bufPointer])) bufPointer++;
            return hasNextByte();
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || b > '9') throw new NumberFormatException();

            while (true) {
                if (b >= '0' && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 998244353;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++)
  {
    if (s[i] == '?')
      s[i] = 'D';
  }
  cout << s;

}

Measured memory_bytes: 3764
//AtCoder ABC043 B - バイナリハックイージー / Unhappy Hacking (ABC Edit)
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    string s;
    cin>>s;
    string out;
    for(const auto& i:s){
        if(i=='0') out.push_back('0');
        else if(i=='1') out.push_back('1');
        else if(i=='B') {
			if(out.length() > 0)
				out.pop_back();
		}
	}
    cout<<out<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        String s = sc.next();
        String result = s.replaceAll(",", " ");
        System.out.println(result);

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 23124
def solution(a):
    A = a[0]
    B = sum(a) - a[0]
    Min = abs(A - B)
    for i in xrange(1, len(a)-1):
        A += a[i]
        B -= a[i]
        if Min > abs(A- B):
            Min = abs(A - B)
    print Min
import math
N = int(raw_input())
a = map( int, raw_input().split())
solution(a)


Measured memory_bytes: 18540
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int u=sc.nextInt()-1;
    int v=sc.nextInt()-1;
    Node[] ns=new Node[n];
    for(int i=0;i<n;i++){
      ns[i]=new Node();
    }
    for(int i=0;i<n-1;i++){
      int a=sc.nextInt()-1;
      int b=sc.nextInt()-1;
      ns[a].add(b);
      ns[b].add(a);
    }
    Deque<Node> dq=new ArrayDeque<>();
    ListIterator<Integer> lit;
    dq.add(ns[v]);
    ns[v].vis();
    while(!dq.isEmpty()){
      Node cur=dq.pollFirst();
      lit=cur.el.listIterator();
      while(lit.hasNext()){
        int idx=lit.next();
        if(!ns[idx].v){
          dq.add(ns[idx]);
          ns[idx].vis();
          ns[idx].al=cur.al+1;
        }
      }
    }
    dq.add(ns[u]);
    ns[u].vis(false);
    while(!dq.isEmpty()){
      Node cur=dq.pollFirst();
      lit=cur.el.listIterator();
      while(lit.hasNext()){
        int idx=lit.next();
        if(ns[idx].v){
          dq.add(ns[idx]);
          ns[idx].vis(false);
          ns[idx].tl=cur.tl+1;
        }
      }
    }
    /*
    for(int i=0;i<n;i++){
      System.out.println(ns[i]);
    }
    */
/*
    dq.add(ns[u]);
    while(!dq.isEmpty()){
      Node cur=dq.pollFirst();
      lit=cur.el.listIterator();
      //System.out.println(lit);
      while(lit.hasNext()){
        int idx=lit.next();
        if(ns[idx].al<cur.al){
          if(ns[idx].al<ns[idx].tl){
              //lit.remove();
              cur.el=new ArrayList<>();
            break;
          }else{
            dq.add(ns[idx]);
          }
        }
      }
    }
*/
    dq.add(ns[u]);
    int max=ns[u].al-1;
    ns[u].vis();
    while(!dq.isEmpty()){
      Node cur=dq.pollFirst();
      lit=cur.el.listIterator();
      while(lit.hasNext()){
        int idx=lit.next();
        if(!ns[idx].v&&ns[idx].al>ns[idx].tl){
          max=Math.max(ns[idx].al-1,max);
          dq.add(ns[idx]);
          ns[idx].vis();
        }
      }
    }
    System.out.println(max);
  }
  static class Node{
    int al;
    int tl;
    boolean v;
    List<Integer> el;
    Node(){
      el=new ArrayList<>();
    }
    void add(int e){
      el.add(e);
    }
    void vis(){
      vis(true);
    }
    void vis(boolean vv){
      v=vv;
    }
    public String toString(){
      return al+":"+tl+":"+el.toString();
    }
  }
  static class Edge{
    int f;
    int t;
    Edge(int from,int to){
      f=from;
      t=to;
    }
  }
}


Measured memory_bytes: 108680
//agc031_a.cpp
//Sun Mar 17 23:17:21 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	unordered_map<char,int> map;
	for (int i=0;i<s.length();i++){
		auto itr = map.find(s[i]);
		if (itr == map.end()){
			map[s[i]] = 1;
		}else {
			map[s[i]]++;
		}
	}

	ll ans = 1;
	for(auto itr = map.begin(); itr != map.end(); ++itr) {
		ans = ans * (itr->second +1) % 1000000007;
	}

	cout << ans -1 << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int x[100010],y[100010],t[100010];
  
int main(){
  int n;cin>>n;
  for(int i=1;i<=n;i++)cin>>t[i]>>x[i]>>y[i];
  for(int i=1;i<=n;i++){
    int T=t[i]-t[i-1];
    int X=x[i]-x[i-1];
    int Y=y[i]-y[i-1];
    //cout<<T<<X<<Y<<endl;
    int po=abs(X)+abs(Y);
    if(T<po || (T-po)%2!=0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 1408
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let x = read::<usize>();
    let y = read::<usize>();
    let z = read::<usize>();
    let k = read::<usize>();
    let mut a = (0..x).map(|_| read::<i64>()).collect::<Vec<_>>();
    let mut b = (0..y).map(|_| read::<i64>()).collect::<Vec<_>>();
    let mut c = (0..z).map(|_| read::<i64>()).collect::<Vec<_>>();
    a.sort();
    b.sort();
    c.sort();
    a.reverse();
    b.reverse();
    c.reverse();

    use std::collections::BinaryHeap;
    let mut bh = BinaryHeap::new();

    'a: for xi in 0..x {
        if bh.len() >= k && rev(*bh.peek().unwrap()) > a[xi] + b[0] + c[0] {
            break 'a;
        }

        'b: for yi in 0..y {
            if bh.len() >= k && rev(*bh.peek().unwrap()) > a[xi] + b[yi] + c[0] {
                break 'b;
            }

            'c: for zi in 0..z {
                if bh.len() >= k && rev(*bh.peek().unwrap()) > a[xi] + b[yi] + c[zi] {
                    break 'c;
                }

                if bh.len() >= k {
                    bh.pop();
                }
                bh.push(rev(a[xi] + b[yi] + c[zi]))
            }
        }
    }

    let mut v = vec![0; k];
    for i in 0..k {
        v[i] = rev(bh.pop().unwrap());
    }
    v.reverse();
    for x in v {
        println!("{}", x)
    }

    fn rev(x: i64) -> i64 {
        x * -1
    }
}


Measured memory_bytes: 4476
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};


int main(){
  string S; cin >> S;
  vector<ll> cnt(30, 0);
  ll ans = 1;
  rep(i, S.size()){
    ans += i - cnt[S[i] - 'a'];
    cnt[S[i] - 'a']++;
  }
  cout << ans << endl;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 998244353LL;

int main() {
  ll N,S;
  cin>>N>>S;
  vector<ll> v(N);
  for(ll i = 0; i < N; i++) cin>>v[i];
  vector<vector<ll>> dp(N,vector<ll>(S+1,0));
  for(ll i = 0; i < N; i++){
    if(i==0) {
      if(v[i]<=S) dp[i][v[i]]=1;
      dp[i][0]=2;
    }
    else{
      for(ll j = 0; j <= S; j++){
        dp[i][j]=(dp[i-1][j]*2)%mod;
        if(j>=v[i]) dp[i][j]=(dp[i][j]+dp[i-1][j-v[i]])%mod;
      }
    }
  }
  cout<<dp[N-1][S]<<endl;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint n;
    cin >> n;

    vector<lint> t(n);
    rep(i, n){
        cin >> t[i];
    }

    lint m;
    cin >> m;

    vector<lint> p(m), x(m);
    rep(i, m){
        cin >> p[i] >> x[i];
        --p[i];
    }

    rep(i, m){
        lint ans = 0;
        rep(j, n){
            if(j == p[i]){
                ans += x[i];
            }else{
                ans += t[j];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
class Node
  attr_accessor :self, :parent
  def initialize(i)
    @self, @parent = i, i
  end
end

class UnionFindTree
  attr_accessor :nodes

  #
  def initialize(n)
    @nodes = (1..n).map{|i| Node.new(i) }
  end

  # 1番上の親を返す.
  def root(x)
    return x if x == @nodes[x-1].parent
    return @nodes[x-1].parent = root(@nodes[x-1].parent)
  end

  # 判定する
  #   2つの木が同じ親に属していればtrue
  def check(a, b)
    return true if root(a) == root(b)
    return false
  end

  # まとめる
  def union(a, b)
    return if check(a, b)
    $ans -= 1
    @nodes[root(b)-1].parent = root(a)
  end

  #
  def parent_size
    parents = []
    @nodes.each do | node |
      parents << node.parent
    end
    return parents.uniq.size
  end
end

n, m = gets.rstrip.split.map(&:to_i)
tree = UnionFindTree.new(n)
#p tree

$ans = n
m.times do
  x, y, _ = gets.rstrip.split.map(&:to_i)
  tree.union(x, y)
end
p $ans

Measured memory_bytes: 11924
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n,h;
    cin>>n>>h;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];   
    }
    ll ans=0;
    sort(ALL(a),greater<ll>());sort(ALL(b),greater<ll>());
    for(int i=0;i<n&&a[0]<b[i];i++){
        //刀を一度ずつ投げ続けろ!!!
        h-=b[i];
        ans++;
        if(h<=0){
            cout<<ans<<endl;return 0;
        }
    }
    cout<<ans+(h+a[0]-1)/a[0]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define debug(x) cout<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=2e6+10;
int main()
{
   ll n,k;
   cin>>n>>k;
   cout<<min(n%k,k-n%k)<<endl;
   //system("pause");
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repb(i, n, a) for (int i = (n - 1); i >= (a); i--)
#define all(x) x.begin(), x.end()
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define pb push_back
#define mp make_pair
#define fir first
#define sec second

int main() {
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    cout << max({(N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E}) + 5 << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
 
using namespace std;
 
int main(){
    int ans=0;
    int n,q;
    vector<int> s;
    vector<int> t;
    cin>>n;
    for (int i=0; i<n; i++) {
        int input;
        cin>>input;
        s.push_back(input);
    }
    cin>>q;
    for (int i=0; i<q; i++) {
        int input;
        cin>>input;
        t.push_back(input);
    }
         
    //???¢??´?¢?????????:t[i]
   for (int i=0; i<q; i++) {
       int low = 0; //???????????????
       int high = n; //???????????????
       int mid;
       while (low <= high) {
           mid = (low + high) / 2;
           if (s[mid] == t[i]) {
               ans++;
               break;
           }
           else if(s[mid] < t[i]){
               low = mid + 1;
           }
           else{
               high = mid - 1;
           }
       }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <stdlib.h>

#define N 50

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ib - ia;
}

int main() {
	static int ll[N];
	int n, k, i, sum;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &ll[i]);
	qsort(ll, n, sizeof *ll, compare);
	sum = 0;
	for (i = 0; i < k; i++)
		sum += ll[i];
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    if( s[0] == s[2] ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll N, D;
    cin >> N >> D;
    ll cnt = 0;

    rep (i, N) {
        ll x = 0;
        ll y = 0;
        cin >> x >> y;
        ll n = x*x + y*y;

        ll d = D*D;

        if (d >= n) cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using li = unsigned long long int;
using namespace std;

int main() {
    fastIO;
    string o, e;
    cin >> o >> e;
    for (size_t i = 0; i < o.size(); i++) {
        cout << o.at(i);
        if (e.size() != i)
            cout << e.at(i);
    }
}

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

ll k, x;

int main()
{
	cin >> k >> x;
	FOR( i, x - k + 1, x + k )
		if ( i >= -1000000 && i <= 1000000 )
			cout << i << " ";
	cout << "\n";
	return 0;
}


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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

ll N;
cin>>N;
cout<<((ceil(N/1000.0))*1000)-N<<endl;
return 0;
}


Measured memory_bytes: 3696
dish=[0]*5
less=[0]*5
cnt = 0

for i in range(5):
    dish[i] = int(input())

for i in range(5):
    less[i] = dish[i]%10
    if less[i]==0:
        less[i]+=10
index_less = less.index(min(less))
time = dish[index_less]

for i in range(5):
    while dish[i]%10>0:
        dish[i]+=1
    time+=dish[i]
    
print(time-dish[index_less])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
//const ll MOD=1000000007LL;
const ll MOD=998244353;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return a + b;
	}
	Seg_Tree(int n0_=1,T initial_=1,T M_=1){
		initsize(n0_,initial_,M_);
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}
 
	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] += x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}
 
	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}
 
	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}
};


int main(){

	ll N,Q;
	cin >> N >> Q;
	Seg_Tree<ll> sg(N+2,0,MOD);
	FOR(i,0,N){
		ll a;
		cin >> a;
		sg.update(i,a);
	}


	FOR(q,0,Q){
		ll a,b,c;
		cin >> a >> b >> c;
		if(a){
			cout << sg.query(b,c) << endl;
		}else{
			sg.update(b,c);
		}
	}
}



Measured memory_bytes: 12516
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main()	{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)	{
		cin>>a[i];
	}
	int mx=a[0],mn=a[0];
	int g=a[0];
	for(int i=1;i<n;i++)	{
		g=__gcd(g,a[i]);
		mx=max(mx,a[i]);
		mn=min(mn,a[i]);
	}
	for(int i=0;i<n;i++)	{
		if((int)abs(a[i]-k)%g==0 && k<=mx)	{
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 640
sub u1{my$i=pop;
	$p[$i]=$p[$i]&&$p[$i]!=$i?u1($p[$i]):$i+0
}
sub u2{my$i=pop;
	$q[$i]=$q[$i]&&$q[$i]!=$i?u2($q[$i]):$i+0
}
($N,$K,$L)=split$",<>;
for(1..$K){
	($a,$b)=split$",<>;
	$a=u1($a+0);
	$b=u1($b+0);
	if($a!=$b){
		$p[$a]=$b
	}
}
for(1..$L){
	($a,$b)=split$",<>;
	$a=u2($a+0);
	$b=u2($b+0);
	if($a!=$b){
		$q[$a]=$b
	}
}
++$h{u1($_),u2($_)}for 1..$N;
print$h{u1($_),u2($_)},$"for 1..$N


Measured memory_bytes: 41220
n,m=map(int,input().split())
s=[list(map(int,input().split()))[1:] for i in range(m)]
t=list(map(int,input().split()))


count=0
pattern=[]
for j in range(2**n):
  for k in range(m):
    switch=0
    for p in range(n):
      if (j>>p)&1 and p+1 in s[k]:
        switch+=1
    if switch%2!=t[k]:
      break
  else:
    count+=1
print(count)


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

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

    char array[h][w];

    int i,j;
    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            cin >> array[i][j];
        }
    }

    int flag;
    for(i=0; i<h; i++){
        flag = 1;
        for(j=0; j<w; j++){
            if(array[i][j] == '#'){
                flag = 0;
            }
        }
        if(flag == 1){
            for(j=0; j<w; j++){
                array[i][j] = '*';
            }
        }
    }

    for(i=0; i<w; i++){
        flag = 1;
        for(j=0; j<h; j++){
            if(array[j][i] == '#'){
                flag = 0;
            }
        }
        if(flag == 1){
            for(j=0; j<h; j++){
                array[j][i] = '*';
            }
        }
    }

    for(i=0; i<h; i++){
        flag = 0;
        for(j=0; j<w; j++){
            if(array[i][j] != '*'){
                cout << array[i][j];
                flag = 1;
            }
        }
        if(flag == 1){
            cout << endl;
        }
    }


    return 0;
}

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

int main()
{
    char col[2][3]={0};
    int i,j,k,count=0;

    for(i=0;i<2;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>col[i][j];

        }
    }

    for(i=0;i<2;i++)
    {
        for(j=0;j<3;j++)
        {
            if(i==0)
            k=1;

            if(i==1)
            k=0;

            if(col[i][j]==col[k][2-j])
            {
                count++;
            }
            else
            {
                cout<<"NO\n";
                exit(0);
            }
        }
    }
if(count==6)
cout<<"YES\n";
  
return 0;
}


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


public class Main {

	public static void main(String[] args) throws IOException {
		
		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");
		String ans = "No";
		
		if(s[2].equals(s[3]) && s[4].equals(s[5])) {
			ans = "Yes";
		}
		
		System.out.println(ans);
		}
}

Measured memory_bytes: 21844
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
typedef long long ll;
#define pii pair<int,pair<int,int>>
#define fi first
#define se second
#define mp make_pair
#define MAXN 106
int n , m;
int A[MAXN];
char S[MAXN][MAXN];
vector<int> G[MAXN];
#define fi first
#define se second
#define mp make_pair
priority_queue<pii> Q;
map<pair<int,int> , long long> dis; //int vis[MAXN];
map<pair<int,int> , int> vis;
void dijk( int s ) {
    dis[mp( 1 , 1 )] = S[1][1] == '#' , Q.push( mp( 0 , mp(1,1) ) );
    while( !Q.empty() ) {
        pair<int,int> u = Q.top().se; Q.pop();
        if( vis[u] ) continue;
        vis[u] = 1;
        pair<int,int> v; int w;
        if( u.fi + 1 <= n ) {
            v = mp(u.fi + 1, u.se);
            w = (S[u.fi + 1][u.se] == '#' && S[u.fi][u.se] == '.');
            if (!dis.count(v) || dis[v] > dis[u] + w)
                dis[v] = dis[u] + w, Q.push(mp(-dis[v], v));
        }
        if( u.se + 1 <= m ) {
            v = mp(u.fi, u.se + 1);
            w = (S[u.fi][u.se + 1] == '#' && S[u.fi][u.se] == '.');
            if (!dis.count(v) || dis[v] > dis[u] + w)
                dis[v] = dis[u] + w, Q.push(mp(-dis[v], v));
        }
    }
    cout << dis[mp( n , m )] << endl;
}
void solve() {
    cin >> n >> m;
    for( int i = 1 ; i <= n ; ++ i ) {
        scanf("%s",S[i] + 1);
    }
    dijk( 0 );
}

int main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
const int inf = 1 << 30;
int n, m, x, y = 0;ll z, w, h, sum = 0, ans = 0;
int main(void) {
	cin >> n; vector<int> a(n);
	map<int, int> mp;
	vector<int> p(1000100, 0);
	set<int> st;
	rep(i, n) {
		cin >> a[i];
		st.insert(a[i]);
		p[a[i]]++;
	}sort(ALL(a));
	if (a[0] == 1 && a[1] == 1) {
		cout << 0 << endl;
		return 0;
	}
  if(a[0] == 1){
    cout << 1 << endl;
    return 0;
  }
	for(int i : st) {
		int point = i;
		while (point <= 1000010) {
			p[point]++;
			point += i;
		}
	}
	rep(i, n) {
		if (p[a[i]] == 2) ans++;
	}cout << ans << endl;
}

Measured memory_bytes: 17164
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    a <- strToInt <$> getLine
    -- 出力
    putStrLn $ if a `mod`(sum $ map digitToInt (show a)) == 0 then "Yes" else "No"


Measured memory_bytes: 508
s=input()
n=len(s)-1
ans=0
for i in range(2**n):
  a=['']*(2*len(s)-1)
  for k in range(2*len(s)-1):
    if k%2==0:
      a[k]=s[k//2]
  for j in range(n):
    if (i>>j)&1==1:
      a[2*j+1]='+'
  ans+=eval(''.join(a))
print(ans)


Measured memory_bytes: 3060
#include  <stdio.h>
bool f[100001];
int c[100002];
int N,L,R;
int  main()
{
    for(int i=2;i <=100000;i++)
        if(!f[i])for(int j=i+i;j <=100000;j+=i)
            f[j]=true;
    for(int i=3;i <=100000;i+=2)
        if(!f[i]&&!f[(i+1)/2])
            c[i]++;
    for(int i=3;i <=100000;i++)
        c[i]+=c[i-1];
    scanf ("%d",&N);
    while(N--)
    {
        scanf ("%d%d",&L,&R);
        printf ("%d\n",c[R]-c[L -1]);
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/range/numeric.hpp>

#ifdef _MSC_FULL_VER
#include"randomizer.hpp"
#include"debug_print.hpp"
#endif

#include<cstdlib>
#include<ctime>

namespace lib
{
	template<class T>using pair = std::pair<T, T>;
	template<class T>constexpr T pow(T base, std::uint64_t p)
	{
		T ret = T(1);
		for (std::uint64_t i = 0; i <= 63; ++i)
		{
			if (((1ull << i) & p) != 0)
			{
				ret *= base;
			}
			base *= base;
		}
		return ret;
	}
	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

	struct union_find
	{
		std::vector<int> upper;
		union_find(std::size_t size):upper(size, -1) {}

		int group(int index)
		{
			if (upper[index] == -1)
			{
				return index;
			}
			else
			{
				return upper[index] = group(upper[index]);
			}
		}

		bool merge(int x, int y)
		{
			auto gx = group(x);
			auto gy = group(y);
			if (gx != gy)
			{
				upper[gx] = gy;
				return true;
			}
			return false;
		}

		auto get()
		{
			std::map<int, std::set<int>> ret;
			for (int i = 0; i < upper.size(); ++i)
			{
				ret[group(i)].emplace(i);
			}
			return ret;
		}

		auto tops()
		{
			std::set<int> ret;
			for (int i = 0; i < upper.size(); ++i)
			{
				ret.emplace(group(i));
			}
			return ret;
		}

		bool is_same_group(int x, int y)
		{
			return group(x) == group(y);
		}
	};
}

namespace out
{
	namespace detail
	{
		template<class>struct void_out
		{
			typedef void type;
		};
		template<class T>auto write(std::ostream& ost, T const& val)
			->typename void_out<decltype(ost << val)>::type
		{
			ost << val;
		}
		template<class T, class... Ts>void write(std::ostream& ost, T const& val, Ts const&... nexts)
		{
			write(ost, val);
			ost << " ";
			write(ost, nexts...);
		}
	}
	void write_line()
	{
		std::cout << std::endl;
	}
	template<class...Ts>void write_line(Ts const&... args)
	{
		detail::write(std::cout, args...);
		write_line();
	}
	template<class Range>void write_range(Range const& rng)
	{
		for (auto const& v : rng)
		{
			write_line(v);
		}
	}
}

namespace adaptor = boost::adaptors;

void Main()
{
	int N, A, B;
	std::cin >> N >> A >> B;
	int count[3] = {};
	for (int i : boost::irange(0, N))
	{
		int p;
		std::cin >> p;
		if (p <= A)
		{
			++count[0];
		}
		else if (p <= B)
		{
			++count[1];
		}
		else
		{
			++count[2];
		}
	}
	out::write_line(*boost::range::min_element(count));
}

int main()
{
	std::cin.tie(nullptr);
	std::cin.sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256