akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <bits/basic_ios.h>

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
string s;
const int N = 1e5 + 55;
const int inf = 1e16;
int cntr[2] = {0}, cntp[2] = {0};
void solve() {
	int n = (int) s.size();
	cin >> s;
	int pref_score = 0, mx = -inf;
	for (int i = 0; i < (int) s.size(); ++i) {
		if (s[i] == 'g')
			cntr[i % 2]++;
		else 
			cntp[i % 2]++;
	}
	for (int i = 0; i < (int) s.size(); i += 1) {
		if (s[i] == 'g')
			cntr[i % 2]--;
		else 
			cntp[i % 2]--, pref_score--;
		int rest_score = 0;
		rest_score += cntr[(i + 1) % 2];
		rest_score -= cntp[i % 2];
		// can convert rock to paper
		// (i + 1) / 2 times
		int rem_length = n - i - 1;
		int rem_rocks = rem_length / 2;
		rem_rocks = min(rem_rocks, (i + 1) / 2);
		rest_score += rem_rocks;
		mx = max(mx, pref_score + rest_score);
	}
	cout << mx;
}	


Measured memory_bytes: 512
N, Y = map(int, input().split())        
Anser = [-1, -1, -1]

flag = False

for i in range(N+1):
    if flag == True: break
    for j in range(N+1-i):
        if flag == True: break
        if Y == 10000*i + 5000*j +1000*(N-i-j): 
            Anser =[i, j, N-i-j]
            flag = True

print(*Anser)

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n);
	for(auto&i:a)cin>>i;
	sort(a.begin(),a.end(),[](auto a,auto b){return a>b;});
	int tmp=a.front(),place=0;
	while(tmp){
		++place;
		tmp/=2;
	}
	vector<int>cnt(place+1,0);
	for(auto&i:a){
		int j=1,p=1;
		while(j<=place){
			if(p&i)++cnt.at(j);
			++j;
			p=p<<1;
		}
	}
	bool yes=true;
	for(int i=1;i<cnt.size();++i){
		if(cnt.at(i)%2!=0)yes=false;
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

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

using std::cin;
using std::vector;
using std::cout;

#define fa for(int i=0;i<5;i++)
int main(){
        int a;
        vector<int> arr;
        bool x=false;
        fa{ 
                cin>>a;
                arr.push_back(a);
        }   
        fa{ 
                if(arr[i]==0){
                        cout<<i+1;
                        x=true;
                  break;
                }   
        }   
        if(x==false){
                cout<<0;
        }   
        return 0;
}

Measured memory_bytes: 3588
N, M = map(int, input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)]

first_element = set()
second_element = set()

for element in input_list:
    if element[0] == 1:
        first_element.add(element[1])
    elif element[1] == N:
        second_element.add(element[0])

if first_element & second_element:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 46472
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std; using ll=long long; const int INF=1e9; using P=pair<int,int>;

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

Measured memory_bytes: 5180
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

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

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc124/tasks/abc124_b

int N, H[20];

int main() {
  cin >> N;

  rep(i, N) { cin >> H[i]; }

  int ans = 0;
  int mx = 0;
  rep(i, N) {
    if (H[i] >= mx)
      ans++;
    mx = max(mx, H[i]);
  }

  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    int numdot = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> s[i][j];
            if (s[i][j] == '.')
            {
                numdot++;
            }
        }
    }
    vector<int> dx = {1, 0, 0, -1};
    vector<int> dy = {0, 1, -1, 0};
    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[0][0] = 0;
    queue<P> que;
    que.push({0, 0});
    while (!que.empty())
    {
        P p = que.front();
        que.pop();
        int x = p.fi;
        int y = p.se;
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx >= 0 && nx < h && ny >= 0 && ny < w && dist[nx][ny] == -1 && s[nx][ny] == '.')
            {
                que.push({nx, ny});
                dist[nx][ny] = dist[x][y] + 1;
            }
        }
    }
    if(dist[h-1][w-1]==-1){
        quit(-1);
    }
    cout << numdot - dist[h - 1][w - 1] - 1 << endl;
    // debug_vec2(dist);
    // debug(numdot);

    return 0;
}


Measured memory_bytes: 3644
N,M,X=list(map(int,input().split()))
A=list(map(int,input().split()))
left_feeStation=0
right_feeStation=0
for i in range(X):
    if i in A:
        left_feeStation+=1
for i in range(X+1, N+1):
    if i in A:
        right_feeStation+=1
print(min(left_feeStation, right_feeStation))

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

def SumDigits(num):
    sum = 0
    while True:
        sum += num % 10
        num //= 10
        if num == 0:
            break
    return sum

infinity = float('inf')
min = infinity

for x in range(1, N):
    if SumDigits(x) + SumDigits(N - x) < min:
        min = SumDigits(x) + SumDigits(N - x)
print(min)


Measured memory_bytes: 2940
#include <stdio.h>

int main(){
    int n=0, q=0, C=0;
    int S[100000]={0}, T[100000]={0};
    int i=0, j=0, k=0;
    int key, left, right, mid;
    
    scanf("%d", &n);
    for (i=0; i<n; i++){
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for (j=0; j<q; j++){
        scanf("%d", &T[j]);
    }
    

    for (j=0; j<q; j++){
        key = T[j];
        left = 0;
        right = n;
        while(left < right){
            //printf("%d %d %d \n",left,mid,right);
            mid = (left + right) / 2;
            if(S[mid] == key) {
                C++;
                break;
            }else if(key < S[mid]){
                right = mid;
            }else{
                left = mid + 1;
            }
        }
    }
    
    printf("%d\n",C);
    return 0;
}


Measured memory_bytes: 2564
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;

void print(vector<int> v){
    for (int i=0; i<(int)v.size(); ++i) {
        cout << (i==0 ? "" : " ") << v[i];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);

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

    print(A);
    for (int j=1; j<n; ++j) {
        int key = A[j];
        int i = j-1;
        while (i >= 0 && A[i] > key) {
            A[i+1] = A[i];
            -- i;
        }
        A[i+1] = key;
        print(A);
    }

    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>

using namespace std;

int main() {
    int n, m, x, y; cin >> n >> m >> x >> y;
    vector<int> xs;
    xs.resize(n);
    for (int i = 0; i < n; ++i) cin >> xs[i];
    vector<int> ys;
    ys.resize(m);
    for (int i = 0; i < m; ++i) cin >> ys[i];

    int xmax = *max_element(xs.begin(), xs.end());
    xmax = max(xmax, x);
    int ymin = *min_element(ys.begin(), ys.end());
    ymin = min(ymin, y);

    cout << (xmax < ymin ? "No War" : "War") << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s;

int main(){
	cin >> s;
	int ma=s.size();
	REP(i,0,s.size()-1) if(s[i]!=s[i+1]) ma=min(ma, max(i+1,(int)s.size()-(i+1)));
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
map<string,int>mp;
string s;
int n,ans;
void solve()
{
    cin>>n;
    rep(i,1,n){
        cin>>s;
        if(mp[s]==0) ans++;
        mp[s]=1;
    }
    cout<<ans<<endl;
}
int main()
{
	//int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr LL maxn = 200000 + 1;
constexpr LL maxm = 40;
pair<LL, LL> p[maxn];
LL x[maxn], xn, pn;
LL dp[maxm];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    LL N, T;
    cin >> N >> T;
    for(LL i = 1, a, b; i <= N; i += 1){
        cin >> a >> b;
        if(a == 0) x[xn += 1] = b;
        else p[pn += 1] = {a, b};
    }
    fill(dp + 1, dp + maxm, T + 1);
    sort(p + 1, p + pn + 1, [](const pair<LL, LL>& p1, const pair<LL, LL>& p2){
        return (p1.second + 1) * (p2.first + 1) + p2.second
              <(p2.second + 1) * (p1.first + 1) + p1.second;
    });
    for(LL i = 1; i <= pn; i += 1)
        for(LL j = maxm - 1; j; j -= 1) dp[j] = min(dp[j], (dp[j - 1] + 1) * (p[i].first + 1) + p[i].second);
    LL ans = 0;
    sort(x + 1, x + xn + 1);
    for(LL i = 0; i < maxm; i += 1){
        if(dp[i] > T) break;
        LL pans = i, t = dp[i];
        for(LL j = 1; j <= xn; j += 1)
            if(t + 1 + x[j] <= T){
                t += 1 + x[j];
                pans += 1;
            }
        ans = max(ans, pans);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3584
#!/usr/bin/env python3

n, m, k = [int(x) for x in input().split()]
for i in range(0, m + 1):
    for j in range(0, n + 1):
        c = i * (n - j) + j * (m - i)
        if c == k:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			int i = 1;
			while (true) {
				String str = reader.readLine();
				String[] arr = str.split(" ");
				int x = Integer.parseInt(arr[0]);
				int y = Integer.parseInt(arr[1]);
				int temp;
				
				if (x > y) {
					temp = x;
					x = y;
					y = temp;
				}
				
				if (x == 0 && y == 0) {
					break;
				}
				System.out.println(x + " " + y);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 27052
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
 
public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        String str=in.next();
        int sum=0;
        for(int i=0;i<str.length();i++)
        {
            int d=str.charAt(i)-48;
            sum+=d;
            sum%=9;
        }
        if(sum==0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 40548
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifndef _MSC_VER
#pragma GCC target ("sse4.2")
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n;
	cin >> n;
	ll res = 0;
	for (int i = 0; i <= n; i++)
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		else
			res += i;
	cout << res;
	return 0;
}

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

int min(int a,int b){
	return(a >= b ? b : a);
}

int main(void){
	int A,B,C; //A:500yen,B:100yen,C:50yen
	int X;//target amount

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> X;

	int payment = 0;//number of payment ways

	for(int i = min(A,X/500); i>=0; i--){	//500yen : i coins
		for(int j = min(B,(X-500*i)/100); j>=0; j--){	//100yen : j coins
			if((X-500*i-100*j)/50 <= C){	//50yen : (X-500*i-100*j)/50 coins
				payment++;
			}
		}
	}

	cout << payment << endl;

	return(0);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  bool debug=true;
  int A, B;
  cin >> A >> B;
  if(8 < A || 8 < B){
    cout << ":(" << endl;
    return 0;
    
  }
  cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

int main() {
	for (;;) {
		int e; cin >> e;
		if (e == 0) break;
		int m = INT_MAX;
		for (int z = 0; z * z * z <= e; z++) {
			int _e = e - z * z * z;
			int y = sqrt((double)_e), x = _e - y * y;
			m = min(m, x + y + z);
		}
		cout << m << endl;
	}
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int k, n;
  cin >> k >> n;
  int res = 0;
  vector<int> ar(n);
  for(int i = 0; i < n; ++i) {
    cin >> ar[i];
  }
  res = k - (k - ar.back() + ar[0]);
  for(int i = 0; i < n - 1; ++i) {
    res = min(res, k - ar[i + 1] + ar[i]);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

def func(dam_num, dam_volumes):
    water_amount = sum(dam_volumes)
    mountains_rain = [0]*dam_num
    mountains_rain[0] = water_amount

    # 最初の山の降水量を計算
    for i in range(dam_num//2):
        mountains_rain[0] -= 2*dam_volumes[2*(i+1)-1]

    # 漸化式　mountains_rain[i+1] = 2*dam_volumes[i] - mountains_rain[i]
    for i in range(dam_num-1):
        mountains_rain[i+1] = 2*dam_volumes[i] - mountains_rain[i]
    
    print(*mountains_rain)
    exit()


def main():
    n = int(input())
    a = [int(i) for i in input().split()] 

    func(n,a)
    
# main関数呼び出し
if __name__ == "__main__":
    main()

Measured memory_bytes: 14108
#include<stdio.h>

#define FOUND '1'
#define NOT_FOUND '0'

int linearSearch(int [1000000], int, int);

int main(){
  int i, n, q, count = 0;
  int S[1000000], T[1000000];

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i = 0; i < q; i++) scanf("%d",&T[i]);
  
  for(i = 0; i < q; i++){
    if(linearSearch(S, T[i], n) == FOUND) count++;
  }
  
  printf("%d\n",count);

  return 0;
}

int linearSearch(int A[], int key, int n){
  int i = 0;

  A[n] = key;

  while(A[i] != key){
    i++;
  }

  if(i == n) return NOT_FOUND;
  else return FOUND;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

int main(){
    int h,w;cin >> h >> w;
    vector<string> mp(h);
    rep(i,h){
        cin >> mp[i];
    }

    vii dist(h,vi(w,-1));
    queue<pair<int,int>> que;
    
    if(mp[0][0] == '#'){
        dist[0][0] = 1;
    }else{
        dist[0][0] = 0;
    }
    que.push({0,0});

    while(!que.empty()){
        int x,y;
        tie(y,x) = que.front();
        que.pop();

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

            if(ny<0 || ny>=h || nx<0 || nx>=w)continue;
            if(dist[ny][nx] != -1 && dist[ny][nx] <= dist[y][x])continue;

            if(dist[ny][nx] == -1){
                que.push({ny,nx});
            }

            if(mp[ny][nx] == '#' && mp[y][x] == '.')dist[ny][nx] = dist[y][x] + 1;
            else dist[ny][nx] = dist[y][x];

        }
    }

    cout << dist[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    bool prime[1000005];
    for(int i = 0 ; i < 1000005 ; i++){ prime[i] = true; }
    prime[0] = false; prime[1] = false;
    for(int k = 2 ; k < 1000005 ; k++){
        if(prime[k] == true){
            for(int j = 2 ; j*k < 1000005 ; j++){
                prime[j*k] = false;
            }
        }
    }
    for(;;){
        int a, d, n;
        cin >> a >> d >> n;
        if(a == 0 && d == 0 && n == 0){
            return 0;
        }
        int ans; 
        bool finish=false;
        for(int i = 0 ; (a+d*i <= 1000000) && (!finish) ; i++){
            if(prime[a+d*i]){
                if(n == 1){
                    ans    = a+d*i;
                    finish = true;
                }else{
                    n--;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4072
#include<iostream>

int main(){
  int n=10; //?±±?????°
  int height[n];

  //?±±????????????????????????
  //std::cout << "Input 10 of height\n";
  for(int i=0; i<n; i++){
    //std::cout << "mountain:";
    std::cin >> height[i];
  }
  
  //????????????????????????
  for(int i=0; i<n; i++){
    for(int j=n-1; j>i; j--){
      if(height[j-1] < height[j]){
	int k = height[j-1];
	height[j-1] = height[j];
	height[j] = k;
      }
    }
  }
  
  //????????????????±±??????????????¨???
  for(int i=0; i<3; i++){
    std::cout << height[i] << '\n';
  }

  return 0;
  
}

Measured memory_bytes: 3100
n = int(input())
l = [[0]*2 for _ in range(n)]
a = list(map(int, input().split()))


for i in range(n):
    l[i][0] = a[i]
    l[i][1] = i

l.sort()

for i in range(n):
    print(l[i][1] + 1, end=" ")

Measured memory_bytes: 24288
use proconio::marker::Chars;
use proconio::{fastout, input};
use std::char;

#[fastout]
fn main() {
    input! {
        n: u32,
        s: Chars,
    }
    let a = 'A' as u32;

    println!(
        "{}",
        s.iter()
            .map(|&x| char::from_u32(((x as u32) - a + n) % 26 + a).unwrap())
            .collect::<String>()
    );
}


Measured memory_bytes: 2236
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r);for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll sx,sy,X,Y,i;
  cin>>sx>>sy>>X>>Y;
  X-=sx;Y-=sy
  REP(i,X)cout<<'R';
  REP(i,Y)cout<<'U';
  REP(i,X)cout<<'L';
  REP(i,Y+1)cout<<'D';
  REP(i,X+1)cout<<'R';
  REP(i,Y+1)cout<<'U';
  cout<<"LU";
  REP(i,X+1)cout<<'L';
  REP(i,Y+1)cout<<'D';
  cout<<'R'<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000000000000
#define inf -100000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//number of edges in a graph equal (v[i].size() ka summation of all the vertices)/2
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll int n;
    cin>>n;
    ll int z;
    while(n!=0)
    {
    	z=n%10;
    	n=n/10;
    	if(z==7)
    	{
    		cout<<"Yes\n";
    		exit(0);
    	}
    }
    cout<<"No\n";
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=1000000007;
const long long inf=1ll<<61;
int a[100006];
signed main(){
  int n;cin>>n;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int lb=-1,ub=n;
  while(ub-lb>1){
    int mi=(ub+lb)/2;
    int fi=0;
    rep(i,mi+1)fi+=a[i];
    int flg=0;
    for(int i=mi+1;i<n;i++){
      if(fi*2<a[i])flg++;
      else{
        fi+=a[i];
      }
    }
    if(flg)lb=mi;
    else ub=mi;
  }
  cout<<n-ub<<endl;
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
string a;
bool wjz;
int main()
{
	cin>>a;
	for(int i=0;i<a.length();i++)
	{
		if(a[i]=='C')
			wjz=1;
		if(a[i]=='F')
		{
			if(wjz)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vector<queue<int>> tennis(n);
    int a;
    rep(i,n)rep(j,n-1){
        cin>>a;
        tennis[i].push(a-1);
    }
    vector<queue<int>> match(2);
    rep(i,n)match[0].push(i);
    int ans=0,cnt=0,tmp,res=0;;bool can;
    while(1){
        ans++;
        vbo already(n,false);
        can=false;
        while(match[res].size()){
            int i=match[res].front();match[res].pop();
            if(tennis[i].size()==0)continue;
            if(!already[i]){
                tmp=tennis[i].front();
                if(i==tennis[tmp].front()&&!already[tmp]){
                    cnt++;
                    tennis[i].pop(); tennis[tmp].pop();
                    match[(res+1)%2].push(i);match[(res+1)%2].push(tmp);
                    already[i]=true;already[tmp]=true;
                    can=true;
                }
            }
        }
        if(cnt==n*(n-1)/2){
            cout<<ans<<endl;
            return 0;
        }
        if(!can){
            cout<<-1<<endl;
            return 0;
        }
        res=(res+1)%2;
    }
}

Measured memory_bytes: 8092
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int ina;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> ina;
        while (ina % 2 == 0)
        {
            ina /= 2;
            sum++;
        }
        
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Deque<Integer> list = new ArrayDeque<>(Arrays.asList(2,1,0));
    try (Scanner sc = new Scanner(System.in)) {   
      int sum = Stream.of(sc.nextLine().split(" "))
                      .map(Integer::valueOf)
                      .reduce(0, (x, y) -> x + y * (int) Math.pow(10,list.removeFirst()));
      System.out.println((sum % 4 == 0) ? "YES" : "NO");
    }
  }
}

Measured memory_bytes: 26964
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int m = sc.nextInt();
        
        int amin = 99999999;
        int bmin = 99999999;
        int[] arraya = new int[a];
        for (int i = 0; i < a; i++) {
            arraya[i] = sc.nextInt();
            amin = Math.min(amin, arraya[i]);
        }
        int[] arrayb = new int[b];
        for (int i = 0; i < b; i++) {
            arrayb[i] = sc.nextInt();
            bmin = Math.min(bmin, arrayb[i]);
        }
        
        int best = amin+bmin;
        
        while (m-- > 0) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            int s = sc.nextInt();
            
            best = Math.min(best ,arraya[x] + arrayb[y]-s);
        }
        
        System.out.println(best);
    }
}


Measured memory_bytes: 130664
/***************************************************
 * Problem Name : A - Apple Pie.cpp
 * Problem Link : https://atcoder.jp/contests/abc128/tasks/abc128_a
 * OJ           : AtCoder
 * Verdict      : Trying
 * Date         : 2019-05-27
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin);
#define __FileWrite freopen ("output.txt", "w", stdout);
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    int n, p;
    cin >> n >> p;
    cout << ( (n * 3) + p) / 2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int euq(int a, int b) {return b ? euq(b, a%b) : a;}

signed main() {
    int a, b;
    cin >> a >> b;

    int res = (a*b)/euq(a, b);

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#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(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

bool isprime(int n){
  if (n==1) return false;
  else if(n==2) return true;
  else if(n%2==0) return false;
  else{
    for(int i=3;i*i<=n;i+=2){
      if(n%i==0) return false;
    }
    return true;
  }
}

int Q;
const int maxr=1e5;
int a[maxr+1];
int S[maxr+3];

int main(){
  cin >> Q;
  for(int i=1;i<=maxr;i+=2){
    if(isprime(i)&&isprime((i+1)/2)) a[i]=1;
  }
  for(int i=1;i<=maxr;i+=2){
    S[i+2]=S[i]+a[i];
  }
  vector<int> ans(Q);
  rep(i,Q){
    int l,r;
    cin >> l >> r;
    ans[i]=S[r+2]-S[l];
  }
  rep(i,Q){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 1792
from collections import deque
import sys
sys.setrecursionlimit(200000)
#input = sys.stdin.readline
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
used = [[0]*w for i in range(h)]
def dfs(x,y):
    if used[x][y]:
        return 0
    global go
    used[x][y] = 1
    if x-1 >=0 and a[x-1][y] != a[x][y]:
            go.add((x-1,y))
            dfs(x-1,y)
    if y-1 >=0 and a[x][y-1] != a[x][y]:
            go.add((x,y-1))
            dfs(x,y-1)
    if x+1 <h and a[x+1][y] != a[x][y]:
            go.add((x+1,y))      
            dfs(x+1,y)
    if y+1 <w and a[x][y+1] != a[x][y]:
            go.add((x,y+1))
            dfs(x,y+1)
ans = 0
for i in range(h):
    for j in range(w):
        go = set()
        if used[i][j]:
            continue
        dfs(i,j)
        kuro = 0
        siro = 0
        for k,l in go:
            if a[k][l] == "#":
                kuro += 1
            else:
                siro += 1
        ans += kuro*siro

print(ans)

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

using namespace std;

void solve(void)
{
	int h, w;
	cin >> h >> w;
	vector<int> ps, qs;
	for (int i = 0; i < h; i++)
	{
		string g;
		cin >> g;
		for (int j = 0; j < w; j++)
		{
			if (g[j] == 'B')
			{
				ps.push_back(i+j);
				qs.push_back(i+w-j);
			}
		}
	}
	sort(ps.begin(), ps.end());
	sort(qs.begin(), qs.end());
	int ans = max(ps.back()-ps.front(), qs.back() - qs.front());
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}




Measured memory_bytes: 9056
N,Y = map(int,input().split())
for x in range(N+1):
    for y in range(N - x + 1):
        if 10000*x+5000*y+1000*(N - x - y) == Y:
            print(x,y,N-x-y)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 65344
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

const int match[10] = {0,2,5,5,4,5,6,3,7,6};

void chmax(int &a,int b) { if (a < b) a = b; }

int main() {
    int N, M; cin >> N >> M;
    map<int, int> match_set;
    for (int i=0; i<M; i++) { int x; cin >> x; chmax( match_set[match[x]], x ); }

    int digit[N+1]; fill(digit,digit+N+1,-1.0e+9); digit[0] = 0;
    for (int i; i<=N; i++) { for(auto m : match_set) { if (i-m.first >= 0) chmax(digit[i],digit[i-m.first]+1); } }

    string result;
    while(N != 0){ 
        int x = 0;
        for(auto m : match_set) if (N-m.first >= 0 and digit[N] == digit[N-m.first]+1) chmax(x, m.second);
        result += to_string(x); N -= match[x];
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
    string s;
    cin >>s;
    rep(i,s.size()){
    if(s[i]!=s[s.size()-1-i]){
       cout<<"No";
       return 0;
    }
    }
    cout <<"Yes";
}

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

int main(){
    int x, y;
    cin >> x >> y;

    int flag = 0;
    for(int i = 0; i <= x; i++){
        int j = x - i;
        if(i * 2 + j * 4 == y){
            flag = 1;
            break;
        }
    }

    if(flag == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3632
t = gets.to_i
arr=Array.new()
t.times do
  arr.push gets.to_i
end

maxv=arr[1]-arr[0]
minv=arr[0]
(1..t-1).each do |j|
  maxv= maxv>(arr[j]-minv) ? maxv : (arr[j]-minv)
  minv= minv<arr[j] ? minv : arr[j]
end
puts maxv

Measured memory_bytes: 10508
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 2e9+7;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vvi roads(n);
    rep(i, m) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        roads[from].pb(to);
    }
    vvi end_nums(n);
    rep(from_ptr, n) {
        int cnt = 0;
        rep(end_ptr, n) {
            for(auto t: roads[from_ptr]) {
                if (t == end_ptr) cnt++;
            }
            end_nums[from_ptr].pb(cnt);
        }
    }

    rep(i, q) {
        int qfrom, qto;
        cin >> qfrom >> qto;
        qfrom--; qto--;
        int ans = 0;
        for(int start = qfrom; start <= qto; start++) {
            ans += end_nums[start][qto];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k, l;
  
  ll N, A, B;
  cin >> N >> A >> B;
  ll C=A+B;
  string s;
  cin >> s;
  ll ca=0, cb=0;
  
  vector<ll> v;
  for(i=0; i<N; i++) {
    if(s[i]=='c') {
      v.push_back(0);
    }else if(s[i]=='a') {
      
      if(ca+cb<C) {
        v.push_back(1);
        ca++;
      }else {
        v.push_back(0);
      }
      
    }else if(s[i]=='b') {
      
      if(ca+cb<C && cb<B) {
        v.push_back(1);
        cb++;
      }else {
        v.push_back(0);
      }
      
    }
  }
  
  for(i=0; i<N; i++) {
    if(v[i]) pt("Yes");
    else pt("No");
  }
  
}




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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N, K;

void solve() {
    cin >> N >> K;
    vector<int> a(N);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end(), greater<int>());
    ll sum = 0;
    for (int i = K; i < N; i++) {
		sum += a[i];
	}
	cout << sum;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3968
// 答えを見た
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Point = pair<int, int>;

// #define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

bool is_valid_point(const int H, const int W, const vector<vector<bool>> S, const int y, const int x) {
    return 0 <= y && y < H && 0 <= x && x < W && S.at(y).at(x);
}

vector<Point> get_next_points(const int y, const int x) {
    vector<Point> ans(4);
    ans.at(0) = make_pair(y, x+1);
    ans.at(1) = make_pair(y, x-1);
    ans.at(2) = make_pair(y+1, x);
    ans.at(3) = make_pair(y-1, x);

    return ans;
}

int distance(const int H, const int W, const vector<vector<bool>> S, const int start_h, const int start_w) {
    vector<vector<int>> d(H, vector<int>(W, -1));
    d.at(start_h).at(start_w) = 0;

    queue<Point> q;
    q.push(make_pair(start_h, start_w));

    int ans = 0;

    while(!q.empty()) {
        Point p = q.front();
        q.pop();

        int y = p.first;
        int x = p.second;

        vector<Point> next_points = get_next_points(y, x);
        for (auto next_p : next_points) {
            int next_y = next_p.first;
            int next_x = next_p.second;

            if (!is_valid_point(H, W, S, next_y, next_x)) {
                continue;
            }

            // もう通ったことがあるなら更新しない
            if (d.at(next_y).at(next_x) != -1) {
                continue;
            }

            int new_distance = d.at(y).at(x) + 1;
            // debug(y);
            // debug(y);
            // debug(d.at(y).at(x));
            // debug(next_y);
            // debug(next_x);
            // debug(new_distance);
            // hyphen();

            d.at(next_y).at(next_x) = new_distance;
            ans = max(ans, new_distance);
            q.push(next_p);
        }
    }
    return ans;
}

signed main() {
    int H, W;
    cin >> H >> W;

    // そのマスが通れるならtrue
    vector<vector<bool>> S(H, vector<bool>(W, false));

    REP(h, H) {
        string s;
        cin >> s;

        REP(w, W) {
            if (s.at(w) == '.') {
                S.at(h).at(w) = true;
            } else if (s.at(w) == '#') {
                S.at(h).at(w) = false;
            }
        }
    }

    int ans = 0;

    // 全探索
    REP(start_h, H) {
        REP(start_w, W) {
            if (!S.at(start_h).at(start_w)) {
                    continue;
            }

            // REP(goal_h, H) {
            //     REP(goal_w, W) {
            // if (!S.at(goal_h).at(goal_w)) {
            //     continue;
            // }

            // if (start_h == goal_h && start_w == goal_w) {
            //     continue;
            // }
            int d = distance(H, W, S, start_h, start_w);
            // int d = distance(H, W, S, start_h, start_w, goal_h, goal_w);
            ans = max(ans, d);
    //     }
    // }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def nyu():
    num1 = input()
    num1 = int(num1)
    #num2 = int(num2)
    return num1

def nyu2(n):
    tmp =[]
    for i in range(n):
        tmp.append(int(input()))
    return tmp

def sort(mochi):
    tmp_mochi = 0
    for i in range(n):
        for k in range(n):
            if mochi[i]>mochi[k] :
                tmp_mochi = mochi[i]
                mochi[i] = mochi[k]
                mochi[k] = tmp_mochi
    return mochi

def check(mochi):
    max =101
    cnt =0

    for i in range(n):
        if max>mochi[i]:
            max = mochi[i]
            cnt +=1
    return cnt

n=nyu()
mochi = nyu2(n)
mochi = sort(mochi)
print(check(mochi))

Measured memory_bytes: 3064
import java.util.*;

class Main
{
    public static  void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String[] array = new String[4];
        
        for (int i = 0; i < 4; i++) {
            array[i] = s.substring(i, i + 1);
        }
        
        //Arrays.sort(array);
        int count = 0;
        
        for (int i = 0; i < 3; i++) {
            if (array[i].equals(array[i + 1])) {
                count++;
            }
        }
        
        if (count != 0) {
            System.out.println("Bad");
        } else {
            System.out.println("Good");
        }
        
    }
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(){
  //counter
  int i,j;

  //input
  int n;
  scanf("%2000000d",&n);
  
  int A[n];
  int k=0;  // TODO serching "k"
  for(i=0;i<n;i++){
    scanf("%10000d",&A[i]);
    if(A[i]>k){
      k = A[i];
  }
  }

  
  //Counting Sort

  int C[k+1];
  for(i=0;i<k+1;i++){
    C[i] = 0;
  }
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<k+1;i++){
    C[i] = C[i] + C[i-1];
  }
    int B[n];
    for(j=(n-1);j>=0;j--){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
    }

  //output
  for(i=0;i<n-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n-1]);
  


    return 0;
}



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

int main(){
	int x,y;
	
	while(1){
		cin>>x>>y;
		if(x==0&&y==0){
			break;
		}
		if(x<y){
			cout<<x<<" "<<y<<endl;
		}else{
			cout<<y<<" "<<x<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3048
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n,m,x;
	cin >> n >> m >> x;

	vector<int> cost(n);
	vector<vector<int>> a(n,vector<int>(m));
	for(int i = 0;i < n;i++){
		cin >> cost[i];
		for(int j = 0;j < m;j++){
			cin >> a[i][j];
		}
	}

	ll ans = 1e18;
	for(int i = 0;i < (1 << n);i++){
		ll now_cost = 0;
		vector<int> now_a(m,0);
		for(int j = 0;j < n;j++){
			if((i >> j) & 1){
				now_cost += cost[j];
				for(int k = 0;k < m;k++)now_a[k] += a[j][k];
			}
		}

		bool flag = true;
		for(int k = 0;k < m;k++){
			if(now_a[k] < x)flag = false;
		}

		if(flag){
			ans = min(ans,now_cost);
		}
	}

	if(ans == 1e18){
		cout << -1 << endl;
	}
	else cout << ans << endl;
}


Measured memory_bytes: 3644