akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2000+100;
ll pow_m(ll n,ll k)
{
    ll ans=1;
    while(k)
    {
        if(k&1) ans=ans*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ans;
}
ll inv[2010];
void init()
{
    inv[0]=inv[1]=1;
    for(int i=2;i<=2000;i++)
    {
        inv[i]=pow_m(i,mod-2);
    }
}
int n,x;
ll d;
ll dp[N][N];
ll f[2][N];

ll C(ll n,ll m)
{
    if(n<m) return 0;
    if(n==m) return 1;
    ll ans=1;
    for(ll i=n;i>=n-m+1;i--)
    {
        ans=(ans*(i%mod))%mod;
    }
    for(int i=1;i<=m;i++)
        ans=(ans*inv[i])%mod;
    //printf("%I64d\n",ans);
    return ans;
}
int main()
{
    init();
    while(scanf("%d%lld%d",&n,&d,&x),n&&d&&x)
    {
        memset(dp,0,sizeof(dp));
        memset(f,0,sizeof(f));
        x--;
        int p=1;
        int mi=(int)min((ll)n,d);
        for(int i=1;i<=n;i++)
        {
            if(i<=x)dp[1][i]=1;
            else dp[1][i]=0;
            f[1][i]=f[1][i-1]+dp[1][i];
        }
        p^=1;
        for(int i=2;i<=mi;i++)
        {
            int tmp=min(n,i*x);
            for(int j=1;j<=tmp;j++)
            {
                if(j-x-1>=0){
                        dp[i][j]=(f[p^1][j-1]-f[p^1][j-x-1])%mod;
                        dp[i][j]=(dp[i][j]+mod)%mod;
                }
                else dp[i][j]=f[p^1][j-1]%mod;
                f[p][j]=(f[p][j-1]+dp[i][j])%mod;
            }
            for(int j=tmp+1;j<=n;j++)
            {
                f[p][j]=f[p][j-1];
            }
            p^=1;
        }
//        for(int i=1;i<=n;i++)
//        {
//            for(int j=1;j<=n;j++)
//            {
//                printf("%d ",dp[i][j]);
//            }printf("\n");
//        }
        ll ans=0;
        for(int i=1;i<=mi;i++)
        {
            ans=(ans+(C(d,i)*dp[i][n])%mod)%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 35696
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <bitset>
#include <cmath>

using namespace std;

int main()
{

    bitset<18> subset, T;
    
    int n, k, b;
    cin >> n >> k;

    while (k--)
    {
        cin >> b;
        T[b] = 1;
    }

    int upper = pow(2, n);
    for (int i = 0; i < upper; i++)
    {
        subset = i;
        if ((subset|T) == subset)
        {
            cout << i << ":";            
            for (int j = 0; j < n; j++)
            {
                if (subset[j])
                {
                    cout << ' ' <<  j;
                }
            }
            cout << endl;            
        }

    }
}


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

const int Maxn = 100005;
int n, ct, cnt, head[Maxn], dep[Maxn], p[Maxn], deg[Maxn], ans[Maxn], ans2[Maxn];
bool vis[Maxn];
struct edg
{
	int nxt, to;
}edge[2 * Maxn];
void add(int x, int y)
{
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
void dfs(int u, int fa)
{
	dep[u] = dep[fa] + 1;
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
			dfs(to, u);
	}
}
void dfs2(int u, int fa, int dep)
{
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
		{
			dfs2(to, u, dep - 1);
			if (ct)
			{
				p[++ct] = u;
				return ;
			}
		}
	}
	if (!dep) p[++ct] = u;
}
void print(int now[])
{
	for (int i = 1; i <= n; i++)
		printf("%d ", now[i]);
	exit(0);
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y);
		add(y, x);
	}
	dfs(1, 0);
	int root = 0, maxi = 0;
	for (int i = 1; i <= n; i++)
		if (dep[i] > maxi) maxi = dep[i], root = i;
	dfs(root, 0);
	for (int i = 1; i <= n; i++)
		if (dep[i] > maxi) maxi = dep[i], root = i; 
	dfs2(root, 0, maxi - 1);
	for (int i = 1; i <= ct; i++)
		vis[p[i]] = true;
	for (int u = 1; u <= n; u++)
	{
		if (vis[u]) continue;
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (!vis[to])
			{
				puts("-1");
				return 0;
			}
			deg[to]++;
		}
	}
	int now = 0;
	for (int i = 1; i <= ct; i++)
	{
		for (int j = now + 1; j <= now + deg[p[i]]; j++)
			ans[j] = j + 1;
		now += deg[p[i]] + 1;
		ans[now] = now - deg[p[i]];
	}
	reverse(p + 1, p + 1 + ct);
	now = 0;
	for (int i = 1; i <= ct; i++)
	{
		for (int j = now + 1; j <= now + deg[p[i]]; j++)
			ans2[j] = j + 1;
		now += deg[p[i]] + 1;
		ans2[now] = now - deg[p[i]];
	}
	for (int i = 1; i <= n; i++)
		if (ans[i] > ans2[i])
			print(ans2);
		else if (ans[i] < ans2[i])
			print(ans);
	print(ans); 
	return 0;
}


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


def RunLengthEncoding(list):
    dict = {}
    for i in list:
        if i in dict.keys():
            dict[i] += 1
        else:
            dict[i] = 1
    return dict


n = int(input())
a = list(map(int, input().split()))
minus = [i-a[i] for i in range(n)]
plus = [i+a[i] for i in range(n)]
minus_cnt = RunLengthEncoding(minus)
plus_cnt = RunLengthEncoding(plus)

cnt=0
for i in minus_cnt:
    if i in plus_cnt:
        cnt += minus_cnt[i] * plus_cnt[i]
print(cnt)


Measured memory_bytes: 62856
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

bool func(int a,int b,int c) {
	vector<int> d = { a,b,c };
	sort(all(d));
	return d[1] == b;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	int res = 0;
	REP(i, n-2) {
		if (func(a[i], a[i + 1], a[i + 2]))res++;
	}
	put(res);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int LCS(string,string);
int dp[3001][3001];
vector<char> ans;

signed main(){
    fast

    string s,t;
    cin>>s>>t;
    LCS(s,t);
    for(auto x:ans) cout<<x;
}

int LCS(string s,string t){
    f1(i,0,s.size())
        f1(j,0,t.size()){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else if(s[i-1]==t[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=s.size(),j=t.size();
    while(i!=0&&j!=0){
        if(s[i-1]==t[j-1]){
            ans.pb(s[i-1]);
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--;
    }
    reverse(ans.begin(),ans.end());
    return dp[s.size()][t.size()];
}

/*
int LCS(stack<char> ss,stack<char> st){
    if(ss.top()==st.top()){
        ss.pop();
        st.pop();
        return 1+LCS(ss,st);
    }
    else{
        char s,t;
        s=ss.top();
        ss.pop();
        int sn=LCS(ss,st);
        ss.push(s);
        s=st.top();
        st.pop();
        int tn=LCS(ss,st);
        return max(sn,tn);
    }
}
*/

Measured memory_bytes: 70656
#include <iostream>
#include <string>

using namespace std;

int ans[26] = {};

int main()
{
	string s;
	cin >> s;
	int n = s.size();

	for (int i = 0; i < n; i++)
	{
		int j;
		j = s[i];
		ans[j - 97] = 1;
	}

	for (int i = 0; i < 26; i++)
	{
		if (ans[i] == 0)
		{
			putchar(i + 97);
			break;
		}
		if (i == 25)
		{
			cout << "None";
		}
	}
	return 0;
}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)){
    cout << "YES" <<endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> n >> m;
  cout << n - m + 1 << endl;



  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
#define LL long long
int n;
LL a[N], f[N][2];
int main(){
    cin>>n;
    for(int i = 1;i <= n; i++){
        scanf("%lld", &a[i]);
    }
    memset(f, -127, sizeof f);
    f[0][0] = 0;
    for(int i = 0;i < n / 2; i++){
        for(int j = 0;j <= 1; j++){
            LL F = f[i][j];
            f[i+1][1] = max(f[i+1][1], F + a[i*2+2]);
            if(j != 1)f[i+1][0] = max(f[i+1][0], F + a[i*2+1]);
        }
    }
    if(n & 1){
        LL sum = a[n];
        LL ans = max(f[n/2][1], f[n/2][0]);
        int num = 1;
        for(int i = n - 2;i > 1; i -= 2){
            ans = max(ans, sum + max(f[(i-1)/2][0], f[(i-1)/2][1]));
            num++;
            sum += a[i];
            if(num == n / 2)ans = max(ans, sum);
        }
        cout<<ans<<endl;

    }
    else {
        printf("%lld\n", max(f[n/2][0], f[n/2][1]));
    }
    return 0;
}


Measured memory_bytes: 8516
/******* all required header files *******/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define mp make_pair
#define ll long long int
#define pb push_back
#define F first
#define S second
/***************************/

int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string str;
	cin>>str;
	for(int i = 0; i < 3; i++)
	{
		cout<<str[i];
	}

	return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <malloc.h>
#include <stack>
#include <cstring>
#include <string>
#include <set>
#include <unordered_map>
#define INT long long int
#define MOD 1000000007
#define oo 987654321
using namespace std;

int n, m, chk[110];
vector<int> G[110];

int dfs(int x)
{
    int cnt = 0, ret = 0;
    for(int i = 1 ; i <= n ; i++ )
        if( chk[i] ) cnt++;
    if( cnt == n ) return 1;
    for(int i = 0 ; i < G[x].size() ; i++ )
        if( !chk[G[x][i]] ) chk[G[x][i]] = 1, ret += dfs(G[x][i]), chk[G[x][i]] = 0;
    return ret;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < m ; i++ )
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    chk[1] = 1;
    cout<<dfs(1)<<endl;
    return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ITP1_4D
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputText = Console.ReadLine();
            int n = int.Parse(inputText);
 
            inputText = Console.ReadLine();
            string[] words = inputText.Split(' ');
 
            if (words.Length < n)
            {
                return;
            }
 
            int[] intArray = new int[n];
            for (int i = 0; i < n; ++i)
            {
                intArray[i] = int.Parse(words[i]);
            }
 
            int minIndex = 0;
            int maxIndex = 0;
            long sum = 0;
            for (int i = 0; i < intArray.Length; ++i)
            {
                sum += intArray[i];
                if (intArray[i] < intArray[minIndex])
                {
                    minIndex = i;
                }
                if (intArray[maxIndex] < intArray[i])
                {
                    maxIndex = i;
                }
            }
 
            Console.WriteLine("{0} {1} {2}", intArray[minIndex], intArray[maxIndex], sum);
        }
    }
}

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

int n = 0;
string s;
bool ch = 1;

int main() {
  cin >> s;
  n = s.size();
  for(int i = 0; i < n; ++i)
    if(s[i] != s[n - 1 - i]) ch = 0;
  n /= 2;
  for(int i = 0; i < n; ++i)
    if(s[i] != s[n - 1 - i]) ch = 0;
  for(int i = 0; i < n; ++i)
    if(s[i + n + 1] != s[2 * n - i]) ch = 0;
  if(ch)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  int n,ans=0,x,y;cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>y;
    ans=gcd(ans,abs(y-x));
    x=y;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dl;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
#define cont continue
using namespace std;
//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}

int main()
{
	ios;
	ll n;
	cin>>n;
	ll q=n/1000;
	ll ans=0;
	if(n%1000)ans=(q+1)*1000-n;
	cout<<ans;
}

Measured memory_bytes: 3668
fun main(args: Array<String>) {
    val C = (1..3).map { readLine()!!.split(" ").map { it.toInt() } }

    val B = arrayOf(C[0][0], C[0][1], C[0][2])
    val A = arrayOf(0,C[1][1]-B[1], C[2][2]-B[2])

    val a = arrayListOf<Boolean>()
    for (i in 0..2) {
        for (j in 0..2) {
            a.add(C[i][j]==A[i]+B[j])
        }
    }
    println(if(a.fold(true) {x,y->x&&y}) "Yes" else "No")
}

Measured memory_bytes: 37900
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n;
	cin >> n;
	vector <int> a(n);
	for(int i = 0;i < n;++i) cin >> a[i];
	lli summ = 0;
	for(int i = 1;i < n;++i){
		if(a[i] < a[i - 1]){
			summ = summ + a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << summ << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int h, w;
    cin >> h >> w;
    
    v2_string meiro(h, v_string(w));
    int ans = 0;
    
    irep(i, h) {
        string tmp;
        cin >> tmp;
        irep(j, w) {
            meiro[i][j] = tmp[j];
            if(meiro[i][j] == "#") { ans++; }
        }
    }

    queue<pii> que;
    v2_bool seen(h, v_bool(w, false));
    v2_int dist(h, v_int(w, 0));
    
    que.push(pii(0, 0));
    dist[0][0] = 1;
    //seen[0][0] = true;

    while(que.size()) {
        pii q = que.front(); que.pop();    
        //cout << q.first << "," << q.second << endl;
        if(seen[q.second][q.first]) continue; 
        seen[q.second][q.first] = true;

        irep(i, 4) {
            int x = q.first + dx[i], y = q.second + dy[i];
            if(x < 0 || x >= w || y < 0 || y >= h) { continue; }
            
            if(seen[y][x] == false && meiro[y][x] != "#") {
                que.push(pii(x, y));
                dist[y][x] = dist[q.second][q.first] + 1;
            }
        }
    }
    if(seen[h-1][w-1]) {
        cout << h*w - dist[h-1][w-1] - ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}
/** atcoder **/


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> s(h + 2, vector<char>(w + 2, '.'));
    for (int i = 1; i <= h; i++) {
        string si;
        cin >> si;

        for (int j = 1; j <= w; j++) {
            s[i][j] = si[j - 1];
        }
    }

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

    bool flag = true;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j] == '#') {
                for (int k = 0; k < 4 && s[i + dy[k]][j + dx[k]] == '.'; k++) {
                    if (k == 3) {
                        flag = false;
                    }
                }
            }
        }
    }

    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
/* Painting */

#include <iostream>
using namespace std;

int main(){
  int h,w,n;
  cin >> h >> w >> n;

  int tmp=0;
  if(w<h){
    tmp=h;
    h=w;
    w=tmp;
  }

  int cnt=0,sum=0;
  while(1){
    if(sum<n){
      if(cnt<=h){
	sum+=w;
	cnt++;
      }
      else{
	if(cnt<=(h+w)){
	  sum+=h;
	  cnt++;
	}
      }
    }
    else{
      cout << cnt << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>
#include<iomanip>
using namespace std;
int main()
{

int k=1000,sum=0,count[1000];
int n[1000],x[1000];
  for(int i=0;i<k;i++)
  {
	  sum++;//???????°±??£??¨?????°
	 
	  cin>>n[i]>>x[i];//???????¢????????????\??????????????\????????????????????????,??????????°±??????????????\????????????
  if(n[i]==0&&x[i]==0)
	  break;

  }	
  memset(count,0,100*sizeof(int));
  for(int p=0;p<sum;p++)
     {
		 for(int i=1;i<=n[p]-2;i++)
		  for(int j=2;j<=n[p]-1;j++)
			  for(int k=3;k<=n[p];k++)
				  if(i+j+k==x[p]&&k>j&&j>i&&k>i)
					  count[p]++;
  }
  for(int i=0;i<sum-1;i++)
	  cout<<count[i]<<endl;










}

Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int INF = 1 << 29;
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define LEN 1000011
#define NIL -1
//_______


int slv(string &a, string &b)
{
   const int alen = a.size();
   const int blen = b.size();
   int dp[alen+1][blen+1] = {};
   a = ' ' + a;
   b = ' ' + b;
   int ret = 0;
   //reps(i, 0, alen)dp[0][i] = 0;
   //reps(i, 0, blen)dp[i][0] = 0;

   reps(i, 1, alen){
      reps(j, 1, blen){
         if(a[i] == b[j]){
            dp[i][j] = dp[i-1][j-1] + 1;
         } else {
            dp[i][j] = max(dp[i-1][j] , dp[i][j-1] );
         }
         chmax(ret, dp[i][j]);
      }
   }
   return(ret);
}

signed main()
{
   FAST();
   int N;
   cin >> N;
   rep(i, N){
      string a,b;
      cin >> a >> b;
      outl( slv(a, b) );
   }
}




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

// a^n mod pを計算　O(log n)
long long int pow_mod(long long int a, long long int n, long long int p) {
    if (n == 0) return 1;
    long long int temp = pow_mod(a, n / 2, p);
    return n & 1 ? (((temp * temp) % p) * a) % p : (temp * temp) % p;
}
// Z_pでのaの逆元を計算 O(log p)
// depend:pow_mod
long long int inv_mod(long long int a, long long int p) {
    return pow_mod(a, p - 2, p);
}
// 階乗テーブルを作ってコンビネーションをキビキビ計算する
// depend:inv_mod
struct combination_mod {
    using lint = long long int;
    int sz;
    vector<lint> data;
    lint mod;
    combination_mod(int _sz, lint _mod) : sz(_sz), mod(_mod) {
        data.assign(sz + 1, 1);
        for (int i = 1; i <= sz; i++) data[i] = (data[i - 1] * i) % mod;
    }
    // nCrを計算 O(log mod)
    lint query(int n, int r) {
        lint res = 1;
        res = (res * data[n]) % mod;
        res = (res * inv_mod(data[r], mod)) % mod;
        res = (res * inv_mod(data[n - r], mod)) % mod;
        return res;
    }
};

int main() {
    lint mod = 1e+9 + 7;
    lint x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x + y) / 3;
    x -= n;
    y -= n;
    if (x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    combination_mod comb(n, mod);
    cout << comb.query(n, x) << endl;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
 int $(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }

signed main(){
  int a,b,e,f;
  cin>>a>>b;
  vector<int> c(a,0);
  vector<double> d(a);
  fo(i,a){
  e=i+1;
  f=0;
  if(i>=b)
    break;
  while(e<b){
    e*=2;
    f++;
  }
  c.at(i)=f;
  }
  for(int i=0;i<a;i++){
    d.at(i)=pow(2,c.at(i));
    d.at(i)=1.0/d.at(i);
  }
  double g=0;
  fo(i,a)
  g+=d.at(i);
  cout<<setprecision(15)<<g/a<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int a, b, c, d; std::cin >> a >> b >> c >> d;
    std::cout << (a != c) << std::endl;    
    return 0;
}


Measured memory_bytes: 256
x,y = [int(i) for i in input().split()]
group1 = [1,3,5,7,8,10,12]
group2 = [4,6,9,11]
if x in group1 and y in group1:
    print("Yes")
elif x in group2 and y in group2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n % 2 == 1) {
        int ans = n / 2 + 1;
        cout << ans << endl;
    }
    else cout << n / 2 << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))






n = in_int()

n = n/3


print(n*n*n)

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

int ppow(int a,int b,int MOD){
	a %= MOD;
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

int main(void){
    ll n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    if(p == 2 || p == 5){
        ll ans = 0;
        rep(i,n){
            if((s[i]-'0')%p == 0){
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    vector<ll> cum(n+1,0);
    map<ll,ll> dict;
    dict[0]++;
    for(ll i=n-1; i>=0; i--){
        cum[i] = (cum[i+1] + (s[i]-'0') * ppow(10,n-1-i, p)) % p;
        dict[cum[i]]++;
    }
    ll ans = 0;
    for(auto ob: dict){
        ll sec = ob.sc;
        ans += sec * (sec-1) /2;
    }
    cout << ans << endl;
}


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

int main() {
    int64_t n=0, m=0, l=0;
    scanf("%d %d %d", &n, &m, &l);
    vector<vector<int64_t>>A(n, vector<int64_t>(m));
    vector<vector<int64_t>>B(m, vector<int64_t>(l));
    vector<vector<int64_t>>C(n, vector<int64_t>(l));
    for(int64_t i=0; i<n; i++){
        for(int64_t j=0; j<m; j++){
            cin >> A.at(i).at(j);
        }
    }
    for(int64_t i=0; i<m; i++){
        for(int64_t j=0; j<l; j++){
            cin >> B.at(i).at(j);
        }
    }
for(int64_t i=0; i<n; i++){
        for(int64_t j=0; j<l; j++){
            for(int64_t k=0; k<m; k++){
                C.at(i).at(j)+=A.at(i).at(k) * B.at(k).at(j);
            }
        }
    }
for(int64_t i=0; i<n; i++){
        for(int64_t j=0; j<l; j++){
            cout << C.at(i).at(j);
            if(j<l-1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}




Measured memory_bytes: 3312
#include<iostream>
using namespace std;
bool is_prime(int x){
	if(x==0||x==1)
		return false;
	for(int i=2;i*i<=x;++i)
		if(x%i==0)
			return false;
	return true;
}
int main(){
	int n;
	cin>>n;
	int i=n-1;
	while(!is_prime(++i));
	cout<<i;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5000],n,ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    int now=114;
    for(int i=0;i<n;i++){
        if(now<=a[i])continue;
        ans++;
        now=a[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))

L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    k=j+1
    while j<N-1:
        while k<N:
            if L[i]+L[j]<=L[k]:
                ans+=k-j-1
                break
            k+=1
        if k==N:
            ans+=k-1-j
        j+=1
    i+=1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main(){
  int x;cin>>x;
  int lim = x+1;
  repd(i,1,lim){
    x -= i;
    if(x <= 0){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int[] str = new int[n];
			for(int i = 0;i < n;i++){
				str[i] = scan.nextInt();
			}
			Arrays.sort(str);
			int[] a = new int[3];
			int count = 0;
			int t = 0;
			for(int i = 0;i < n && i < 4;i++){
				for(int j = 0;j < n && j < 4;j++){
					if(i == j){
						continue;
					}
					t = Integer.parseInt(str[i] + "" + str[j]);
					if(count < 3){
						a[count] = t;
						count++;
					}else{
						if(count == 3){
							Arrays.sort(a);
							count++;
						}
						if(a[2] > t){
							if(a[1] > t){
								a[2] = a[1];
								if(a[0] > t){
									a[1] = a[0];
									a[0] = t;
								}else{
									a[1] = t;
								}
							}else{
								a[2] = t;
							}
						}
					}
				}
			}
			System.out.println(a[2]);
		}
	}
}

Measured memory_bytes: 30112
//C - Bridge: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

bool vis[55];

void dfs(int no, int i, int j, vector<int> adj[]) {
    if(vis[no]) return;
    vis[no] = true;
    loop(k, 0, adj[no].size()) {
        if(no == i and k == j) continue;
        else dfs(adj[no][k], i, j, adj);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int total;
    int n, m, x, y, ans = 0;
    cin >> n >> m;
    vector<int> adj[n+1];
    loop(i, 0, m) {
        cin >> x >> y;
        adj[x].pb(y); adj[y].pb(x);
    }
    loop(i, 1, n+1) {
        loop(j, 0, adj[i].size()) {
            memset(vis, false, sizeof(vis));
            dfs(1, i, j, adj);
            total = 0;
            loop(i, 1, n+1) if(vis[i]) total++;
            //cout << total  << " " << n << "\n";
            if(total != n) ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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


    VI kouho;
    int isPrime[300000] = {};
    FOR(i,6,300000){
        if(i%7 == 1 || i%7 == 6){
            isPrime[i] = 1;
        }
    }
    for(int i = 6; i < 300000;){
        for(int j = i*2; j < 300000; j += i){
            isPrime[j] = 0;
        }
        if(i%7 == 6) i+= 2;
        else i += 5;
    }
    REP(i,300000){
        if(isPrime[i] == 1) kouho.eb(i);
    }


    while(1){
        int N; cin >> N;
        if(N == 1) break;
        cout << N << ":";
        VI ans;

        for(int p : kouho){
            if(N%p==0) ans.eb(p);
        }
        for(int p : ans){
            cout << " " << p;
        }
        cout << endl;
   }

}


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

#define INF (INT64_MAX/2)
#define MAX 100000

long long A, B;

long long f( long long n )
{
	long long cnt = (n + 1) / 2;
	long long lsb = 0;
	if( cnt % 2 ) {
		lsb = 1;
	}
	if( n % 2 ) {
		return lsb;
	}
	return lsb ^ max( n, 0LL );
}

int main() {
	cin >> A >> B;

	long long ans =  f( A - 1) ^ f( B );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>

#define N 1000001
#define ALPHA_N 10

using namespace std;

double solve(double *expect){
  double possible[ALPHA_N];
  double npossible[ALPHA_N];

  expect[0] = 0;
  expect[1] = 1;
  expect[2] = 1.5;

  possible[0]=1;
  for(int i = 1; i < ALPHA_N; ++i){
    double pos = 1.0/((double)(1<<i));
    possible[i] = pos * possible[i-1];
    npossible[i] = (1-pos)*possible[i-1];
  }

  for(int n = 3; n < N; ++n){
    expect[n] = 0;
    for(int j = 1; j < ALPHA_N && n-j-1 >= 0; ++j){
      expect[n] += npossible[j] * ( j + expect[n-j-1] );
    }
    if( n-1 < ALPHA_N )
      expect[n] += n * possible[n-1];
  }
}

int main(){
  double ans[N];
  solve( ans );
  while(true){
    int n;
    scanf("%d", &n);
    if(n==0)break;
    printf("%.3lf\n", ans[n]);
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int X, Y; cin >> X >> Y;
    cout << X + Y/2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[100001],b[100001];
long long suma,sumb;
long long sum[100001];
int c[200001],cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		c[++cnt]=a[i],c[++cnt]=b[i];
		suma+=a[i],sumb+=b[i];
	}
	sort(c+1,c+cnt+1);
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+c[i];
	long long ans=min(suma,sumb);
	for(int i=1;i<=n;i++)
	{
		long long x=a[i],y=b[i];
		if(x>y) swap(x,y);
		if(lower_bound(c+1,c+cnt+1,x)-c<=n-2)
  		{
   			if(lower_bound(c+1,c+cnt+1,y)-c<=n-1) ans=min(ans,sum[n]);
   			else ans=min(ans,y+sum[n-1]);
  		}
  		else ans=min(ans,x+y+sum[n-2]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi tens;
  vi ntens;
  int sum = 0;
  rep(i,N) {
    int a;
    cin >> a;
    if(a % 10 == 0) {
      tens.push_back(a);
    } else {
      ntens.push_back(a);
    }
    sum += a;
  }
  if(sum % 10 == 0 && sz(ntens) == 0) {
    cout << 0 << endl;
    return 0;
  } else if(sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  sort(rng(ntens));
  cout << sum - ntens[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

typedef long long ll;

int main()
{
  ll Q, H, S, D;
  ll N;

  std::cin >> Q >> H >> S >> D;
  std::cin >> N;
  N *= 100;

  std::vector< std::pair< double, ll > > vp(4, std::make_pair(0.0, 0));
  vp[0].first = 25;
  vp[1].first = 50;
  vp[2].first = 100;
  vp[3].first = 200;

  vp[0].second = Q;
  vp[1].second = std::min(vp[0].second * 2, H);
  vp[2].second = std::min(vp[1].second * 2, S);
  vp[3].second = std::min(vp[2].second * 2, D);

  std::reverse(vp.begin(), vp.end());

  ll ans = 0;
  std::vector< std::pair< double, ll > >::iterator it;
  for (it = vp.begin(); it != vp.end(); it++) {
    ll num = N / it->first;
    ans += it->second * num;
    N -= num * it->first;
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;  
int n,m,p[20],v[20];
string s[20];
bool chk()
{
	memset(v,0,sizeof(v));
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(v[i]!=0||v[j]!=0||i==j)continue;
			bool f=1;
			for(int k=0;k<n;k++)
			{
				if(s[p[k]][i]!=s[k][j])
				{
					f=0;
					break;
				}
			}
			if(f)v[i]=v[j]=1;
		}
	}
	int cc=0,t=0;
	for(int i=0;i<m;i++)
	{
		if(!v[i])
		{
			cc++;
			t=i;
		}
	}
	if(!cc)return true;
	if(cc>=2||m&1==0)return false;
	for(int i=0;i<n;i++)
	{
		if(s[p[i]][t]!=s[i][t])return false;
	}
	return true;
}
void dfs(int x,int v)
{
	if(x>=((n+1)>>1))
	{
		if(chk())
		{
			puts("YES");
			exit(0);
		}
		return;
	}
	for(int i=x;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(p[i]==-1&&p[j]==-1)
			{
				p[i]=j;p[j]=i;
				dfs(x+1,v);
				p[i]=-1;
				p[j]=-1;
			}
		}
		if(v!=0&&p[i]==-1)
		{
			p[i]=i;
			dfs(x+1,false);
			p[i]=-1;
		}
	}
}
int main()
{
	//freopen("qc.in","r",stdin);
	memset(p,-1,sizeof(p));
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}  
    dfs(0,n&1);
	puts("NO");
    return 0;
}

Measured memory_bytes: 256
def getSumDigits(k):
   ret = 0
   while k:
      ret += k%10
      k //= 10
   return ret

N,A,B = map(int, input().split())
ret = 0
for i in range(1,N+1):
   if A <= getSumDigits(i) <= B:
      ret += i

print(ret)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main(){
char moji[201],temp[201];
int m,i,n;
while(1){
scanf("%s",moji);
if(strcmp(moji,"-")==0) break;
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%d",&n);
strcpy(temp,&moji[n]);
strncat(temp,moji,n);
strcpy(moji,temp);
}
printf("%s\n",moji);
}
return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 300005;
int st[4*N], v[N];
int query(int id, int l, int r, int i, int j){
    if(r < i or l > j) return 0;
    if(l >= i and r <= j)
        return st[id];
    return max(query(2*id, l, (l+r)/2, i, j) ,
            query(2*id+1, (l+r)/2+1, r, i, j));
}
void update(int id, int l, int r, int i, int x){
    if(r < i or l > i)
        return ;
    if(l == i and r == i) {
        st[id] = x;
    } else {
        update(2*id, l, (l+r)/2, i, x);
        update(2*id+1, (l+r)/2+1, r, i, x);
        st[id] = max(st[2*id], st[2*id+1]);
    }
}
int main(){
	//fastio;
	int n,k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%d", &v[i]);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int temp = query(1,0,300000,v[i]-k, v[i]+k) + 1;
		ans = max(ans, temp);
		update(1,0,300000, v[i], temp);
	}
	printf("%d\n", ans);
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n)    FOR(i, 0, n)
#define pb           push_back
#define all(a)       (a).begin(), (a).end()
#define UNIQUE(v)    v.erase(unique(all(v)), v.end());
#define fill(a, x)   memset(a, x, sizeof(a))
#define zero(a)      fill(a, 0)
#define minus(a)     fill(a, -1)
#define dbg(x)       cout << #x "=" << x << endl
#define MAX          100005
#define NIL          -1

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

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if (T[u].p == NIL) {
    cout << "root, ";
  } else if (T[u].l == NIL) {
    cout << "leaf, ";
  } else {
    cout << "internal node, ";
  }

  cout << "[";

  for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i) {
      cout << ", ";
    }
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL) {
    rec(T[u].r, p);
  }
  if (T[u].l != NIL) {
    rec(T[u].l, p + 1);
  }
}

int main() {
  int i, j, d, v, c, l, r;
  cin >> n;
  rep(i, n) {
    T[i].p = T[i].l = T[i].r = NIL;
  }

  rep(i, n) {
    cin >> v >> d;
    rep(j, d) {
      cin >> c;
      if (j == 0) {
        T[v].l = c;
      } else {
        T[l].r = c;
      }
      l = c;
      T[c].p = v;
    }
  }

  rep(i, n) {
    if (T[i].p == NIL) {
      r = i;
    }
  }

  rec(r, 0);

  rep(i, n) {
    print(i);
  }

  return 0;
}



Measured memory_bytes: 7736
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int isprime(int);


int main()
{
  int n, i, h,z=0;
  int *x;
  scanf("%d", &n);
  x = (int *)malloc(sizeof(int)*n);
  for ( i=0; i<n; i++ ){
  scanf("%d", &x[i]);
  h = isprime(x[i]);
  if(h == 1) z++;
  }
  printf("%d\n",z);
  free(x);
  return 0;
}

int isprime(int x)
{
  int i;
  
  if(x == 2) return 1;
  else if(x < 2 || x%2 == 0) return 0;
  
  i = 3;
  while(i <= sqrt((double)x)){
    if(x%i == 0) return 0;
    i = i + 2;
  }
    return 1;
  }

Measured memory_bytes: 628