akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	string t(s);
	reverse(begin(t),end(t));
	int ans=0;
	rep(i,s.size()){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 2e6+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll X, Y;
ll fact[MAXN];
ll inv[MAXN];
ll bp(ll a, ll b){
    ll res = 1;
    while(b){
        if(b % 2) res = (res * a) % mod;
        a = (a * a) % mod;
        b = b / 2;
    }
    return res;
}




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>X>>Y;
    fact[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= 2e6; i++){
        fact[i] = (fact[i - 1]*i)%mod;
        inv[i] = bp(fact[i], mod - 2);
    }
    ll ani = (X + Y);
    if(ani % 3){
        cout<<0<<endl;
    }else{
        ani = ani / 3;
        ll ans = 0;
        for(int i = 0; i <= ani; i++){
            if(2*i + ani - i == X)
            ans += ((fact[ani]*inv[i])%mod*inv[ani - i])%mod;
            ans %= mod;
        }
        cout<<ans<<endl;
    }
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 31488
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  vector<int>b;
  for(int i=0;i<N;i++){
    if(a.at(i)%2==0){
      b.push_back(a.at(i));
    }
  }
  for(int i=0;i<b.size();i++){
    if(b.at(i)%3!=0 && b.at(i)%5!=0){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
  return 0;
}
    
      

  


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy.Builder as BLB
import Data.List
import Data.Int
import Data.Char
import Text.Printf

main = do
    s <- getLine
    putStrLn $ solve s

mmCandidates :: [String]
mmCandidates = [printf "%02d" (i :: Int32) | i <- [1..12]]

mightNotMm :: String -> Bool
mightNotMm s = not $ elem s mmCandidates

solve :: String -> String
solve s
    | (mightNotMm forward) && (mightNotMm backward) = "NA"
    | (mightNotMm forward) = "YYMM"
    | (mightNotMm backward) = "MMYY"
    | otherwise = "AMBIGUOUS"
    where forward = take 2 s
          backward = drop 2 s

Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
int cnt[101010];
int main()
{
	int n,x,ans=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int i=0;i<=n-1;i++)
		if(cnt[i])
			(ans*=cnt[i])%=mod;
	if(n&1)
	{
		if(cnt[0]!=1)
		{
			printf("0");
			return 0;
		}
		for(int i=2;i<n;i+=2)
			if(cnt[i]!=2)
			{
				printf("0");
				return 0;
			}
	}
	else
	{
		for(int i=1;i<n;i+=2)
			if(cnt[i]!=2)
			{
				printf("0");
				return 0;
			}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long int ll;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pow2(i) (1 << (i))
#define modi(a,b) ((a%b+b)%b)
#define uni(a,b) (((a+b)*(a+b+1)/2)+b)
const int MAXN=1e9+7;
ll int_pow(ll base, ll exp){
	ll result=1;
	while (exp){
		if (exp & 1)
		   result *= base;
		exp/=2;
		base*=base;
	}
	return result;
}
ll a[1000000];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,j=1,ans=0;cin >> n;
	for (ll i=0;i<n;i++){
		cin >> a[i];
		a[i]--;
	}
	for (ll i=0;i<n-1;i++){
		if (a[i] != i)continue;
		swap(a[i], a[i+1]);
		ans++;
		i++;
	}
	if (a[n-1] == n-1)ans++;
	cout << ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define INF 111123456789
#define pb push_back
#define mp make_pair
#define bhp true
#define nhp false
#define eps 1e-9
#define eps2 1e-6
using namespace std;

struct point {    double x,y;   } p[505];
struct node{    double angle;int in;    } arc[100005];
double dist(point p,point q)
{
    return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}
int cmp(node a,node b)
{
    if(a.angle!=b.angle) return a.angle<b.angle;
    else return a.in>b.in;
}
bool hp(int n,int m,double r)
{
    int ans=1;
    for(int i=0;i<n;i++)
    {
        int cnt=0;
        for(int j=0;j<n;j++)
        {
            if(i==j) continue;
            if(dist(p[i],p[j])>(2.0*r)+eps) continue;
            double b=atan2(p[j].y-p[i].y,p[j].x-p[i].x);
            double a=acos(dist(p[i],p[j])/(2.0*r));
            arc[cnt].angle=b-a; arc[cnt++].in=1;
            arc[cnt].angle=b+a; arc[cnt++].in=-1;
        }
        sort(arc,arc+cnt,cmp);
        int tmp=1;
        for(int j=0;j<cnt;j++)
        {
            ///if(arc[j].in) tmp++;
            tmp+=arc[j].in;
            ans=max(ans,tmp);
        }
    }
    if(ans>=m) return bhp;
    else return nhp;
}
double BS(int n,int m,double x)
{
    double l=0.0,r=x;
    while((r-l)>eps2)
    {
        double mid=(l+r)/2.0;
        ///cout<<l<<" "<<r<<" "<<mid<<'\n';
        if(hp(n,m,mid)) r=mid;
        else l=mid;

    }
    return l;
}
int main()
{
    int n,m;
    scanf("%d",&n);
    m=n;
    for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
    double rmax=0.0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
            rmax=max(rmax,dist(p[i],p[j]));
    }
    ///cout<<rmax<<'\n';
    double res=BS(n,m,rmax);
    printf("%.6f\n",res);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int k;
  cin>>k;
  string s,t;
  cin>>s;
  if(s.size()<=k){
     // cout<<s.size()<<endl;
      cout<<s;
  }
  else{
      for(int i=0;i<k;i++){
          t+=s[i];
      }
      for(int i=0;i<3;i++){
          t.push_back('.');
      }
      cout<<t<<endl;
  }
}

Measured memory_bytes: 3108
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		char a = scan.next().charAt(0);
		
		if (Character.isUpperCase(a)) {
			System.out.println("A");	// 大文字
		}
		else {
			System.out.println("a");	// 小文字
		}
		
		scan.close();
	}
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int C = 0 ;
  C = A + B;
  if (A % 3 == 0 || B % 3 == 0 || C % 3 == 0){
  cout << "Possible";
  }else{
  cout << "Impossible";
  }
}


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

int main(){
    long long N, M; cin >> N >> M;
//    if(N==1) swap(N,M);
//    if(M==1){
//        if(N==1) {cout << 1 << endl; return 0;}
//        cout << N-2 << endl; return 0;
//    }
    cout << abs ( (N-2)*(M-2) ) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			if (a < b) {
				Console.WriteLine(new string(a.ToString()[0], b));
			} else {
				Console.WriteLine(new string(b.ToString()[0], a));
			}


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13396
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a + b == 15)
    {
        cout << "+\n";
    }
    else if(a * b == 15)
    {
        cout << "*\n";
    }
    else
    {
        cout << "x\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,i;
    i=1;
    do{
        cin >> n;
        if (n==0){
            break;
        }
        cout << "Case " <<i<<": "<< n << endl;
        i++;
    }
    while (n !=0);
    return 0;
}


Measured memory_bytes: 3072
N = int(input())
s = {}
ans = 0
for i in range(N):
    tmp = list(input())
    tmp = sorted(tmp)
    tmp = "".join(tmp)
    if tmp not in s:
        s[tmp] = 1
    else:
        ans += s[tmp]
        s[tmp] = s[tmp] + 1
print(ans)

Measured memory_bytes: 17804
from collections import deque

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


N, M = read_tuple()
E = [[] for i in range(N+1)]
for i in range(M):
    u, v = read_tuple()
    E[u].append(v)
S, T = read_tuple()

dst = [[-1, -1, -1] for i in range(N+1)]
dst[S][0] = 0

Q = deque([(S,0)])
while len(Q):
    v, c = Q.popleft()
    for u in E[v]:
        k = (c + 1) % 3
        if dst[u][k] == -1:
            dst[u][k] = c + 1
            Q.append((u, c + 1))

print(dst[T][0] // 3 if dst[T][0] != -1 else -1)

Measured memory_bytes: 72352
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    int n;cin>>n;
    if(n%10==3)cout<<"bon"<<endl;
    if(n%10==0||n%10==1||n%10==6||n%10==8)cout<<"pon"<<endl;
    if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9) cout<<"hon"<<endl;


    
}

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

int daycount(int y, int m, int d) {
  if (m==1 || m==2) {
    --y;
    m+=12;
  }
  return (365*y + y/4 - y/100 + y/400 + (306*(m+1))/10 + d - 428);
}

int main() {
  int y1, m1, d1, y2, m2, d2;
  while (1) {
    cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2; 
    if (y1==-1 || m1==-1 || d1==-1 || y2==-1 || m2==-1 || d2==-1) break;
    cout << daycount(y2, m2, d2) - daycount(y1, m1, d1) << endl;
  }
  return 0;
}

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

count = [0, 0, 0, 0]
for i in range(N):
    out = input()
    if out == "AC":
        count[0] += 1
    elif out == "WA":
        count[1] += 1
    elif out == "TLE":
        count[2] += 1
    elif out == "RE":
        count[3] += 1

for i, a in zip(["AC", "WA", "TLE", "RE"], count):
    print(f"{i} x {a}")

Measured memory_bytes: 9204
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+3,M=1e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

int tc,n,a[N];

char s[N];

int main(){
    //IO();
    scanf("%s",s);
    if (s[1] == 'R')
        s[1] = 'B';
    else
        s[1] = 'R';
    printf("%s\n",s);
}

Measured memory_bytes: 3764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Vector;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        Node[] nodes = new Node[N];
        for (int i = 0; i < N; i++) {
            nodes[i] = new Node();
        }
        for (int i = 0; i < N-1; i++) {
            StringTokenizer st = new StringTokenizer(reader.readLine());
            int src = Integer.parseInt(st.nextToken()) - 1;
            int dst = Integer.parseInt(st.nextToken()) - 1;
            nodes[src].edges.add(dst);
            nodes[dst].edges.add(src);
        }

        Process p = new Process(nodes);
        Result r = p.dfs(0, -1);
        System.out.println((r.black + r.white) % mod);
    }

    private static class Process{
        private Node[] nodes;
        Process(Node[] nodes){
            this.nodes = nodes;
        }

        Result dfs(int nodeIndex, int parent){
            int allWhite = 1;
            int somethingIsBlack = 0;
            for (int e : nodes[nodeIndex].edges){
                if (e != parent){
                    Result r = dfs(e, nodeIndex);
                    somethingIsBlack = (mul(allWhite, r.black) + mul((r.black + r.white), somethingIsBlack))% mod;
                    allWhite = mul(allWhite, r.white);
                }
            }
            Result current = new Result();
            current.white = (allWhite + somethingIsBlack) % mod;
            current.black = allWhite;
            return current;
        }
    }

    private static int mul(int a, int b){
        return (int) (((long)a * b) % mod);
    }

    private static int mod = (int) (1e9 + 7);

    private static class Node{
        Vector<Integer> edges = new Vector<>();
    }

    private static class Result{
        int black, white;
    }
}


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

void testCase(){
    long long n, k;
    cin>>n>>k;
    long long mini = LONG_LONG_MAX;
    n = n%k; 
    if(mini > n) mini = n;
    n = abs(n-k);
    if(mini > n) mini = n;
    cout<<mini<<endl;
}

int main(){
    int t;
    t = 1;
    // cin>>t;
    while(t--){
        testCase();
    }
}



Measured memory_bytes: 3640
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] m = new int[n];
        int ans = 0;
        
        m[0] = sc.nextInt();
        x = x-m[0];
        int min = m[0];
        
        for(int i=1; i<n; i++){
            m[i] = sc.nextInt();
            x = x-m[i];
            if(min>m[i]){
                min = m[i];
            }
        }
        
        ans = x/min + n;
        
		System.out.println(ans);
    }
}


Measured memory_bytes: 35988
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<string.h>
 
 
int main()
{
	char s[101];
	scanf("%s", s);
	
	int len = strlen(s);
	for (int i = 0; i < len; i++) {
	printf("x");
	}
  printf("\n");
}

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

int f(int a){
  int res=0;
  while(a){
    res++;
    a/=10;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1; i<=n; i++){
    if(f(i)%2) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long X = long.Parse(Console.ReadLine());
            var Z = new long[(long)Math.Pow(Math.Pow(10.0, 19.0), 0.20)];
            for (int i = 0; i < Z.Length; i++)
            {
                Z[i] = (long)Math.Pow(i, 5);
            }
            for (var a = 0; a < Z.Length; a++)
            {
                for (var b = 0; b < Z.Length; b++)
                {
                    if (Z[a] - Z[b] == X)
                    {
                        Console.WriteLine(a + " " + b);
                        return;
                    }
                    else if (Z[a] + Z[b] == X)
                    {
                        Console.WriteLine(a + " " + (-b));
                        return;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 28024
#include<stdio.h>
int main()
{
int a[100005];
 int n,x;
 while(~scanf("%d%d",&n,&x))
 {
 long long num=0;
  int i;
  for(i=0;i<n;i++)
  scanf("%d",&a[i]);
   if(a[0]>x)
  {
  num+=a[0]-x;
   a[0]=x;
  }
  for(i=1;i<n;i++)
  {int s=a[i]+a[i-1]-x;
   if(s>0)
   {a[i]=a[i]-s;
    num+=s;
   }
  }
  printf("%lld\n",num);
 }
 
}

Measured memory_bytes: 512
import sys
from scipy.optimize import fmin

input = sys.stdin.readline

n = int(input())

XR = []
XL = []
XS = []
YU = []
YD = []
YS = []

for _ in range(n):
    x, y, d = input().split()
    x = int(x)
    y = int(y)
    if d == "D":
        XS.append(x)
        YD.append(y)
    elif d == "U":
        XS.append(x)
        YU.append(y)
    elif d == "R":
        XR.append(x)
        YS.append(y)
    elif d == "L":
        XL.append(x)
        YS.append(y)

max_YD = max(YD + [float("-inf")])
max_YS = max(YS + [float("-inf")])
max_YU = max(YU + [float("-inf")])
min_YD = min(YD + [float("inf")])
min_YS = min(YS + [float("inf")])
min_YU = min(YU + [float("inf")])

max_XR = max(XR + [float("-inf")])
max_XL = max(XL + [float("-inf")])
max_XS = max(XS + [float("-inf")])
min_XR = min(XR + [float("inf")])
min_XL = min(XL + [float("inf")])
min_XS = min(XS + [float("inf")])


def diff_xy(t):
    if t < 0:
        return float("inf")
    diff_y = max(max_YD - t, max_YU + t, max_YS) - min(min_YD - t, min_YU + t, min_YS)
    diff_x = max(max_XL - t, max_XR + t, max_XS) - min(min_XL - t, min_XR + t, min_XS)
    return diff_x * diff_y


def binary_search(min_t, max_t):
    mid_t = (min_t + max_t) / 2
    if max_t - min_t < 10 ** (-10):
        return diff_xy(mid_t)

    if diff_xy(min_t) < diff_xy(mid_t):
        return binary_search(min_t, mid_t)
    elif diff_xy(max_t) < diff_xy(mid_t):
        return binary_search(mid_t, max_t)
    else:
        return opt(min_t, mid_t, max_t)


def opt(a, b, c):
    optimal_a = fmin(diff_xy, a, full_output=False, disp=False, xtol=10 ** (-10))
    optimal_b = fmin(diff_xy, b, full_output=False, disp=False, xtol=10 ** (-10))
    optimal_c = fmin(diff_xy, c, full_output=False, disp=False, xtol=10 ** (-10))
    ans = min(diff_xy(optimal_a[0]), diff_xy(optimal_b[0]), diff_xy(optimal_c[0]))
    return (ans)


print(binary_search(0, 2 * 10 ** 8))

Measured memory_bytes: 26756
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef unsigned long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, k; string s; cin >> n >> k >> s;
	deque<int> q;
	vector<ll> base(n + 1, 1);
	map<pair<ll, int>, int> m;
	ll h = 0, hb = 0;
	
	rep(i, n) base[i + 1] = base[i] * 29;
	rep(i, n){
		q.push_back(s[i] - 'A');
		h += base[n - i - 1] * (s[i] - 'A' + 1);
		hb += base[n - i - 1] * 3;
	}
	
	int r = 0;
	for(; k; k--){
		if(m.count(pair<ll, int>(h, r))){
			k %= m[pair<ll, int>(h, r)] - k;
			if(!k) break;
		}
		m[pair<ll, int>(h, r)] = k;
		
		if((q[0] ^ r) == 0){
			q[0] = 1 ^ r;
			h += base[n - 1];
		}
		else{
			q.pop_front();
			r ^= 1;
			q.push_back(r);
			h -= base[n - 1] * 2;
			h = hb - h * 29 - 2;
		}
	}
	
	string ans;
	rep(i, n) ans += (q[i] ^ r) + 'A';
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 27796
import sys
sys.setrecursionlimit(100000)

N,M=[int(a) for a in input().split()]
AB=[[int(a) for a in input().split()] for _ in range(M)]
edges = [[] for _ in range(N)]
for a, b in AB:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

colors = [0]*N
def dfs(curr, c):
    colors[curr] = c
    for node in edges[curr]:
        if colors[node] == colors[curr]:
            return False
        if colors[node]== 0 and not dfs(node, -c):
            return False
    return True

if not dfs(0, 1):
    print((N*(N-1))//2 - M)
else:
    WH = [c==1 for c in colors]
    nw = sum(WH)
    print(nw*(N-nw)-sum([WH[a-1]^WH[b-1] for a, b in AB]))


Measured memory_bytes: 116568
#include <iostream>

int main() {
	int r, g, b, n;
	std::cin >> r >> g >> b >> n;
	int ans = 0;
	for (int nr = 0; nr <= n; ++nr) {
		for (int ng = 0; ng <= n; ++ng) {
			int left = (n - nr * r - ng * g);
			if (left >= 0 && left % b == 0)
				++ans;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

const int MAX = 1e6 + 5;
int go[MAX][26];
bool leaf[MAX];
int sz = 1;
void add(string s){
    int cur = 0;
    for(auto c: s){
        if(!go[cur][c - 'a']) go[cur][c - 'a'] = sz++;
        cur = go[cur][c - 'a'];
    }
    leaf[cur] = true;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i], reverse(s[i].begin(), s[i].end());
    for(auto& x: s) add(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int cnt[26];
        for(int j = 0; j < 26; j++) cnt[j] = 0;
        for(auto c: s[i]){
            cnt[c - 'a']++;
        }
        int cur = 0;
        for(int j = 0; j < (int) s[i].size() - 1; j++){
            for(int c = 0; c < 26; c++){
                if(cnt[c] && go[cur][c]){
                    ans += leaf[go[cur][c]];
                }
            }
            cnt[s[i][j] - 'a']--;
            if(!go[cur][s[i][j] - 'a']) break;
            cur = go[cur][s[i][j] - 'a'];
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 106968
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
long long k,s,ans;
int main(){
    ios::sync_with_stdio(0);
    cin>>k>>s;
    for(int i=0; i<=k; i++){
        for (int j=0; j<=k; j++){
            if (s-i-j >=0 && s-i-j<=k) ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3552
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        List<int>[] graph = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            graph[st[0]].Add(st[1]);
            graph[st[1]].Add(st[0]);
        }

        int[] depth = Enumerable.Repeat(-1, n).ToArray();
        Stack<int> stack = new Stack<int>();
        stack.Push(0);
        depth[0] = 0;
        while (stack.Count > 0)
        {
            var elem = stack.Pop();
            foreach (var item in graph[elem])
            {
                if (depth[item] != -1) continue;
                depth[item] = depth[elem] ^ 1;
                stack.Push(item);
            }
        }
        var zeroCount = depth.Count(x => x == 0);
        var oneCount = depth.Count(x => x == 1);

        var permZeroCount = n / 3;

        int[] res = new int[n];
        
        if (zeroCount <= permZeroCount || oneCount <= permZeroCount)
        {
            var zeroClearSig = oneCount <= permZeroCount ? 1 : 0;
            bool[] used = new bool[n + 3];
            //HashSet<int> unused = new HashSet<int>(Enumerable.Range(1, n));
            int next = 3;
            for (int i = 0; i < depth.Length; i++)
            {
                if (depth[i] == zeroClearSig)
                {
                    res[i] = (next += 3) - 3;
                    used[res[i]] = true;
                    //unused.Remove(res[i]);
                }
            }
            int ptr = 1;
            for (int i = 0; i < depth.Length; i++)
            {
                if (res[i] == 0)
                {
                    while (used[ptr]) ptr++;
                    res[i] = ptr;
                    used[res[i]] = true;
                    //unused.Remove(res[i]);
                }
            }
        }
        else
        {
            int lastOne = 1;
            int lastTwo = 2;
            int lastZero = 3;
            for (int i = 0; i < depth.Length; i++)
            {
                if (depth[i] == 0) res[i] = lastOne <= n ? (lastOne += 3) - 3 : (lastZero += 3) - 3;
                else res[i] = lastTwo <= n ? (lastTwo += 3) - 3 : (lastZero += 3) - 3;
            }
        }

        Console.WriteLine(string.Join(" ", res));
    }
}


Measured memory_bytes: 49504
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100+5],b[100+5],c[100+5],x;
int f1=0,f2=-1,f3=-1,alen,blen,clen;
char ans;
int main()
{
	scanf("%s%s%s",a,b,c);
	alen=strlen(a);
	blen=strlen(b);
	clen=strlen(c);
	x=a[0];
	while(1)
	{
		if(x=='a')
		{
			f1++;
			if(f1>=alen)
			{
				ans='A';
				break;
			}
			x=a[f1];
		}
		if(x=='b')
		{
			f2++;
			if(f2>=blen)
			{
				ans='B';
				break;
			}
			x=b[f2];
		}
		if(x=='c')
		{
			f3++;
			if(f3>=clen)
			{
				ans='C';
				break;
			}
			x=c[f3];
		}
	}
	printf("%c\n",ans);
	return 0;
}


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

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

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    int X, L;
    for (int i = 0; i < N; i++)
    {
        cin >> X >> L;
        q.push(make_pair(X + L, X - L));
    }

    int ans = 0;
    int current = -2e9;
    while (!q.empty())
    {
        int start = q.top().second;
        int end = q.top().first;
        q.pop();
        if (start >= current)
        {
            ans++;
            current = end;
        }
    }
    cout << ans << endl;
}


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

int main(){
	double n;
	int m;
	cin>>n;
	m=n;
	if(m%2==0){
		cout<<0.5<<endl;
	}else{
		cout<<(n+1)/2/n<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    println!("{}", s.chars().filter(|&c| c =='1').count());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
    int k;
    cin >> k;
    
    string ans = "ACL";
    rep (i, k)
        cout << ans;
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
A = list(map(int,input().split()))
ans = 0
from functools import reduce
import fractions
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
lc = lcm(A)
for i in range(n):
    ans += lc//A[i]
print(ans % (10**9+7))

Measured memory_bytes: 5576
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,s,dis[maxn],s1,t1,s2,t2,N,M;
struct node{int v,w;};
vector <node> mp[maxn];
struct node2{int dis,to;};
char p[1005][1005];

inline bool operator < (node2 a,node2 b){return a.dis>b.dis;}

priority_queue <node2> que;
bool vis[maxn];

inline int A(int x,int y){return M*(x-1)+y;}
inline void Add(int u,int v,int w){mp[u].pb({v,w}),mp[v].pb({u,w});}

const int kx[4]={0,0,1,-1};
const int ky[4]={1,-1,0,0};

int main()
{
	N=read(),M=read(); s1=read(); t1=read(); s2=read(); t2=read();
	rep(i,1,N) scanf("%s",p[i]+1);
	rep(i,1,N) rep(j,1,M)
	{
		if(p[i][j]=='.')
		{
			rep(k,0,3)
			{
				int tx=i+kx[k],ty=j+ky[k];
				if(tx<=0||tx>N||ty<=0||ty>M||p[tx][ty]=='#') continue;
				Add(A(i,j),A(tx,ty),0);
			}
			
			rep(w,-2,2) rep(k,-2,2)
			{
				int tx=i+w,ty=j+k;
				if(tx<=0||tx>N||ty<=0||ty>M||p[tx][ty]=='#') continue;
				Add(A(i,j),A(tx,ty),1);
			}
		}
	}
	
	n=N*M; s=A(s1,t1);
	for(int i=1;i<=n;i++) dis[i]=inf; dis[s]=0;
	que.push((node2){0,s});
	while(!que.empty())
	{
		node2 u=que.top(); que.pop();
		if(vis[u.to]) continue;
		vis[u.to]=1; int uu=u.to; //cout<<uu<<endl;
		for(int i=0;i<mp[uu].size();i++)
		{
			node v=mp[uu][i];
			if(vis[v.v]) continue;
			if(dis[uu]+v.w<dis[v.v])
			{
				dis[v.v]=dis[uu]+v.w;
				que.push((node2){dis[v.v],v.v});
			}
		}
	}
	if(dis[A(s2,t2)]==inf) puts("-1");
	else printf("%d ",dis[A(s2,t2)]);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[100010],b[100010];

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

  cin>>n;
  rep(i,n+1)cin>>a[i];
  rep(i,n)cin>>b[i];

  ll res=0;
  rep(i,n){
    ll cnta=min(a[i],b[i]);
    res+=cnta;
    b[i]-=cnta;
    ll cntb=min(a[i+1],b[i]);
    res+=cntb;
    a[i+1]-=cntb;
  }
  cout<<res<<endl;

  return 0;
}


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

void f(vector<int> matrica [],vector<int> &matrica1,int g,int v)
{
    v=v+matrica1[g];
    matrica1[g]=v;
    int velicina=matrica[g].size();
    for (int j=0;j<velicina;j++)
        f(matrica,matrica1,matrica[g][j],v);
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q,a,b,g,v;
    cin >> n >> q;
    vector<int> matrica[n+1];
    vector<int> matrica1(n+1,0);
    for (int i=0;i<n-1;i++)
    {
        cin >> a >> b;
        matrica[a].push_back(b);
    }
    for (int i=0;i<q;i++)
    {
        cin >> g >> v;
        matrica1[g]+=v;
    }
    f(matrica,matrica1,1,0);
    for (int i=1;i<=n;i++)
        cout << matrica1[i] << " ";
}


Measured memory_bytes: 26624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n ;
    ll ans = 0;
    rep (i, 1, n) {
        ans += (n - 1) / i;
    }
    cout << ans << "\n";
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

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

    int s;
    cin >> s;
    set<int> comp;
    int a = s;
    while (comp.count(a) == 0) {
        comp.insert(a);
        if (a%2==0) a /= 2;
        else a = a * 3 + 1;
    }
    cout << comp.size()+1 << '\n';

    return 0;
}



Measured memory_bytes: 256
import heapq
n, m = map(int, input().split(' '))
df = []
for _ in range(n):
    x, y = map(int, input().split(' '))
    df.append([x, y])
df.sort()
h = []
result = 0
counter = 0
for i in range(1, m+1):
    while counter < len(df) and df[counter][0] <= i:
        heapq.heappush(h, (-1)*df[counter][1])
        counter += 1
    if len(h) == 0:
        continue
    else:
        result -= heapq.heappop(h)
print(result)

Measured memory_bytes: 23880
#include <stdio.h>





int main(void) {


	// 1_7-A Grading

	

	int m,f,r;
	char result;



	scanf("%d",&m);

	scanf("%d",&f);

	scanf("%d",&r);



	while( (m!=-1) || (f!=-1) || (r!=-1) ){

		if( (m==-1) || (f==-1) ){

			result = 'F';

		}else if( (m+f) < 30 ){

			result = 'F';

		}else if( (m+f) < 50 ){

			if( 50 <= r ){

				result = 'C';

			}else{

				result = 'D';

			}

		}else if( (m+f) < 65 ){

			result = 'C';

		}else if( (m+f) < 80 ){

			result = 'B';

		}else{

			result = 'A';

		}

		printf("%c\n",result);

		

		scanf("%d",&m);

		scanf("%d",&f);

		scanf("%d",&r);

	}


	return 0;


}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int num = 1;
		while(2*num <= n) {
			num *= 2;
		}
		System.out.println(num);
		sc.close();
	}

}


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

bool num(char c) {
	return ('0' <= c and c <= '9');
}

bool check(string &s0) {
	string s; cin >> s;
	for(int i = 0; i < min(s0.size(), s.size()); ++i) {
		if(num(s0[i]) and num(s[i])) {
			int num0 = 0;
			for(int j = i; j < (int)s0.size() and num(s0[j]); ++j) {
				num0 *= 10;
				num0 += (s0[j] - '0');
			}
			int num1 = 0;
			for(int j = i; j < (int)s.size() and num(s[j]); ++j) {
				num1 *= 10;
				num1 += (s[j] - '0');
			}
			if(num0 == num1) {
				continue;
			}
			return (num0 < num1);
		}
		if(s0[i] != s[i]) {
			return (s0[i] < s[i]);
		}
	}
	return (s0.size() <= s.size());
}

int main() {
	int n; cin >> n;
	string s0; cin >> s0;
	while(n--) {
		if(check(s0)) {
			cout << '+' << '\n';
		} else {
			cout << '-' << '\n';
		}
	}
	return 0;
}



Measured memory_bytes: 3192
n = int(input())
a = []
mx12 = [0,0]
for i in range(1,n+1):
    a.append(int(input()))
    if min(mx12) <= a[-1]:
        mx12.sort()
        mx12[0] = mx12[1]
        mx12[1] = a[-1]
mx12.sort()
for j in range(1,n+1):
    if a[j-1] == mx12[1]:
        print(mx12[0])
    else:
        print(mx12[1])


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

int main(){
    char s[200],p[100];
    
    cin>>s>>p;

    char s2[100];
    strcpy(s2,s);
    strcat(s,s2);

    if( strstr(s,p)!=NULL)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
int A,B,x,sum=0;
  
  cin>>A>>B;
 
  for(x=A;x<=B;x++)
  {
  int x0=0,x1=0,x3=0,x4=0;
    
    x0 = x%10;
    x1 = (x%100)/10;
    x3 = (x%10000)/1000;
    x4 = x/10000;
    
    if(x0==x4&&x1==x3)
    {
    sum++;
    }
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#AOJ B
from collections import deque

def bfs():
    while 1:
        W,H = map(int,input().split())
        if W == 0 and H == 0:
            break
        maze = [list(input()) for _ in range(H)]
        check = [[False for _ in range(W)] for _ in range(H)]
        #print(maze)
        dx = [1,0,-1,0]
        dy = [0,1,0,-1]
        for i in range(H):
            for j in range(W):
                if maze[i][j] == '@':
                    sx,sy = j,i
                    check[i][j] = True

        ans = 1
        que = deque()
        que.append((sx,sy))
        while que:
            x,y = que.pop()
            for i in range(4):
                nx,ny = x + dx[i],y + dy[i]

                if 0 <= nx < W and 0 <= ny < H and maze[ny][nx] == '.' and check[ny][nx] == False:
                    que.append((nx,ny))
                    check[ny][nx] = True
                    ans += 1
        print(ans)
    return

if __name__ == '__main__':
    bfs()


Measured memory_bytes: 6016
#include<stdio.h>
int main()
{
	char S[11],T[12];
	scanf("%s",S);
	scanf("%s",T);
	for(int i=0;S[i]!='\0';i++){
		if(S[i]!=T[i]){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

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

using namespace std;

long long x,y,z,K,a[1005],b[1005],c[1005];
vector<long long>vec;

int main()
{
	cin>>x>>y>>z>>K;
	
	for (int i=0;i<x;++i)
	    cin>>a[i];
	sort(a,a+x,greater<long long>());
	
	for (int i=0;i<y;++i)
	    cin>>b[i];
	sort(b,b+y,greater<long long>());
	
	for (int i=0;i<z;++i)
	    cin>>c[i];
	sort(c,c+z,greater<long long>());
	
	for (int i=0;i<x;++i){
		for (int j=0;j<y;++j){
			for (int k=0;k<z;++k){
				if ((i+1)*(j+1)*(k+1)<=K)
				    vec.push_back(a[i]+b[j]+c[k]);
				else
				    break;
			}
		}
	}
	
	sort(vec.begin(),vec.end(),greater<long long>());
	for (int i=0;i<K;++i)
	    cout<<vec[i]<<endl;
}

Measured memory_bytes: 1400
/*
  AtCoder Beginner Contest 104
  B - AcCepted
*/

#include<iostream>
using namespace std;

string S;

int main() {
  cin >> S;

  int cnt = -1;
  bool check = true;

  if (S[0] == 'A') {
    cnt = 0;
    for (int i = 2; i < S.length() - 1; ++i) {
      if (S[i] == 'C') cnt += 1;
    }
  }

  for (int i = 1; i < S.length(); ++i) {
    if (!('a' <= S[i] && S[i] <= 'z')) {
      if (2 <= i && i <= S.length() - 2 && S[i] == 'C') continue;
      check = false;
    }
  }
 
  if (check && cnt == 1) printf("AC\n");
  else printf("WA\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int cnt=0,mini=1e9,maxi=-1;
int mini1=1e9,maxi1=-1,cnt1=0,cnt2=0;
int main(){
ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	string a;
	cin>>a;
	for(int i=0; i<a.size(); i++){
		if(a[i]=='A' && a[i+1]=='B' && a[i+2]=='C'){
			cnt++;
		i+=2;
		}
	}
	cout<<cnt;
}
//     *    *  *  ****    *    *   *
//    *	*   * *   *      * *   *   *
//   *****  **    ****  *****  *****
//   *   *  * *      *  *   *      *
//   *   *  *  *  ****  *   *  *****

//   ****  ****  *       *
//   *      **   *      * *
//   ****   **   *     *****
//      *   **   *     *   *
//   ****  ****  ****  *   *


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

int main()
{
    char a,b;
    while(scanf("%c %c",&a,&b)!=EOF)
    {
        getchar();
        if(a=='H')
        {
            if(b=='H')
                printf("H\n");
            else
                printf("D\n");
        }
        else
        {
           if(b=='H')
                printf("D\n");
            else
                printf("H\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let mut h = HashMap::new();

    for c in util::line().chars() {
        *h.entry(c).or_insert(0) += 1;
    }
    h.entry('a').or_insert(0);
    h.entry('b').or_insert(0);
    h.entry('c').or_insert(0);

    let values: Vec<usize> = h.values().cloned().collect();
    let m = values.iter().cloned().min().unwrap();

    if values.iter().map(|&x| x - m).all(|x| x <= 1) {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352