akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        long N = in.nextLong();
        long K = in.nextLong();

        long B[] = new long[100001];

        // 配列を0で満たす
        Arrays.fill(B,0);

        for(int cnt = 0;cnt < N; cnt++){
        	int a = in.nextInt();
        	int b = in.nextInt();
        	B[a] += b;
        }
        in.close();
        for(int cnt = 0; cnt < 100001; cnt++){
        	if(K <= B[cnt]){
        		System.out.println(cnt);
        		break;
        	}
        	else{
        		K -= B[cnt];
        	}
        }

    }



}

Measured memory_bytes: 61240
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
        }
        int s1=0,s2=0,ans=100000000;
        for(int i=2; i<n; i++)
        {
            s1=0;
            s2=0;
            for(int j=1; j<=n; j++)
            {
                if(j<=i)
                {
                    s1+=a[j];
//                    printf("s1=%d\n",s1);
                }
                else
                {
                    s2+=a[j];
//                    printf("s2=%d\n",s2);
                }
            }
            if(abs(s1-s2)<ans)
            {
                ans=abs(s1-s2);
//                printf("*%d\n",ans);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int a, b;
    cin >> a >> b;
    if (b % a == 0)
        cout << a + b << endl;
    else
        cout << b - a << endl;
    return 0;
}

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

typedef long long ll;

int main() {
  ll l, r; cin >> l >> r;
  if (r - l >= 2019) { 
    cout << 0 << endl;
    return 0;
  }
  ll ans = 2018;
  for (ll i = l; i < r; ++i) { 
    for (ll j = i+1; j <= r; ++j) { 
      ans = min(ans, i*j%2019);
    }
  }
  cout << ans << endl;
}



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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
        }

        Arrays.sort(A);

        int t = 0;
        long sum = 0;
        for (int i = 0; i < N - 1; ++i) {
            if (2 * (sum + A[i]) < A[i + 1]) {
                t = i + 1;
            }
            sum += A[i];
        }
        _out.println((N - t));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 51092
#include <stdio.h>
#include <ctype.h>

int main() {

  char ch[1200];
  int i,n;
  n=0;
  char a[1200];

  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;

    }
    
    
    n = n +1;
    
  }
  
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
  
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

int calc(string s, string t){
    int n = s.size();
    rep(i,n){
        if(s[i]>t[i]) return 1;
        if(s[i]<t[i]) return -1;
    }
    return 0;
}

ll toI(string s){
    ll ret = 0;
    rep(i,s.size()) ret = (ret*10+s[i]-'0')%mod;
    return ret;
}

const int N = 10010;
ll pw[N];

ll f(string s, string c){
    // dbg(s);
    int S = s.size(), C = c.size();

    ll ret = 0;
    rep(i,S-C+1){
        string L = s.substr(0,i);
        string t = s.substr(i,C);
        string R = s.substr(i+C);

        int flg = calc(t,c);

        // cout << L << " " << t << " " << R << endl;

        if(L == ""){
            if(c != "0"){
                if(flg == 0) (ret += toI(R)) %= mod;
                else if(flg == 1) (ret += pw[R.size()]) %= mod;
            }
        }
        else{
            ll nL = toI(L);
            ll nR = toI(R);

            if(c != "0") nL = (nL+1)%mod;

            if(flg == 1){
                (ret += nL*pw[R.size()]) %= mod;
            }
            else if(flg == 0){
                (ret += (nL-1+mod)*pw[R.size()]) %= mod;
                (ret += nR+1) %= mod;
            }
            else{
                (ret += (nL-1+mod)*pw[R.size()]) %= mod;
            }
        }
        // dbg(ret);
    }

    return ret;
}

ll g(string s, string c){
    int S = s.size(), C = c.size();

    ll ret = 0;
    rep(i,S-C+1){
        if(s.substr(i,C) == c) ++ret;
    }

    return ret;
}

int main(){
    pw[0] = 1;
    rep(i,N-1) pw[i+1] = (pw[i]*10)%mod;

    string a,b,c;
    cin >>a >>b >>c;

    ll ans = f(b,c);
    ans = (ans-f(a,c)+mod)%mod;
    ans = (ans+g(a,c))%mod;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3284
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	int max3(int a, int b, int c) {
		int max = ((a < b) ? b : a);
		return (max < c)? c : max;
	}

	void doIt() {
		int h = sc.nextInt();
		int w = sc.nextInt();
		char f[][] = new char[h][];
		for(int i = 0; i < h; i++) {
			f[i] = sc.next().toCharArray();
		}
		int num[][] = new int[h][w];
		for(int i = 0; i < h; i++) Arrays.fill(num[i], -1);

		for(int i = 0; i < w; i++) {
			int cnt = 0;
			int s = 0;
			for(int j = 0; j < h; j++) {
				if(f[j][i] == '.')
					cnt++;
				else {
					for(int k = s; k < j; k++) {
						num[k][i] = cnt;
					}
					cnt = 0;
					s = j + 1;
				}
			}

			for(int k = s; k < h; k++) {
				num[k][i] = cnt;
			}


		}
		

		for(int i = 0; i < h; i++) {
			int cnt = 0;
			int s = 0;
			for(int j = 0; j < w; j++) {
				if(f[i][j] == '.') {
					cnt++;
				}
				else {
					for(int k = s; k < j; k++) {
						num[i][k] += cnt;
					}
					cnt = 0;
					s = j + 1;
				}
			}
			for(int k = s; k < w; k++) {
				num[i][k] += cnt;
			}


		}
		int max = 0;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				int val = num[i][j];
				max = (max < val)?val:max;
			}
		}
		System.out.println(max - 1);
	
		
	}


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


Measured memory_bytes: 58744
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;
 std::vector<pii> v;
 multiset<ll> s;
 for (int i = 0; i < n; ++i)
 {
  cin>>x;
  s.insert(x);
 }

 while(s.size()>1)
 {
    x = *s.begin();
    s.erase(s.begin());
    y = *s.rbegin();

    s.erase(s.find(y));
    if(x>0)
    {
      v.pb({x,y});
      s.insert(x-y);
    }
    else if(y<0)
    {
      v.pb({y,x});
      s.insert(y-x);
    }
    else
    {
      if(!s.empty() and *s.rbegin()>=0)
      {
         v.pb({x,y});
      s.insert(x-y);
      }
      else
      {
        v.pb({y,x});
        s.insert(y-x);
      }
    }
 }
 c(*s.begin());
  for (int i = 0; i < v.size(); ++i)
  {
    cout<<v[i].F<<" "<<v[i].S<<'\n';
  }
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 8188
#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);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	vector<int> sume(n + 1), sumw(n + 1);
	rep(i, n) {
		if (s[i] == 'W') sumw[i + 1]++;
		else sume[i + 1]++;
		sumw[i + 1] += sumw[i];
		sume[i + 1] += sume[i];
	}
	int ans = inf;
	rrep(i, n + 1) {
		int tmp = sumw[i - 1] + sume[n] - sume[i];
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2964
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
using vi = vector<int>;

// 特別に1を最初の要素とする
int64_t f (vector<int> &A, int i, int m, vi const &a, vi const &b, vi const &c,
           vi const &d)
{
    int64_t high = 0;
    if ((i + 1) < A.size ()) {
        for (A[i + 1] = A[i]; A[i + 1] <= m; A[i + 1]++) {
            auto ret = f (A, i + 1, m, a, b, c, d);
            if (high < ret)
                high = ret;
        }
        return high;
    } else {
        // スコアを求める
        int q = a.size ();
        int64_t score = 0;
        for (int j = 0; j < q; j++) {
            if ((A[b[j]] - A[a[j]]) == c[j])
                score += d[j];
        }
        return score;
    }
}

int main ()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a (q), b (q), c (q), d (q);
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    int64_t high = 0;
    vi A (n + 1); // 特別に1を最初の要素とする
    A[0] = 1;
    high = f (A, 0, m, a, b, c, d);
    cout << high;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String S = sc.next();
    	
    	int start = 0;
    	int end = 0;
    	int ml = 0;
    	boolean flag = false;
    	for( int i = 0; i < S.length(); i++ ) {
    		char c = S.charAt(i);
    		if( (c== 'A' || c == 'C' || c == 'G' || c == 'T') && flag == false && i != S.length() - 1  ) {
    			start = i;
    			end = i+1;
    			flag = true;
    		}
    		else if( (c== 'A' || c == 'C' || c == 'G' || c == 'T') && flag == false && i == S.length() - 1 ) {
    			start = i;
    			end = i+1;
    			int temp = end - start;
    			if( ml < temp ) {
    				ml = temp;
    			}
    		}
    		else if( (c== 'A' || c == 'C' || c == 'G' || c == 'T') && flag == true && i != S.length() - 1 ) {
    			end = i+1;
    		}
    		else if( (c== 'A' || c == 'C' || c == 'G' || c == 'T') && flag == true && i == S.length() - 1 ) {
    			end = i+1;
    			int temp = end - start;
    			if( ml < temp ) {
    				ml = temp;
    			}
    		}
    		else {
    			int temp = end - start;
    			if( ml < temp ) {
    				ml = temp;
    			}
    			flag = false;
    		}
    	}
    	System.out.println( ml );
    	sc.close();
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
string s; 
int main()
{
	cin>>s;
	for(int i=0;i<=s.size();i++)
	{
	if(s[i]=='7')
	{
		cout<<"Yes";
		return 0;
	} 
    }
	cout<<"No";
    return 0;
}


Measured memory_bytes: 3596
import Data.List
import Data.Array
import Data.Maybe
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt
 
solve :: [Int] -> Int
solve = sum . map calc . group . sort
    where calc xs@(x:_)
            | length xs >= x = length xs - x
            | otherwise = length xs

main :: IO ()
main = do
    [n] <- getInts
    ls <- getInts
    print (solve ls)

Measured memory_bytes: 17788
n = int(input())
min_val, max_val = zip(*[map(int, input().split()) for _ in range(n)])
min_val = sorted(min_val)
max_val = sorted(max_val)

if n % 2:
    mid = n//2
    min_median = min_val[mid]
    max_median = max_val[mid]
    print(max_median-min_median+1)
else:
    midl = (n-1)//2
    midr = midl+1
    min_median = min_val[midl]+min_val[midr]
    max_median = max_val[midl]+max_val[midr]
    print(max_median-min_median+1)


Measured memory_bytes: 113496
N = input()

origin = 0
for i in range(len(N)):
    origin += int(N[i])
    
if N[0] == '1':
    tmp = '9' * (len(N) - 1)
    
else:
    tmp = str(int(N[0]) - 1)
    tmp = tmp + '9' * (len(N) - 1)
    
res = 0
for i in range(len(tmp)):
    res += int(tmp[i])
    
res = max(origin, res)
print(res)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair < int, int >;

int main() {
	ios_base::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	int n; cin >> n;
	ll sum = 0LL;
	for (int x = 1; x <= n; x++) {
		if (x % 3 != 0 && x % 5 != 0) {
			sum += x;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3652
n=int(input())
a,b=map(int,input().split())
p=sorted(list(map(int,input().split())))
x,y=-1,-1
for i in range(n):
    if x==-1 and p[i]>a:
        x=i
    if y==-1 and p[i]>b:
        y=i
if x==-1 or y==-1:
    print(0)
    exit()
print(min(x,y-x,n-y))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef bitset<100>B;
const int mod=998244353;
int dfs(string s){
	static map<string,int>rec;
	if(!s.length())return 1;
	if(s.length()==1)return s[0]-'0'+1;
	if(rec.count(s))return rec[s];
	int&ans=rec[s];
	for(size_t i=1;i<=s.length();i++){
		B mask=B(s.substr(0,i));
		for(int j=(1+(i!=1));i*j<=s.length();j++){
			mask&=B(s.substr(i*(j-1),i));
			ans=(ans+1ll*dfs(mask.to_string().substr(100-i))*dfs(s.substr(i*j)))%mod;
		}
	}
	return ans;
}
int main(){
	string s;cin>>s;
	B mask=B(s.substr(0,3));
	cout<<dfs(s)<<"\n";
	return 0;
}

Measured memory_bytes: 5888
#include<iostream>
#include<algorithm>
using namespace std;
int n,r;pair<int,char>d[10];
int main(){
	  while (true) {
       cin>>n;
        if (n == 0)break;
        for (int i = 0; i < n; i++) {
            cin >> d[i].second; d[i].first = i;
            for (int j = 0; j < n - 1; j++) {
				cin>>r;
                if (r == 0) d[i].first -= 100;
                if (r == 1) d[i].first += 10;
            }
        }
        sort(d, d + n);
        for (int i = 0; i < n; i++) cout<<d[i].second<<endl;
    }

	return 0;
}

Measured memory_bytes: 3024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int a;
    int b;
    try(Scanner sc = new Scanner(System.in)) {
      a = sc.nextInt();
      b = sc.nextInt();
    }
    int am;
    int bm;
    am = a % 2;
    bm = b % 2;
    if ( am == bm ) {
      System.out.println((a+b)/2);
    }
    else {
      System.out.println("IMPOSSIBLE");
    }
  }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n,sum = 0;

        n = sc.nextLong();
        
        for(long i = 1; i <= n; i++){
            if((i % 3 != 0) && (i % 5 != 0) && (i % 15 != 0)){
                sum += i;
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 35784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> v(n), p(n), q(n);
  iota(ALL(v), 1);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  int c = 0;
  int cntA = 0;
  int cntB = 0;
  do {
    ++c;
    int bA = true;
    rep(i,n) {
      if (v[i] != p[i]) {
        bA = false;
        break;
      } 
    }
    if (bA) cntA = c;

    int bB = true;
    rep(i,n) {
      if (v[i] != q[i]) {
        bB = false;
        break;
      } 
    }
    if (bB) cntB = c;
  } while (next_permutation(ALL(v)));

  cout << abs(cntA - cntB) << endl;
}

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

Measured memory_bytes: 3624
base_num = input()
unit = base_num.split(' ')
vec_n_max = int(unit[0])
vec_m_max = int(unit[1])
vec_o_max = int(unit[2])
end_num = 0

input_list = []
while True:
    base_suit = input()
    input_list.append(base_suit)

    end_num += 1
    if (vec_n_max + vec_m_max) == end_num:
        break

matrix_a = []
matrix_b = []
for i, r in enumerate(input_list):
    if i < vec_n_max: 
        row = r.split(' ')
        matrix_a.append([int(x) for x in row])
    else:
        row = r.split(' ')
        matrix_b.append([int(x) for x in row])

for i in range(vec_n_max):
    for j in range(vec_o_max):
        c = 0
        for k in range(vec_m_max):
            c += matrix_a[i][k] * matrix_b[k][j]
        print('{}'.format(c),end='')
        if j != vec_o_max-1:
            print(' ',end='')
    print()



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



int main(){
	string num;
	rep(i,4) cin >> num[i];
	int ans; 
	vector<char> op(3);
	rep(bit,(1<<3)){
		bitset<3> tmp(bit);
		ans = num[0]-'0';
		rep(i,3){
			if (tmp.test(i)){
				ans += num[i+1]-'0';
				op[i] = '+';
			}
			else {
				ans -= num[i+1]-'0';
				op[i] = '-';
			}
		}
		if (ans == 7) {
			cout << num[0] << op[0] << num[1] << op[1] << num[2] << op[2] << num[3] << "=7" << endl;
			return 0;
		}
	}



}




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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 100000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

int main_(){
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)cout<<A[i]<<" \n"[i==N-1];
  for(int i=1;i<N;i++){
    for(int j=i;j>0;j--){
      if(A[j]<A[j-1])swap(A[j],A[j-1]);
      else break;
    }
    for(int j=0;j<N;j++)cout<<A[j]<<" \n"[j==N-1];
  }
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<endl;
  }
#else
  main_();
#endif

  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define int long long
#define M 1000000007
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    string s;
    cin >> s;
    int l = s.length();
    rep(i, 0, l)
    {
        if (s[i] == '7')
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n, k;
    cin >> n >> k;
    long double rui[200100];
    rui[0] = 0;
    bool ok = true;
    ll a[200100];
    rep1(i, n) {
        cin >> a[i];
        rui[i] += rui[i-1] + a[i];
        if(i>1)if(a[i] != a[i - 1]) ok = false;
    }
    if(ok) {
        cout << (rui[1]+1)/2 * k << endl;
        return 0;
    }
    long double ma = -1;
    for(int i = k; i <= n; i++) ma = max(ma, rui[i] - rui[i - k]);
    cout << fixed << setprecision(10) << (ma + k) / 2 << endl;
    return 0;
}

Measured memory_bytes: 8428
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>
#include <complex>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

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




int main() {
    int h, w, n;
    cin >> h >> w >> n;
    map<P, bool> mp;
    set<P> s;
    rep(i, n) {
        int a, b; cin >> a >> b;
        a--; b--;
        mp[make_pair(a, b)] = 1;
        rep(x, 3) rep(y, 3) {
            int na = a - x;
            int nb = b - y;
            if (0 <= na && na + 2 < h && 0 <= nb && nb + 2 < w) {
                s.insert(make_pair(na, nb));
            }
        }
    }

    vector<ll> ans(10);
    for (auto p: s) {
        int i = p.first;
        int j = p.second;
        int cnt = 0;
        rep(di, 3) rep(dj, 3) {
            int ni = i + di;
            int nj = j + dj;
            if (mp.count(make_pair(ni, nj))) {
                cnt++;
            }
        }
        ans[cnt]++;
    }

    ll cnt = 0;
    rep(i, 10) {
        cnt += ans[i];
    }
    ans[0] = ll(h-2) * ll(w-2) - cnt;
    
    rep(i, 10) {
        cout << ans[i] << endl;
    }




    return 0;
}


    

Measured memory_bytes: 48640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int parent[n];
	for(int i=0;i<n;i++)
	{
		parent[i] = -1;
	}
	int first,second;
	for(int i=0;i<m;i++)
	{
		cin>>first>>second;
		while(parent[first]!=-1)
		{
			first=parent[first];
		}
		while(parent[second]!=-1)
		{
			second=parent[second];
		}
		if(second!=first)
		{
			parent[second]=first;
		}
	}
	int cases,first1,second1;
	cin>>cases;
	for(int i=0;i<cases;i++)
	{
		cin>>first1>>second1;
		while(parent[first1]!=-1)
		{
			first1=parent[first1];
		}
		while(parent[second1]!=-1)
		{
			second1=parent[second1];
		}
		if(first1==second1)
			cout<<"yes";
		else
			cout<<"no";
		cout<<endl;
	}
}


Measured memory_bytes: 3508
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

int dp[200001];

void solve(){
		int n, d, x;
		cin >> n >> d >> x;
		vector<vector<int>> inputs;
		REP(i, d) {
			inputs.push_back(vector<int>());
			REP(q, n) {
				int a;
				cin >> a;
				inputs.back().push_back(a);
			}
		}
		REP(i, d - 1) {
			REP(te, 200001) {
				dp[te] = te;
			}
			REP(q, n) {
				for (int j = 0; j <= 100000; ++j) {
					dp[j + inputs[i][q]] = max(dp[j + inputs[i][q]], dp[j] + inputs[i+1][q]);
				}
			}
			x = dp[x];
		}
		cout << x << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3996
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n,i,j;
  int ans = 0;
  cin >> n;
  vector<int> d(n);
  for(i=0;i<n;i++) cin >> d[i];

  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*int fun(vector<int> v,int index)
{
	int count=0;
	for(int i=index;i<v.size()-1;i++)
	{
		if(v[i]>=v[i+1])
			count++;
		else
			break;
	}
	return count;
}*/
int main()
{
	int n;
	cin>>n;
	vector<int> height(n);
	for(int i=0;i<n;i++)
		cin>>height[i];
	int max_step=0;
	int count=0;
	for(int i=0;i<n-1;i++)
	{
		if(height[i]>=height[i+1])
		{
			count++;
			max_step=max(max_step,count);
			continue;
		}
		count=0;
	}
	cout<<max_step;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int n,x;
    long long c=0;
    cin >> n >> x;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>x){
            c+=a[i]-x;
            a[i]=x;
        }
        if(i>0){
            if(a[i-1]+a[i]>x){
                int d=a[i-1]+a[i]-x;
                c+=d;
                a[i]-=d;
            }
        }
    }
    cout<<c<<endl;
    
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll ans;
  ll A,B,K;
  cin >> A >> B >> K;
  int ma=max(A,B);
  int cnt=0;
  for(int i=ma;i>=1;i--){
    if(A%i==0 && B%i==0){
      cnt++;
      if(cnt==K){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        mut abc: [i32; 3],
    }
    abc.sort();
    if abc[0] == abc[1]+abc[2] || abc[0]+abc[1] == abc[2]{
        println!("Yes");
    }else{
        println!("No");
    }
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}

	ll c=1e13,d=1e13;
	if (H >= 3) {
		c = (H/3+1)*W - H/3*W;
	}
	if (W >= 3) {
		d = (W/3+1)*H - W/3*H;
	}

	ll a=1e13;
	for (ll i = 1; i < H; i++) {
		vector<ll> b(3);
		b[0] = i*W;
		if (W % 2 == 0) {
			b[1] = (H-i)*(W/2);
			b[2] = b[1];
		}
		else {
			b[1] = (H-i)*(W/2);
			b[2] = (H-i)*(W/2+1);
		}
		sort(b.begin(), b.end());
		a = min(a, b[2]-b[0]);
	}
	for (ll i = 1; i < W; i++) {
		vector<ll> b(3);
		b[0] = i*H;
		if (H % 2 == 0) {
			b[1] = (W - i)*(H / 2);
			b[2] = b[1];
		}
		else {
			b[1] = (W - i)*(H / 2);
			b[2] = (W - i)*(H / 2 + 1);
		}
		sort(b.begin(), b.end());
		a = min(a, b[2] - b[0]);
	}
	
	cout << min(a,min(c,d)) << endl;	
}


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


int main()
{
	char s[5];
	int cnt[30]={},f=1;
	scanf("%s",s+1);
	for(int i=1;i<=4;++i) cnt[s[i]-'A']++;
	for(int i=1;i<=4;++i) if(cnt[s[i]-'A']!=2) f=0;
	puts(f==1?"Yes":"No");
}

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

int main () {
  int i, j, k, N, D, X[10][10], count=0, sum;
  
  cin >> N >> D;
  
  rep(i,N){
    rep(j,D){
      cin >> X[i][j];
    }
  }
  

  rep(i,N){
    for(j=i+1;j<N;j++){
      sum =0;
      for(k=0; k<D; k++){
        sum += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      }
      for(k=0;k*k<=sum;k++){
        if(sum==k*k){
          count +=1;
          break;
        }
      }
    }
  }
  cout << count;
}




Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int N,M;
    cin >> N >> M;
    int ans = (N*(N-1)+M*(M-1))/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
 $n = trim(fgets(STDIN));
 $a = explode(" ",trim(fgets(STDIN)));
 $right = array_sum($a);
 $left = 0;
 for($i=0;$i<$n;$i++) {
   $left += $a[$i];
   $right -= $a[$i];
   $d[$i] = abs($right-$left);
 }
echo min($d);

Measured memory_bytes: 31284
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    string t;
    cin >> s;
    cin >> t;
    for(int i = 0;i < n;i++) {
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
/* binary_indexed_tree_2D.cpp
    2次元に対応させたBIT
*/

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

/* BIT2D:
    初期値は全て 0
    ・add(h,w,x): (h,w) に x を加算する
    ・sum(h,w): 1≦i≦h かつ 1≦j≦w の範囲の合計値を求める
    ・query(h1,w1,h2,w2): h1≦i<h2 かつ w1≦j<w2 の範囲の合計値を求める(1-indexed)
    計算量は全て O(logW * logH)
*/
template <typename T>
struct BIT2D {
    int H, W;
    vector<vector<T>> bit;  // データの格納先
    BIT2D(int H_, int W_) { init(H_, W_); }
    void init(int H_, int W_) {
        H = H_ + 1;
        W = W_ + 1;
        bit.assign(H, vector<T>(W, 0));
    }

    void add(int h, int w, T x) {
        for (int i = h; i < H; i += (i & -i)) {
            for (int j = w; j < W; j += (j & -j)) {
                bit[i][j] += x;
            }
        }
    }
    // 1≦i≦h かつ 1≦j≦w
    T sum(int h, int w) {
        T s(0);
        for (int i = h; i > 0; i -= (i & -i)) {
            for (int j = w; j > 0; j -= (j & -j)) {
                s += bit[i][j];
            }
        }
        return s;
    }

    // h1≦i<h2 かつ w1≦j<w2
    T query(int h1, int w1, int h2, int w2) {
        return sum(h2 - 1, w2 - 1) - sum(h2 - 1, w1 - 1) - sum(h1 - 1, w2 - 1) + sum(h1 - 1, w1 - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < H; ++i) {
            for (int j = 1; j < W; ++j) cout << query(i, j, i + 1, j + 1) << ",";
            cout << endl;
        }
    }
};

int main() {
    int H, W, T, Q;
    cin >> H >> W >> T >> Q;
    BIT2D<int> baking(H, W), baked(H, W);
    queue<tuple<int, int, int>> que;

    for (int i = 0; i < Q; i++) {
        int t, c, h, w;
        cin >> t >> c >> h >> w;
        while (!que.empty()) {
            tuple<int, int, int> tup = que.front();
            if (get<0>(tup) <= t) {
                que.pop();
                baking.add(get<1>(tup), get<2>(tup), -1);
                baked.add(get<1>(tup), get<2>(tup), 1);
            } else {
                break;
            }
        }

        if (c == 0) {
            baking.add(h, w, 1);
            que.push(make_tuple(t + T, h, w));
        } else if (c == 1) {
            if (baked.query(h, w, h + 1, w + 1) == 1) baked.add(h, w, -1);
        } else if (c == 2) {
            int h2, w2;
            cin >> h2 >> w2;
            cout << baked.query(h, w, h2 + 1, w2 + 1) << " " << baking.query(h, w, h2 + 1, w2 + 1) << endl;
        }
    }
    return 0;
}



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

int main(){
  int n;
  vector<pair<int, long long> > tree[100010];
  long long memo[100010];
  cin >> n;

  int a, b, c;
  for(int i = 0;i < n-1;i++){
    cin >> a >> b >> c;
    tree[a].push_back(make_pair(b, c));
    tree[b].push_back(make_pair(a, c));
  }

  int q, k;
  cin >> q >> k;

  queue<pair<int, long long> > que;
  pair<int, long long> tmp;

  memset(memo,-1,sizeof(memo));

  que.push(make_pair(k,0));
  while(!que.empty()){
    tmp = que.front(); que.pop();
    if(memo[tmp.first] == -1){
      memo[tmp.first] = tmp.second;
      for(int i = 0;i < tree[tmp.first].size();i++){
        que.push(make_pair(tree[tmp.first][i].first,tmp.second+tree[tmp.first][i].second));
      }
    }
  }

  int x, y;
  for(int i = 0;i < q;i++){
    cin >> x >> y;
    cout << memo[x] + memo[y] << endl;
  }

  return 0;
}






Measured memory_bytes: 10864
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#define mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e6 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
int a[maxn];
int main(){
	int n,k;cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> a[i];
	sort(a + 1,a + 1 + n);
	int ans = 0;
	for(int i = 1;i <= k;i++) ans += a[i];
		cout << ans;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, h[100010], dp[100010];

signed main() {
	cin >> n;
	rep(i, n)cin >> h[i];
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
	}
	cout << dp[n - 1] << endl;
	ggr
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,K,x,y;
    cin>>n>>K;
    vector<pair<ll,ll>> A(n);
    rep(i,n) cin>>x>>y,A[i]=make_pair(x,y);
    sort(A.begin(),A.end());
    ll m=4e18;
    rep(i,n)rep(j,n){
        if(j-i>=K-1){
            ll Xa=A[i].first,Xb=A[j].first;
            vector<ll> B;
            rep(k,j-i+1) B.push_back(A[i+k].second);
            sort(B.begin(),B.end());
            rep(k,j-i+2-K) m=min(m,(Xb-Xa)*(B[k+K-1]-B[k]));
        }
    }
    cout<<m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a;
	long long int sum=0;
	cin >> a;
	for(int i=1; i<=a; i++){
		if(i%3!=0&&i%5!=0) sum+=i;
	}
	cout <<sum;
    return 0;
}

Measured memory_bytes: 3652
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	sum := 0
	for {
		for i, v := range ar {
			if v%2 != 0 {
				fmt.Println(sum)
				return
			}
			ar[i] = v / 2
		}
		sum++
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>
#include<queue>

using namespace std;

#define INF 10000

queue<int> px, py;
int h, w, sx=1, sy=1, gx, gy, d[50][50], dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
string s[50];


int bfs() {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			d[i][j] = INF;
		}
	}
	px.push(sx - 1); py.push(sy - 1);
	d[sy - 1][sx - 1] = 0;

	while (px.size()) {

		int x = px.front(), y = py.front();
		px.pop(); py.pop();
		if (x == gx - 1 && y == gy - 1) {
			return d[y][x];
		}
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx >= 0 && nx < w && ny >= 0 && ny < h && s[ny][nx] == '.' && d[ny][nx] == INF) {
				d[ny][nx] = d[y][x] + 1;
				px.push(nx); py.push(ny);
			}
		}
	}
	return INF;
}

int main() {
	int b=0,dmin;
	cin >> h >> w;
	gx = w; gy = h;
	for (int i = 0; i < h; i++)cin >> s[i];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#')b++;
		}
	}
	dmin = bfs();
	if (dmin == INF)cout << -1 << endl;
	else {
		cout << w * h - b - dmin - 1 << endl;
	}
	return 0;
}

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

int main(){
  long a, dum, wait;
  priority_queue<long,vector<long>, greater<long>> q;
  cin >> a;
  for(int i=0;i<5;i++){
  	cin >> dum;    
  	q.push(dum);
  }
  if (q.top()==1){
	  cout <<a+4<<endl;  
  }else{
	  cout << a/q.top() +5<<endl;
  }
}

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

const int INF = 1e9 + 1;

int main() {

    int D, G;
    cin >> D >> G;

    vector<int> P(D), C(D);
    rep(i, D) cin >> P[i] >> C[i];

    int ans = INF;
    for (int bit = 0; bit < (1 << D); bit++) {
        int s = 0, num = 0, res_max = -1;

        rep(i, D) {
            if (bit >> i & 1) {
                s += 100 * (i + 1) * P[i] + C[i];
                num += P[i];
            } else {
                res_max = i;
            }
        }

        if (s < G) {
            int s1 = 100 * (res_max + 1);
            int n = (G - s + s1 - 1) / s1;
            if (n >= P[res_max]) {
                continue;
            }
            num += n;
        }
        ans = min(ans, num);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    from itertools import chain

    N, M, K = map(int, input().split())
    A = map(int, input().split())
    *B, = map(int, input().split())

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48600
#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;


void add(int *tree, int n, int k, int x) {
    k += n;
    tree[k] = x;
    for (k /= 2; k >= 1; k /= 2) {
        tree[k] = tree[2 * k] | tree[2 * k + 1];
    }
}

int sum(int *tree, int n, int a, int b) {
    a += n;
    b += n;
    int s = 0;
    while (a <= b) {
        if (a % 2 == 1) s |= tree[a++];
        if (b % 2 == 0) s |= tree[b--];
        a /= 2;
        b /= 2;
    }
    return s;
}

int popcount(int x) {
    int s = 0;
    while (x) {
        if (x & 1) s++;
        x >>= 1;
    }
    return s;
}

int main(int argc, char **argv) {
    int N, Q; // N <= 500000. (2^19  = 500000 + eps)
    int n = 1 << 19;
    string S;
    cin >> N >> S >> Q;

    // use segment tree for efficient data retrieval. Store the Bits of used characters.

    int *tree = (int *) calloc(2 * n, sizeof(int));

    // fill with input
    for (int i = 0; i < N; i++) {
        int c = S[i] - 'a';
        add(tree, n, i, 1 << c);
    }

    for (int i = 0; i < Q; i++) {
        int command;
        cin >> command;

        if (command == 1) {
            // update character
            int i;
            char c;
            cin >> i >> c;
            add(tree, n, i-1, 1 << (c - 'a'));
        } else {
            // query different characters
            int l, r;
            cin >> l >> r;
            int chars = sum(tree, n, l - 1, r - 1);
            cout << popcount(chars) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4868
#include <stdio.h>

int main(){

  int x,y,r,tmp;

  scanf("%d %d",&x,&y);

  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }

  r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
printf("%d\n",y);

 return 0;
}



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

int main()
{
 int N;
 int A;
 int B;
 int i;

 scanf("%d %d %d",&N,&A,&B);

 for(i=0;i<N;i++)
 {
  if(A<B-1)
  { 
   A++;
  }else if(A>1){
   A--;
  }else{
   printf("Borys\n");
   break;
  }
  if(A<B-1)
  {
   B--;
  }else if(B<N){
   B++;
  }else{
   printf("Alice\n");
   break;
  }
 }

 return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;

#define N 100010
#define lowbit(x) x&-x
int c[N*10];
int n,a[N],s[N*10];
void add(int x){
    for(int i=x;i<=2*N;i+=lowbit(i))c[i]++;
}
ll query(int x){
    ll sum=0;
    for(int i=x;i>0;i-=lowbit(i))sum+=c[i];
    return sum;
}
bool check(int x){
    for(int i=1;i<=2*N;i++)c[i]=0;
    s[0]=0;
    for(int i=1;i<=n;i++)
        s[i]=s[i-1]+(a[i]>=x?1:-1);
    ll sum=0;
    for(int i=0;i<=n;i++){
        sum+=query(s[i]+N);
        add(s[i]+N);
    }
    return sum>=1ll*n*(n+1)/4;
}
int main(){
    in1(n);
    int l=0,r=0;
    for(int i=1;i<=n;i++){
        in1(a[i]);
        r=max(r,a[i]);
    }
    int ans=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",r);
}

Measured memory_bytes: 4608
import sys
import math

def kyori(a, b):
    return math.sqrt((int(a[0])-int(b[0]))**2+(int(a[1])-int(b[1]))**2)

n=int(input())
xy=[input().strip().split() for i in range(n)]

k = 0

for Mfrom in range (n):
	for Mto in range (n):
		k = k + kyori(xy[Mfrom],xy[Mto])
        
print(k/n)
  
sys.exit()

Measured memory_bytes: 3064
/* ***************************************
Author        :Scau.ion
Created Time  :2017/03/18 20:28:25 UTC+8
File Name     :ion.cpp
*************************************** */

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

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

const int maxn=5010;

int a[maxn];
bool dp[maxn];

int main()
{
    IOS;
    int n,goo;
    cin>>n>>goo;
    for (int j=1;j<=n;++j)
    {
        int x;
        cin>>x;
        if (x>=goo) continue;
        ++a[x];
    }
    VPII v;
    int sum=0;
    for (int j=1;j<=goo;++j)
    {
        if (a[j])
        {
            for (int k=1;k<=a[j];++k)
                v.PB(MP(j,1));
        }
        sum+=j*a[j];
    }
    sort(v.begin(),v.end());
    int have=0;
    int ans=0;
    dp[0]=1;
    for (int j=v.size()-1;j>=0;--j)
    {
        have+=v[j].X;
        int last=sum-have;
        bool flag=0;
        if (last+v[j].X>=goo) flag=1;
        for (int k=goo-v[j].X;k<goo;++k)
            if (dp[k]) flag=1;
        for (int k=1;k<=goo;++k)
        {
            if (dp[k]==0) continue;
            int la=goo-k;
            if (v[j].X<la&&v[j].X+last>=la) flag=1;
        }
        if (!flag) ans+=v[j].Y;
        for (int k=1;k<=v[j].Y;++k)
        {
            for (int l=goo-1;l>=v[j].X;--l)
                if (dp[l-v[j].X]) dp[l]=1;
        }
        have+=v[j].X*(v[j].Y-1);
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N; cin >> N;
	vector<pair<ll, ll>> task(N);
	rep(i, N) {
		cin >> task[i].second >> task[i].first;
	}

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

	bool ans = true;

	ll t = 0;
	for (auto x : task) {
		t += x.second;
		if (t > x.first) {
			ans = false;
			break;
		}
	}

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

	return 0;
}

Measured memory_bytes: 6428
import numpy as np
import itertools

N, M, Q = map(int,input().split())

A = np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)))

n = len(A)
s = np.zeros(n, np.int32)

for i in range(Q):
    a, b, c, d = map(int,input().split())
    s += d * (A[:,b-1] - A[:,a-1] == c)

print(max(s))

Measured memory_bytes: 46672