akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<int> ai(n), bi(n);
  for(int i=0; i<n; ++i) cin >> ai[i] >> bi[i];
  sort(ai.begin(),ai.end());
  sort(bi.begin(),bi.end());
  if(n%2){
    cout << bi[n/2]-ai[n/2]+1 << endl;
    return 0;
  }
  int a1 = ai[n/2-1], a2 = ai[n/2];
  int b1 = bi[n/2-1], b2 = bi[n/2];
  cout << (b1-a1) + (b2-a2) +1 << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll h, n;
    cin >> h >> n;
    rep(i, n)
    {
        ll a;
        cin >> a;
        h -= a;
    }
    if (h > 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  let height_list = [0];
  let current_height = 0;

  // 初めの上昇と平坦を除去
  while (line.length > 0 && line[0] !== '\\') line.shift();
  // 終わりの下降と平坦を除去
  while (line.length > 0 && line[line.length - 1] !== '/') line.pop();

  line.forEach(function(e, i){
      if (e === '\\') current_height -= 1
      else if (e === '_') current_height += 0
      else current_height += 1
      height_list.push(current_height);
  });

  let h, sum = 0;
  let holes = [];
  for (;height_list.length > 1;) {
    if (h = makeHole(height_list)) {
      sum += h;
      holes.push(h);
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (list[0] < begin && begin <= list.reduce((a, b) => Math.max(a, b), -100000)) {
    let area = 0;
      while (!(list.length === 0 || begin <= list[0])) area += begin - list.shift();
      return area;
    }
    return 0;
}



Measured memory_bytes: 23036
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> color(3,0);
    rep(i,n){
        if(s[i] == 'R') color[0]++;
        if(s[i] == 'G') color[1]++;
        if(s[i] == 'B') color[2]++;
    }
    ll count = 0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            int k = 2*j - i;
            if(k >= n) continue;
            if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]) count++;
        }
    }
  	ll ans = color[0]*color[1]*color[2] - count;
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

typedef struct _node {
    int x;
    struct _node *prev;
    struct _node *next;
} Node;

typedef struct {
    Node *head;
} List;

Node *alloc() {
    return malloc(sizeof(Node));
}

void set(Node *ptr, int x, Node *prev, Node *next) {
    ptr->x = x;
    ptr->prev = prev;
    ptr->next = next;
}

bool initList(List *list) {
    if((list->head = alloc()) == NULL) {
        return false;
    }

    list->head->prev = list->head->next = list->head;
}

bool isEmptyList(List *list) {
    return list->head->next == list->head;
}

bool insertAfter(Node *ptr, int x) {
    Node *new = alloc();
    
    if(new == NULL) {
        return false;
    }

    Node *next = ptr->next;

    ptr->next = next->prev = new;
    set(new, x, ptr, next);

    return true;
}

bool insertFront(List *list, int x) {
    return insertAfter(list->head, x);
}

bool insertRear(List *list, int x) {
    return insertAfter(list->head->prev, x);
}

Node *search(List *list, int x) {
    Node *ptr = list->head->next;

    while(ptr != list->head) {
        if(ptr->x == x) {
            return ptr;
        }
        ptr = ptr->next;
    }

    return NULL;
}

void _remove(Node *ptr) {
    Node *prev = ptr->prev;
    Node *next = ptr->next;

    prev->next = next;
    next->prev = prev;
    free(ptr);
}

bool removeFront(List *list) {
    if(isEmptyList(list)) {
        return false;
    }

    _remove(list->head->next);
    
    return true;
}

bool removeRear(List *list) {
    if(isEmptyList(list)) {
        return false;
    }

    _remove(list->head->prev);
    
    return true;
}

bool removeX(List *list, int x) {
    if(isEmptyList(list)) {
        return false;
    }

    Node *ptr = search(list, x);
    if(ptr == NULL) {
        return false;
    } else {
        _remove(ptr);
        return true;
    }
}

void printList(List *list) {
    Node *ptr = list->head->next;

    while(ptr != list->head) {
        printf("%d", ptr->x);
        ptr = ptr->next;
        if(ptr == list->head) {
            break;
        }
        printf(" ");
    }

    puts("");
}

void terminateList(List *list) {
    while(!isEmptyList(list)) {
        removeFront(list);
    }
}

int main(void) {
    List list;
    char buf[32];
    int n;

    initList(&list);

    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d", &n);

    for(int i = 0; i < n; i++) {
        fgets(buf, sizeof(buf), stdin);
        char command[16];
        int x;
        sscanf(buf, "%s %d", command, &x);
        if(!strcmp(command, "insert")) {
            insertFront(&list, x);
        } else if(!strcmp(command, "delete")) {
            removeX(&list, x);
        } else if(!strcmp(command, "deleteFirst")) {
            removeFront(&list);
        } else if(!strcmp(command, "deleteLast")) {
            removeRear(&list);
        }
    }

    printList(&list);

    terminateList(&list);

    return 0;
}


Measured memory_bytes: 32956
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;


int main(void){
    lint A,B;
    cin >> A >> B;
    lint ans=0;
    set<lint> Adiv,Bdiv;
    Adiv.insert(1),Bdiv.insert(1);
    for(int i=2;i<=1100000;i++){
        if(A==1 && B==1) break;
        while(A%i==0 && A!=1) Adiv.insert(i),A/=i;
        while(B%i==0 && B!=1) Bdiv.insert(i),B/=i;
        if(i==1000001 && A!=1) Adiv.insert(A);
        if(i==1000001 && B!=1) Bdiv.insert(B);
    }
    for(int i=1;i<=1000000;i++){
        if(Adiv.count(i) && Bdiv.count(i)) ans++;
    }
    auto A1=Adiv.end(),B1=Bdiv.end();
    A1--,B1--;
    if(*A1==*B1 && *A1>1000000) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(void)
{
    long long int sum=0,range=0,a=0,b=0;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0;
    long long int longnum[200005];
    //vector <int> v;
    //float f,g,h;
    char c,d;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>longnum[i];
        sum+=longnum[i];
    }
    for(i=0;i<n;i++)
    {
        a+=longnum[i];
        if(a*2>sum)
        {
            a-=longnum[i];
            a=sum-2*a;
            break;
        }
        else if(a*2==sum)
        {
            a=0;
            break;
        }

    }
    for(i=n-1;i>=0;i--)
    {
        b+=longnum[i];
        if(b*2>sum)
        {
            b-=longnum[i];
            b=sum-2*b;
            break;
        }
        else if(b*2==sum)
        {
            b=0;
            break;
        }
    }
    cout<<min(a,b);
    return 0;
}




Measured memory_bytes: 1920
#include <iostream>

int main(){

	int n, m, flag;
	int count=0;
	int k[30], a[30][30];

	std::cin>> n >> m;

	for(int i=0;i<30;i++){
		for(int j=0;j<30;j++){
			a[i][j]=0;
		}
	}

	for(int i=0;i<n;i++){
		std::cin>> k[i];
		for(int j=0;j<k[i];j++){
			std::cin>> a[i][j];
		}
	}

	for(int l=1;l<=m;l++){
		flag=0;
		for(int i=0;i<n;i++){
			flag=0;
			for(int j=0;j<k[i];j++){
				if(a[i][j]==l){
					flag=1;
					break;
				}
			}
			if(flag==0) break;
		}
		if(flag==1) count++;
	}
	std::cout<< count << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 +c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 A,B;
int64 dp[MAXN][2 * MAXN],s[MAXN][2 * MAXN];
int p[MAXN],pos[MAXN];
void Solve() {
    read(N);read(A);read(B);
    for(int i = 1 ; i <= N ; ++i) {read(p[i]);pos[p[i]] = i;}
    for(int i = 1 ; i <= N ; ++i) {
        s[i][0] = 1e18;
        for(int j = 1 ; j <= 2 * N + 1 ; ++j) {
            if(j & 1) {
                dp[i][j] = s[i - 1][j] + (j < pos[i] * 2 ? B : A);
            }
            else {
                dp[i][j] = s[i - 1][j - 1] + (j != pos[i] * 2 ? (j < pos[i] * 2 ? B : A): 0);
            }
            s[i][j] = min(s[i][j - 1],dp[i][j]);
        }
    }
    out(s[N][2 * N + 1]);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 782720
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<i64> A(X), B(Y), C(Z);
  for (auto& x : A) cin >> x;
  for (auto& x : B) cin >> x;
  for (auto& x : C) cin >> x;
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());
  priority_queue<tuple<i64, int, int, int>> que;
  set<tuple<int, int, int>> done;
  que.emplace(A[0] + B[0] + C[0], 0, 0, 0);
  auto maybe_push = [&](int ai, int bi, int ci) -> void {
    auto tpl = make_tuple(ai, bi, ci);
    if (ai < X && bi < Y && ci < Z && !done.count(tpl)) {
      done.insert(tpl);
      que.emplace(A[ai] + B[bi] + C[ci], ai, bi, ci);
    }
  };
  int cnt = 0;
  while (que.size()) {
    i64 sm = get<0>(que.top());
    int ai = get<1>(que.top());
    int bi = get<2>(que.top());
    int ci = get<3>(que.top());
    que.pop();
    cout << sm << "\n";
    if (++cnt == K) break;
    maybe_push(ai + 1, bi, ci);
    maybe_push(ai, bi + 1, ci);
    maybe_push(ai, bi, ci + 1);
  }
}

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

int main(){
    int N;cin>>N;
    vec L(N);
    for(int i=0;i<N;i++)cin>>L[i];
    sort(L.begin(),L.end());
    ll ans=0;
    for(int i=2;i<N;i++){
        for(int j=0;j<i-1;j++){
            auto itr=upper_bound(L.begin(),L.end(),L[i]-L[j]);
            int index=distance(L.begin(),itr);
            if(index<=j)index=j+1;

            if(j<index && index<i){
                ans+=i-index;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import exit

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                if 0 <= i + dx[k] < h and 0 <= j + dy[k] < w:
                    if s[i+dx[k]][j+dy[k]] == '#':
                        flag = True
            if not flag:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 70152
k= int(input())
s= input().rstrip().split()
a = int(s[0])
b = int(s[1])
f = "NG"
for i in range(a,b+1):
  if i%k == 0:
    f = "OK"
if a == b:
  if a%k == 0:
    f = "OK"
print(f)

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <limits>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 100005
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<ull> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a[n-1]-a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var intArray = IO.ReadIntArray();
			var combinationNum = intArray[0];
			var numberMax = intArray[1];

			var gcdSum = 0L;
			var gcdNums = new long[numberMax + 1];
			for(var iIndex = numberMax ; iIndex >= 1 ; -- iIndex) 
			{
				var num = Util.ModPow(numberMax / iIndex , combinationNum , ModNumber);
				for(var iSubtractIndex = iIndex * 2 ; iSubtractIndex <= numberMax ; iSubtractIndex += iIndex)
				{
					num -= gcdNums[iSubtractIndex];
				}
				gcdNums[iIndex] = num % ModNumber;
				gcdSum += ((iIndex * gcdNums[iIndex]) % ModNumber);
			}
			IO.Write(gcdSum % ModNumber);
		}
		private const long ModNumber = 1000000007;
	}

	public static class IO
	{
		public static string   Read()							  { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')	  { return Read().Split(iSplitter); }
		public static int	   ReadInt()						  { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ') { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()					  { return Read().ToCharArray(); }

		public static void Write(string iValue)  { Console.WriteLine(iValue); }
		public static void Write(int iValue)	 { Console.WriteLine(iValue); }
		public static void Write(long iValue)	 { Console.WriteLine(iValue); }
		public static void Write(decimal iValue) { Console.WriteLine(iValue); }
		public static void Write(bool iValue)	 { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1)	{ return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i0 , i1); }
		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}
	}
}


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

signed main(){
    int n , a , b[3] = {};
    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> a;
        if(a%4 == 0){
            b[2]++;
        } else if(a%2 == 0){
            b[1]++;
        } else {
            b[0]++;
        }
    }
    
    n -= max(0 , b[1]-1);
    
    if(n/2 <= b[2]){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return(0);
}


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

int main() {
    int x , y;
    cin >> x >> y;
    if(x % y == 0){
        cout << -1 << endl;
    }
    else{
        cout << x << endl;
    }
    return 0;
}

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

using namespace std;

int MOD = 1e9 + 7;

int a[405], b[405];
long long pw[405][405], ps[405][405], dp[405][405];

int main() {
	int n, c;
	scanf("%d%d", &n, &c);
	
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	
	for (int i = 1; i <= 400; i++) {
		pw[i][0] = 1LL;
		for (int j = 1; j <= 400; j++) pw[i][j] = (pw[i][j - 1] * i) % MOD;
		for (int j = 0; j <= 400; j++) ps[i][j] = (pw[i][j] + ps[i - 1][j]) % MOD;
	}
	
	long long res = 0LL;
	
	dp[0][0] = 1LL;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= c; j++) {
			for (int k = 0; k <= j; k++) {
				long long mul = (ps[b[i]][k] - ps[a[i] - 1][k] + MOD) % MOD;
				dp[i][j] = (dp[i][j] + mul * dp[i - 1][j - k]) % MOD;
			}
		}
	}
	
	printf("%lld\n", dp[n][c]);
}


Measured memory_bytes: 4096
#include <iostream>

using namespace std;

int n;

int main() {
    cin >> n;

    long long tx = 1;
    long long ax = 1;

    long long t, a;
    for (int i = 0; i < n; ++i) {
        cin >> t >> a;
        long long factor = 1;
        factor = max(factor, (tx / t) + (tx % t == 0 ? 0 : 1));
        factor = max(factor, (ax / a) + (ax % a == 0 ? 0 : 1));

        tx = t * factor;
        ax = a * factor;
    }

    cout << (tx + ax) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
const int N=1e5+5;
ll p=998244353;
char s[N*3];
int n;ll ans=1LL;
ll R,G,B,RG,BG,RB;
/**/
int main()
{
    read(n);
    scanf("%s",s+1);
    for(int i=1;i<=n*3;i++)
    {
        if(s[i]=='R')
        {
            if(BG){ans=ans*BG%p;BG--;continue;}
            if(!B&&!G){R++;continue;}
            if(B) ans=ans*B%p,B--,RB++;
            if(G) ans=ans*G%p,G--,RG++;
        }
        if(s[i]=='G')
        {
            if(RB){ans=ans*RB%p;RB--;continue;}
            if(!R&&!B){G++;continue;}
            if(R) ans=ans*R%p,R--,RG++;
            if(B) ans=ans*B%p,B--,BG++;
        }
        if(s[i]=='B')
        {
            if(RG){ans=ans*RG%p;RG--;continue;}
            if(!R&&!G){B++;continue;}
            if(R) ans=ans*R%p,R--,RB++;
            if(G) ans=ans*G%p,G--,BG++;
        }
    }
    for(int i=1;i<=n;i++) ans=ans*i%p;
    cout<<ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
string s;
int k[100010];
int main()
{
	cin>>s;
	for(int i=0;i<s.length()-1;i++)
	{
		int l=0,r=0;
		int pos=0;
		if (s[i]=='R'&&s[i+1]=='L')
		{
			for (int j=i-1;j>=0;j--)
			{
				if (s[j]=='R') l ++;
				else break;
			}
			for (pos=i+2;pos<s.length();pos ++)
			{
				if (s[pos]=='L') r ++;
				else break;
			}
			k[i]=l/2+r-r/2+1;
			k[i+1]=l-l/2+r/2+1;
			i=pos-1;
		}
	}
	for (int i=0;i<s.length();i++) printf("%d ",k[i]);
	printf("\n");
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return (lx<=x&&x<ux&&ly<=y&&y<uy);
}

int main()
{
	int w,h;
	while(cin>>w>>h,w!=0&&h!=0){
		vector<string> s(h);
		rep(i,h)cin>>s[i];

		queue<P> que;
		rep(i,h)rep(j,w)if(s[i][j]=='@')s[i][j]='x',que.push(P(i,j));
		while(!que.empty()){
			P p = que.front();que.pop();
			int y=p.first,x=p.second;
			rep(i,4){
				if(valid(0,w,0,h,x+dx[i],y+dy[i])){
					if(s[y+dy[i]][x+dx[i]]=='.'){
						s[y+dy[i]][x+dx[i]]='x';
						que.push(P(y+dy[i],x+dx[i]));
					}
				}
			}
		}
		int ans=0;
		rep(i,h)rep(j,w)if(s[i][j]=='x')ans++;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3012
N = int(input())
H = [int(i) for i in input().split()]
dp = [0] * N

dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
    
print(dp[-1])

Measured memory_bytes: 52208
n = int(input())
a = list(map(int,input().split()))
L = len(set(a))
if L ==1:
  if a[0] < n//2+1 or a[0]==n-1:
    print('Yes')
  else:
    print('No')
elif L == 2:
  M,m =max(a),min(a)
  m_c =a.count(m)
  if M == m+1 and m_c <= m and n-m_c >= 2*(M-m_c):
    print('Yes')
  else:
    print('No')
else:
  print('No')
  
  
  
  
  

Measured memory_bytes: 14204
N = int(input())
mod = 10**9 + 7

dp_A = [1] + [0] * (N + 5)
dp_G = [1] + [0] * (N + 5)
dp_C = [1] + [0] * (N + 5)
dp_T = [1] + [0] * (N + 5)
dp_AG = [0] * (N + 5)
dp_AC = [0] * (N + 5)
dp_GA = [0] * (N + 5)
dp_AGA = [0] * (N + 5)
dp_AGG = [0] * (N + 5)
dp_AGT = [0] * (N + 5)
dp_AAG = [0] * (N + 5)
dp_AGG = [0] * (N + 5)
dp_ATG = [0] * (N + 5)
dp_ok = [4] + [0] * (N + 5)
#ng=AGC,ACG,GAC,AG*C,A*GC
for i in range(1, N):
    dp_A[i] = dp_ok[i - 1]
    dp_C[i] = dp_ok[i - 1] - dp_AG[i - 1] - dp_GA[i - 1] - dp_AGG[
        i - 1] - dp_AGT[i - 1] - dp_ATG[i - 1]
    dp_C[i] %= mod
    dp_G[i] = dp_ok[i - 1] - dp_AC[i - 1]
    dp_G[i] %= mod
    dp_T[i] = dp_ok[i - 1]
    dp_T[i] %= mod
    dp_AG[i] = dp_A[i - 1]
    dp_AG[i] %= mod
    dp_AC[i] = dp_A[i - 1] - dp_GA[i - 1]
    dp_AC[i] %= mod
    dp_GA[i] = dp_G[i - 1]
    dp_GA[i] %= mod
    dp_AGG[i] = dp_AG[i - 1]
    dp_AGG[i] %= mod
    dp_AGT[i] = dp_AG[i - 1]
    dp_AGT[i] %= mod
    dp_ATG[i] = dp_A[i - 2]
    dp_ATG[i] %= mod
    dp_ok[i] = dp_A[i] + dp_C[i] + dp_G[i] + dp_T[i]
    dp_ok[i] %= mod
print(dp_ok[N - 1])


Measured memory_bytes: 3188
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    int H = scan.nextInt();
    int M = scan.nextInt();
    scan.close();

    double rateH = (double)(60*H + M) / 720;
    double rateM = (double)M / 60;

    double rateDiff = Math.abs(rateH - rateM);
    if(rateDiff > 0.5) {
      rateDiff = 1 - rateDiff;
    }

    System.out.println(Math.sqrt(A*A + B*B -2*A*B*Math.cos(2*Math.PI*rateDiff)));
  }
}

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

int main(void)
{
    vector<int> num(3, 0);
    for (int i = 0; i < 3; i++)
    {
        cin >> num[i];
    }
    sort(num.begin(), num.end(), greater<int>());

    int ans = (num[0] * 10 + num[1]) + num[2];
    cout << ans << endl;

    return (0);
}

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

int main()
{
	ll a, b, n;
	cin >> a >> b >> n;
	if (n < b) {
		cout << a * n / b << endl;
	}
	else {
		ll x = (n / b) * b - 1;
		cout << a * x / b - a * (x / b) << endl;
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint x;
    cin >> x;
    lint ret = 1;
    for (lint i = 2; i < 1000; ++i) {
        lint temp = i;
        for (lint j = 0; j < 1000; ++j) {
            temp *= i;
            if (temp <= x) {
                chmax(ret, temp);
            } else {
                break;
            }
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
a = [list(map(int,input().split())) for l in range(3)]
n = int(input())
b = [int(input()) for l in range(n)]
for k in range(n):
  for i in range(3):
    for j in range(3):
      if a[i][j] == b[k]:
        a[i][j] = 0

ans = "No"
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
  ans = "Yes"
elif a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
  ans = "Yes"
else:
  for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
      ans = "Yes"
    elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
      ans ="Yes"
print(ans)


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int m, f, r, sub;
        for(int i = 0; i < 50; i++){
            m = scanner.nextInt();
            f = scanner.nextInt();
            r = scanner.nextInt();

            if(m == -1 && f == -1 && r == -1){
                break;
            }else if(m == -1 || f == -1){
                System.out.println("F");
            }else{
                sub = m + f;
                if(sub >= 80){
                    System.out.println("A");
                }else if(sub >= 65){
                    System.out.println("B");
                }else if(sub >= 50){
                    System.out.println("C");
                }else if(sub >= 30){
                    if(r >= 50){
                        System.out.println("C");
                    }else{
                        System.out.println("D");
                    }
                }else{
                    System.out.println("F");
                }
            }
        }
        scanner.close();
    }
}



Measured memory_bytes: 26248
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

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

    map<string, ll> mp;
    rep(i,n){
        string tmp;
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        mp[tmp]+=1;
    }
    damp(mp)
    ll ans=0LL;
    for(auto p : mp){
        ans+= (p.second-1LL)*(p.second)/2LL;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
import itertools
while True:
    n, x = map(int, input().split())
    if n == 0\
    and x == 0:
        break

    a = [i for i in range(1, n+1)]
    b = [i for i in itertools.combinations(a, 3)]
    c = 0
    cnt = 0
    for i in range(len(b)):
        for j in range(3):
            c += b[i][j]
        if c == x:
            cnt += 1
        c = 0
    print(cnt)

Measured memory_bytes: 33452
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=200111;

vector<int>g[maxn],ng[maxn];
int n,fa[maxn],mx[maxn],sz[maxn],nsz[maxn],dt[maxn],ans[maxn];
void dfs(int x)
{
	sz[x]=1;nsz[x]=1;
	for(auto&v:g[x])if(v!=fa[x])
	{
		fa[v]=x;
		mx[v]=max(mx[x],x);
		dfs(v);
		sz[x]+=sz[v];
		nsz[x]+=nsz[v];
	}
	
	if(x>mx[x])
	{
		nsz[x]=0;
		if(mx[x])ng[mx[x]].pb(x);
	}
	if(mx[x]==fa[x])dt[x]=nsz[x];
}

void dfs2(int x)
{
	for(auto&v:g[x])if(v!=fa[x])
	{
		ans[v]=ans[x]+dt[v];
		dfs2(v);
	}
}

int f[maxn],fsz[maxn];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
void merge(int u,int v)
{
	u=gf(u);v=gf(v);
	if(u==v)return;
	f[u]=v;fsz[v]+=fsz[u];
}
int main()
{
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);g[v].pb(u);
	}
	dfs(1);
	
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
		fsz[i]=1;
	}
	for(int x=1;x<=n;x++)
	{
		if(x>mx[x])
		{
			for(auto&v:ng[x])
			{
				int sum=0;
				for(auto&v2:g[v])if(v2!=fa[v]&&v2<=x)
				{
					sum+=fsz[gf(v2)];
					dt[v2]-=fsz[gf(v2)];
				}
				dt[v]+=sum+1;
			}
		}
		for(auto&v:g[x])if(v<=x)merge(x,v);
	}
	dfs2(1);
	for(int i=2;i<=n;i++)printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 32896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
ll n,m;int cnt;
int main()
{
    fastio;
    cin>>n;
    m = 100ll;
    while(1){
        m = m + m / 100;
        cnt++;
        if(m >= n) break;
    }
    cout<<cnt;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    char a;
    cin >> a;
    if (a <= 'Z') cout << "A" << endl;
    else cout << "a" << endl;
}


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

A = []

for i in range (0, N):
	A.append(list(map(int, input().split())))

def Sort(F): 
  
    # reverse = None (Sorts in Ascending order) 
    # key is set to sort using second element of  
    # sublist lambda has been used 
    F.sort(key = lambda x: x[1]) 
    return F 

A = Sort(A)

date = 0

for i in range (0, N):
	if date + A[i][0] > A[i][1]:
		print('No')
		exit()
	else:
		date+=A[i][0]

print('Yes')

Measured memory_bytes: 47104
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        d: usize,
        g: usize,
        pcs: [(usize, usize); d]
    }
    let mut answer = std::usize::MAX;
    for i in 0..1<<d {
        let mut score = 0;
        let mut count = 0;
        'middle: for j in (0..d).rev() {
            if i & 1 << j == 0 {
                for k in 0..pcs[j].0 {
                    score += 100 * (j+1);
                    count += 1;
                    if k == pcs[j].0-1 {
                        score += pcs[j].1;
                    }
                    if score >= g {
                        break 'middle;
                    }
                }
            }
        }
        if score >= g {
            answer = std::cmp::min(answer, count);
        }
    }
    println!("{}", answer);
}


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

int main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    int needed_A,needed_C;
    needed_A = N/A;
    if(N%A!=0) needed_A++;
    needed_C = N/C;
    if(N%C!=0) needed_C++;
    cout << min(B*needed_A,D*needed_C) << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
int main()
{
    int a[100],i,j,t,n,count=0;
    scanf("%d",&n);  
    for(i=1;i<=n;i++)  
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n-1;i++) 
    {
        for(j=1;j<=n-i;j++) 
        {
            if(a[j]>a[j+1])
            { 
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
                count++;
            }
        }
    }
    int q=0;
    for(i=1;i<=n;i++)  
    {
        if(q)
        {
            printf(" ");
        }
        printf("%d",a[i]);
        q++;
    }
    printf("\n");
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2716
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i = Integer.parseInt(scanner.nextLine()) - 1;
        String[] temp = scanner.nextLine().split(" ");

        for (; i != -1; i--) {
            if (i != 0) {

                System.out.print(temp[i] + " ");
            } else {
                System.out.print(temp[i]);
            }
        }
        System.out.println();
        scanner.close();
    }
}



Measured memory_bytes: 26348
N,K = (int(x) for x in input().split())
h = list(map(int,input().split()))
cost = [float('inf')]*N

cost[0] = 0
for i in range(N-1):
  l = min(i,K-1)
  for j in range(l+1):
    num2 = cost[i-j] + abs(h[i+1]-h[i-j])
    if cost[i+1] > num2:
      cost[i+1] =  num2
      
print(cost[N-1])

Measured memory_bytes: 55008
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n+1);
	for(int i=0;i<n;i++) cin>>a[i];
	ll res=0;
	for(int i=0;i<=n;i++){
		if(a[i]>i||i&&a[i-1]+1<a[i]){
			cout<<-1<<endl;
			return 0;
		}
		if(i&&a[i-1]>=a[i]) res+=(ll)a[i-1];
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,mod;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
int dp[5050][5050],ans;
int main()
{
	scanf("%d %d",&n,&mod);
	for(int i=1;i<=n;++i)dp[n-i][i-1]=1;
	for(int t=1;t<=(n-1)/2;++t)
	{
		for(int k=0;k<=n;++k)
		{
			int sum=0,tot=0;
			for(int i=n/t;~i;--i)
			{
				add(sum,dp[i][k]);
				add(tot,sum);
				dp[i][k]=tot;
	//			printf("%d %d %d\n",i,k,tot);
			}
		}
	//	printf("\n");
		for(int i=0;i<=n/t;++i)
			for(int k=i;k<=n;++k)
				dp[i][k-i]=dp[i][k],i!=0?dp[i][k]=0:0/*,printf("%d %d %d\n",i,k-i,dp[i][k-i])*/;
	}
	if(n%2==0)
	{
		for(int i=0;i<=1;++i)
			for(int k=0;k<=n;++k)
				add(ans,1ll*dp[i][k]*(i+1)%mod);
	}
	else
	{
		for(int i=0;i<=1;++i)
			for(int k=0;k<=n;++k)add(ans,dp[i][k]);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 98816
while 1:
    l,r=0,int(input())
    if r==0:break
    a=[int(input()) for _ in range(r)]
    r-=1;c=0
    k=int(input())
    while l<=r:
        c+=1
        m=(l+r)//2
        if a[m]==k:break
        if a[m]<k:l=m+1
        else:r=m-1
    print(c)

Measured memory_bytes: 7632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

const long long mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    long long ans = 1;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    long long num = 1;
    long long num2 = 1;
    for (int i = 0; i < n; ++i) {
        ans *= 10;
        ans %= mod;
        num *= 9;
        num %= mod;
        num2 *= 8;
        num2 %= mod;
    }
    ans -= num * 2;
    ans += num2;
    while (ans < 0) ans += mod;
    cout << ans << endl;
}

Measured memory_bytes: 3628
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    f(input, String::new(), 0).to_string()
}

fn f(s1: String, s2: String, sum: i64) -> i64 {
    if s2.len() == 0 {
        let s2 = s1.clone().chars().take(1).collect::<String>();
        let s1 = s1.clone().chars().skip(1).collect::<String>();
        f(s1, s2, sum)
    } else if s1.len() == 0 {
        sum + s2.parse::<i64>().unwrap()
    } else {
        //s2を使う
        let sum1 = {
            let sum = sum + s2.parse::<i64>().unwrap();
            let s2 = String::new();
            f(s1.clone(), s2, sum)
        };
        //s2を使わない
        let sum2 = {
            let s2 =
                format!("{}{}", s2, s1.clone().chars().take(1).collect::<String>()).to_string();
            let s1 = s1.clone().chars().skip(1).collect::<String>();
            f(s1, s2, sum)
        };
        sum1 + sum2
    }
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "125" => "176",
    test2: "9999999999" => "12656242944",
}


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

int main(){
    ll A,B,N,X,Ans;
    cin >> N >> A >> B;
    X = N / (A+B);
    Ans = min(N%(A+B),A);
    cout << A*X + Ans << endl;
    return 0;
}

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

const int MAX_N = 1000;
int x[MAX_N];
int y[MAX_N];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int w, h, n;
	cin >> w >> h >> n;
	
	for(int i = 0; i < n; ++i){
		cin >> x[i] >> y[i];
	}
	
	int sx = x[0];
	int sy = y[0];
	int ans = 0;
	for(int i = 1; i < n; ++i){
		if(x[i] - sx >= 0 && y[i] - sy >= 0){
			ans += max(x[i] - sx, y[i] - sy);
		}
		else if(sx - x[i] >= 0 && sy - y[i] >= 0){
			ans += max(sx - x[i], sy - y[i]);
		}
		else {
			ans += abs(x[i] - sx) + abs(y[i] - sy);
		}
		sx = x[i];
		sy = y[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>

using namespace std;

int main(){

   int r, c;

   cin >> r >> c;

   int table[r + 1][c + 1] = {{0}};

   for(int i = 0; i < r; i++){
      for(int j = 0; j < c; j++){
         cin >> table[i][j];
      }
   }

   for(int i = 0; i < r; i++){
      table[i][c] = 0;
      for(int j = 0; j < c; j++){
         table[i][c] += table[i][j];
      }
   }

   int num = 0;
   for(int i = 0; i < c; i++){
      table[r][i] = 0;
      for(int j = 0; j < r; j++){
         table[r][i] += table[j][i];
         num += table[j][i];
      }
   }

   table[r][c] = num;

   for(int i = 0; i < r + 1; i++){
      for(int j = 0; j < c + 1; j++){
         if(j){
            cout << " ";
         }
         cout << table[i][j];
      }
      cout << endl;
   }

   return 0;
}


Measured memory_bytes: 3124
var
	n:Longint;
function f(x:int64;a,b,c:Longint):Longint;
begin
	f:=0;
	if x<=n then f:=a*b*c+f(x*10+3,1,b,c)+f(x*10+5,a,1,c)+f(x*10+7,a,b,1);
end;
begin
	read(n);
	if n>700000000 then writeln(17656+f(7,0,0,1))
	else if n>500000000 then writeln(8828+f(5,0,1,0))
	else writeln(f(0,0,0,0));
end.

Measured memory_bytes: 128
num = list(map(int, input().split()))

R = num[0]
G = num[1]
B = num[2]
N = num[3]
ans = 0

rmax = N // R

for r in range(rmax + 1):
    gmax = (N - R * r) // G 
    for g in range(gmax + 1):
        if (N - R * r - G * g) % B ==0:
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
using ll = long long;

int main(){
  ll N,K; cin >> N >> K;
  ll t = N/K;
  ll ans = t*t*t;
  if(K%2==0){
  	t = (N + K/2)/K;
    ans+=t*t*t;
  }
  cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
fun main(args: Array<String>) {
    a68(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a68(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val num = args[0].toInt()
    println("ABC$num")
}


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

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

int main(){
  int N;
  cin >> N;
  if (N < 1000) {
    cout << "ABC" << endl;
  }
  else{
    cout << "ABD" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M),KEY(M,0);
	for (int i = 0; i < M; ++i) {
		int b;
		cin >> A[i] >> b;
		int key=0;
		for (int k = 0; k < b; ++k) {
			int c;
			cin >> c;
			c -= 1;
			key |= (1 << c);
		}
		KEY[i] = key;
	}
	vector<vector<int> > DP(M + 1, vector<int>(1 << N,INF));
	DP[0][0] = 0;
	for (int i = 0; i < M; ++i) {
		int key2 = KEY[i];
		for (int key = 0; key < (1 << N); ++key) {
			if (DP[i][key] == INF)continue;

			DP[i + 1][key | key2] =
				min(DP[i + 1][key | key2],
					DP[i][key] + A[i]);
			DP[i + 1][key] = min(DP[i + 1][key],
				DP[i][key]);
		}
	}
	int ans = DP[M][(1 << N) - 1];
	if (ans == INF) {
		ans = -1;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 16384
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
//#include <unordered_set>
//#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
//using ll = long long;

const int INF = 1001001001;

int main()
{
    int h(0), w(0);
    bool flag1=true, flag2=true;
	while(true){
	    flag1=true;
	    flag2=true;
	    cin>>h>>w;
	    if(h==0&&w==0)break;
	    rep(j, h){
	        rep(k, w){
	            if(flag2)cout<<"#";
	            else cout<<".";
	            flag2=!flag2;
	            if(k==w-1)cout<<endl;
	        }
	        flag2=!flag1;
	        flag1=flag2;
	    }
	    cout<<endl;
	}
}


Measured memory_bytes: 3088