akhauriyash/Code-Regression huggingface dataset:
H,W=list(map(int,input().split()))
A=[]
for i in range(H):
    A.append(list(map(int,input().split())))
sum_=0
ans=[]
for i,aline in enumerate(A):
    for j in range(W-1):
        if aline[j]%2==1:
            aline[j+1]+=1
            sum_+=1
            ans.append('{0} {1} {2} {3}'.format(i+1,j+1,i+1,j+2))
for i,aline in enumerate(A[:-1]):
    if aline[W-1]%2==1:
        A[i+1][W-1]+=1
        sum_+=1
        ans.append(('{0} {1} {2} {3}'.format(i+1,W,i+2,W)))
print(sum_)
for x in ans:
    print(x)

Measured memory_bytes: 16408
n = int(input())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
  a = input()
  if a[0] == "M":
    Mnum+=1
  elif a[0] == "A":
    Anum+=1
  elif a[0] == "R":
    Rnum+=1
  elif a[0] == "C":
    Cnum+=1
  elif a[0] == "H":
    Hnum+=1
alist = []
alist.append(Mnum)
alist.append(Anum)
alist.append(Rnum)
alist.append(Cnum)
alist.append(Hnum)
from itertools import combinations
print(sum([a*b*c for a,b,c in combinations(alist,3)]))

Measured memory_bytes: 9196
unittest
{
	assert( [ "3", "3 5 -1" ].parse.expand.solve == "12\n8\n10" );
	assert( [ "5", "1 1 1 2 0" ].parse.expand.solve == "4\n4\n4\n2\n4" );
	assert( [ "6", "-679 -2409 -3258 3095 -3291 -4462" ].parse.expand.solve == "21630\n21630\n19932\n8924\n21630\n19288" );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 出発地点と帰着地点として座標0を足す
	as = [ 0L ] ~ as ~ [ 0L ];
	
	// 普通に全部回ったときの金額を出す
	auto f = 0L;
	foreach( i; 1 .. as.length )
	{
		f += ( as[ i ] - as[ i - 1 ] ).abs;
	}
	
	// 1 .. n のどれかをスキップした時の金額を出す
	auto ss = new long[ as.length - 2 ];
	foreach( i; 1 .. as.length - 1 )
	{
		if( ( as[ i - 1 ] <= as[ i ] && as[ i ] <= as[ i + 1 ] ) ||
		    ( as[ i + 1 ] <= as[ i ] && as[ i ] <= as[ i - 1 ] ) )
		{
			// 通過なら金額減らない
			ss[ i - 1 ] = f;
		}
		else
		{
			// 折り返しているなら往復分の金額が減る
			auto dl = ( as[ i - 1 ] - as[ i ] ).abs;
			auto dr = ( as[ i ] - as[ i + 1 ] ).abs;
			ss[ i - 1 ] = f - 2 * min( dl, dr );
		}
	}
	
	return ss.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 13176
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,q;
  cin>>n>>k>>q;
  std::vector<int> a(q);
  std::vector<int> hp(n,k);

  for(int i=0;i<q;i++){
    cin>>a.at(i);
  }

  for(int i=0;i<q;i++){
    hp.at(a.at(i)-1)+=1;
  }

  for(int i=0;i<n;i++){
    if(hp.at(i)-q<=0){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }


  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	static char[] voice;
	static int i = 0;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		voice = sc.next().toCharArray();
		check();
		System.out.println(i == voice.length ? "Cat" : "Rabbit");
	}

	public static void check() {
		if (voice[i] != 'm')
			return;
		i++;
		check();
		if (voice[i] != 'e')
			return;
		i++;
		check();
		if (voice[i] != 'w')
			return;
		i++;
		return;
	}
}

Measured memory_bytes: 12000
h, w, k=map(int, input().split())
l = [[] for _ in range(h)]
for _ in range(h):
  s=str(input())
  for o in s:
    if o=="#":
      l[_].append(1)
    else:
      l[_].append(0)
import numpy as np
l=np.array(l)
cnt=0

from itertools import product
s = [0,1]
for v1 in sorted(list(product(s, repeat=h)), reverse=1):
  for v2 in sorted(list(product(s, repeat=w)), reverse=1):
    lcal=l
    v1a=[]
    for i in v1:
      v1a.append([i])
    v1a=np.array(v1a)
    v2a=np.array(v2)
    lcal=v2a*lcal
    lcal=v1a*lcal
    if sum(sum(lcal))==k:
      cnt+=1
print(cnt)


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

int N, C;
int D[31][31], c[510][510];
int cnt[3][31];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> C;
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      cin >> D[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> c[i][j];
      c[i][j]--;
      cnt[(i + j + 2) % 3][c[i][j]]++;
    }
  }
  int ans = 1 << 30;
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      for (int k = 0; k < C; k++) {
        if (i == j || j == k || k== i) continue;
        int sum = 0;
        for (int l = 0; l < C; l++) {
          sum += cnt[0][l] * D[l][i];
          sum += cnt[1][l] * D[l][j];
          sum += cnt[2][l] * D[l][k];
        }
        ans = min(ans, sum);
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1280
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val As = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    
    As.sortDescending()
    
    var longer = 0L
    var shorter = 0L
    
    var now = As[0]
    var index = 1
    
    while (index < N) {
        if (As[index] == now) {
            if (longer == 0L) {
                longer = now
                index++
            } else {
                shorter = now
                break
            }
        }
        if (index < N) {
            now = As[index]
            index++
        }
    }

    println(longer * shorter)
}

fun readInputLine(): String {
    return readLine()!!
}



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

const int N = 2010;
const int moder = (int) 1e9 + 7;

int a[N];
int cnt[N];

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++ i){
        scanf("%d", &a[i]);
        ++ cnt[a[i]];
    }
    int ans = 0;
    for (int i = 0; i < n; ++ i){
        for (int j = i + 1; j < n; ++ j){
            if (a[i] > a[j]){
                ans = (ans + k) % moder;
            }
        }
    }
    for (int i = 0; i < N; ++ i){
        for (int j = i + 1; j < N; ++ j){
            ans = (ans + 1ll * cnt[i] * cnt[j] % moder * (1ll * k * (k - 1) / 2 % moder)) % moder;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int l, c;
string s;

int f(){
    assert(s[c] == '[');
    c++;
    if(isdigit(s[c])){
        int ret = 0;
        while(isdigit(s[c])){
            ret = ret * 10 + s[c] - '0';
            c++;
        }
        //cerr << ret << endl;
        return (ret + 1) / 2;
    }
    vector<int> v;
    while(c < s.size() && s[c] == '['){
        v.push_back(f());
        assert(s[c] == ']');
        c++;
    }
    sort(v.begin(), v.end());
    int sum = 0;
    for(int i = 0; i < (v.size() + 1) / 2; i++){
        sum += v[i];
    }
    return sum;
}

int main(){
    int T;
    cin >> T;
    while(T--){
        cin >> s;
        l = s.size();
        c = 0;
        cout << f() << endl;
    }

}

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

int main(){
  int N , M ;
  cin >> N >> M;
  //要は2個の中に奇数が混じったらカウントしない
  int sum = 0;
  sum += N * (N - 1) / 2;
  sum += M *(M - 1) / 2;

  
  cout << sum << endl;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())
anslist = set()

for i in range(K):
    upnum = A + i
    if upnum <= B:
        anslist.add(upnum)

    downnum = B - i
    if downnum >= A:
        anslist.add(downnum)

sortedlist = sorted(anslist)

for n in sortedlist:
    print(n)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 INF = 1e10;
typedef pair<ll,ll> P;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int c = 0;
    rep(i,n-2){
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            c++;
        }
    }
    PRINT(c);
}

Measured memory_bytes: 256
from pprint import pprint
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

S, T = rs().split()
A, B = rl()
U = rs()

if S == U:
	print(A-1, B)
else:
	print(A, B-1)


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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define sz(a) a.size()

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a,b,c; cin>>a>>b>>c;
	if((c-a-b)<0) { cout <<"No"; return 0;}
	if((c-a-b)*(c-a-b)>4*a*b) cout <<"Yes"; else cout <<"No";
	
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  if (s[0] != s[1] && s[1] != s[2] && s[2] != s[3]) cout << "Good" << endl;
  else cout << "Bad" << endl;
  return 0;
}


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

#define ii(i,start,end,inc) for(int i = start; i < end; i += inc)
#define dd(i,start,end,inc) for(int i = start; i > end; i -= inc)
#define zz(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define BHAAG ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll, ll> pll; 
typedef pair<int, int> pii; 
typedef pair<ull, ull> pull; 

const int  MAX = 1e6 + 3;
template <typename T> istream &operator>>(istream &os, vector<T> &v) { for (auto &e : v) os >> e; return os; }
template <typename T> void print(vector<T> &v, string sep = " ", string end = "\n") { for (auto it = v.begin(); it != v.end() - 1; ++it) { cout << *it << sep ; } cout << v.back() << end; }

// PRIMES 
vi my_primes;
void computePrimes(int mx) { my_primes.assign(mx + 1, 0); ii(i, 2, mx, 1) if (my_primes[i] == 0) ii(j, i + i, mx, i) if (my_primes[j] == 0) my_primes[j] = i; my_primes[0] = my_primes[1] = -1; }
inline bool isPrime(int x){ return my_primes[x] == 0; }

#define divs(a,b) ( b % a == 0 )

int main(int argc, char const *argv[])
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n;
  	cin >> n;
    vi v(n); cin >> v;
    ll curMoney = 1000;
    for(int i = 0; i < n - 1; ++i){
        ll stocks = 0;
        if(v[i] < v[i+1]) stocks = curMoney / v[i];
        curMoney += (v[i+1] - v[i]) * stocks;
    }

    cout << curMoney ;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define sqr(x) ((LL)(x)*(x))
using namespace std;
typedef long long LL;
vector <pair<LL,int> > a; 
int n,k;
stack <LL> stc;
set <int> types;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int t;
		LL d;
		cin>>t>>d;
		a.push_back(make_pair(d,t));
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	LL ans=0;
	for(int i=0;i<k;i++)
	{
		ans+=a[i].first;
		if(types.count(a[i].second))stc.push(a[i].first);
		types.insert(a[i].second);
	}
	ans+=sqr(types.size());
	LL res=ans;
	for(int i=k;i<n;i++)
	{
		if(stc.empty())break;
		if(!types.count(a[i].second))
		{
			res=res-stc.top()+a[i].first-sqr(types.size())+sqr(types.size()+1);
			stc.pop();
			types.insert(a[i].second);
			ans=max(ans,res);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4976
a1 = input()
n = 0
a = [a1[i] for i in range(len(a1))]
for i in range(len(a)):
    if a[i] == 'C':
        n = 1
    if n == 1 and a[i] == 'F':
        n = 2
if n == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
using namespace std;

int main() {
	string ymd;
	cin >> ymd;
	if(ymd[5] == '1')
		cout << "TBD" << endl;
	else if(ymd[6] == '1' || ymd[6] == '2' || ymd[6] == '3' || ymd[6] == '4')
		cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}

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

int main(){
  int c[3][3];
  int x,y;
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++) cin >> c[i][j];
  }
  int a1=0;
  int b1=c[0][0];
  int b2=c[0][1];
  int b3=c[0][2];
  string ans="No";
  for(int i=-100; i<=100; i++){
    for(int j=-100; j<=100; j++){
      int cnt=0;
      if(i+b1==c[1][0]) cnt++;
      if(i+b2==c[1][1]) cnt++;
      if(i+b3==c[1][2]) cnt++;
      if(j+b1==c[2][0]) cnt++;
      if(j+b2==c[2][1]) cnt++;
      if(j+b3==c[2][2]) cnt++;
      if(cnt==6) ans="Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, W;
  cin >> N >> W;

  vector<int> w(N);
  vector<i64> v(N);
  F0R(i, N) {
    cin >> w[i] >> v[i];
  }

  vector<vector<i64>> dp(N + 1, vector<i64>(1e3 * N + 1, INT64_MAX));
  FOR(i, 1, N + 1) {
    dp[i][0] = 0;
    FOR(j, 1, dp[i].size()) {
      if (j < v[i - 1]) {
        dp[i][j] = dp[i - 1][j];
      }
      else if (j == v[i - 1]) {
        dp[i][j] = min(dp[i - 1][j], (i64)w[i - 1]);
      }
      else if (dp[i - 1][j - v[i - 1]] < INT64_MAX) {

        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
      }
      else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }

  i64 result = 0;
  F0R(j, dp[0].size()) {
    if (dp[N][j] <= W && j > result) {
      result = j;
    }
  }
  cout << result;
}
#endif


Measured memory_bytes: 80256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vll h(n);
    REP(i,n) cin >> h[i];
    vll nei(n,0LL);
    REP(i,m){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        nei[a] = max(nei[a],h[b]);
        nei[b] = max(nei[b],h[a]);
    }
    ll cnt = 0;
    REP(i,n){
        if(h[i]>nei[i]){
            cnt++;
        }
    }
    cout << cnt << endl;


    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  ll res=0;
  std::vector<int> b(n-1);
  for(int i=0;i<n-1;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    if(i==0){
      res += b[i];
    } else if (i == n - 1) {
      res += b[n-2];
    }else{
      res += min(b[i-1], b[i]);
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;


ll m=1000000007;

int main()
{
 ll n;
 cin>>n;
 ll k=1;
 ll l=1;
 ll f=1;
 if(n==1){
     cout<<0<<endl;
     return 0;
 }
 
 rep(i,n){
    k*=10; 
    k%=m;
 }
 
 rep(i,n){
    l*=9; 
    l%=m;
 }
 
  rep(i,n){
    f*=8; 
    f%=m;
 }
 
 ll j=l-f;
 
 ll ans=k-f-j-j;
 ans%=m;
 if(ans<0)ans+=m;
 cout<<ans<<endl;
}
 


 

 




Measured memory_bytes: 3608
<?php
$n=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
$s=0;
$i=0;
while($i<$n){
  if($p[$i]!=$i+1){
    if($s==0){
      if($p[$p[$i]-1]==$i+1){
        ++$s;
        $p[$p[$i]-1]=$p[$i];
      }else{
        echo "NO";
        exit;
      }
    }else{
      echo "NO";
      exit;
    }
  }
  ++$i;
}
echo "YES";

Measured memory_bytes: 4728
#include <iostream>
#include <sstream>      // std::ostringstream
using namespace std;
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }

int i,a,b;
string s;

int main() {
	while(cin>>a>>b){
		a = a+b;
		s = to_string(a);
		cout << s.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second


ll h, w, d[1010][1010] = { 0 };
char c[1010][1010];

void bfs(ll a, ll b, ll e, ll f) {
	queue<P>que;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			d[i][j] = INF;
		}
	}
	que.push(make_pair(a, b));
	d[a][b] = 0;
	while (!que.empty()) {
		P p = que.front();que.pop();
		if (p.first == e&&p.second == f) {
			break;
		}
		for (int i = 0;i < 4;i++) {
			ll nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&c[nx][ny] != '#'&&d[nx][ny] == INF) {
				que.push(make_pair(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
}

int main() {
	cin >> h >> w;
	int cnt = 0;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> c[i][j];
			if (c[i][j] == '.')cnt++;
		}
	}

	
	bfs(0, 0, h - 1, w - 1);
	for (int i = 0;i < h;i++) {
		//for (int j = 0;j < w;j++)cout << d[i][j] << endl;
	}
	if (d[h - 1][w - 1] == INF)cout << -1 << endl;
	else cout << cnt-d[h - 1][w - 1]-1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>

int main(void)
{
	double a,b,c,d,e;
        double A,B,C,D,E;

	scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
	A = c - a;
	B = d - b;
	C = pow(A,2);
	D = pow(B,2);
	e = C + D;
        E = sqrt(e);
	printf("%lf\n",E);
	return 0;
}

Measured memory_bytes: 652
/*
	2400: You Are the Judge
*/
#include	<iostream>
#include	<string>
#include	<utility>
#include	<algorithm>
#include	<vector>

using namespace std;

typedef struct tms {
	short	PrStats[10];
	int		ID;
	int		AcceptC;
	int		Penalty;
	bool operator<(const tms& another) const {
		if (AcceptC != another.AcceptC) {
			return AcceptC > another.AcceptC;
		}
		if (Penalty != another.Penalty) {
			return Penalty < another.Penalty;
		}
		return ID < another.ID;
	}
} Teams_1;

int main(void) {
	while (1) {
		int		T, P, R;

		cin >> T >> P >> R;
		if (T == 0 && P == 0 && R == 0) { break; }
		vector< Teams_1 > TeamDatas(T);
		for (int i = 0; i < T; i++) {
			for (int j = 0; j < P; j++) {
				TeamDatas[i].PrStats[j] = 0;
			}
			TeamDatas[i].ID = i + 1;
			TeamDatas[i].AcceptC = 0;
			TeamDatas[i].Penalty = 0;
		}
		for (int i = 0; i < R; i++) {
			int		tID, pID, time;
			string	message;
			cin >> tID >> pID >> time >> message;
			tID--;		pID--;
			if (message == "CORRECT" && TeamDatas[tID].PrStats[pID] != -1) {
				TeamDatas[tID].AcceptC++;
				TeamDatas[tID].Penalty += TeamDatas[tID].PrStats[pID] * 1200 + time;
				TeamDatas[tID].PrStats[pID] = -1;
			}
			else {
				TeamDatas[tID].PrStats[pID]++;
			}
		}
		sort(TeamDatas.begin(), TeamDatas.end());
		for (int i = 0; i < T; i++) {
			cout << TeamDatas[i].ID << ' ' << TeamDatas[i].AcceptC << ' ' << TeamDatas[i].Penalty << endl;
		}
	}
	return 0;
}

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

int main(){
  int r,d,x,ans;
  cin >> r >> d >> x;
  ans = 0;
  for(int i = 0;i < 10;i++){
    ans = r*x-d;
    cout << ans << endl;
    x = ans;
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
mod = 10**9 + 7
if n == 1:
    print(0)
    exit()
    
def fact(a, n): #aのn乗
    ans = 1
    while n:
        if n % 2 == 1:
            ans = ans*a % mod
        a = a*a % mod
        n = n // 2
    return ans % mod

#10**n - (9**n * 2 - 8**n) # 9がないまたは0がない
print( (fact(10, n)%mod - (fact(9, n)%mod * 2 - fact(8, n)%mod) ) % mod)


Measured memory_bytes: 61672
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc001 {
    export class TaskA implements AtCoder.Task, AtCoder.Paramable {
        public constructor(public readonly args: string[][]) {
        }

        public main(this: TaskA): void {
            const n: number = parseInt(this.args[0][0], 10);
            const h: number[] = this.args[1].map(Number);
            const wk: number[] = this.args[1].map(Number);
            const target: any = [];
            let ans: number = 0;
            h.forEach(x => {
                target.push(wk.shift());
                const max = Math.max(...target);
                if (x >= max) ans++;
            });
            console.log(ans);
        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: AtCoder.Task = new TaskA(args);
    task.main();
}



Measured memory_bytes: 7500
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n;
vector<int> G[MAXN];
int sz[MAXN];
bool dfs(int v,int p)
{
    sz[v]=1;
    int cnt=0;
    for(auto to:G[v])
    {
        if(to==p) continue;
        if(!dfs(to,v)) return false;
        if(sz[to]&1) cnt++;
        sz[v]+=sz[to];
    }
    if(cnt>1) return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    if(n%2==0&&dfs(1,0)) puts("Second"); else puts("First");
    return 0;
}



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

const string nodeType[] = { "root", "internal node", "leaf" };
const int nil = -1;

struct Node { int  p, l, r; };

void print(int nod, const vector<Node>& T, const vector<int>& D)
{
    cout << "node " << nod
         << ": parent = " << T[nod].p
         << ", depth = " << D[nod]
         << ", "
         << (T[nod].p == nil ? "root" : T[nod].l == nil ? "leaf" : "internal node");

    cout << ", [";

    for (int i = 0, c = T[nod].l; c != nil; i++, c = T[c].r) {
        cout << (i ? ", " : "") << c;
    }

    cout << "]" << endl;
}
void calcDepth(int nod, int dep, const vector<Node>& T, vector<int>& D)
{
    D[nod] = dep;
    if (T[nod].r != nil) calcDepth(T[nod].r, dep, T, D);
    if (T[nod].l != nil) calcDepth(T[nod].l, dep + 1, T, D);
}
int main()
{
    int N;
    cin >> N;

    vector<Node> Tree(N, { nil, nil, nil });

    for (int i = 0; i < N; i++) {
        int id, k, c, l;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> c;
            if (!j) Tree[id].l = c;
            else Tree[l].r = c;
            l = c;
            Tree[c].p = id;
        }
    }

    int root;
    for (int i = 0; i < N; i++) {
        if (Tree[i].p == nil) root = i;
    }

    vector<int> Depth(N);
    calcDepth(root, 0, Tree, Depth);

    for (int i = 0; i < N; i++) print(i, Tree, Depth);

    return 0;
}



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

#include <iostream>
#include <vector>
// #include <map>
#include <string>
#include <functional>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

int n;
const short type_n = 0; // number
const short type_p = 1; // plus
const short type_s = 2; // star

struct Data {
	short type = -1;
	int level = 0;
	int val = -1;

	Data() {}

	Data(string str) {
		for (auto c : str) {
			if (c == '.') {
				level++;
			} else if (isdigit(c)) {
				type = type_n;
				val = c - '0';
			} else {
				if (c == '+') {
					type = type_p;
				} else {
					type = type_s;
				}
			}
		}
	}

	void print() {
		cout << "level " << level << " type " << type << " : " << val << endl;
	}

};

vector<Data> datas;

void input() {
	datas.resize(n);
	string str;
	for (int i = 0; i < n; i++) {
		cin >> str;
		Data d(str);
		datas[i] = d;
	}
}

int run(int key) {
	auto& d = datas[key];
	if (d.val != -1) {
		return d.val;
	}
	function<int(int, int)> func;
	if (d.type == type_p) {
		d.val = 0;
		func = plus<int>();
	} else {
		d.val = 1;
		func = multiplies<int>();
	}
	int l = d.level + 1; // target level
	for (key += 1; key < n; key++) {
		if (datas[key].level == l) {
			d.val = func(d.val, run(key));
			continue;
		}
		if (datas[key].level < l) {
			break;
		}
	}
	return d.val;
}

void solve() {
	input();
	cout << run(0) << endl;
	//std::cout << "debug " << std::endl; // debug
	//for (auto d : datas) {
	//	d.print();
	//}
	//std::cout << "debug end " << std::endl; // debug
}

int main() {

	while (true) {
		cin >> n;
		if (n == 0) {
			break;
		}
		solve();
	}

	//std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

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

static const int N = 100;

int main(){
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> p[i - 1] >> p[i];
	}

	for(int i=1;i<=n;i++) m[i][i] = 0;
	for(int l=2;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			int j=i+l-1;
			m[i][j] = (1 << 21);
			for(int k=i;k<=j-1;k++){
				m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

	return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int A,B,C;
	cin>>A>>B>>C;
	cout<<min(C, A+B+1)+B;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));



int main(){	
	long long n;
	scanf("%lld",&n);
	vector<long long> a(n-1+1);
	vector<long long> s(n-1+1);
	for(int i = 0 ; i <= n-1 ; i++){
		scanf("%lld",&a[i]);
		if (i != 0) s[i] = s[i-1]+a[i]; else s[i] = a[i];
	}

	ll res = 0, cur = 0, sum = 0;
	rep(i, n) {
		if (i%2 == 0) {
			if (s[i]+cur <= 0) {
				sum += abs(-(s[i]+cur)+1);
				cur += -(s[i]+cur)+1;
			}
		} else {
			if (s[i]+cur >= 0) {
				sum += abs(-(s[i]+cur)-1);
				cur += -(s[i]+cur)-1;
			}
		}
	}
	res = sum;

	cur = 0; sum = 0;
	rep(i, n) {
		if (i%2 == 1) {
			if (s[i]+cur <= 0) {
				// cout << i << ": " << s[i]+cur << " " << cur << " " << sum << endl;
				sum += abs(-(s[i]+cur)+1);
				cur += -(s[i]+cur)+1;
			}
		} else {
			if (s[i]+cur >= 0) {
				// cout << i << ": " << s[i]+cur << " " << cur << " " << sum << endl;
				sum += abs(-(s[i]+cur)-1);
				cur += -(s[i]+cur)-1;
			}
		}
	}
	res = min(res, sum);

	cout << res << endl;

	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll a,b,k;
  cin >> a >> b >> k;
  rep(i,k){
    if(i%2==0){
      if(a%2==1){
        a--;
      }
        b+=a/2;
        a/=2;
    }
    else{
      if(b%2==1){
        b--;
      }
        b/=2;
        a+=b;
    }
  }
  cout << a << " " << b << endl;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> R(N),C(N);
    for(int i=0;i<N;i++) cin>>R[i]>>C[i],R[i]--,C[i]--;

    vector<int> rCnt(N);
    for(int i=0;i<N;i++){
        rCnt[R[i]]++;
    }
    vector<int> cCnt(N);
    for(int i=0;i<N;i++){
        cCnt[C[i]]++;
    }

    if(*max_element(rCnt.begin(),rCnt.end())>=2 ||
        *max_element(cCnt.begin(),cCnt.end())>=2){
            cout<<-1<<endl;
            return 0;
    }

    vector<int> pos(N);
    for(int i=0;i<N;i++){
        pos[R[i]]=C[i];
    }

    vector<int> inv(N);
    for(int i=0;i<N;i++){
        inv[C[i]]=R[i];
    }

    int res=0;
    for(int i=0;i<N;i++){
        if(pos[i]==i) continue;
        int tar=inv[i];
        int tmp=pos[tar];
        int x=pos[i];
        res++;
        swap(pos[i],pos[tar]);
        swap(inv[tmp],inv[x]);
    }
    
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 5204
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n;
const int N = 1e5;
int a[N], b[N];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  vector<pair<int, int>> v;
  for(int i = 0; i < n; i++) {
    v.emplace_back(a[i] - b[i], i);
  }
  sort(v.rbegin(), v.rend());
  int ans = 0;
  ll need = 0;
  int k = n;
  for(int i = n - 1; i >= 0; i--) {
    if(v[i].first < 0) ans++, need += v[i].first, k = i;
  }
  for(int i = 0; i < n; i++) {
    if(need >= 0) break;
    if(i == k) {
      cout << -1 << endl;
      return 0;
    }
    ans++;
    need += v[i].first;
  }
  if(need < 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int T;
int N;
int K[202020],L[202020],R[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		cin>>N;
		ll ret=0;
		vector<pair<int,int>> A,B;
		set<int> AS,BS;
		FOR(i,N) {
			cin>>K[i]>>L[i]>>R[i];
			
			if(L[i]>=R[i]) {
				ret+=R[i];
				A.push_back({L[i]-R[i],K[i]});
			}
			else {
				ret+=L[i];
				B.push_back({R[i]-L[i],K[i]});
			}
		}
		FOR(i,A.size()) AS.insert(i);
		FOR(i,B.size()) BS.insert(A.size()+i);
		sort(ALL(A));
		reverse(ALL(A));
		
		FORR(v,A) {
			auto it=AS.lower_bound(v.second);
			if(it==AS.begin()) {
				AS.erase(*AS.rbegin());
			}
			else {
				it--;
				ret+=v.first;
				AS.erase(it);
			}
		}
		sort(ALL(B));
		reverse(ALL(B));
		FORR(v,B) {
			auto it=BS.lower_bound(v.second);
			if(it==BS.end()) {
				BS.erase(BS.begin());
			}
			else {
				ret+=v.first;
				BS.erase(it);
			}
		}
		cout<<ret<<endl;
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 16452
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b = Is()
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3564
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
ans = 10 ** (N - 1) if N != 1 else 0
while ans < 10 ** N:
    for s, c in C:
        if str(ans)[s - 1] == str(c):
            continue
        else:
            break
    else:
        print(ans)
        break
    ans += 1
else:
    print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
*/
typedef long long ll;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;

/*******\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\*     */
double dist(double a,double b){
    // sqrt(p^2+q^2)
    return sqrt(a*a+b*b);
}
const int eps = -(1e9+7);
int main(){
    double n,d;
    cin>>n>>d;
    double a,b;
    int res = 0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(d >= dist(a,b) )res++;
    }
    cout<<res<<'\n';
    return 0;
}

Measured memory_bytes: 3840
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
if n % 2 == 0:
    ans = A[0] + 2 * sum(A[1:n//2])
else:
    ans = A[0] + 2 * sum(A[1:n//2]) + A[n//2]
print(ans)

Measured memory_bytes: 31616
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Pyramid
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                int n = GetIntInput();
                var xyhs = new List<int[]>();
                var zerolist = new List<int[]>();
                for (int i = 0; i < n; i++)
                {
                    var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    if (tmp[2] == 0)
                    {
                        zerolist.Add(tmp);
                        continue;
                    }
                    xyhs.Add(tmp);
                }
                var a = xyhs.Concat(zerolist).ToList();
                bool result = false;
                for (int i = 0; i <= 100; i++)
                {
                    for (int j = 0; j <= 100; j++)
                    {
                        int expH = Math.Abs(xyhs[0][0] - i) + Math.Abs(xyhs[0][1] - j) + xyhs[0][2];
                        var flg = true;
                        for (int k = 0; k < a.Count; k++)
                        {
                            if (a[k][2] != Math.Max(expH - Math.Abs(a[k][0] - i) - Math.Abs(a[k][1] - j), 0))
                            {
                                flg = false;
                                break;
                            }
                        }
                        if (flg && expH >= 1) { Console.WriteLine($"{i} {j} {expH}"); result = true; break; }

                    }
                    if (result) { break; }
                }
            }
        }

        static string[] GetArrayCharInput() => Console.ReadLine().Split();
        static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray();
        static int GetIntInput() => Console.ReadLine().ToInt();
        static void CWrite(string str) => Console.WriteLine(str);

    }

    class SetConsole : IDisposable
    {
        public SetConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
        }
        public void Dispose()
        {
            Console.Out.Flush();
        }
    }

    static class ExtentionsLibrary
    {
        public static int[] StringToIntArray(this string str) =>
            str.Split().Select(int.Parse).ToArray();
        public static int ToInt(this string str) => int.Parse(str);
    }
}


Measured memory_bytes: 13524
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
rows = [int(input()) for _ in range(N)]
rows.sort()
maxnum = sum(rows)
if maxnum%10 != 0:
    print(maxnum)
    exit()
else:
    for i in rows:
        if i%10 != 0:
            print(maxnum - i)
            exit()

print(0)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, D; cin >> n >> D;
  vector<ll> a(n); cin >> a;
  ll g = 0;
  rep(i, n) {
    g ^= (a[i]-1) % (D+1);
  }
  if (g == 0) {
    cout << "Second" << endl;
  }
  else {
    cout << "First" << endl;
  }
}



Measured memory_bytes: 4776
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	foreach (line; stdin.byLine) {
		auto input = line.split(",").map!(to!int);

		auto itv = input[0..10].array;
		auto v = input[10..12];
		auto lm = v[0].to!double * itv.reduce!("a+b") / (v[0]+v[1]);

		int len;
		foreach (i, it; itv) {
			len += it;
			if (lm <= len) {
				(i+1).writeln;
				break;
			}
		}
	}
}

Measured memory_bytes: 1084
#include <iostream>

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char dc[4] = {'E', 'N', 'W', 'S'};

int main() {
	int n;
	bool b[21][21];
	int m;
	int x, y;
	while (true) {
		std::cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < 21; i++) {
			for (int j = 0; j < 21; j++) {
				b[i][j] = false;
			}
		}
		for (int i = 0; i < n; i++) {
			std::cin >> x >> y;
			b[y][x] = true;
		}
		std::cin >> m;
		char c;
		int d;
		x = y = 10;
		if (b[y][x]) {
			b[y][x] = false;
			n--;
		}
		for (int i = 0; i < m; i++) {
			std::cin >> c >> d;
			for (int j = 0; j < 4; j++) {
				if (c != dc[j]) {
					continue;
				}
				for (int k = 0; k < d; k++) {
					x += dx[j];
					y += dy[j];
					if (b[y][x]) {
						b[y][x] = false;
						n--;
					}
				}
			}
		}
		if (n) {
			std::cout << "No" << std::endl;
		} else {
			std::cout << "Yes" << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
require "prime"
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

ans=array(10**5+1,0)
1.upto(10**5) do|i|
    ans[i]=ans[i-1]
    next if i.even?
    ans[i]+=1 if Prime.prime?(i) and Prime.prime?((i+1)/2)
end
Q=gets.to_i

Q.times do|i|
  l,r=get_i
  l-=1
  r-=1
  puts ans[r+1]-ans[l]
end

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main(){
    int n; cin>>n;
    string s; cin>>s;
    int count = 0;
    rep(i,n-2){
        if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C')
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 45

int F[N];

int fibonacci(int);

int main(){

  int a,b,n;

  scanf("%d",&n);

  b=fibonacci(n);

  printf("%d\n",b);

  return 0;

}

int fibonacci(int n){

  int i;

  F[0]=1;
  F[1]=1;

  for(i=2;i<=n;i++){

    F[i]=F[i-2]+F[i-1];
  }
  return F[n];
}

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

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
}; 

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

    return 0;
}



Measured memory_bytes: 256
#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++)
typedef long long ll;
 
int main() {
    int n; cin >> n;
    if(n % 10 == 7){
        cout << "Yes" << endl;
    }else if(n / 100 == 7){
        cout << "Yes" << endl;
    }else if((n % 100) / 10 == 7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define MAX 100002

int n;

vector<int> va;
vector<int> vb;
map<int,int> mp;
vector<int> vv;
struct UF{
	vector<int> belong;
	vector<int> size;
	void resize(int n){
		belong.assign(n + 1, -1);
		size.assign(n + 1, 1);
	}
	inline int root(int b){
		if (belong[b] == -1){
			return b;
		}
		belong[b] = root(belong[b]);
		return belong[b];
	}
	void merge(int a, int b){
		a = root(a);
		b = root(b);
		if (a == b)return;
		belong[a] = b;
		size[b] += size[a];
	}
};


vector<int> idx;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		va.push_back(a);
	}
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		vb.push_back(a);
	}
	vv=va;
	for(int i=0;i<vb.size();i++){
		idx.push_back(i);
	}
	auto cmp=[&](int a,int b)->bool{
		return vb[a]<vb[b];
	};
	sort(idx.begin(),idx.end(),cmp);
	sort(vv.begin(),vv.end());
	sort(vb.begin(),vb.end());
	for(int i=0;i<n;i++){
		if(vv[i]>vb[i]){
			puts("No");
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		mp[vv[i]]=idx[i];
	}
	UF uf;
	uf.resize(n);
	for(int i=0;i<n;i++){
		uf.merge(mp[va[i]],i);
	}
	int cn=0;
	for(int i=0;i<n;i++){
		if(uf.root(i)==i){
			cn++;
		}
	}
	cerr<<"OK"<<endl;
	if(cn==1){
		for(int i=0;i+1<n;i++){
			if(vv[i+1]<=vb[i]){
				puts("Yes");
				exit(0);
				return 0;
			}
		}
		puts("No");
		exit(0);
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 7288
#include <stdio.h>

int main(void) {
	// your code goes here
	int r[3],n;

	scanf("%d%d%d%d",&r[0],&r[1],&r[2],&n);
	int i,dp[n+1];
	for(i=0;i<n+1;i++)
		dp[i] = 0;
	dp[0] = 1;
	int j;
	for(i=0;i<3;i++)
		for(j=r[i];j<=n;j++)
			dp[j] = dp[j] + dp[j - r[i]];
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  if(S.at(0)==S.at(1)){
    if(S.at(0)==S.at(2))cout<<"No"<<endl;
    else if(S.at(2)==S.at(3))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else if(S.at(0)==S.at(2)){
    if(S.at(1)==S.at(3))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else{
    if(S.at(0)==S.at(3)&&S.at(1)==S.at(2))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256