akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
int t[17][17];
int dp[64 * 1024];
int main() {
	int n, m, k;
	while (cin >> n >> m >> k, n) {
		vector<int> dice(n, 1);
		int sum = n;
		double e = 0;
		for (;;) {
			e += max(sum - k, 1);
			for (int i = 0; i < n; i++) {
				dice[i]++;
				sum++;
				if (dice[i] > m&&i!=n-1) {
					dice[i] = 1;
					sum -= m;
				}
				else break;
			}
			if (dice.back() > m)break;
		}
		cout << fixed << setprecision(10) << e / pow(m, n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3380
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const ll mod = 998244353;
const int DEG = 20;
const double PI = acos(-1.0);
const double eps = 1e-10;
const ll inf = 1e18;
static auto faster_iostream = []() {
    std::ios::sync_with_stdio(false);  // turn off sync
    std::cin.tie(nullptr);             // untie in/out streams
    return 0;
}();
int main(){
  int n;
  cin >> n;
  int flag = 0;
  while(n){
    flag += (n % 10 == 7);
    n /= 10;
  }
  if(flag) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);

  if (a < b) {
    printf("a < b\n");
  } else if (a > b) {
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }

  return 0;
}

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

int main(){
  int n,k,ans=0;
  cin >> n>>k;
  vector<int>b(n);
  for(int i=0;i<n;i++){
    cin >> b.at(i);
  }
  sort(b.begin(),b.end());
  for(int i=0;i<k;i++){
    ans=ans+b.at(i);
  }
  
  cout<<ans;
}



Measured memory_bytes: 3628
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
imos = [0]*(N+1)

for i in range(M):
    l,r = inpl()
    l,r = l-1,r-1
    imos[l] += 1
    imos[r+1] -= 1

tmp = 0
for i in range(N+1):
    tmp += imos[i]
    imos[i] = tmp

ans = 0
for k in imos:
    if k == M:
        ans += 1
print(ans)


Measured memory_bytes: 8176
#include <stdio.h>
#include <string.h>

int pari(char *a, int len)
{
    for( int i=0; i<len/2; i++)   if( a[i] != a[len-i-1] )   return 0;
    return 1;
}

int main()
{
    char s[100];
    scanf("%s",s);
    
    int len = strlen(s);
    
    char s_l[50], s_r[50];
    for( int i=0; i<len/2; i++ ){
        s_l[i] = s[i];
        s_r[i] = s[len-i-1];
    }
    
    if( pari(s, len) && pari(s_r, len/2) && pari(s_l, len/2) ){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k,w;
vector<int> v;
bool d[5001][5001];
bool f(int x){
    for(int i=0;i<w;i++){
        fill(d[i], d[i]+k+1, false);
    }
    d[0][0]=true;
    if(x>0)d[0][v[0]]=true;
    for(int i=1;i<w;i++){
        for(int j=0;j<k;j++){
            d[i][j]=d[i-1][j];
            if(i!=x&&j-v[i]>=0){
                if(d[i-1][j-v[i]])d[i][j]=true;
            }
        }
    }
    for(int j=k-v[x];j<k;j++){
        if(d[w-1][j])return true;
    }
    return false;
}
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a<k){
            v.push_back(a);
        }
    }
    w=v.size();
    sort(v.begin(), v.end());
    int l=-1,r=w;
    while(l+1<r){
        int m=(l+r)/2;
        if(f(m)){
            r=m;
        }else{
            l=m;
        }
    }
    cout<<r<<endl;
}


Measured memory_bytes: 24704
def main():
    N, A, B = map(int, input().split())
    
    sub = B - A

    left_s = A - 1
    right_s = N - B
        
    # 偶数なら
    if sub % 2 == 0:
        return sub // 2
    # 奇数なら
    else:
        return (min(left_s, right_s) + 1 + ((sub - 1)//2))
    
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
	int n, p1, p2;
	while(cin >> n >> p1 >> p2, n|p1|p2){
		vector< vector< pair<int, int> > > vp(p1+p2);
		bool invalid = false;
		for(int i=0;i<n;i++){
			int a, b; string c;
			cin >> a >> b >> c;
			if(a!=b){
				vp[a-1].push_back(make_pair(b-1, c=="no"));
				vp[b-1].push_back(make_pair(a-1, c=="no"));
			} else if(c=="no"){
				invalid = true;
			}
		}
		if(invalid) { puts("no"); continue; }
		vector< vector<int> > ga, gb;
		int visit[600];
		memset(visit, -1, sizeof(visit));
		for(int i=0;i<p1+p2;i++){
			if(visit[i] != -1) continue;
			vector<int> vi[2];
			queue< pair<int, int> > qu; qu.push(make_pair(i,0));
			while(!qu.empty()){
				pair<int, int> pr = qu.front(); qu.pop();
				int pos = pr.first;
				if(visit[pos] != -1) continue;
				visit[pos] = pr.second;
				vi[pr.second].push_back(pos+1);
				for(int j=0;j<vp[pos].size();j++){
					int next = vp[pos][j].first;
					if(visit[next] != -1){
						if(visit[next] != (pr.second + vp[pos][j].second)%2) invalid = true;
						continue;
					}
					qu.push(make_pair(next, (pr.second + vp[pos][j].second)%2));
				}
			}
			ga.push_back(vi[0]);
			gb.push_back(vi[1]);
		}
		if(invalid) { puts("no"); continue; }
		int dp[601][601];
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for(int i=0;i<ga.size();i++){
			for(int j=0;j<=p1+p2;j++){
				if(dp[i][j]==0) continue;
				dp[i+1][j+ga[i].size()] = min(2, dp[i+1][j+ga[i].size()]+dp[i][j]);
				dp[i+1][j+gb[i].size()] = min(2, dp[i+1][j+gb[i].size()]+dp[i][j]);
			}
		}
		if(dp[ga.size()][p1]!=1){ puts("no"); continue; }
		vector<int> res;
		int cur = p1;
		for(int i=ga.size()-1;i>=0;i--){
			if(cur-ga[i].size() >= 0 && dp[i+1][cur] == dp[i][cur-ga[i].size()]){
				for(int j=0;j<ga[i].size();j++) res.push_back(ga[i][j]);
				cur -= ga[i].size();
			} else {
				for(int j=0;j<gb[i].size();j++) res.push_back(gb[i][j]);
				cur -= gb[i].size();
			}
		}
		sort(res.begin(), res.end());
		for(int i=0;i<res.size();i++) cout << res[i] << endl;
		puts("end");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;

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

  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h){rep(j,w){
    cin>>a[i][j];
  }}
  rep(i,h){rep(j,w){
    int b;
    cin>>b;
    a[i][j]-=b;
  }}

  int eoff=(80+80)*(h+w);
  int esize=eoff*2+1;
  vector<vector<vector<bool>>> p(h,vector<vector<bool>>(w,
    vector<bool>(esize,false)
  ));
  p[0][0][eoff+a[0][0]]=true;
  p[0][0][eoff-a[0][0]]=true;
  rep(i,h){rep(j,w){
    //cout<<i<<j<<endl;
    if(i>0){
      rep(pre,esize){
        if(p[i-1][j][pre]){
          p[i][j][pre+a[i][j]]=true;
          p[i][j][pre-a[i][j]]=true;
        }
      }
    }
    if(j>0){
      rep(pre,esize){
        if(p[i][j-1][pre]){
          p[i][j][pre+a[i][j]]=true;
          p[i][j][pre-a[i][j]]=true;
        }
      }
    }
  }}

  rep(o,eoff){
    if(p[h-1][w-1][eoff+o]) return o;
  }
  return 0;
}

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


Measured memory_bytes: 41088
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
typedef unsigned long long ull;
ull B=5575777;
ull ans=0;
int n,a,b;
vector<int> G[MAX_N];
unordered_map<ull,ull> mp;

ull dfs(int pos){
  ull res=0;
  for(int to:G[pos])res+=dfs(to);
  res=res*B+1;
  ans+=mp[res];
  mp[res]++;
  return res;
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n-1;i++){
    scanf("%d %d",&a,&b);
    G[a].push_back(b);
  }
  dfs(1);
  printf("%lld\n",ans);
  return 0;
}

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

ll n;
string s;
string alter(char p){
	string str = "";
	str += p;
	return str; 	
}

ll qqpow(ll a, ll n){
    if (n == 0)
        return 1;
    else if (n % 2 == 1)
        return qqpow(a, n - 1) * a;
    else{
        ll tempp = qqpow(a, n / 2);
        return tempp * tempp;
    }
}
string dfs(ll m,ll k){
//	cout <<  m << ' ' <<  k << endl;
	ll x = qqpow(26,k);
	if 	(m > x) return dfs(m-x,k+1);
	if (k==1){
		char p = 'a'+m-1;
		string q = alter(p);
		return q;	
	}
	x /= 26;
	ll ex = (m-1)/x;
	char p = 'a'+ex;
	return p + dfs(m-ex*x,k-1);
}
int main(){
	cin >> n;
	s = dfs(n,1);
	cout << s;
	return 0;		
}

Measured memory_bytes: 3608
N = int(input())
S = input()

list_S = list(S)

for i in range(len(list_S)):
    list_S[i] = chr( ord(list_S[i]) + N )

    if ord(list_S[i]) > ord('Z'):
        list_S[i] = chr( ord('A') + ( ord(list_S[i])- ord('Z') ) -1 )

print("".join(list_S))

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <unordered_map>
#include <utility>
#include <array>
#include <cstring>

bool isObstacle[1000][1000];
bool done[1000][1000];

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

	std::unordered_map<int, int> factories;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			char c;
			std::cin >> c;

			if (c == 'S')
				factories[0] = j * 1000 + i;
			else if ('1' <= c && c <= '9')
				factories[c - '0'] = j * 1000 + i;
			else if (c == 'X')
				isObstacle[j][i] = true;
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		const int sx = factories[i] / 1000, sy = factories[i] % 1000;
		const int gx = factories[i + 1] / 1000, gy = factories[i + 1] % 1000;

		std::memset(done, 0, sizeof(done));

		done[sx][sy] = true;

		auto candidate = [h, w](int x, int y) {
			std::array<int, 4> arr;
			arr[0] = ((x == 0 || isObstacle[x - 1][y] || done[x - 1][y]) ? -1 : (done[x - 1][y] = true, (x - 1) * 1000 + y));
			arr[1] = ((x == w - 1 || isObstacle[x + 1][y] || done[x + 1][y]) ? -1 : (done[x + 1][y] = true, (x + 1) * 1000 + y));
			arr[2] = ((y == 0 || isObstacle[x][y - 1] || done[x][y - 1]) ? -1 : (done[x][y - 1] = true, x * 1000 + y - 1));
			arr[3] = ((y == h - 1 || isObstacle[x][y + 1] || done[x][y + 1]) ? -1 : (done[x][y + 1] = true, x * 1000 + y + 1));

			return std::move(arr);
		};

		std::queue<std::pair<int, int>> q;
		q.push({ factories[i], 0 });
		while (!q.empty()) {
			const auto& top = q.front();
			const int nx = top.first / 1000, ny = top.first % 1000;
			int cost = top.second;

			auto&& c = candidate(nx, ny);
			for (auto v : c) {
				if (v != -1) {
					if (v / 1000 == gx && v % 1000 == gy) {
						ans += cost + 1;
						q.pop();
						goto end;
					}
					q.push({ v, cost + 1 });
				}
			}

			q.pop();
		}
	end:;
	}

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

Measured memory_bytes: 5076
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF (ll)1e18
#define m_p make_pair
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define UNIQUE(X) sort(all(X)) X.resize( unique( all(X)) - X.begin() )
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
ll lcm(ll a,ll b){return (a/__gcd(a,b))*b;}
ll bigmod(ll a,ll p,ll mod){ll ans=1;while(p){if(p&1)ans=ans*a%mod;a=a*a%mod;p>>=1;}return ans;}
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0){ll y=power(x,n/2);return y*y;}else return x*power(x,n-1);}
struct point{double x,y;point(){}point(double xx,double yy){x=xx;y=yy;}};
inline double Distance(point  a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
#ifdef shaft
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<endl;
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
const int N=(int)1e6;
const ll mod=(ll)1e9+7;
void yes(){
    cout<<"Yes"<<endl;
    exit(0);
}
void no(){
    cout<<"No"<<endl;
    exit(0);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef shaft
        //freopen("in.txt","r",stdin);
        ///freopen("out.txt","w",stdout);
    #endif ///shaft
    string s;
    cin>>s;
    if(s[0] == s[1] && s[1] == s[2])yes();
    if(s[2] == s[1] && s[3] == s[2])yes();
    no();
    return 0;
}



Measured memory_bytes: 256
N,Z,W=map(int, input().split())
cards=[int(i) for i in input().split()]

if N == 1:
    print(abs(cards[0]-W))
elif abs(cards[-1]-W) > abs(cards[-2]-cards[-1]):
    print(abs(cards[-1]-W))
else:
    print(abs(cards[-2]-cards[-1]))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int menseki = a * b;
        int shu = a * 2 + b * 2;
        System.out.println(menseki +" "+ shu);
        sc.close();
    }
}


Measured memory_bytes: 26348
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;

struct Color{
	double r,g,b;
};

double sq( double a ){
	return a * a;
}

int main(int argc, char const* argv[])
{
	const char *color[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	Color colorStrong[] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};

	Color inputColor;
	int rgb;
	double d[8];
	char damy;

	while( cin >> damy && damy != '0' ){
		cin >> hex >> rgb;
		inputColor.r = rgb >> 16;
		inputColor.g = ( rgb >> 8 ) & 0xff;
		inputColor.b = rgb & 0xff;

		for( int i = 0;i < 8;i++ ){
			d[i] = sqrt( sq( inputColor.r - colorStrong[i].r ) + sq( inputColor.g - colorStrong[i].g ) + sq( inputColor.b - colorStrong[i].b ) );
		}

		double* answer = min_element( d, d + 8 );

		for( int i = 0;i < 8;i++ ){
			if( answer == &d[i] ){
				cout << color[i] << endl;
				break;
			}
		}
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    rep(i,n){
        if(s[i] == 'A'){
            if(s[i+1] == 'B' && s[i+2] == 'C'){
                ans += 1;
            }
        }
    }
    OP(ans);
}


Measured memory_bytes: 256
while a = gets
  a,b,c,d,e,f = a.split.map(&:to_f)
  x = (c-b*(d*c-a*f)/(d*b-a*e))/a; y = (d*c-a*f)/(d*b-a*e)
  puts "#{sprintf("%.3f", x)} #{sprintf("%.3f", y)}"
end
=begin
ax+by=c, dx+ey=f
dax+dby=dc ,adx+aey=af
(db-ae)y=dc-af => y=(dc-af)/(db-ae)
ax=c-by=c-b(dc-af)/(db-ae) => x=(c-b(dc-af)/(db-ae))/a
=end

Measured memory_bytes: 8636
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    string S;
    cin >> S;
    if(S[0] == S[1] && S[1] == S[2]){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main()
{
  long N,x; cin>>N; x = N % 10;
  if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
    	cout<<"hon";
  else if(x == 0 || x == 1 || x == 6 || x == 8)
    	cout<<"pon";
  else if(x == 3)
    	cout<<"bon";
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int h, w;
	cin >> h >> w;
	vector<string> ma;

	for(int i=0; i<h; i++){
		string t;
		cin >> t;
		ma.pb(t);
	}

	for(int i=0; i<2*h; i++){
		for(int j=0; j<w; j++){
			cout << ma[i/2][j];
		}
		puts("");
	}

	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {

    ll N;
    cin >> N;
    ll bN = sqrt(N);
    ll bC = N / bN;
    ll b[bN + 1][30];
    for (int yi = 0; yi < bN + 1; ++yi) {
        for (int xi = 0; xi < 30; ++xi) {
            b[yi][xi] = 0;
        }
    }
    string S;
    cin >> S;
    for (int i = 0; i < N; ++i) {
        ll bi = i / bC;
        b[bi][S[i] - 'a']++;
    }
    ll Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        ll type;
        cin >> type;
        if(type == 1){
            ll a;
            char c;
            cin >> a >> c;
            a--;
            ll bi = a / bC;
            b[bi][S[a] - 'a']--;
            b[bi][c - 'a']++;
            S[a] = c;
        }else{
            ll l,r;
            cin >> l >> r;
            l--; r--;
            ll lBi = l / bC;
            ll rBi = r / bC;
            ll lBn = l - bC * lBi;
            ll rBn = r - bC * rBi;
            if(lBi == rBi){
                bool ex[30];
                for (int j = 0; j < 30; ++j) {
                    ex[j] = false;
                }
                for (int j = l; j <= r; ++j) {
                    ex[S[j] - 'a'] = true;
                }
                ll count = 0;
                for (int j = 0; j < 30; ++j) {
                    if(ex[j]){
                        count++;
                    }
                }
                cout << count << endl;
                continue;
            }
            bool ex[30];
            for (int j = 0; j < 30; ++j) {
                ex[j] = false;
            }
            for (int j = lBi + 1; j < rBi; ++j) {
                for (int xi = 0; xi < 30; ++xi) {
                    if(b[j][xi] != 0){
                        ex[xi] = true;
                    }
                }
            }
            for (int j = l; j < bC * (lBi + 1); ++j) {
                ex[S[j] - 'a'] = true;
            }
            for (int j = bC * rBi; j <= r; ++j) {
                ex[S[j] - 'a'] = true;
            }
            ll count = 0;
            for (int j = 0; j < 30; ++j) {
                if(ex[j]){
                    count++;
                }
            }
            cout << count << endl;

        }
    }
}


Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

using mint=modint998244353;
struct S{
    mint a,sz;
};

S op(S l,S r){
    return {l.a*r.sz+r.a,l.sz*r.sz};
}

S e(){
    return {0,1};
}

S mapping(int l,S r){
    if(l) return {(r.sz-1)/9*l,r.sz};
    return r;
}

int composition(int l,int r){
    if(l) return l;
    return r;
}

int id(){
    return 0;
}

void solve(){
    int n,q;
    cin>>n>>q;
    lazy_segtree<S, op, e, int, mapping, composition, id> seg(vector(n,S{1,10}));
    {
        int l,r,d;
        for(int i{};i<(q);++i){
            cin>>l>>r>>d;
            --l;
            seg.apply(l,r,d);
            cout<<seg.all_prod().a.val()<<endl;
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 9824
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
 string a,b,c;
 cin >> a >> b >> c;
 char upper = 'A' - 'a';
 cout << char(a[0]+upper) << char(b[0]+upper) << char(c[0]+upper) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
        int H, W;
    int i, j;
    
    while(scanf("%d %d\n", &H, &W) != "EOF"){
        if(H == 0 && W == 0) break;
        
        for(i = 0; i < H; i++) {
            for(j = 0; j < W; j++) {
                if ((i + j) % 2 == 0) {
                    printf("#");
                } else { 
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s, t;
    cin >> s >> t;
    if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ac = a * c;
        long ad = a * d;
        long bc = b * c;
        long bd = b * d;
        long max = ac;
        if (max < ad) max = ad;
        if (max < bc) max = bc;
        if (max < bd) max = bd;
        System.out.print(max);
    }
}


Measured memory_bytes: 35668
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1)
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    ll x,k,d; cin >> x >> k >> d;
    if(x > 0){
        if(k > LINF/d){
            ll p = x%d;
            ll t = x/d;
            if((t+k)%2 == 0) cout << p << endl;
            else cout << d-p << endl;
        }
        else{
            if(x-k*d > 0){
                cout << x-k*d << endl;
            }
            else{
                ll p = x%d;
                ll t = x/d;
                if((t+k)%2 == 0) cout << p << endl;
                else cout << d-p << endl;
            }
        }
    }
    else{
        if(k > LINF/d){
            ll p = x%d;
            ll t = x/d;
            if((t+k)%2 == 0) cout << -p << endl;
            else cout << p+d << endl;
        }
        else{
            if(x+k*d < 0){
                cout << -x-k*d << endl;
            }
            else{
                ll p = x%d;
                ll t = x/d;
                if((t+k)%2 == 0) cout << -p << endl;
                else cout << p+d << endl;
            }
        }
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;

int main() {
	
	int w, a, b;
	
	cin >> w >> a >> b;

	if (a < b) {

		if (a + w > b)cout << "0" << endl;
		else cout << b - (a + w) << endl;
	}
	else if(a>b){
		if (b + w > a)cout << "0" << endl;
		else cout << a - (b + w) << endl;
	}else cout << "0" << endl;



	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt[200005],a[200005],cover[200005],ans;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i) a[i]=read(),cnt[a[i]]++,cover[a[i]-cnt[a[i]]+1]++;
	for(int i=1;i<=n;++i) if(cover[i]==0) ans++;
	for(int i=1;i<=m;++i){
		int x,y;
		x=read(),y=read();
		cnt[a[x]]--; if(a[x]-cnt[a[x]]>0){cover[a[x]-cnt[a[x]]]--; if(cover[a[x]-cnt[a[x]]]==0) ans++;}
		cnt[y]++; if(y-cnt[y]+1>0){cover[y-cnt[y]+1]++; if(cover[y-cnt[y]+1]==1) ans--;}
		a[x]=y;
		printf("%d\n",ans);
	}
}

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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

void solve() {
        int n;
        cin >> n;
        string s;
        cin >> s;
        ll ans = 0;
        FOR(i,0,n) {
        	if(i+2 < n) {
        		if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C') {
        			ans++;
        		}
        	}
        }
        cout << ans << endl;
}

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

using namespace std;
int ms[3002][3002]={0};
int n,m;
string s1,s2;
int main()
{
    int i,j;
    cin>>s1;
    cin>>s2;
    n=s1.size();
    m=s2.size();
    string s="";
    for(i=0;i<m+1;i++)
    {
        for(j=0;j<n+1;j++)
        {
            if(s2[i]==s1[j])
            {
                ms[i+1][j+1]=ms[i][j]+1;
            }
            else
            {
                ms[i+1][j+1]=max(ms[i+1][j],ms[i][j+1]);
            }
            //cout<<ms[i][j]<<" ";
        }
        //cout<<endl;
    }
    i=m;
    j=n;
    while(i > 0 && j > 0){
    		if(s2[i-1] == s1[j-1]){
    			s=s2[i-1]+s;
    			i--;
    			j--;
    		}
    		else if(ms[i-1][j] >= ms[i][j - 1])
    			i--;
    		else
    			j--;
    	}
   // reverse(s.begin(), s.end()); 
    cout<<s;
}

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

//関数
long del(long x){ //独立なペア数
    if(x==0){
        return 0;
    }else if(x%2==0){
        return x/2-1;
    }else{
        return x/2;
    }
}

    
    
    
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    
    vector<long> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    
    
    
    
    
    
    
    //計算
    long ans=0;
    for(int i=0;i<N;i++){
        long indpair=del(A.at(i));
        ans+=indpair;
        A.at(i)-=2*indpair;
    }
    
    long count=0;
    for(int i=0; i<N;i++){
        if(A.at(i)>0){
            count+=A.at(i);
        }else{
            ans+=count/2;
            count=0;
        }
    }
    ans+=count/2;
    
    //出力
    cout <<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
double n;
double r[3];
int main(){
// 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	double ans = (n / 3) * (n / 3) * (n / 3);
	printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>data(N);
  for(int i=0;i<N;i++)cin>>data[i];
  int j=1;
  int ans=0;
  for(int i=0;i<N;i++){
    if(data[i]==j){
      j++;
    }else{
      ans++;
      if(ans==N)ans=0;
      
  }
  }
  if(j==N+1)cout<<0<<endl;
  else if(ans==0)cout<<-1<<endl;
  else{
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 300005;
const int mo = 1e9+7;

char s[N];
int n;
int f[N][4][3];
int suf[N];
LL mi[N];

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	mi[0]=1;
	fo(i,1,n)mi[i]=mi[i-1]*2%mo;
	fd(i,n,1){
		suf[i]=suf[i+1];
		if (s[i]=='?')suf[i]++;
	}
	if (s[1]=='0')f[1][0][1]=1;
	if (s[1]=='1')f[1][1][0]=1;
	if (s[1]=='?')f[1][0][1]=f[1][1][0]=1;
	LL ans=0;
	fo(i,1,n){
		if (s[i]=='?'||s[i]=='0'){
			fo(x,0,3)fo(y,0,2)f[i][x][y%2+1]=add(f[i][x][y%2+1],f[i-1][x][y]);
		}
		if (s[i]=='?'||s[i]=='1'){
			//0 zeros
			f[i][1][0]=add(f[i][1][0],f[i-1][0][0]);
			f[i][3][0]=add(f[i][3][0],f[i-1][1][0]);
			f[i][1][0]=add(f[i][1][0],f[i-1][2][0]);
			ans=add(ans,mi[suf[i+1]]*f[i-1][3][0]%mo);
			//1 zero
			f[i][2][0]=add(f[i][2][0],f[i-1][0][1]);
			f[i][1][0]=add(f[i][1][0],f[i-1][1][1]);
			f[i][2][0]=add(f[i][2][0],f[i-1][2][1]);
			f[i][3][0]=add(f[i][3][0],f[i-1][3][1]);
			//2 zeros 
			f[i][0][1]=add(f[i][0][1],f[i-1][0][2]);
			f[i][1][1]=add(f[i][1][1],f[i-1][1][2]);
			f[i][2][1]=add(f[i][2][1],f[i-1][2][2]);
			f[i][3][1]=add(f[i][3][1],f[i-1][3][2]);
		}
	}
	ans=add(ans,f[n][1][0]);
	ans=add(ans,f[n][3][1]);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  char c;
  int kazu[26];
  for(int i=0;i<26;i++){
    kazu[i]=0;
  }
  while(cin>>c){
    if(islower(c)){
      kazu[c-97]++;
    }else if(isupper(c)){
      kazu[c-65]++;
    }
  }
  for(int i=0;i<26;i++){
    char a=97+i;
    cout<<a<<" : "<<kazu[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3104
import itertools
N = int(input())
p = tuple(list(map(int,input().split())))
q = tuple(list(map(int,input().split())))
# <class 'itertools.combinations'>
count=0
l = []
for i in range(1,N+1):
  l.append(i)
for i,v in enumerate(itertools.permutations(l)):
  if p==v:
    a = i+1
  if q==v:
    b=i+1
    
print(abs(a-b))
  

Measured memory_bytes: 9132
#include<stdio.h>

int main(){

    int h,w,i,j;

    while(1){

      scanf("%d %d",&h,&w);

      if(h==0 && w==0) break;

        for(i=0;i<h;i++){
          for(j=0;j<w;j++){
            if((j!=0 && j!=w-1) && (i!=0 && i!=h-1)) printf(".");
            else printf("#");
          }
          printf("\n");
        }
        printf("\n");

    }

    return 0;

}


Measured memory_bytes: 2032
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
#define INF (100000000)
ll dp[100010];
ll h[100010];
int main(void) {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	string s;
	cin >> s;
	int n = stoi(s), sum = 0;
	for (auto t : s) {
		sum += t - '0';
	}

	if (n % sum == 0)
		Yes();
	else
		No();

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

const int N = 3e5;
int n, ans[N];
vector <int> g[N];

main() {
	cin >> n;
	rep(i, 0, n - 1) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	rep(v, 0, n) {
		sort(g[v].begin(), g[v].end());
		reverse(g[v].begin(), g[v].end());
	}
	ans[0] = 1;
	rep(v, 1, n) {
		int bal = 1;
		int lst = v;
		int add = 0;
		for (int u : g[v]) {
			if (u > v) {
				continue;
			}
			add += (lst - u) * bal;
			bal--;
			lst = u;
		}
		add += (lst - -1) * bal;
		ans[v] = ans[v - 1] + add;
		if (debug) {
			cerr << " lst: " << lst << " bal: " << bal << '\n';
			cerr << " add: " << add << '\n';
			cerr << " ans[v]: " << ans[v] << '\n';
		}
	}
	int sum = 0;
	rep(v, 0, n) {
		sum += ans[v];
	}
	cout << sum << '\n';
}

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

struct node{
  
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;

};

typedef struct node * Node;

Node root, NIL;
int maxh;


void insert(int);
void inorder(Node );
void preorder(Node );



int main(){

  int n, i, x;
  char com[20];

  scanf("%d", &n);

  maxh = 0;

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

    scanf("%s", com);

    if ( strcmp(com, "insert") == 0 ){

      scanf("%d", &x);

      insert(x);
    }
    else if ( strcmp(com, "print") == 0 ){

      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");

    }
  }

  return 0;
}

void insert(int k){
  
  int H;
  Node y;
  Node x;
  Node z;

  y = NIL; // x ??????
  x = root; // T??????

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    
    y = x; // ???????¨????

    if ( z->key < x->key ){

      x = x->left; // ?????????????§????
    }
    else {

      x = x->right; // ?????????????§????

    }
  }

  z->parent = y;

  if ( y == NIL ){ // T ???????????´???

    root = z;

  }
  
  else {
    if (z->key < y->key) {

      y->left = z; // z ??? y ?????????????????????
    }
    else {

      y->right = z;// z ??? y ?????????????????????

    }
  }
}

void inorder(Node u){
  
  if ( u == NIL ) return;

  inorder(u->left);

  printf(" %d", u->key);

  inorder(u->right);

}
void preorder(Node u){

  if ( u == NIL ) return;

  printf(" %d", u->key);

  preorder(u->left);
  preorder(u->right);

}

Measured memory_bytes: 24040
def main():
  import bisect
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  cnt = [list() for _ in range(10)]
  for id,s in enumerate(S):
    cnt[s].append(id)
  for i in range(10):
    for j in range(10):
      for k in range(10):
        if not cnt[i] or not cnt[j] or not cnt[k]:
          continue
        index = cnt[i][0] + 1
        index = bisect.bisect_left(cnt[j],index)
        if index == len(cnt[j]):
          continue
        index = cnt[j][index] + 1
        index = bisect.bisect_left(cnt[k],index)
        if index == len(cnt[k]):
          continue
        ans += 1
  print(ans)

main()

Measured memory_bytes: 4548
#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 500005
//#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);
}
string s;
void Solve() {
    cin >> s;
    cout << s.substr(0,4) << " " << s.substr(4) << endl;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
///
// File:  1130.cpp
// Author: ymiyamoto
//
// Created on Sat Nov 11 02:36:17 2017
//

#include <array>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void dfs(int32_t H, int32_t W, array<array<char, 20>, 20> &tiles, array<array<bool, 20>, 20> &visited, int32_t i, int32_t j, char index)
{
  visited[i][j] = true;
  tiles[i][j] = index;

  for (int32_t l = -1; l <= 1; l++) {
    if (0 <= j + l && j + l < W) {
      if (tiles[i][j + l] == '.') {
        dfs(H, W, tiles, visited, i, j + l, index);
      }
    }
  }

  for (int32_t k = -1; k <= 1; k++) {
    if (0 <= i + k && i + k < H) {
      if (tiles[i + k][j] == '.') {
        dfs(H, W, tiles, visited, i + k, j, index);
      }
    }
  }
}

int32_t main()
{
  while (true) {
    int32_t W, H;
    cin >> W >> H;
    if (W == 0) break;

    array<array<char, 20>, 20> tiles;
    array<array<bool, 20>, 20> visited;
    uint32_t start_x = 0;
    uint32_t start_y = 0;
    for (int32_t i = 0; i < H; i++) {
      for (int32_t j = 0; j < W; j++) {
        cin >> tiles[i][j];
        if (tiles[i][j] == '@') {
          start_x = i;
          start_y = j;
          tiles[i][j] = '.';
        }
      }
    }

    char index = 0;
    for (int32_t i = 0; i < H; i++) {
      for (int32_t j = 0; j < W; j++) {
        if (tiles[i][j] == '.') {
          dfs(H, W, tiles, visited, i, j, index);
          index++;
        }
      }
    }

    char start_index = tiles[start_x][start_y];
    uint32_t count = 0;
    for (int32_t i = 0; i < H; i++) {
      for (int32_t j = 0; j < W; j++) {
        if (tiles[i][j] == start_index) {
          count++;
        }
      }
    }

    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 3048
#include <stdio.h>

int main()
{
	int i, N, M, Q, L[200001], R[200001], p[100001], q[100001];
	scanf("%d %d %d", &N, &M, &Q);
	for (i = 1; i <= M; i++) scanf("%d %d", &(L[i]), &(R[i]));
	for (i = 1; i <= Q; i++) scanf("%d %d", &(p[i]), &(q[i]));
	
	int j, k, count[501][501] = {}, ans[501][501] = {};
	for (i = 1; i <= M; i++) count[L[i]][R[i]]++;
	for (i = 1; i <= N; i++) {
		ans[i][i] = count[i][i];
		for (j = i + 1; j <= N; j++) {
			ans[i][j] = ans[i][j-1];
			for (k = i; k <= j; k++) ans[i][j] += count[k][j];
		}
	}
	
	for (i = 1; i <= Q; i++) printf("%d\n", ans[p[i]][q[i]]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6028
N = int(input())
a = list(map(int, input().split()))
a.sort()
k = a.count(a[0])
if a[-1] - a[0] > 1:
    print('No')
elif a[-1] == a[0]:
    if N == a[0] + 1:
        print('Yes')
    elif N//2 >= a[0]:
        print('Yes')
    else:
        print('No')
elif a[-1] < k + 1:
    print('No')
elif a[-1] > (N-k)//2 + k:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 14004
import sys

count = 0

array = raw_input().split(' ')

a = int(array[0])
b = int(array[1])
c = int(array[2])

if (a < 1 or a > 10000) or (b < 1 or b > 10000) or (c < 1 or c > 10000):
	sys.exit()

for x in xrange(a,b+1):
	if c % x == 0:
		count =  count + 1

print count

Measured memory_bytes: 6408
import sys

def main():
    input = sys.stdin.readline
    A = list(map(int, input().split()))
    A = sorted(A)

    if A[0] == A[1] == 5 and A[2] == 7:
        return 'YES'
    else:
        return 'NO'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
func readIntTuple() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

let (N, M) = readIntTuple()
var adjacent: [[Int]] = Array(repeating: [], count: N + 1)
(1...M).forEach({ _ in
    let (A, B) = readIntTuple()
    adjacent[A].append(B)
    adjacent[B].append(A)
})

var parent = Array(repeating: -1, count: N + 1)
var queue = [1]
while !queue.isEmpty {
    var nextQueue: [Int] = []
    queue.forEach({ room in
        adjacent[room].forEach({
            if parent[$0] < 0 {
                parent[$0] = room
                nextQueue.append($0)
            }
        })
    })
    queue = nextQueue
}

print("Yes")
(2...N).forEach({print(parent[$0])})


Measured memory_bytes: 18792
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  map<ll, ll> an;
  rep(i, n) {
    ll x;
    cin >> x;
    an[x]++;
  }
  ll m;
  cin >> m;
  map<ll, ll> tgt;
  rep(i, m) {
    ll x;
    cin >> x;
    tgt[x]++;
  }

  string ans = "YES";
  for (P p : tgt) {
    if (an[p.first] < p.second) {
      ans = "NO";
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>

using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    int count = 0;
    bool is_joint;
    while(true){
        is_joint = false;
        for(int i=0; i<N; i++){
            h[i] --;
            if(h[i] >= 0){
                if(is_joint == false){
                    count++;
                    is_joint = true;
                }
            }else{
                is_joint = false;
            }
        }

        int minus_count = 0;
        for(int i=0; i<N; i++){
            if(h[i] < 0){
                minus_count++;
            }
        }
        if(minus_count == N){
            break;
        }

    }

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

Measured memory_bytes: 256
n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(1, min(n, k) + 1):
  for j in range(i + 1):
    l_tmp = l[:j] + l[n - i + j:]
    l_tmp.sort()
    for m in range(min(k - i, i)):
      if l_tmp[m] < 0:
        l_tmp[m] = 0
    ans = max(ans, sum(l_tmp))
print(ans)

Measured memory_bytes: 3064
#include <cstdio>

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int a[200][3];
	rep(i,n) rep(j,3) scanf("%d",a[i]+j);

	rep(i,n){
		int ans=0;
		rep(j,3){
			int cnt=0;
			rep(k,n) if(a[i][j]==a[k][j]) cnt++;
			if(cnt==1) ans+=a[i][j];
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    int k,ans = 0;
    cin>>k;
    for(int i= 1; i<=k; i++){
        for(int j = 1; j<=k; j++){
            for(int c  = 1; c<=k; c++)
                ans+=__gcd(__gcd(i,j),c);
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3636