akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS=1e-10,pi=M_PI;
typedef complex<double> P;
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
bool cmp(P a, P b) {
  double at=atan2(a.imag(),a.real()),at2=atan2(b.imag(),b.real());
  return at!=at2?at<at2:max(abs(a.real()),abs(a.imag()))<max(abs(b.real()),abs(b.imag()));
}
int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c)>EPS)return +1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}

int main() {
  ll n,m,x,y,sum[2];
  cin >> n >> m;
  for(int k=0; k<2; k++) {
    cin >> x >> y;
    if(x==n-1 && y==m-1) x=0,y=0;
    vector<P> v;
    map<double,ll> d;
    for(ll i=0; i<n; i++) {
      for(ll j=0; j<m; j++) {
        if(i-x || j-y) v.push_back(P(i-x,j-y));
      }
    }
    sort(v.begin(),v.end(),cmp);
    sum[k]=n*m*(n*m-1)*(n*m-2)/6;
    ll cnt=0,j=v.size()-1;
    while(j && (ccw(v[0],P(0,0),v[j])==1 || ccw(v[0],P(0,0),v[j])==0)) {
      cnt++;
      j--;
    }
    j=(j+1)%v.size();
    for(int i=0; i<v.size(); i++) {
      while(i!=j && ccw(v[i],P(0,0),v[j])!=1 && ccw(v[i],P(0,0),v[j])!=0) {
        cnt--;
        j=(j+1)%v.size();
      }
      sum[k]-=cnt*(cnt-1)/2;
      double at=atan2(v[i].imag(),v[i].real()),xx=v[i].real(),yy=v[i].imag();
      if(xx) xx=-xx;
      if(yy) yy=-yy;
      double at2=atan2(yy,xx);
      sum[k]-=d[at2]*(d[at2]+1)/2+d[at]*(d[at2]+1);
      cnt++;
      d[at]++;
    }
  }
  cout << abs(sum[0]-sum[1]) << endl;
  return 0;
}


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

using namespace std;

const int MAX_N = 2e5 + 10;

long long n;
long long a[MAX_N];
set<pair<long long, int>> s;
long long ans[MAX_N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s.insert({a[i], -i});
    }
    auto itr = s.end();
    itr--;
    int id = -itr->second;
    long long am = a[id];
    long long cnt = 1;
    while (1) {
        while (itr != s.begin() && itr->first == am) {
            itr--;
            cnt++;
        }
        if (itr->first != am) {
            cnt--;
            long long d = am - itr->first;
            ans[id] += d * cnt;
            id = min(id, -itr->second);
            am = itr->first;
            cnt++;
        } else {
            ans[id] += am * cnt;
            break;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }
}



Measured memory_bytes: 8960
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): any => {
  const N = +lines[0]
  const obj = { N }
  debug(obj)
  return obj
}

// solver
export const solve = (lines: string[]): string => {
  const { N } = parseLines(lines)

  return `${N * N * N}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


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

int main()
{
    int W, a, b;

    cin >> W >> a >> b;

    int aw = a + W;
    int bw = b + W;

    bool cnd1 = (a <= b && b <= aw);
    bool cnd2 = (a <= bw && bw <= aw);

    if (cnd1 | cnd2)
    {
        cout << 0;
        return 0;
    }

    if (aw < b)
    {
        cout << b - aw;
    }
    else
    {
        cout << (a - bw);
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

vector<int> pre, in, post;

int N;

vector<pair<ll, pair<ll, ll> > > ab;


int main(){
  cin >> N;

  REP(i,N){
    ll a,b;
    cin >> a >> b;
    ab.push_back(make_pair(a+b, make_pair(a,b)));
  }

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

  ll ans = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      ans += ab[N-1-i].second.first;
    }else{
      ans -= ab[N-1-i].second.second;

    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 4852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String S=scan.next();
		char[] y=S.toCharArray();
		if(y[0]==y[1] && y[1]!=y[2] && y[2]==y[3])
		{
			System.out.println("Yes");
		}
		else if(y[0]==y[2] && y[2]!=y[1] && y[1]==y[3])
		{
			System.out.println("Yes");
		}
		else if(y[0]==y[3] && y[3]!=y[1] && y[1]==y[2]) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}

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

/*
When n is odd, 5 for instance, the sequence of the absolute differences of the left and the right will be:
4, 2, 0, 2, 4
so, there should be one 0 and two identical even numbers to have the consistent order.
When n is even, 6 for instance, the sequence of the absolute differences of the left and the right will be:
5, 3, 1, 1, 3, 5
so, there should be two identical odd numbers to have the consistent order.
If the consistent order exists, there are 2^(n/2) possible orders since there are two identical values
for each different values.
*/

const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<int, int> diffs;  // how many identical abs diffs
  rep(i, n) {
    int pos;
    cin >> pos;
    diffs[pos]++;
  }

  // start from 0 if n is odd; start from 1 if n is even
  // if n is odd, possible abs diffs are 0, 2, 4, 6...
  // if n is even, possible abs diffs are 1, 3, 5, 7...
  for (int i = !(n%2); i < n; i += 2) {
    if (i == 0) {
      if (diffs[i] != 1) {  // there is no possible orders if there is more than one person with only one possible position
        cout << 0 << endl;
        return 0;
      }
    }
    else if (diffs[i] != 2) {  // there must be two people with the same abs diffs
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i, n/2) ans = (ans * 2) % mod;  // there are 2^(n/2) possible orders if it exists
  cout << ans << endl;
}

Measured memory_bytes: 6588
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, A, B, C, D;
  std::string S;
  std::cin >> N >> A >> B >> C >> D >> S;
  --A, --B, --C, --D;

  for (i64 i = A; i + 1 <= C; ++i) {
    if (S[i] == '#' && S[i + 1] == '#') goto FAILED;
  }
  for (i64 i = B; i + 1 <= D; ++i) {
    if (S[i] == '#' && S[i + 1] == '#') goto FAILED;
  }
  if (A < C && C < B && B < D) goto SUCCEEDED;
  if (A < B && B < C && C < D) goto SUCCEEDED;

  // A < B < D < C
  for (i64 i = B - 1; i + 2 <= D + 1; ++i) {
    if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') goto SUCCEEDED;
  }
  goto FAILED;

SUCCEEDED:
  std::cout << "Yes" << std::endl;
  return 0;

FAILED:
  std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 640
N,K = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
time=[]
for i in range(N-K+1):
    minSign='minus' if x[i]<0 else 'plus'
    maxSign='minus' if x[i+K-1]<0 else 'plus'
    if minSign=='minus' and maxSign=='minus':
        time.append(abs(x[i]))
    elif minSign=='plus' and maxSign=='plus':
        time.append(abs(x[i+K-1]))
    else:
        time.append(abs(x[i])+abs(x[i+K-1])+min(abs(x[i]),abs(x[i+K-1])))
print(min(time))


Measured memory_bytes: 14484
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a%b);
}

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", gcd(a, b));
    return 0;
}



Measured memory_bytes: 3224
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;
#define A first
#define B second
#define pb push_back
void chmax(int &a, int b) { a = (a > b ? a : b); }
void chmin(int &a, int b) { a = (a < b ? a : b); }

int main() {
    int A, B;
    cin >> A >> B;
    cout << (B % A == 0 ? A + B : B - A) << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    n, p = map(int, input().split())
    pp = p
    if n == p == 0:
        break
    stones = [0] * n
    for i in range(1000000):
        er = i % n
        if p >= 1:
            stones[er] += 1
            p -= 1
            if p == 0 and stones[er] == pp:
                print(er)
                break
        else:
            p = stones[er]
            stones[er] = 0

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

int main(){
	string a;
	int b,c;
	while(cin >> a >> b >> c){
		cout << a << " " << b+c << " " << b * 200 + c * 300 << endl;
	}
}

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

const int MOD = 1e9 + 7;

int n, k;
int dp[5005][5005];
char s[5005];

inline int lgput(int x, int p){
    int ans = 1, aux = x;
    for(int i = 1; i <= p ; i = i << 1){
        if(i & p) ans = (1LL * ans * aux) % MOD;
        aux = (1LL * aux * aux) % MOD;
    }
    return ans;
}

int main()
{
    scanf("%d", &k);
    scanf("%s", s);
    n = strlen(s);

    dp[0][0] = 1;
    for(int i = 1; i <= k ; ++i){
        for(int j = 0; j <= k ; ++j){
            if(j > 0) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * 2LL) % MOD;
            if(j == 0) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % MOD;
        }
    }

    int i2 = lgput(2, MOD - 2);
    int ans = dp[k][n];
    for(int i = 1; i <= n ; ++i)
        ans = (1LL * ans * i2) % MOD;

    printf("%d", ans);

    return 0;
}












Measured memory_bytes: 98048
x = []
for i in range(5):
    x.append(int(input()))
k = int(input())

def solve(x,k):
    for i in range(5):
        for j in range(5):
            if abs(x[i]-x[j]) > k:
                return ":(" 
                
    return "Yay!"
print(solve(x,k))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void c_p_c(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
string lcs(string a,string b){
	int m = a.length();
	int n = b.length();
	int dp[m+1][n+1];
	string ans = "";
	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(i==0 or j==0)
				dp[i][j] = 0;
			else if(a[i-1]==b[j-1])
				dp[i][j] = dp[i-1][j-1] + 1;
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	int i=m,j=n;
	while(i>0 and j>0){
		if(a[i-1]==b[j-1]){
			ans += a[i-1];
			i--,j--;
		}
		else if(dp[i][j] == dp[i][j-1]){
			j--;
		}
		else{
			i--;
		}
	}
	reverse(ans.begin(),ans.end());
	return ans;
}
int main()
{
	c_p_c();
	string a,b;
	cin>>a>>b;
	cout<<lcs(a,b);
}

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

const string AC = "AC";
const string WA = "WA";

int main() {
  int N, M;
  cin >> N >> M;

  vector<bool> ac(N + 1, false);
  vector<int> wa(N + 1, 0);

  rep(i, M) {
    int p;
    string s;
    cin >> p >> s;

    if (!ac.at(p) && s == WA) wa.at(p)++;
    if (s == AC) ac.at(p) = true;
  }

  int a = 0, p = 0;
  rep1(i, N) {
    if (ac.at(i)) {
      a++;
      p += wa.at(i);
    }
  }

  cout << a << " " << p << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string s; cin >> s;
  ll N = s.size();
  bool ok = true;
  for (ll i = 0; i < N; i++) {
    if (s[i] != s[N-1-i]) {ok = false;}
  }
  
  for (ll i = 0; i <(N-1)/2; i++) {
    if (s[i] != s[(N-1)/2-1-i]) {ok = false;}
  }
  
  if (ok) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,ans=0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    int sum=0,tmp=i;
    while(tmp/10!=0){
      sum+=tmp%10;
      tmp/=10;
    }
    sum+=tmp;
    if(sum>=a&&sum<=b){
      ans+=i;
    }
  }
  cout << ans << endl; 
  return 0;
}

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

int main() {
    int n;
    ll d;
    cin >> n >> d;
    d *= d;
    int ans=0;
    for(int i = 0; i < n; i++) {
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=d) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

x, k, d = MAP()
n = x//d

if k <= abs(n):
    if x > 0:
        ans = x - d*k
    else:
        ans = x + d*k
elif ( k - abs(n) ) % 2 == 0:
    ans = x - d*n
else:
    ans = x - d*(n+1)

print(abs(ans))

Measured memory_bytes: 10296
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) { a += b, a %= MOD; }

int main() {
  // Input
  int N;
  int K;
  std::cin >> N >> K;
  std::string S;
  std::cin >> S;
  assert(S.size() == (size_t)N);
  S.insert(S.begin(), '-');

  // Main
  std::vector<int> segment;
  // segment.push_back(0);
  bool on = false;
  int num = 0;
  if (S[1] == '0')
    segment.push_back(0);
  for (int i = 1; i <= N; ++i) {
    if (S[i] == '0') {
      if (on) {
        // Shutdown
        on = false;
        assert(num >= 1);
        segment.push_back(num);
        num = 1;
      } else {
        // down
        num += 1;
      }
    } else {
      assert(S[i] == '1');
      if (on) {
        // up
        num += 1;
      } else {
        // startup
        on = true;
        segment.push_back(num);
        num = 1;
      }
    }
  }
  segment.push_back(num);
  // if (S[N] == '0')
  //   segment.push_back(0);

  int numSegment = segment.size();
  std::vector<int> sum(1 + numSegment, 0);
  for (int i = 0; i < numSegment; ++i) {
    sum[i + 1] = sum[i] + segment[i];
  }

  int len = 2 * K + 1;
  int res = -1;
  for (int i = 0; i < numSegment; i += 2) {
    int left;
    int right;
    if (S[1] == '0') {
      left = i;
      right = i + len;
    } else {
      left = i + 1;
      right = i + len + 1;
    }

    // int left = i + 1;
    // int right = i + len + 1;
    int q;
    if (right <= numSegment)
      q = sum[right] - sum[left];
    else
      q = sum[numSegment] - sum[left];
    chmax(res, q);
  }

  // Output
  std::cout << res << std::endl;


  return 0;
}


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

GRID = [["."] * (w + 2)]
for _ in range(h):
    GRID.append(["."] + list(input()) + ["."])
GRID.append(["."] * (w + 2))

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if GRID[i][j] == "#":
            continue
        cnt = 0
        for a in range(-1, 2):
            for b in range(-1, 2):
                if GRID[i + a][j + b] == "#":
                    cnt += 1
        GRID[i][j] = str(cnt)

for row in GRID[1:h + 1]:
    print("".join(row[1:w + 1]))


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    vector<int> DP(K+1000);
    REP(i,K+1){
        REP(j,N){
            ll a = A[j];
            if(i+a > K) continue;
            if(DP[i] == 0)
                DP[i+a] = 1;
        }
    }

    ll ans = DP[K];

    if(ans == 0)
        cout << "Second" << endl;
    else
        cout << "First" << endl;

    return 0;
}


Measured memory_bytes: 640
from collections import deque as dq
n,m = list(map(int,input().split()))
graph = [[] for i in range(n)]
for i in range(m):
    a,b = list(map(int,input().split()))
    a -= 1;b -= 1
    graph[a].append(b)
s,t = list(map(int,input().split()))
s -= 1;t -= 1
check = [[-1,-1,-1] for i in range(n)]
que = dq()
que.appendleft([s,0])
check[s][0] = 0
while (que):
    v,l = que.pop()
    for i in graph[v]:
        if check[i][(l+1)%3] == -1:
            que.appendleft([i,(l+1)%3])
            check[i][(l+1)%3] = check[v][l] + 1
if check[t][0] == -1:
    print(-1)
else:
    print(check[t][0] // 3)

Measured memory_bytes: 41316
#include <iostream>

using namespace std;

int n, k;

int main() {
    int result = 0;
    cin >> n >> k;
    int array[n];
    for (int i=0; i<n; i++){
        cin >> array[i];
    }

    for (int i=0; i<n; i++){
        if(array[i] >= k){
            result++;
        }
    }

    cout << result;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}


	sort(a.begin(),a.end(), greater<ll>());
	ll ans = a[0];
	for (int i = 2; i < n; i++)
	{
		ans += a[i / 2];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4780
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for _ in range(n):
  s = input()
  if s == 'AC':
    ac += 1
  elif s == 'WA':
    wa += 1
  elif s ==  'TLE':
    tle += 1
  elif s == 'RE':
    re += 1
print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))

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

const double EPS=1e-6;

double evaluate(vector<double>&r){
    double res=r[0]+r[r.size()-1];
    for(int i=0;i+1<r.size();i++){
        double h=(r[i]+r[i+1]);
        double s=abs(r[i]-r[i+1]);
        res+=sqrt(h*h-s*s);
    }
    return res;
}

double optimize(vector<double>r){
    double T=10000;
    double cool=0.99;
    double step=1;

    double mi=evaluate(r);

    while(T>0.00001){
        int a,b;
        while(true){
            a=rand()%r.size();
            b=rand()%r.size();
            if(a!=b)break;
        }

        double score=evaluate(r);
        swap(r[a],r[b]);
        double new_score=evaluate(r);

        double p=exp(-abs(new_score-score)/T);

        if(new_score>score || rand()<p*RAND_MAX);
        else{
            swap(r[a],r[b]);
        }

        mi=min(mi,new_score);
        T*=cool;
    }
    return mi;
}

int main(){
    int l;
    while(cin>>l){
        string str;
        getline(cin,str);
        stringstream ss(str);
        vector<double>r;
        while(!ss.eof()){
            double t;
            ss>>t;
            r.push_back(t);
        }

        double ans;
        if(r.size()==1)ans=r[0]*2;
        else ans=optimize(r);

        if(ans<l+EPS)puts("OK");
        else puts("NA");
    }

    return 0;
}

Measured memory_bytes: 3432
#include <iostream>
#include<algorithm>
using namespace std;
int main(){
    int N, A, B, C, D;
    cin>>N;
    int a[100];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int minimum = 100000;
    int lef = 0;
    int rif = 0;
    for(int t=0;t<=100;t++){
        lef=0;
        rif=0;
        for(int i=0;i<N;i++){
            if(i<=t)
                lef+=a[i];
            else
                rif+=a[i];
        }
        minimum=min(minimum,abs(lef-rif));
    }
    cout<<minimum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0; i<n; i++)
int main()
{
	int N,D1,D2;
	cin >> N;
	int suc = 0;
	int judge = 0;
	
	for(int i = 0; i<N; i++){
		cin >> D1 >> D2;
		if(D1==D2)
			suc++;
		else
			suc = 0;
		if(suc == 3){
			judge++;
		}
	}

	if(judge == 0)
		cout << "No";
	else
		cout << "Yes";

	cin >> suc;

	return 0;	
}


Measured memory_bytes: 3628
/*
    2014.07.04 1259~1310
    C language Lecture week ∞
*/

#include <stdio.h>
#include <string.h>

char classify ( int score_math, int score_eng, int score_jpn );

int main (void) {
    
    int score_math = -1;
    int score_eng = -1;
    int score_jpn = -1;
    
    int max = -1;
    
    while (1) {
        
        scanf ( "%d", &max );
        
        if ( max == 0 ) {
            break;
        }
        
        for ( int cnt = 0; cnt < max; cnt ++ ) {
            scanf ( "%d", &score_math );
            scanf ( "%d", &score_eng );
            scanf ( "%d", &score_jpn );
            printf ( "%c\n", classify ( score_math, score_eng, score_jpn ) );
        }
    
    }
    
    return 0;
    
}

char classify ( int score_math, int score_eng, int score_jpn ) {
    char out;
    int score_me = ( score_math + score_eng );
    int score_mej = ( score_math + score_eng + score_jpn );
    
    if ( score_math == 100 || score_eng == 100 || score_jpn == 100 ) {
        out = 'A';
    } else if ( score_me >= 180 ) {
        out = 'A';
    } else if ( score_mej >= 240 ) {
        out = 'A';
    } else if ( score_mej >= 210 ) {
        out = 'B';
    } else if ( score_mej >= 150 && ( score_math >= 80 || score_eng >= 80 ) ) {
        out = 'B';
    } else {
        out = 'C';
    }
    
    return out;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

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 / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
bool cmp1(vi& a, vi& b) {
  return a[1] < b[1] || (a[1] == b[1] && a[2] < b[2]);
}
bool cmp2(vi& a, vi& b) {
  return a[0] < b[0];
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m, p, y;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  vector< vi > arr(m, vi(3));
  fi(0, m) {
    cin >> p >> y;
    arr[i][0] = i;
    arr[i][1] = p;
    arr[i][2] = y;
  }
  sort(all(arr), cmp1);
  p = arr[0][1];
  int cnt = 1;
  fi(0, m) {
    if(arr[i][1] != p) {
      p = arr[i][1];
      cnt = 1;
    }
    arr[i][2] = cnt++;
  }
  sort(all(arr), cmp2);
  for(vi v: arr) {
    cout << setw(6) << setfill('0') << v[1];
    cout << setw(6) << setfill('0') << v[2];
    cout << endl;
  }
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 7040
import numpy
N = int(input())
ary = list(map(int, input().split(' ')))
ary_int = numpy.cumsum(ary).tolist()
ary_int.sort()
ary_int.append(float('inf'))

count = 0
same_count = 0
for i in range(N):
    if ary_int[i] == ary_int[i+1]:
        same_count += 1
    else:
        count += same_count * (same_count + 1) // 2
        same_count = 0
count += ary_int.count(0)
print(int(count))

Measured memory_bytes: 34652
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second

#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {
    clue();
    return 0;
}
int clue() {
    
    lli n,d;
    cin>>n>>d;
    multimap<lli,lli>m;
    multimap<lli,lli>::iterator it;
    // list<pair<lli,lli> >m;
    // list<pair<lli,lli> >::iterator it;

    lli count=0;
    while(n-->0) {
        lli x,y;
        cin>>x>>y;
        m.insert(MP(x,y));
        // m.pub(MP(x,y));
    }
    for(it=m.begin();it!=m.end();++it) {
        lli x,y;
        x=it->first MULTIPLY it->first;
        y=it->second MULTIPLY it->second;

        lli p=x+y;
        double dd=sqrt(p);
        if(dd<=d)++count;
    }
    // for(it=m.begin();it!=m.end();++it) {
        // cout<<it->first<<" "<<it->second<<endl;
    // }

    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 16108
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N;
  cin >> N;
  pair<string, int> S[N];
  rep(i,N){
    cin >> S[i].first >> S[i].second;
  }
  string T;
  cin >> T;
  int a, ans = 0;
  for(int i=0;i<N;i++){
    if(S[i].first == T) a = i;
  }
  for(int i=a+1;i<N;i++){
    ans += S[i].second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<int>> mat;

int main(){
    ll H,W;cin>>H>>W;
    int N;cin>>N;
    pair<int,int> P[100010];
    map<pair<int,int>,int> mp;
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        P[i]={a,b};
        mp[P[i]]++;
    }
    vec ans(10,0);
    for(int i=0;i<N;i++){
        int x=P[i].first,y=P[i].second;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                //9通りの位置を固定
                bool B=true;
                //左or上にあるかどうかcheck
                for(int l=0;l<j;l++){
                    for(int m=0;m<3;m++)
                        if(mp[{x-j+l,y-k+m}]==1)B=false;
                }
                for(int m=0;m<k;m++)
                    if(mp[{x,y-k+m}]==1)B=false;

                //右or下を数える
                if(B && x-j>0 && y-k>0 && x-j<H-1 && y-k<W-1){
                    int count=0;
                    for(int u=0;u<3;u++){
                        for(int v=0;v<3;v++)
                            if(mp[{x-j+u,y-k+v}]==1)count++;
                    }
                    ans[count]++;
                }
            }
        }
    }
    ans[0]=(ll)(H-2)*(W-2);
    for(int i=1;i<=9;i++)
        ans[0]-=ans[i];
    for(int i=0;i<10;i++)
        cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 157312
X=int(input())
n5=[n**5 for n in range(1000)]
for i,a in enumerate(n5):
    for j,b in enumerate(n5):
        if a-b==X: print(i,j); exit()
        elif a+b==X: print(i,-j); exit()
        elif -a-b==X: print(-i,j); exit()
        elif -a+b==X: print(-i,-j); exit()


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n)
    {
        cin >> p.at(i);
    }

    int count = 1;
    int mini = p.at(0);
    for (int i = 1; i < n; i++)
    {
        if (p.at(i) <= mini)
        {
            count++;
            mini = p.at(i);
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
N,M = [int(i) for i in input().split()]
table = [[] for i in range(N)]


for l in range(M):
    command,num = [int(i) for i in input().split()]
    if command == 0:
        print(table[num-1].pop(0))
    else:
        minSize = 10000
        minId = -1
        for i in range(N):
            if len(table[i]) < minSize:
                minSize = len(table[i])
                minId = i
        #print(minId,num)
        table[minId].append(num)


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

int main(){
  long n,k;
  cin>>n>>k;
  long h[n],c=0;
  for(int i=0;i<n;i++){
     cin>>h[i];
     if(h[i]>=k)c++;
  }
  cout<<c;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.Map (Map)
import qualified Data.Map as M
import Data.Sequence (Seq,ViewR(..),(<|))
import qualified Data.Sequence as Sq

main = do
  [h,w] <- map read.words <$> getLine
  s <- replicateM h getLine
  print $ solve h w (generateMap s)

solve height width map
  | shortest == -1 = -1
  | otherwise = M.size (M.filter (/='#') map) - shortest
  where
  shortest = go map $ Sq.singleton ((1,1),1)
  go map q = inner map $ Sq.viewr q
  inner map (q:>(p@(x,y),l))
    | x == width && y == height = l
    | map!?p == Just '.' = go (M.insert p '%' map) ((e,l+1)<|(w,l+1)<|(n,l+1)<|(s,l+1)<|q)
    | otherwise = go map q
    where [e,w,n,s] = [(x+dx,y+dy) | (dx,dy) <- [(1,0),(-1,0),(0,1),(0,-1)]]
  inner map EmptyR = -1

generateMap = go 1 1
  where
  go _ _ [] = M.empty
  go x y ([]:sss) = go 1 (y+1) sss
  go x y ((s:ss):sss) = M.insert (x,y) s $ go (x+1) y (ss:sss)

(!?) :: Ord k => Map k a -> k -> Maybe a
map !? k = M.lookup k map

Measured memory_bytes: 1532
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (int)1e8
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int c[3][3];
int a[3], b[3];
/**********************************************/

signed main(){
    REP(i, 3){
        REP(j, 3){
            cin >> c[i][j];
        }
    }
    
    a[0] = 0;
    REP(i, 3){
        b[i] = c[0][i] - a[0];
    }
    FOR(i, 1, 3){
        a[i] = c[i][0] - b[0];
    }

    REP(i, 3){
        REP(j, 3){
            if(a[i] + b[j] != c[i][j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes"  << endl;
}


Measured memory_bytes: 256
x = int(input())

if 400 <= x < 600:
    print(8)
elif 600 <= x < 800:
    print(7)
elif 800 <= x < 1000:
    print(6)
elif 600 <= x < 1200:
    print(5)
elif 1200 <= x < 1400:
    print(4)
elif 1400 <= x < 1600:
    print(3)
elif 1600 <= x < 1800:
    print(2)
elif 1800 <= x < 2000:
    print(1)

Measured memory_bytes: 61620
#include <stdio.h>          // printf(), fprintf(), getline()
#include <stdlib.h>         // exit(), free()
#include <string.h>         // strlen(), strcpy(), strncmp()
#include <ctype.h>          // tolower()
#include <stdbool.h>
#include <errno.h>          // errno
#ifdef linux
 #include <error.h>         // error()
#endif

#define MAX_L 10
const char NUL = '\0';

int lineno;
char* linebuff = NULL;
size_t linebuffsize = 0;

char w[MAX_L + 1];
int len;
int count;

void
cleanup(int ecode)
{
	if (linebuff)
	{
		free(linebuff);
		linebuff = NULL;
		linebuffsize = 0;
	}

	exit(ecode);
}

const char*
strcasestr(const char* s, const char* t)
{
	while (true)
	{
		if (*s == NUL)
			return NULL;

		int i = 0;
		while (tolower(s[i]) == tolower(t[i]))
		{
			i++;
			if (t[i] == NUL)
				return s;
		}

		s++;
	}
}

bool
ope_line(char* linebuff)
{
	lineno++;
	const char* s = linebuff;
	if (strncmp(s, "END_OF_TEXT", 11) == 0)
		return false;

	while (true)
	{
		s = strcasestr(s, w);
		if (s == NULL)
			break;

		if ((s == linebuff || s[-1] == ' ') && (s[len] == ' ' || s[len] == '\n' || s[len] == NUL))
			count++;

		s += len;
	}

	return true;
}

void
first_line(const char* linebuff)
{
	lineno++;
	strcpy(w, linebuff);
	int i = strlen(w) - 1;
	for (; i > 0 && w[i] != ' ' && w[i] != '\n' && w[i] != NUL; --i)
		;

	w[i] = NUL;
	len = strlen(w);
}

int
main(int argc, char** argv)
{
	count = 0;
	lineno = 0;
	while (true) // process for each line
	{
		errno = 0;
		if(getline(&linebuff, &linebuffsize, stdin) == -1) // read line
		{
			if(errno == 0)  // EOF?
				break;

#ifdef linux
			error(0, errno, "Can't read line");
#else
			fprintf(stderr, "Can't read line\n");
#endif
			cleanup(1);
		}

		if (lineno == 0)
			first_line(linebuff);
		else
		{
			if (!ope_line(linebuff))
				break;
		}
	}

	printf("%d\n", count);
	cleanup(0);
	return 0;
}

Measured memory_bytes: 568
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  ll ans=0;
  for(int i=1;i<=N;i++)
  {
    ans+=N/i*(N/i+1)/2*i;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
typedef long long ll;
ll n,a[100002],c[100011];
ll getSum(ll x)
{
	ll i;
	ll sum=0;
	for(i=x+1;i>0;)
	{
		sum+=c[i];
		i-=(i & -i);
	}
return sum;
	}
void update(ll x,ll y)
{
	ll i;
a[x]+=y;
	for(i=x+1;i<=n;)
	{
		c[i]+=y;
		i+=(i & -i);
	}
	
}

int main()
{
	ll q,com,x,y;
	scanf("%lld%lld",&n,&q);
	for(ll i=0;i<n+1;i++) 
	{
		a[i]=0;
		c[i]=0;
	}
	for(ll i=0;i<q;i++)
	{
		scanf("%lld%lld%lld",&com,&x,&y);
		if(com==0)
		 update(x-1,y);
		 else
		 printf("%lld\n",getSum(y-1)-getSum(x-2)); 
	}

	
	return 0;
	
	}

Measured memory_bytes: 2752
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N,a;
	int index[Nmax]={};
	cin >> N;
	REP(i,N){
		cin >> a;
		if(a-1>=0) index[a-1]++;
		index[a]++;
		index[a+1]++;
	}
	sort(index, index+Nmax);
	cout << index[Nmax-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
'''
https://atcoder.jp/contests/abc088/tasks/abc088_d
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    h,w = map(int, input().split())
    a = [list(input().rstrip()) for _ in range(h)]
    kuro = 0
    for i in a:
        kuro += i.count('#')
    d = deque([[0,0]])
    dxy = [[0,1],[0,-1],[1,0],[-1,0]]
    a[0][0] = 1
    while d:
        x,y = d.popleft()
        for dx, dy in dxy:
            nx = x + dx
            ny = y + dy
            if 0<=nx<=h-1 and 0<=ny<=w-1:
                if a[nx][ny] == '.':
                    a[nx][ny] = a[x][y] + 1
                    d.append([nx, ny])
    if a[h-1][w-1] == '.':
        print(-1)
    else:
        print(h*w - a[h-1][w-1]-kuro)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40176
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,num=0,sum=0,flag=0;string S;
  cin >> S;
  N=S.size();
  DV(dp,int,2,2019,0);//dp[i文字目まで見た][2019で割った余りがj]
  dp[0][(S[0]-'0')]=1;
  rep(i,1,N){
    if(i%2==1)flag=1;
    else flag=0;
    rep(j,0,2019)dp[flag][(10*j+(S[i]-'0'))%2019]+=dp[flag^1][j];
    dp[flag][S[i]-'0']++;
    sum+=dp[flag][0];
    rep(j,0,2019)dp[flag^1][j]=0;
  }
  Out(sum);
}


Measured memory_bytes: 3772
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    yyy=10**18
    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))

    x=1
    for a in arr:
        if a==0:
            print(0)
            return
        
        if x==-1:
            continue

        x*=a

        if x > yyy:
            x=-1
    
    print(x)

    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 29564
N = int(input())
S = [input() for i in range(N)]
d = {}
for s in S:
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1

max_cnt = 0
for i in d:
    max_cnt = max(max_cnt, d[i])

t = []
for i in d:
    if d[i]==max_cnt:
        t.append(i)
t.sort()
print(*t, sep='\n')

Measured memory_bytes: 35600
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = 0
mae = -1

for i in range(n):
    ans += b[a[i]-1]
    if a[i] == mae+1:
        ans += c[a[i]-2]
    mae = a[i]
        
print(ans)

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

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

    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
const int inf = 1 << 30;
int N, K, Q;
int A[2010];

int solve(){
    int ans = inf;
    vector<int> vs;
    for(int i = 0; i < N; i++){
        vs.push_back(A[i]);
    }
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());
    for(auto u : vs){
        vector<int> val;
        vector<int> sec;
        for(int i = 0; i < N; i++){
            if(A[i] >= u) sec.push_back(A[i]);
            if(A[i] < u || i == N - 1){
                sort(sec.begin(), sec.end());
                int size = sec.size();
                for(int j = 0; j <= size - K; j++){
                    val.push_back(sec[j]);
                }
                sec.clear();
            }
        }
        if(val.size() >= Q){
            sort(val.begin(), val.end());
            ans = min(ans, val[Q - 1] - val[0]);
        }
    }
    return ans;
}

void init(){
    cin >> N >> K >> Q;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
}

int main(){
    init();
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 256
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define SZ(c) int(c.size())
#define ff first
#define ss second
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
int LCM(int a, int b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n;
	cin >> n;
	map<LL, LL>mpp;
	int i = 1;
	mpp[n] = i;
	i++;
	while (1)
	{
		if (n % 2 == 0)
		{
			if (mpp[n / 2] > 0)
				return cout <<i<< endl, 0;
			else mpp[n / 2] = i, i++,n=n/2;
		}
		else
		{
			if (mpp[3 * n + 1] > 0)
				return cout << i << endl, 0;
			else mpp[3 * n + 1] = i, i++,n=3*n+1;
		}
	}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()
BC = [lr() for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
count = 0
for b, c in BC:
    x = [c] * b
    D.extend(x)
    count += b
    if count >= N:
        break

E = A + D
E.sort(reverse=True)
answer = sum(E[:N])
print(answer)


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int x, a, b; scanf("%d%d%d", &x, &a, &b);
	if (abs(x-a) < abs(x-b)) puts("A");
	else puts("B");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256