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

using ll = long long int;
using P = pair<int,int>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;

void chmin(int &a, int b){
    a = min(a, b);
}

int l[55], dp[55][50005];  // dp[i][j] i番目の切れ目まで見て最小長さがjであるときの最大長さの最小値
bool solve(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> l[i+1];
        l[i+1] += l[i];
    }
    for(int i=0;i<=n;i++){
        fill(dp[i], dp[i]+l[n]+1, INF);
    }
    dp[0][l[n]] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=l[n];j++){
            if(dp[i][j] == INF) continue;
            for(int k=i+1;k<=n;k++){
                int L = l[k]-l[i];
                chmin(dp[k][min(j,L)], max(dp[i][j], L));
            }
        }
    }
    int ans = INF;
    for(int i=0;i<l[n];i++){
        chmin(ans,dp[n][i]-i);
    }
    cout << ans << endl;
    return true;
}

int main(){
    solve();
    return 0;
}



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

int main(){
int n,i;
long a,min,max,sum;
min= 1000000;
max= -1000000;
sum=0;
cin >>n;
i=1;
while(i<=n){
     cin >> a;
      if (a<min) min=a;
      if (a>max) max=a;
      sum=sum+a;
      i++;
}
cout << min<<" "<<max<<" "<<sum<<endl;;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> pii;
 
mat mul(mat &A,mat &B){
    mat C(A.size(),vec(B[0].size()));
    for(int i = 0 ; i < (int)A.size() ; i++){
        for(int k = 0 ; k < (int)B.size() ; k++){
            for(int j = 0 ; j < (int)B[0].size() ; j++){
                C[i][j] = (C[i][j] + A[i][k]*B[k][j]);
            }
        }
    }
    return C;
}
 
mat pow(mat A,int n){
    mat B(A.size(),vec(A.size()));
    for(int i = 0 ; i < (int)A.size() ; i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mul(B,A);
        A = mul(A,A);
        n >>= 1;
    }
    return B;
}
 
int main(){
    int N,M,Z,s,t;
    while(cin >> N >> M >> Z, N){
        vector<pii> v;
        v.push_back(pii(0,0));
        for(int i = 0 ; i < M ; i++){
            cin >> s >> t;
            s--; t--;
            v.push_back(pii(s,t));
            v.push_back(pii(t,s));
        }
        int size = 2*M+1;
        mat A(size,vec(size,0));
        for(int i = 0 ; i < size ; i++){
            int n1 = v[i].second,p1 = v[i].first;
            for(int j = 0 ; j < size ; j++){
                if(i == j || j == 0) continue;
                int n2 = v[j].second,p2 = v[j].first;
                if(n2 == p1) continue;
                if(n1 == p2) A[i][j] = 1;
            }
        }
        bool ok = false;
        mat res = pow(A,Z);
        for(int i = 0 ; i < size ; i++){
            int now = v[i].second;
            ok |= (now == N-1 && res[0][i] != 0);
 
        }
        cout << (ok ? "yes" : "no") << endl;
    }
    return 0;
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=2019;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	string s;
	cin>>s;
	int i,n=sz(s);
	ll ans=0;
	vector<ll> v(2019);
	int a[n+1],ten=1;
	a[n]=0;
	v[0]++;
	RAP(i,n-1,0){
		a[i]=(a[i+1]+(s[i]-'0')*ten)%mod;
		v[a[i]]++;
		(ten*=10)%=mod;
	}
	REP(i,0,2018){
		ans+=v[i]*(v[i]-1)/2;
	}
	cout<<ans;
	return 0;
}

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

// a.cpp
// author: Seong Yong-ju ( @sei40kr )
// Copyright (c) 2017 Seong Yong-ju

#define DEBUG(x) cout << #x << ": " << x << endl

#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)

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

using namespace std;

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

  int a,b,c;
  cin >> a>> b>>c;
  cout << (a == b ? c : (b == c ? a : b)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    vector<int> d(n),a(q);
    rep(i,n)d[i]= k-q;
    rep(i,q)cin >> a[i];
    rep(i,q){
        ++d[a[i]-1];
    }
    rep(i,n){
        if(d[i]>0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;

}


Measured memory_bytes: 1408
// F# の詳細については、http://fsharp.org を参照してください
// 詳細については、'F# チュートリアル' プロジェクトを参照してください。
open System

[<EntryPoint>]
let main argv = 
  let n = Console.ReadLine() |> int
  
  let a = 
    Console.ReadLine().Split(' ')
    |> Array.map int
    |> Array.sort
  
  let myround x = 
    if x >= 0.0 then int (x + 0.5)
    else int (x - 0.5)
  
  let x = float (Array.sum a) / float n |> myround
  let f y = (y - x) * (y - x)
  let ans = Array.fold (fun s a -> s + f a) 0 a
  printfn "%A" ans
  0 // 整数の終了コードを返します



Measured memory_bytes: 6096
# coding: utf-8
s = list(input())
q = int(input())

first = []
end = []
f = 0
for _ in range(q):
    li = list(input().split())
    if len(li) == 1:
        f = ~f
    else:
        if li[1] == '1':
            if f == 0:
                first.append(li[2])
            else:
                end.append(li[2])
        else:
            if f == 0:
                end.append(li[2])
            else:
                first.append(li[2])
s = first[::-1] + s + end
if f == -1:
    s = s[::-1]
    
print(''.join(s))

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

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int,int> pii;

char a[1005][1005];
int par[1000005],vis[1000005],dis[1000005];
vector<int> g[1000005];
int find(int x) {return x==par[x]?x:par[x]=find(par[x]);}
int dir1[] = {-1,1,0,0};
int dir2[] = {0,0,1,-1};
int main() {
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n*m;++i) par[i]=i;
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    ii jj cin>>a[i][j];
    auto get = [&](int i,int j) {return (i-1)*m+j;};
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j) {
            if(a[i][j]=='#') continue;
            for(int k=0;k<4;++k) {
                int xx=i+dir1[k],yy=j+dir2[k];
                if(xx<=0||yy<=0||xx>n||yy>m||a[xx][yy]=='#') continue;
                par[find(get(xx,yy))] = find(get(i,j));
            }
        }
    }
    if(find(get(sx,sy)) == find(get(tx,ty))) return cout<<0<<endl,0;
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j) {
            if(a[i][j] == '#') continue;
            int u=find(get(i,j));
            for(int di=-2;di<=2;++di) {
                for(int dj=-2;dj<=2;++dj) {
                    int xx=i+di,yy=j+dj;
                    if(xx<=0||yy<=0||xx>n||yy>m||a[xx][yy]=='#') continue;
                    int v=find(get(xx,yy));
                    if(g[u].empty() || v!=g[u].back()) {
                        g[u].push_back(v);
                        g[v].push_back(u);
                    }

                }
            }
        }
    }
    queue<int> q;
    q.push(find(get(sx,sy)));
    vis[find(get(sx,sy))]=1;
    while(!q.empty()) {
        int cur=q.front();q.pop();
        for(int v:g[cur]) {
            if(vis[v]) continue;
            vis[v]=1;
            dis[v]=dis[cur]+1;
            q.push(v);
        }
    }
    if(!vis[find(get(tx,ty))])cout<<-1<<endl;
    else cout<<dis[find(get(tx,ty))]<<endl;
}

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

int main()
{
  int N, r[1000], w[1000];
  bool dp[1000];
  
  while(cin >> N, N) {
    for(int i = 0; i < N; i++) {
      cin >> r[i] >> w[i];
    }
    int sum = accumulate(r, r + N, 0);
    int* big = max_element(r, r + N);
    int add = 0;
  
    if(*big * 2 > sum) {
      int space = *big * 2 - sum;
      swap(w[big - r], w[N - 1]);
      memset(dp, false, sizeof(bool) * (space + 1));
      dp[0] = true;
      for(int i = 0; i < N - 1; i++) {
        for(int j = space; j >= w[i]; j--) {
          dp[j] |= dp[j - w[i]];
        }
      }
      for(int i = space; i >= 0; i--) {
        if(dp[i]) {
          add = space - i;
          break;
        }
      }
    }
    cout << sum + accumulate(w, w + N, 0) + add << endl;
  }
}

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

int w, h;
int dw[4] = {1,0,-1,0};
int dh[4] = {0,1,0,-1};
int brd[50][50];
int c[4];
int cost[4][50][50];//dir*50*50+h*50+w

void solve(){
	rep(i,4) rep(j,50) rep(k,50) cost[i][j][k] = INF;
	rep(i,h) rep(j,w) cin >> brd[i][j];
	rep(i,4) cin >> c[i];
	cost[0][0][0] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0,0));
	while(true){
		if(que.size() == 0) break;
		P q = que.top();
		que.pop();
		int dir = q.second/2500, hh = (q.second%2500)/50, ww = q.second%50;
		rep(i,4){
			int co, di;
			if(i == brd[hh][ww]) co = 0;
			else co = c[i];
			di = (dir+i)%4;
			if(0>hh+dh[di]||hh+dh[di]>=h||0>ww+dw[di]||ww+dw[di]>=w) continue;
			if(cost[di][hh+dh[di]][ww+dw[di]] <= cost[dir][hh][ww]+co) continue;
			cost[di][hh+dh[di]][ww+dw[di]] = cost[dir][hh][ww]+co;
			que.push(P(cost[di][hh+dh[di]][ww+dw[di]],di*2500+(hh+dh[di])*50+ww+dw[di]));
		}
	}
	int ans = INF;
	rep(i,4) ans = min(ans,cost[i][h-1][w-1]);
	cout << ans << endl;
}

int main(){
	while(true){
		cin >> w  >> h;
		if(w == 0 && h == 0) break;
		solve();
	}
}
	
	
	
	
	
	
	

Measured memory_bytes: 1304
r,g,b,n = $stdin.read.split(" ").map(&:to_i)
 
result = 0
 
(n+1).times do |i|
  (n+1).times do |j|
    ko = i * r + j * g
      if ko > n
        break
    elsif (n - ko) % b == 0
        result +=1
    end    
          
  end
end
 
puts result

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

bool dp[2000009];

int main()
{
    int n, i, j, a[2009], sum = 0;

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

    dp[0] = 1;


    for(i = 0; i < n; i++)
    {
        for(j = sum/2; j >= a[i]; j--)
        {
            dp[j] |= dp[j - a[i]];
        }
    }

    for(i = sum/2; i >= 0; i--)
    {
        if(dp[i])
        {
            cout << sum - i;
            return 0;
        }
    }
}


Measured memory_bytes: 5552
#include<iostream>
#include<map>
using namespace std;
int main()
{
	string s,t,t1;
	map<string,int>p;
	cin>>s>>t;
	cin>>p[s]>>p[t];
	cin>>t1;
	p[t1]--;
	cout<<p[s]<<" "<<p[t]<<endl;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define size_of(a) (int)(a).size()

class Alphabet {
public:
	static const int N = 4;
	
	inline int toInt(char c) {
		if (c == 'A') return 0;
		if (c == 'C') return 1;
		if (c == 'G') return 2;
		if (c == 'T') return 3;
		return -1;
	}
};

class Trie {
private:
	struct Node {
		vector< int > link;
		bool end;
		Node(int n) : link(n, -1),  end(false) {}
	};
	
	Alphabet& alph;
	vector< Node > node;
	
public:
	Trie(Alphabet& alph_) : alph(alph_) {
		node.push_back(Node(alph.N));
	}
	
	void insert(string& str) {
		insert(str, 0, 0);
	}
	
	void insert(string& str, int i, int vi) {
		if (i == size_of(str)) {
			node[vi].end = true;
			return;
		}
		
		int ci = alph.toInt(str[i]);
		
		if (node[vi].link[ci] != -1) {
			insert(str, i + 1, node[vi].link[ci]);
		} else {
			node.push_back(Node(alph.N));
			node[vi].link[ci] = size_of(node) - 1;
			insert(str, i + 1, node[vi].link[ci]);
		}
	}
	
	bool find(string& str) {
		return find(str, 0, 0);
	}
	
	bool find(string& str, int i, int vi) {
		if (i == size_of(str)) return node[vi].end;
		
		int ci = alph.toInt(str[i]);
		
		if (node[vi].link[ci] == -1) return false;
		return find(str, i + 1, node[vi].link[ci]);
	}
};

int main() {
	Alphabet alph;
	Trie trie(alph);
	
	int n;
	cin >> n;
	
	for_(i,0,n) {
		string op, str;
		cin >> op >> str;
		
		if (op == "insert") {
			trie.insert(str);
		} else {
			if (trie.find(str)) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
}

Measured memory_bytes: 34280
const MAX: i64 = 100_000_000_000;
fn solve(graph: Vec<Vec<(usize, i64)>>) {
    let size = graph.len();
    let mut shortest: Vec<Vec<_>> = vec![vec![MAX; size]; size];
    let mut prev: Vec<Vec<_>> = vec![vec![size + 1; size]; size];
    for i in 0..size {
        shortest[i][i] = 0;
        prev[i][i] = i;
    }
    for _ in 0..size - 1 {
        for (from, edges) in graph.iter().enumerate() {
            // Update for label i.
            for layer in 0..size {
                if shortest[layer][from] == MAX {
                    continue;
                }
                for &(to, weight) in edges {
                    let alternative_path = shortest[layer][from] + weight;
                    if alternative_path < shortest[layer][to] {
                        shortest[layer][to] = alternative_path;
                        prev[layer][to] = from;
                    }
                }
            }
        }
    }
    // Check negative cycle.
    for layer in 0..size {
        for from in (0..size).filter(|&from| shortest[layer][from] != MAX) {
            for &(to, weight) in &graph[from] {
                let alternative_path = shortest[layer][from] + weight;
                if alternative_path < shortest[layer][to] {
                    // Negative cycle.
                    println!("NEGATIVE CYCLE");
                    return;
                }
            }
        }
    }
    for layer in 0..size {
        for i in 0..size {
            let s = shortest[layer][i];
            if s == MAX && i < size - 1 {
                print!("INF ");
            } else if s == MAX && i == size - 1 {
                println!("INF");
            } else if i < size - 1 {
                print!("{} ", s);
            } else {
                println!("{}", s);
            }
        }
    }
}

use std::io::{BufRead, BufReader};
fn main() {
    let mut read = BufReader::new(std::io::stdin())
        .lines()
        .filter_map(|e| e.ok());
    let (v, _e) = {
        let line = read.next().unwrap();
        let line: Vec<&str> = line.split(' ').collect();
        let v: usize = line[0].parse().unwrap();
        let e: usize = line[1].parse().unwrap();
        (v, e)
    };
    let graph = {
        let mut graph: Vec<Vec<_>> = vec![vec![]; v]; // Adj list
        for edge in read {
            if edge.is_empty() {
                break;
            }
            let mut edge = edge.split(' ');
            let start: usize = edge.next().unwrap().parse().unwrap();
            let end: usize = edge.next().unwrap().parse().unwrap();
            let weight: i64 = edge.next().unwrap().parse().unwrap();
            graph[start].push((end, weight));
        }
        graph
    };
    solve(graph);
}



Measured memory_bytes: 5060
array_index = gets(chomp:true).to_i
  array = gets(chomp:true).split.map(&:to_i)

  rep_count = 0

  for loop_num in 0...array_index

    rigth_ope_index = array_index - 1
    left_cmp_index = rigth_ope_index - 1

    while left_cmp_index >= loop_num 

      while array[left_cmp_index] > array[rigth_ope_index]

        temp_elem = array[rigth_ope_index]

        array[rigth_ope_index] = array[left_cmp_index]
        array[left_cmp_index] = temp_elem

        rep_count += 1
      end

      left_cmp_index -= 1
      rigth_ope_index -= 1
    end

  end

  puts array.join(" ")
  puts rep_count



Measured memory_bytes: 6872
#include<stdio.h>
int main()
{
    double a,b,c,d,e,f,x,y,z;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
            z=(a*e-d*b);
            if((int)z!=0){
            x=(e*c-b*f)/z;
            y=(a*f-d*c)/z;
            if(x==-0){
                x=0;
            }
            else if (y==-0){
                y=0;
            }
            printf("%0.3lf %0.3lf\n",x,y);


       }
    }
    return 0;
}

Measured memory_bytes: 652
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 2e6 + 10 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T> void read(T &a)
{
	int f = 1 ; a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	a *= f;
}

ll n, k, a[maxn];

ll ans;

signed main()
{
	scanf("%lld %lld", &n, &k);
	rep(i, 1, n) scanf("%lld", &a[i]);
	rep(i, 1, n)
	{
		rep(j, i + 1, n)
		{
			if(a[i] > a[j]) (ans += k * (k + 1) / 2) %= mod;
			if(a[i] < a[j]) (ans += k * (k - 1) / 2) %= mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (IsPrime(int.Parse(Console.ReadLine()))) {
                cnt++;
            }
        }

        Console.WriteLine(cnt);
    }

    static bool IsPrime(int x) {
        if (x == 2) { return true; }
        if (x % 2 == 0) { return false; }

        for (int i = 3; i <= Math.Sqrt(x); i += 2) {
            if (x % i == 0) { return false; }
        }
        return true;
    }
}



Measured memory_bytes: 17848
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
map<ll,bool>mp;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll i,a,b,c,n,m,l,r;
    cin>>a>>b>>c;
    r=a;
    m=c%b;
    l=a%b;
    if(l==m)
    {
        cout<<"YES\n";
        return 0;
    }
    mp[l]=true;
    for(i=1; ;i++)
    {
        a+=r;
        l=a%b;
        if(mp[l]==true)
        {
            break;
        }
        if(l==m)
        {
            cout<<"YES\n";
            return 0;
        }
        mp[l]=true;
    }
    cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.range, std.format, std.numeric, std.string, std.conv, std.array;

void main() {
    int a, b, c, d;
    readf("%d\n", &a);
    readf("%d\n", &b);
    readf("%d\n", &c);
    readf("%d\n", &d);
    writeln(min(a, b) + min(c, d));
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,len,cnt,ans;
string str;
int main(){
  while(cin>>n&&n){
    cin>>len>>str;
    cnt=ans=0;

    for(int i=0;i+2<len;i++){
      if(str[i]=='I'&&str[i+1]=='O'&&str[i+2]=='I'){
	i++;cnt++;
	if(cnt>=n)ans++;
      }else cnt=0;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;
ll f(ll n, ll x) {
    if (n == -1) {
        return 0;
    }
    return n / x + 1;
}

int main() {
    STARTUP;

    ll A, B, X;
    cin >> A >> B >> X;

    cout << f(B, X) - f(A - 1, X) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [0 for _ in range(N)]
b = [0 for _ in range(N)]
c = [0 for _ in range(N)]

for i in range(N):
    a[i], b[i], c[i] = map(int, input().split(" "))
happy = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    if i == 0:
        happy[i][0] = a[i]
        happy[i][1] = b[i]
        happy[i][2] = c[i]
    else:
        happy[i][0] = max(happy[i-1][1]+a[i], happy[i-1][2]+a[i])
        happy[i][1] = max(happy[i-1][0]+b[i], happy[i-1][2]+b[i])
        happy[i][2] = max(happy[i-1][0]+c[i], happy[i-1][1]+c[i])
print(max(happy[-1]))

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

int main(void){

    char S[100000],S_sub[100000];
    int i,lenth,result = 0;

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

    if(S[0] == '0'){
        for(i = 0;i < lenth;i++){
            if(i % 2 == 0){
                S_sub[i] = '0';
            }else{
                S_sub[i] = '1';
            }
        }
    }else{
        for(i = 0;i < lenth;i++){
            if(i % 2 == 0){
                S_sub[i] = '1';
            }else{
                S_sub[i] = '0';
            }
        }
    }

    for(i = 0;i < lenth;i++){
        if(S[i] != S_sub[i]){
            result++;
        }
    }
    
    printf("%d",result);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

using namespace std;


int main() {
	int a , b , c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;

	return 0;

}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n;
  cin >> n;
  
  if(n>=1 && n<=9){
    cout << "Yes" << endl;
  }
  
  else{
    bool can = false;
    for(int i = 2; i <= 9; i++){
      if(n%i == 0 && n/i>=2 && n/i<=9){
        cout << "Yes" << endl;
        can = true;
        break;
      }
    }
    
    if(!can) cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
def solve(a,b):
  def needTaps(a,b,holes=1,res=0):
    if holes >= b:
      return res
    else:
      return needTaps(a,b,holes+a-1,res+1)
    
  return needTaps(a,b)

a,b=map(int,input().split())
print(solve(a,b))


Measured memory_bytes: 9152
n, m = map(int, input().split())

a = [[1, False] for _ in range(n+1)]
a[1] = [1, True]

for _ in range(m):
    x, y = map(int, input().split())
    if a[x][1]:
        a[y][1] = True
    
    a[x][0] -= 1
    if a[x][0] == 0:
        a[x][1] = False
    a[y][0] += 1

print(sum(x[1] for x in a))

Measured memory_bytes: 13172
h,w,k = map(int,input().split())

c = list(input() for i in range(h))

for i in range(h):
    c[i]=list(c[i])


#いじってもいいやつを設定する
import copy
c_copy = copy.deepcopy(c)

#行の操作(h)
g = []
for i in range(2 ** h) :
    gyou = ["0"] * h
    for j in range(h):
        if ((i >> j) & 1):
            gyou[j] = "1"
    g.append(gyou)
#列の操作(w)
r = []
for p in range(2 ** w):
    retsu = ["0"] * w
    for q in range(w):
        if ((p >> q) & 1):
            retsu[q] = "1"
    r.append(retsu)

#行列を"."にする
def aka(a,b):
    #行を.にする
    for i in range(h) :
        if g[a][i] == "1" :
            for k in range(w) :
                c_copy[i][k] = "."
    #列を.にする
    for j in range(w) :
        if r[b][j] == "1" :
            for l in range(h) :
                c_copy[l][j] = "."
    return c_copy

import itertools

ans = 0
for a in range(2**h):
    for b in range(2**w):
        l = list(itertools.chain.from_iterable(aka(a,b)))
        if l.count('#') == k :
            ans += 1
        c_copy = copy.deepcopy(c)

print(ans)


Measured memory_bytes: 9324
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return set(divisors)


def is_dividable(x, d_set):
    for d in d_set:
        if x % d == 0 and d != 1:
            return True

    return False


a, b = map(int, input().split(' '))
divs_a = make_divisors(a)
divs_b = make_divisors(b)

common_div = [x for x in divs_a if x in divs_b]
common_div.sort()

seq = set()
for x in common_div:
    if not is_dividable(x, seq):
        seq.add(x)

# print(seq)
print(len(seq))


Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main(){
  ll n,ans=0,cnt=10;
  cin>>n;
  if(n%2==0){
    while(n>=cnt){
      ans+=n/cnt;
      cnt*=5;
    }
  }else{
    ans=0;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  if (A + B < C + D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  
  long long a,b,c,d,e,ans2,ans1,i; 
  
  while(scanf("%lld %lld",&a,&b)!=EOF){
    
    if(b>a){
      c=a;
      a=b;
      b=c;
    }

    d=a;
    e=b;

    while(1){
      c=a%b;
       a=b;
       b=c;
       if(c==0){
	 break;
       }
    }
     ans1=a;

     ans2=(d*e)/ans1;
     
     printf("%lld %lld\n",ans1,ans2);
     a=b=c=ans1=0;
     ans2=0;
  }
  
  return 0;
}

Measured memory_bytes: 596
LRC = $<.map{|ln| ln.split.map(&:to_i) }
N,M = LRC.shift

RC = [[1,0]]
LRC.sort_by{|_,r| r }.each{|l,r,c|
	i = (0...RC.size).bsearch{|i| l<=RC[i][0] }||next
	c += RC[i][1]
	j = (i...RC.size).bsearch{|j| c<RC[j][1] }
	RC.pop(RC.size-j) if j
	RC.push([r,c]) if RC[-1][0] < r
}

r,c = RC[-1]
p(r<N ? -1 : c)


Measured memory_bytes: 44572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> v(n);
    vector<int> hist(2 * 1010, 0);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        hist[v[i] - 1]++;
    }
    
    // ヒストグラムの累積とるよー
    vector<int> sum(hist.size() + 1, 0);
    for(int i = 1; i < sum.size(); i++) {
        sum[i] = sum[i - 1] + hist[i - 1];
    }
    
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int left = abs(v[i] - v[j]) + 1;
            int right = v[i] + v[j] - 1;
            
            ans += sum[right] - sum[left - 1];
            
            // 既に固定してる2点が選ばれたら引いておく
            if(left <= v[i] && v[i] <= right) ans--;
            if(left <= v[j] && v[j] <= right) ans--;
        }
    }
    
    // 同じ三角形が3回出てくるから割ってあげるよー
    cout << ans / 3 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

//----------------------------------------



int main(void)
{
	int n, d;

	cin >> n >> d;


	int ten[11][11];

	rep(i, n)
	{
		rep(j, d)
		{
			cin >> ten[i][j];
		}
	}

	int ans = 0;

	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < i; j++)
		{
			float dist = 0;
			rep(k, d) dist += pow(ten[i][k] - ten[j][k], 2);

			float root = sqrt(dist);

			if (root == round(root)) ans++;

		}

	}



	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
n = min(N, 10**6)
is_Prime = [True] * (n + 1)
is_Prime[0] = False
is_Prime[1] = False
for i in range(2, int(n**(1/2)+1)):
    for j in range(2*i, n+1, i):
        if j % i == 0:
            is_Prime[j] = False
P = [i for i in range(n+1) if is_Prime[i]]

count = 0
for p in P:
    count_p = 0
    while N % p == 0:
        count_p += 1
        N /= p
    count += int((-1+(1+8*count_p)**(1/2))/2)
    if p == P[-1] and N != 1:
        count += 1
print(count)

Measured memory_bytes: 82596
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define MAX 1000

using namespace std;
long int N, ans, cnt, sum;
bool flg;

int main() {
	int S, K;
	cin >> K >> S;
	rep(i, K) {
		rep(j, K) {
			int temp = S - i - j;
			if (temp >= 0 && temp <= K)
				cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		//????????¨?¨???????????????????
		Scanner sc = new Scanner(System.in);

		//
		while(true){
			int intH = sc.nextInt();
			int intW = sc.nextInt();

			if((intH == 0) && (intW == 0)){
				break;
			}

			for(int i = 0; i < intH; i++){
				String A = "";
				for(int j = 0; j < intW; j++){
					A += "#";
					//if(j == (intW - 1)){
					//	System.out.println("#");
					//}else{
					//	System.out.print("#");
					//}
				}
				System.out.println(A);
			}
			System.out.println("");


		}
	}
}

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }//Nｺの整数配列

    
    int p = 0;
    for (int k = 0; k < 30; k++) {
        int x = 0;
        for (int j = 0; j < N; j++) {
            if (vec.at(j) % 2 == 0) x++;
        }
        if (x == N) {
            p++;
            for (int l = 0; l < N; l++)vec.at(l) = vec.at(l) / 2;
        }
        else break;
    }
    cout << p << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int[] stack = new int[200];
        int idx = 0;
        while (in.hasNext()) {
            String next = in.next();
            if (next.equals("+")) {
                stack[idx - 2] = stack[idx - 2] + stack[idx - 1];
                idx--;

            } else if (next.equals("-")) {
                stack[idx - 2] = stack[idx - 2] - stack[idx - 1];
                idx--;

            } else if (next.equals("*")) {
                stack[idx - 2] = stack[idx - 2] * stack[idx - 1];
                idx--;

            } else {
                int n = Integer.valueOf(next);
                stack[idx++] = n;
            }
        }
        System.out.println(stack[0]);
    }
}

Measured memory_bytes: 26304
MOD = 10**9 + 7
N,A,B= map(int,input().split())

n = 200000
fact = [1]*(n+1)
inv = [1]*(n+1)
ifact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = fact[i-1]*i % MOD
    inv[i] = pow(i,MOD-2,MOD)
    ifact[i] = ifact[i-1]*inv[i] % MOD

pa = 1
for i in range(N,N-A,-1):
    pa = (pa * i) % MOD

pb = pa

for i in range(N-A,N-B,-1):
    pb = (pb * i) % MOD

q = 1
for i in range(B,A,-1):
    q  = (q * i) % MOD

bans =( (pow(2,N,MOD) * fact[B]) - q * pa - pb) % MOD

ans = (bans * ifact[B] -1) % MOD
print(ans)








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

using namespace std;

//Shortcut
#define long long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define sz size
#define ft(i , a , b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i , a , b) for (long i = (long)a ; i >= (long)b ; i--)
#define lt(i , a , b , c) for (long i = (long)a ; i <= (long)b ; i += (long)c)
#define ld(i , a , b , c) for (long i = (long)a ; i >= (long)b ; i -= (long)c)
#define pll pair <long , long>
#define pls pair <long , string>
#define vtl vector <long>
#define vts vector <string>
#define mll map <long , long>

//Variable
const long mxN = 1e5 + 5;
const long base = 311;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const long d4i[4] = {-1 , 0 , 1 , 0} , d4j[4] = {0 , 1 , 0 , -1};
const long d8i[8] = {-1 , -1 , 0 , 1 , 1 , 1 , 0 , -1} , d8j[8] = {0 , 1 , 1 , 1 , 0 , -1 , -1 , -1};

long TestCase;
long n , s;
long ans[mxN];

void Solve() {
    ft(i , 1 , 100)
    ft(j , 1 , 100)
    ft(l , 1 , 100) {
        s = i * i + j * j + l * l + i * j + j * l + i * l;
        if (s <= 1e4) ans[s]++;
    }
    cin >> n;
    ft(i , 1 , n) cout << ans[i] << "\n";
}   

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}

Measured memory_bytes: 3588
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin>>s>>t;
    ll n=s.sz,ans=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int n, t, a, h;

    cin >> n;
    cin >> t >> a;
    int  ans = 0;
    double min;
    for(int i = 0; i < n; i++){
        cin >> h;
        double tmp = t - h*0.006;
        if(i == 0){
            ans = 0;
            min = abs(tmp-a);
        }else{
            if(min > abs(tmp-a)){
                min = abs(tmp-a);
                ans = i;
            }
        }
    }

    cout << (ans+1) << endl;
}

Measured memory_bytes: 3576
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 500005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n;
ll a,b,c,d;
int main()
{
    scanf("%d",&n);
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    for(int i=0;i<=n-1;i++)
    {
        ll l=a+i*c-(n-1-i)*d,r=a+i*d-(n-1-i)*c;
        if(b>=l&&b<=r) {puts("YES"); return 0;}
    }
    puts("NO");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <set>
//#define LOCAL
using namespace std;
typedef long long ll;
set<ll>s;

int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll q;
cin>>q;
for(ll i=0;i<q;i++){
    ll a,b;
    cin>>a>>b;
    if(0==a){
        s.insert(b);
        cout<<s.size()<<endl;
    }else if(1==a){
        cout<<s.count(b)<<endl;
    }else if(2==a){
        s.erase(b);
    }else{
        ll t;
        cin>>t;
        set<ll>::iterator i1=s.lower_bound(b);
        set<ll>::iterator i2=s.upper_bound(t);
        for(;i1!=i2;i1++) cout<<(*i1)<<endl;
    }
}

#ifdef LOCAL
fin.close();
#endif // LOCAL
}



Measured memory_bytes: 12336
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;

int main()
{
	int n, d, x;
	cin >> n;
	cin >> d >> x;
	for(int i = 1; i <= n; i++)
	{
		int m;
		cin >> m;
		for(int i = 0; i * m + 1 <= d; i++)
			x++;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
def gridbfs(grid):
    INF = 10**18

    gridy = len(grid)
    gridx = len(grid[0])

    dist = [[INF]*gridx for _ in range(gridy)]
    q = deque()
    for y in range(gridy):
        for x in range(gridx):
            if grid[y][x] == '#':
                dist[y][x] = 0
                q.append((y,x))

    while q:
        y,x = q.popleft()
        for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
            ny,nx = y+dy, x+dx
            if not (0 <= ny < gridy and 0 <= nx < gridx):
                continue
            if dist[ny][nx] != INF:
                continue
            dist[ny][nx] = dist[y][x] + 1
            q.append((ny,nx))

    return dist

H,W = map(int,input().split())
Grid = [input() for _ in range(H)]
d = gridbfs(Grid)
print(max(max(d[i]) for i in range(H)))


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

int main() {
    int a, b;  cin >> a >> b;
    if (a % 3 == 0)  cout << "Possible" << endl;
    else if (b % 3 == 0)  cout << "Possible" << endl;
    else if ((a+b) % 3 == 0)  cout << "Possible" << endl;
    else  cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll x, y;
  cin >> x >> y;
  if (y % 2 != 0) {
    no();
  }

  ll b = y / 2 - x;
  if (b < 0 || b > x) {
    no();
  }

  yes();
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>

bool input(std::map<std::string, int> & data)
{
	int    no;
	char   comma;
	std::string blood_type;
	if (std::cin >> no >> comma >> blood_type) {
		data[blood_type]++;
	}
	else {
		return false;
	}
	return true;
}
void output(std::map<std::string, int> data)
{
	std::cout << data["A"]  << std::endl;
	std::cout << data["B"]  << std::endl;
	std::cout << data["AB"] << std::endl;
	std::cout << data["O"]  << std::endl;
}
int main()
{
	std::map<std::string, int> data;
	while (input(data));
	output(data);
}

Measured memory_bytes: 1216
using System;
using System.Linq;

namespace AGC017
{
    class A2
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long P = input[1];
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long eCount = 0;
            long oCount = 0;

            for (int i = 0; i < N; i++)
            {
                if (A[i] % 2 == 0) eCount++;
                else oCount++;
            }

            if (N == eCount && P == 1) Console.WriteLine(0);
            else if (N == eCount && P == 0) Console.WriteLine(Math.Pow(2, N));
            else Console.WriteLine(Math.Pow(2, N - 1));
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k, res = INF; cin >> n >> k;
    ll x[n];
    for(ll i = 0; i < n; i++) cin >> x[i];
    for(ll i = 0; i + k - 1 < n; i++){
        chmin(res, min(x[i+k-1]-x[i]+abs(x[i+k-1]), x[i+k-1]-x[i]+abs(x[i])));
    }
    cout << res;
    cout << endl;
    return 0;
}



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

int main(){
 int N;
 cin >> N;
 int count = 0;
 for(int i = 1; i <= N; i++){
   if((0 <= log10(i) && log10(i) < 1) || (2 <= log10(i) && log10(i) < 3) || (4 <= log10(i) && log10(i) < 5)){
    count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3852
#include<stdio.h>
int main(void)
{
    long sum;
    int min,max,a[10000],n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(i==0)
        {
            min=a[i];
            max=a[i];
        }
        else if(a[i]>max)
        {
            max=a[i];
        }
        else if(a[i]<min)
        {
            min=a[i];
        }
        sum+=a[i];
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}
   

Measured memory_bytes: 636
#include <iostream>
#include <string>
using namespace std;
int main(){
    string a;
    cin >> a;
    int count_max=0;
    for(int i = 0;i<a.length();i++){
    int count=0;
    int j = i;
    while(a[j]=='A'||a[j]=='G'||a[j]=='C'||a[j]=='T'){
     count++;
     j++;
    }
    if(count_max<count) count_max = count;
    }
    cout << count_max<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
const int maxn = 2e5+10;
long long A[maxn];
map<long long, int> mp;
int main(){
    int n;
    cin>>n;
    mp.clear();
    long long ans = 0;
    for(int i=1; i<=n; i++){
        cin>>A[i];
        ans += mp[i-A[i]];
        mp[i + A[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 27836
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <iostream>
#include <cmath>
#include <queue>

using namespace std;

typedef long long ll;

const int N = 501;

int n , k,g[500 * 500 + 10],a;

vector< pair<int,int> > x;

int idx = 1;

vector< pair<int,int> > h;

int main(){
//	freopen("input.txt","r",stdin);
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i){
		scanf("%d",&a);
		x.push_back(make_pair(a,i));
		g[a] = i;
	}
	sort(x.begin(),x.end());
	for (int j = 0 ; j < x.size(); ++j){
		int i = x[j].second;
		int last = x[j].first;
		int need = i - 1;
		while(need && idx < last){
			if(g[idx]){
				idx++;
				continue;
			}
			g[idx] = i;
			need--;
			idx++;
		}
		if(need){
			puts("No");
			return 0;
		}
	}
	for (int j = 0 ; j < x.size(); ++j){
		int rem = n - x[j].second;
		int last = x[j].first;
		while(rem && idx <= n * n){
			if(g[idx]){
				idx++;
				continue;
			}
			if(idx < last){
				puts("No");
				return 0;
			}
			g[idx] = x[j].second;
			rem--;
			idx++;
		}
	}
	puts("Yes");
	for (int i = 1 ; i <= n * n; ++i){
		if(i > 1)
			printf(" ");
		printf("%d", g[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 2176