akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

int ans=0, x, y, b[101010];
bool vis[202020];
vector<pi> v;

int main(){
int n, m;

rep(i, 1, 101010){
b[i]=1;
}
vis[1]=true;
cin >> n >> m;
rep(i, 1, m){
cin >> x >> y;
v.pb({x,y});
}

rep(i, 0, m-1){

if(v[i].f==1){
    vis[v[i].s]=true;
    b[v[i].f]--;
    b[v[i].s]++;
    if(b[v[i].f]<=0)vis[v[i].f]=false;
    rep(j, i+1, m-1){
        int x = v[j].f;
        int y = v[j].s;
        if(vis[x]){
            vis[y]=true;

        }
            b[x]--;
            b[y]++;
        if(b[x]<=0)vis[x]=false;
    }
    break;
}

int x = v[i].f;
int y = v[i].s;

b[x]--;
b[y]++;

}

rep(i, 1, n){
if(vis[i])ans++;
}

cout << ans << endl;

return 0;}


Measured memory_bytes: 2804
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    char a[250],b[250];
    int flag=0,sus;
    scanf("%s",a);
    scanf("%s",b);
    int lena=strlen(a);
    int lenb=strlen(b);
    int w,v;
        for (int i=lena-lenb+1;i>=0;i--)
        {
            for (w=i,v=0;v<lenb;w++,v++)
            {
                if (a[w]!='?'&&a[w]!=b[v])
                    break;
            }
            if (v==lenb)
            {
                flag=1;
                sus=i;
                break;
            }
        }

    if (!flag)
        printf("UNRESTORABLE\n");
    else
    {
        for (int i=sus,j=0;j<lenb;i++,j++)
            a[i]=b[j];
        for (int i=0;i<lena;i++)
            if (a[i]=='?')
            a[i]='a';
        printf("%s\n",a);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int t,ac=0,tle=0,re=0,wa=0;
  string a;
  cin >> t;
  while(t--)
  {
    cin >> a;
    if(a[0]=='A')
        ac++;
    else if(a[0]=='W')
        wa++;
    else if(a[0]=='T')
        tle++;
    else if(a[0]=='R')
        re++;
  }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
set<string> q;
string s;
int k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s >> k;
  FOR(i, 0, sz(s))FOR(j, 1, min(sz(s)-i, k)+1){
    q.insert(s.substr(i, j));
    if(sz(q) > k) q.erase(*q.rbegin());
  }
  cout << *q.rbegin() << endl;
  return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define reps(i, n) for (int i = 1; i <= (int) n; i++)
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << x << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &p) {
    os << "{";
    for (auto itr = p.begin(); itr != p.end(); itr++) {
        itr++;
        if (itr != p.end()) { os << ", "; }
        itr--;
    }
    os << "}";
    return os;
}
struct SetUp {
    static constexpr int PREC = 20;
    SetUp() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setUp;

int N;
int a[110000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> a[i]; }
    sort(a, a + N);
    if (N % 3) {
        if (a[0] == a[N - 1]) { cout << "Yes" << endl; }
        else { cout << "No" << endl; }
    } else {
        int r = N / 3;
        if (a[0] == a[r - 1] && a[r] == a[r * 2 - 1] && a[r * 2] == a[r * 3 - 1] && (a[0] ^ a[r] ^ a[r * 2]) == 0) {
            cout << "Yes" << endl;
        } else { cout << "No" << endl; }
    }

}

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

struct Node{
  int key;
  Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
  Node *cur = nil -> next;
  while(cur !=nil && cur ->key !=key){
    cur = cur -> next;
  }
  return cur;
}

void init(){
  nil=(Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  Node *cur = nil->next;
  int isf=0;
  while(1){
    if(cur==nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur =cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t==nil) return ;
  t->prev->next =t->next;
  t->next->prev= t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  Node *x=(Node *)malloc(sizeof(Node));
  x->key =key;
  x->next =nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev =nil;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0,nd=0;

  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }else if(com[0]=='d'){
      if(strlen(com)>6){
        if(com[6]=='F') deleteFirst();
        else if(com[6]=='L') deleteLast();
      }else{
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }

printList();
return 0;
}


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

float half[7] = {35.5, 37.5, 40.0, 43.0, 50.0, 55.0, 70.0};
float full[7] = {71.0, 77.0, 83.0, 89.0, 105.0, 116.0, 148.0};
string rank[8] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};

int main(){
	float t1, t2;
	int i, j;
	
	while(cin >> t1 >> t2){
		
		for(i = 0; i < 7; ++i){
			if(t1 < half[i]) break;
		}
		
		for(j = 0; j < 7; ++j){
			if(t2 < full[j]) break;
		}
		cout << rank[max(i, j)] << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
from collections import defaultdict

N = int(input())
a = [int(input()) for _ in range(N)]
seen_list = defaultdict(int)
n = 1
ans = 0
while True:
    if seen_list[n] == 1:
        print(-1)
        exit()
    else:
        if n == 2:
            print(ans)
            exit()
        else:
            seen_list[n] = 1
            n = a[n - 1]
            ans += 1


Measured memory_bytes: 16632
import sys
from heapq import heappop, heappush

N, d = map(int, sys.stdin.readline().split())
a = sorted([(b, x, y) for l in sys.stdin.readlines() for x, y, b in (map(int, l.split()),)])
x_max, x_min, y_max, y_min = [], [], [], []

ans = 0
for b, x, y in a:
    heappush(x_max, (-x, b))
    heappush(x_min, (x, b))
    heappush(y_max, (-y, b))
    heappush(y_min, (y, b))
    for _a in (x_max, x_min, y_max, y_min):
        while _a[0][1] < b-d:
            heappop(_a)

    ans = max(ans, (-x_max[0][0]-x_min[0][0])*(-y_max[0][0]-y_min[0][0]))
print(ans)


Measured memory_bytes: 114972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;//行動の回数

  int a;
  int b;
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>a>>b;
    
    if(a==b){
      sum++;
      if(sum==3){
        cout<<"Yes"<<endl;
        break;
      }
    }
    if(a!=b){
      sum=0;
    }
  }
  if(sum!=3){
    cout<<"No"<<endl;
  }

 
}

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

using namespace std;

long long rez(long long a, long long b) {
  long long s = 0LL;
  while(b > 0) {
    long long r = a % b;
    s = s + a / b * 2 * b;
    a = b;
    b = r;
  }
  return s - a;
}

int main() {
  long long n, x;
  scanf("%lld%lld", &n, &x);

  printf("%lld", n + rez(x, n - x));
  return 0;
}


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

#define all(x) x.begin(), x.end()

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

struct state { int y, x, step; };

int main() {
        int w, h;
        while (cin >> w >> h && w) {
                int can[33][33][4];
                bool used[33][33];
                for (int i = 0; i < 33; i ++) {
                        for (int j = 0; j < 33; j ++) {
                                for (int d = 0; d < 4; d ++) {
                                        can[i][j][d] = true;
                                }
                        }
                }
                memset(used, 0, sizeof(used));
                for (int y = 0; y < 2 * h - 1; y ++) {
                        int ww = (y % 2 == 0 ? w - 1: w);
                        for (int x = 0; x < ww; x ++) {
                                int a;
                                cin >> a;
                                if (a == 1) { 
                                        if (y % 2 == 0) {
                                                can[y / 2][x][0] = false;
                                                can[y / 2][x + 1][2] = false;
                                        } else {
                                                can[y / 2][x][1] = false;
                                                can[y / 2 + 1][x][3] = false;
                                        }
                                }
                        }
                }
                queue<state> q;
                q.push((state) { 0, 0, 0 });
                used[0][0] = true;
                int ans = 0x3f3f3f3f;
                while (!q.empty()) {
                        state s = q.front(); q.pop();
                        if (s.y == h - 1 && s.x == w - 1) {
                                ans = s.step;
                                break;
                        }
                        for (int d = 0; d < 4; d ++) {
                                int yy = s.y + dy[d], xx = s.x + dx[d];
                                if (yy < 0 || yy > h - 1 || xx < 0 || xx > w - 1) continue;
                                if (!can[s.y][s.x][d]) continue;
                                if (used[yy][xx]) continue;
                                used[yy][xx] = true;
                                q.push((state) { yy, xx, s.step + 1 });
                        }
                }
                cout << (ans == 0x3f3f3f3f ? 0 : ans + 1) << endl;
        }
        return 0;
}

Measured memory_bytes: 3132
#include <cstdint>
#include <vector>


using namespace std;

int maximum_profit(vector<int32_t> &vec)
{
  int32_t max_val = INT32_MIN;
  int32_t min_val = INT32_MAX;
  for (auto iter = vec.begin(); iter != vec.end(); iter++) {
    max_val = max(max_val, *iter - min_val);
    min_val = min(min_val, *iter);
  }

  return max_val;
}

#if !defined(TEST)
#include <iostream>
int32_t main(void)
{
  int32_t num;
  cin >> num;

  vector<int32_t> vec;
  for (uint32_t i = 0; i < num; i++) {
    int32_t d;
    cin >> d;
    vec.push_back(d);
  }

  int32_t val = maximum_profit(vec);

  cout << val << endl;

  return 0;
}
#endif

Measured memory_bytes: 3940
#include <iostream>

using namespace std;

int main(void)
{
    long A, B, N;
    cin >> A >> B >> N;

    long x;

    if (B <= N)
    {
        x = B - 1;
    }
    else
    {
        x = N;
    }

    long ans = (long)(A * x / B) - A * (long)(x / B);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
bomb=[]
for i in range(0,M):
    a,b=map(int,input().split())
    bomb.append((b-1,a-1))

bomb.sort()

count=0
last=-1
for i in range(0,len(bomb)):
    b,a=bomb[i]
    if b-1>=last and last>=a:
        continue
    else:
        count+=1
        last=b-1

print(count)


Measured memory_bytes: 49428
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
using namespace std;
typedef long long int ll;
const ll MOD=10007;
const ll INF=1000000000;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    ll n;
    cin>>n;
    ll a[100001];
    ll s=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    ll k=s/(n*(n+1)/2);
    if(s%(n*(n+1)/2)!=0){
        cout<<"NO"<<endl;
        return 0;
    }
    bool f=true;
    for(int i=0;i<n-1;i++){
        ll d=a[i+1]-a[i];
        if(d-k>0||(k-d)%n!=0){
            f=false;
        }
    }
    if(f){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

                           


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int a[110],b[110],c[110],n;
double f(int i,int j,int k){
  int w=0,l;
  if(j==0)return 0;
  for(l=0;l<n;l++){
    if(j&(1<<l))w+=c[l]*20;
  }
  return abs(b[k]-b[i])/2000.0*(w+70);
}
double d[20][1<<16]={};
int fr[20][1<<16]={};
int main(){
  int i,j,k,r[110];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  for(i=0;i<n;i++){
    for(j=0;j<(1<<n);j++)d[i][j]=1e18;
  }//printf("a\n");
  for(i=0;i<n;i++){
    for(j=0;j<(1<<n);j++)fr[i][j]=-1;
  }
  for(i=0;i<n;i++)d[i][1<<i]=0;
  for(j=0;j<(1<<n);j++){
    for(i=0;i<n;i++){
      if((1<<i)&j==0)continue;
      for(k=0;k<n;k++){
	if(j&(1<<k))continue;
	if(d[k][j+(1<<k)]>d[i][j]+f(i,j,k)){
	  d[k][j+(1<<k)]=d[i][j]+f(i,j,k);
	  fr[k][j+(1<<k)]=i;
	}
      }
    }
  }//printf("b\n");
  /*for(i=0;i<n;i++){
    for(j=0;j<(1<<n);j++)printf("%f ",d[i][j]);printf("\n");
  }
  for(i=0;i<n;i++){
    for(j=0;j<(1<<n);j++)printf("%d ",fr[i][j]);printf("\n");
    }//*/
  k=j-1;
  for(i=j=0;i<n;i++){
    if(d[i][k]<d[j][k])j=i;
  }//printf("%d %d\n",j,fr[j][k]);
  r[n-1]=j;
  for(i=1;i<n;i++){//printf("%d:",j);
    r[n-i-1]=fr[r[n-i]][k];
    k-=(1<<r[n-i]);
    //j=fr[r[n-i-1]][k];
  }//printf("d\n");
  //for(i=0;i<n;i++)printf("%d ",r[i]);printf("\n");
  for(i=0;i<n-1;i++)printf("%d ",a[r[i]]);
  printf("%d\n",a[r[i]]);
  return 0;
}

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

int main(int argc, char const *argv[])
{
	int d,g;
	cin>>d>>g;
	int p[d],c[d];
	for (int i = 0; i < d; ++i)
	{
		cin>>p[i]>>c[i];
	}
	int memo[d+1]={},ans=10000;
	while (memo[d]==0)
	{
		int now=0,nans=0,cab=-1;
		for (int i = 0; i < d; ++i)
		{
			if (memo[i]==1)
			{
				now+=(i+1)*100*p[i]+c[i];
				nans+=p[i];
			}
			else
			{
				cab=i;
			}
		}
		if (now<g)
		{
			if (cab!=-1&&(g-now)<=(cab+1)*100*p[cab])
			{
				nans+=(g-now+(cab+1)*100-1)/((cab+1)*100);
				now+=g;
			}
		}
		if (now>=g)
		{
			ans=min(ans,nans);
		}
		int tmp=0;
		while (memo[tmp]==1)
		{
			memo[tmp]=0;
			++tmp;
		}
		++memo[tmp];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
TimeList = input().split(" ")
M = int(input())

for i in range(M):
    array = input().split(" ")
    sum = 0
    for j in range(N):
        sum += int(TimeList[j])
    print(sum + int(array[1]) - int(TimeList[int(array[0])-1]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int f[2][2020],x,n=1,ans;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<=s.size()-1;i++)
	{
		int x=s[i]-'0';
		for(int j=0;j<=2019;j++)
			f[1][(j*10+x)%2019]+=f[0][j];
		f[1][x]++;
		ans+=f[1][0]; 
		for(int j=0;j<=2019;j++)
		{
			f[0][j]=f[1][j];
			f[1][j]=0;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n, x, y, z;
  cin >> n;
  vector<bool> ga(n), gb(n), gc(n);
  cin >> x;
  for (i64 i = 0; i < x; i++)
  {
    i64 a;
    cin >> a;
    a--;
    ga[a] = true;
  }
  cin >> y;
  for (i64 i = 0; i < y; i++)
  {
    i64 b;
    cin >> b;
    b--;
    gb[b] = true;
  }
  cin >> z;
  for (i64 i = 0; i < z; i++)
  {
    i64 c;
    cin >> c;
    c--;
    gc[c] = true;
  }
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
    if ((!ga[i] && gc[i]) || (gb[i] && gc[i]))
      ans++;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3104
#include<stdio.h>
int main(void)
{
	int a,b,c,o=0;
	scanf("%d %d %d",&a,&b,&c);
	o=a*100+b*10+c;
	if(o==100||o==10||o==0)
	printf("Close\n");
	if(o==110||o==1)
	printf("Open\n");
	return 0;
}

Measured memory_bytes: 2676
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };

    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let (a, b) = scan!(i64, i64);
    if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 {
        println!("Possible");
    } else {
        println!("Impossible")
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>

#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

int main(void){
    string w;
    cin >> w;
    transform(w.begin(), w.end(), w.begin(), ::toupper);
    
    string s;
    cin >> s;
    
    int count = 0;
    while(s != "END_OF_TEXT"){
        transform(s.begin(), s.end(), s.begin(), ::toupper);
        if(s == w){
            count++;
        }
        cin >> s;
    }
    cout << count << endl;
}


Measured memory_bytes: 3216
s=gets.chomp
k=gets.to_i
s.each_char.with_index do |c,i|
  l=122-c.ord+1
  if c!="a"&&l<=k
    k-=l
    s[i]="a"
  end
end
s[-1]=((s[-1].ord-97+k)%26+97).chr
puts s


Measured memory_bytes: 2172
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  int A, B, C, K;
  cin >> A >> B >> C;
  cin >> K;

  int count = 0;
  while(true){
    if(A >= B){
      count++;
      B = B*2;
    }else{
      break;
    }
  }
  while(true){
    if(B >= C){
      count++;
      C = C*2;
    }else{
      break;
    }
  }

  if(count <= K){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3588
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        ts: [chars; n],
        m: usize,
        ss: [chars; m],
    };

    let mut p = HashMap::new();
    for t in &ts {
        let i = p.entry(t).or_insert(0);
        *i += 1;
    }
    for s in &ss {
        let i = p.entry(s).or_insert(0);
        *i -= 1;
    }
    let mut ans: i32 = 0;
    for (_, pp) in p {
        ans = max(ans, pp);
    }

    println!("{}", ans);
}


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

int n, s;
int ans;

void dfs(int num, int total, int minNum){
	if(num == n){
		if(total == s) ans++;
	}
	else {
		for(int i=minNum+1; i <= 9; i++){
			dfs(num+1, total+i, i);
		}
	}
}

int main(){
	while(cin >> n >> s, n||s){
		ans = 0;
		dfs(0, 0, -1);

		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, m;
vpi adj[N];
int vis[N];
vpi ans(N);

void input()
{
	cin >> n >> m;
	FOR (i, 1, m)
	{
		readc(x, y, z);
		adj[x].pb({y, z});
		adj[y].pb({x, z});
	}
}

int a = inf, mx = inf, mn = 1;
void dfs (int cur = 1, int prev = 0)
{
    vis[cur] = 1;
    
	for (pi i: adj[cur])
		if (!vis[i.fi])
		{
		    int v = i.fi;
		    ans[v] = {i.se - ans[cur].fi, -ans[cur].se};
		    
		    if (ans[v].se == 1) mn = max(mn, -ans[v].fi + 1);
		    else mx = min(mx, ans[v].fi - 1);
			dfs(v, cur);
		}
		
		else if (vis[cur] == 1 && i.fi != prev)
		{
		    int s = i.se, v = i.fi, x = ans[cur].fi + ans[v].fi;
		    if (ans[cur].se != ans[v].se)
		    {
		        if (x != s) {cout << 0; exit(0);}
		    }
		    
		    else
		    {
		        if ((s - x) & 1) {cout << 0; exit(0);}
		        if (ans[cur].se == 1) a = (s - x)/2;
		        else a = (x - s)/2;
		        
		        if (a <= 0) {cout << 0; exit(0);}
		    }
		}
	
	vis[cur] = 2;
}

int ch[N];
void checkdfs (int cur = 1, int prev = 0)
{
    vis[cur] = 1;
    
	for (pi i: adj[cur])
		if (!vis[i.fi])
		{
		    int v = i.fi;
		    ch[v] = i.se - ch[cur];
		    if (ch[v] <= 0) {cout << 0; exit(0);}
			checkdfs(v, cur);
		}
		
		else if (vis[cur] == 1 && i.fi != prev)
		{
		    int s = i.se, v = i.fi;
		    if (ch[cur] + ch[v] != s) {cout << 0; exit(0);}
		}
	
	vis[cur] = 2;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
	ans[1] = {0, 1};
	dfs();
	
	if (a < inf)
	{
	    FOR (i, 1, n) vis[i] = 0;
	    ch[1] = a;
	    checkdfs();
	    cout << 1;
	}
	
	else cout << max(0LL, mx - mn + 1);
}















Measured memory_bytes: 19584
import sys
readline = sys.stdin.readline

N, K = map(int, readline().split())
A = [a - 1 for a in map(int, readline().split())]

count = 0
a = 0
visited = {0:0}
while True:
    count += 1
    K -= 1
    a = A[a]
    if K == 0:
        print(a + 1)
        exit(0)
    if a in visited:
        T = count - visited[a]
        K = K % T
        break
    else:
        visited[a] = count

for i in range(K):
    a = A[a]

print(a + 1)

Measured memory_bytes: 30968
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,k,s;
    cin>>n>>k>>s;
    int cnt=0;
    rep(i,n){
        while(k!=cnt){
            cout<<s<<" ";
            cnt++;
            i++;
        }
        if(n!=cnt){
            if(s==1e9)cout<<1<<" ";
            else cout<<s+1<<" ";
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1280
H,W=map(int,input().split())
A=[]

for i in range(H):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(W+2))
A.append(K*(W+2))
for i in range(1,H):
    for j in range(1,W):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')


Measured memory_bytes: 3064
#### import ####
import sys
sys.setrecursionlimit(10**7)
import math
from collections import defaultdict

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

N,M = II()
a,b = Line(M)

can_visit = defaultdict(list)
for i in range(M):
  can_visit[a[i]-1].append(b[i]-1)
  can_visit[b[i]-1].append(a[i]-1)
from itertools import permutations
road = list(permutations([i for i in range(N)]))
counter = 0
for r in road:
  if r[0]!=0:
    continue
  temp = 0
  check_visited = [False]*N
  check_visited[0] = True
  for i in r[1:]:
    if (i in can_visit[temp]) and (check_visited[i]==False):
      temp = i
      check_visited[i] = True
      if check_visited == [True]*N:
        counter += 1
        break
    else:
      break
print(counter)

Measured memory_bytes: 46064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>

using ll = long long;

using namespace std;

template <typename dist_t>
class Tree {
    using edge_t = pair<dist_t, int>;

    int n; // number of nodes
    vector<edge_t> *G;
    bool *visited;

public:
    Tree() = default;
    Tree(int _n) : n(_n), G(new vector<edge_t>[(size_t)_n]), visited(new bool[(size_t)_n]) {
        fill(visited, visited+n, false);
    }

    inline void add_edge(int from, int to, dist_t dist=1) {
        G[from].push_back(edge_t{dist, to});
    }

    inline bool has_visited(int i) { return visited[i]; }
    inline void set_visited(int i) { visited[i] = true;}

    vector<edge_t> &operator[](int i) { return G[i]; }
    const vector<edge_t> &operator[](int i) const { return G[i]; }
};

ll dfs(int i, Tree<int> &tree, vector<ll> &cnt, vector<int> &color, vector<ll> &ans) {
    ll subtree_size  = 1, clean_sum = 0;
    tree.set_visited(i);
    for (auto &next:tree[i]) {
        if (tree.has_visited(next.second)) continue;
        tree.set_visited(next.second);
        ll before = cnt[color[i]];
        ll child_size = dfs(next.second, tree, cnt, color, ans);
        ll after = cnt[color[i]];
        subtree_size += child_size;
        ll clean = child_size - (before - after);
        ans[color[i]] += clean * (clean + 1) / 2;
        clean_sum += clean;
    }
    cnt[color[i]] -= clean_sum + 1;
    return subtree_size;
}

int main() {
    int n;
    cin >> n;
    vector<int> color(n);
    for (auto &ci:color) {
        cin >> ci;
        ci--;
    }
    Tree<int> t(n);
    for (int i=0, ai, bi; i<n-1; i++) {
        cin >> ai >> bi;
        t.add_edge(--ai, --bi);
        t.add_edge(bi, ai);
    }
    vector<ll> ans(n, 0);
    vector<ll> cnt(n, n);
    dfs(0, t, cnt, color, ans);
    ll total = (ll)n * (n+1) / 2;
    for (int i=0; i<n; i++) {
        ans[i] += cnt[i] * (cnt[i] + 1) / 2;
        cout << total - ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 36956
inf = float('inf')


def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p = list(map(int, input().split()))

    ans = inf
    score = inf
    for i in range(-1, 102):
        tmp = abs(x - i)
        if score > tmp and i not in p:
            ans = i
            score = tmp
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9188
from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

queue = deque()
queue.append([0, 0])
visited = [[False] * w for _ in range(h)]
visited[0][0] = True

def judge():
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#" and not visited[i][j]:
                return False
    return True
def bfs(queue):
    while len(queue) > 0:
        n_y, n_x = queue.popleft()
        if 0 <= n_x < w - 1 and 0 <= n_y < h - 1:
            if a[n_y][n_x + 1] == "#" and a[n_y + 1][n_x] == "#":
                print("Impossible")
                exit()
        for i, j in [[0, 1], [1, 0]]:
            y, x = n_y + i, n_x + j
            if 0 <= x < w and 0 <= y < h:
                if a[y][x] == "#":
                    queue.append([y, x])
                    visited[y][x] = True
    print("Possible" if judge() else "Impossible")
bfs(queue)


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

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    for (auto& e : a) cin >> e;
    partial_sum(begin(a), end(a), begin(a));
    int64_t ans = 1e18;
    for (int64_t i = 0; i+1 < n; i++) {
        ans = min(ans, abs(a[i] - a.back() + a[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 5000

ll dpa[4 + 1][MAX + 1], dpb[4 + 1][MAX * MAX + 1];

signed main(){
    ll n;
    cin >> n;
    ll va[4], vb[4];
    cin >> va[0] >> va[1] >> va[2];
    cin >> vb[0] >> vb[1] >> vb[2];
    va[3] = 1;
    vb[3] = 1;
    for(int i = 0; i < 4; i++){
        for(int j = 0; j <= n; j++){
            dpa[i + 1][j] = max(dpa[i + 1][j], dpa[i][j]);
            if(j - va[i] < 0) continue;
            dpa[i + 1][j] = max(dpa[i + 1][j], dpa[i + 1][j - va[i]] + vb[i]);
        }
    }
    for(int i = 0; i < 4; i++){
        for(int j = 0; j <= dpa[4][n]; j++){
            dpb[i + 1][j] = max(dpb[i + 1][j], dpb[i][j]);
            if(j - vb[i] < 0) continue;
            dpb[i + 1][j] = max(dpb[i + 1][j], dpb[i + 1][j - vb[i]] + va[i]);
        }
    }
    cout << dpb[4][dpa[4][n]] << endl;
    return 0;
}

Measured memory_bytes: 782464
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    int num[100008] = {0};
    for(int i = 0; i < n; i++) {
        num[v[i]]++;
    }
    
    int index = 0;
    int sum = 0;
    int ans;
    for(int i = 1; i < 100000; i++) {
        sum += num[i];
        if(2*sum == n) {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}




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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, K;
  cin >> N >> K;
  map<LL,LL> xs;
  REP(i,N){
	LL a, b;
	cin >> a >> b;
	xs[a] += b;
  }

  for(auto&& it: xs){
	if(K <= it.SS){
	  cout << it.FF << endl;
	  break;
	}
	K -= it.SS;
  }

  return 0;
}


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

int main()
{
  char str[12];
  cin>>str;
  int min=999;
  for(int i=0;i<strlen(str)-2;i++)
  {
    int num=100*(str[i]-'0')+10*(str[i+1]-'0')+(str[i+2]-'0');
    int diff = abs(num-753);
    if(diff<min)
      min=diff;
  }
  cout<<min;
	
  return 0;
}

Measured memory_bytes: 256
xs = %w(dreameraser dreamerase dreamer eraser dream erase)
s = gets.chomp
while s.size > 0
	x = xs.find do |x|
		pos = s.index(x)
		(not pos.nil?) && pos == 0
	end
	break if x.nil?
	s = s[x.size, s.size]
end

puts s.size > 0 ? 'NO' : 'YES'


Measured memory_bytes: 2812
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
  int x,y,w,h,r;

  cin>>w>>h>>x>>y>>r;

  if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)
    cout<< "Yes"<<endl;
  else
    cout<<"No"<<endl;

  return 0;
  
}




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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define sp cout << " ";
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';				

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


clock_t time_p = clock();

void ktj(){
    time_p = clock() - time_p;
	cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
	IOS

	int x,y;
	cin >> x >> y;
	cout << (x < y ? 0 : 10) << '\n';

	ktj();
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int f(int x){
	int i,ret=0;
	for(i=1; i<=x; ++i){
		if(!(x%i)){
			++ret;
		}
	}
	return ret;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define br cout << "\n";
#define pb push_back
#define ll long long 
#define ff first 
#define ss second
#define all(x) x.begin(),x.end()
#define in(a , idx , n ) for (int i = idx ; i < n ; ++i)cin >>a[i];
using namespace std;
const int MOD = 1000*1000*1000 + 7 ; 
const int MAXN = 1000*100 +10 ;
void solve(){
	int n ;
	cin >> n  ;
	vector<array<int ,3 >> a(n) ;
	for(auto &x : a )
		cin >> x[0] >> x[1] >> x[2] ;
	int dp[n][3];
	for(int i = 0 ; i < n ; ++i )
		for (int j = 0 ; j < 3 ; ++j )
			dp[i][j] = 0 ;
			
	dp[n-1][0] = a[n-1][0] ; 
	dp[n-1][1] = a[n-1][1] ; 
	dp[n-1][2] = a[n-1][2] ;
	
	for (int i = n - 2 ; i >= 0 ; -- i )
	{
		for(int  j = 0 ; j < 3 ; ++j )
		{
			for(int k = 0 ; k < 3 ; ++k )
			{
				if ( j == k ) continue ;
					
				dp[i][j] = max (dp[i][j] , dp[i + 1 ][ k ]  + a[i][j]) ; 
			}	
		}	
	}	

	
	
	cout << max ({ dp[0][0],dp[0][1], dp[0][2] }) ; 
	
}
int main (){ 
	int t = 1  ;
	// cin >> t ;
	while (t--){
		solve() ; 
	}
    
return 0 ; 
}


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

constexpr int inf = 0x3f3f3f3f;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int t, n;
  while (cin >> t >> n, t) {
    vector<vector<bool>> b(121, vector<bool>(121, true));
    while (n--) {
      int x, y;
      cin >> x >> y;
      x += 60, y += 60;
      b[x][y] = false;
    }
    int sx, sy;
    cin >> sx >> sy;
    sx += 60, sy += 60;
    vector<vector<int>> d(121, vector<int>(121, inf));
    queue<pair<int, int>> que;
    d[sx][sy] = 0;
    que.emplace(sx, sy);
    while (not que.empty()) {
      int x, y;
      tie(x, y) = que.front();
      que.pop();
      for (int dx = -1; dx <= 1; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
          if (dx + dy) {
            int nx = x + dx, ny = y + dy;
            if (0 <= nx and nx <= 120 and 0 <= ny and ny <= 120 and b[nx][ny] and d[nx][ny] == inf) {
              d[nx][ny] = d[x][y] + 1;
              que.emplace(nx, ny);
            }
          }
        }
      }
    }
    int res = 0;
    for (int x = 0; x <= 120; ++x) {
      for (int y = 0; y <= 120; ++y) {
        res += d[x][y] <= t;
      }
    }
    cout << res << '\n';
  }
}



Measured memory_bytes: 3208
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long h = 0;
		long w = 0;
		Long[] A = new Long[N];
		for(int i = 0; i < N; i++) {
			A[i] = scan.nextLong();
		}
		Arrays.sort(A, Collections.reverseOrder());
		for(int i = 1; i < N; i++) {
			if(h == 0) {
				if(A[i - 1].equals(A[i])) {
					h = A[i];
					i++;
				}
			} else {
				if(A[i - 1].equals(A[i])) {
					w = A[i];
					break;
				}
			}
		}
		System.out.println((long)h * w);
		scan.close();

	}

}


Measured memory_bytes: 62488
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        char[][] A = new char[N][N];
        for (int i = 0; i < N; i++) {
            String t = scan.next();
            A[i] = t.toCharArray();
        }
        char[][] B = new char[M][M];
        for (int i = 0; i < M; i++) {
            String t = scan.next();
            B[i] = t.toCharArray();
        }

        boolean answer = false;
        for (int i = 0; i < N - M + 1 && !answer; i++) {
            for (int j = 0; j < N - M + 1 && !answer; j++) {
                boolean found = true;
                for (int k = 0; k < M; k++) {
                    for (int l = 0; l < M; l++) {
                        if (A[i+k][j+l] != B[k][l]) {
                            found = false;
                            break;
                        }
                    }
                    if (!found) {
                        break;
                    }
                }
                if (found) {
                    answer = true;
                    break;
                }
            }
        }
        System.out.println(answer ? "Yes" : "No");
    }
}


Measured memory_bytes: 22100
open System

#nowarn "25"

let readLine _ = Console.In.ReadLine()
let readInt<'a> = readLine >> int
let readLong<'a> = readLine >> int64
let readFloat<'a> = readLine >> float
let readArray _ = readLine().Split ' '
let readArrayInt _ = readArray() |> Array.map (int)

[<EntryPoint>]
let main _ =
    let n = readInt()
    let P = readArrayInt()
    let mutable min = Int32.MaxValue
    let mutable cnt = 0
    for pi in P do
        if pi <= min then
            min <- pi
            cnt <- cnt + 1
    printfn "%d" cnt
    0 // return an integer exit code


Measured memory_bytes: 32088
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
signed main() 
{ 
    fast;
    int n;
    cin>>n;
    if(n%2 == 1)
    {
        cout<<0;
        return 0;
    }
    int five = 0;
    for(int i=5;(n/i)>=1 ;i = i*(int)5)
    {
        int temp = n/i;
        five+=(temp/2);
    }
    cout<<five;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	map<int,int> mp;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	
	int ans = mp.size();
	
	int k = 0;
	
	for(auto a:mp){
		k += a.second-1;
	}
	
	if(k%2==1){
		ans--;
	}
	
	cout<<ans<<endl;

	
	
    return 0;
}



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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define WHITE 0  // 未訪問
#define BLACK 1  // 訪問ずみ

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; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
const int N=100000;
//const ll M = 1000000000+7;


int main(){
  ll a,b,m;
  cin>>a>>b>>m;

  vector<ll> A(a);
  vector<ll> B(b);

  
  rep(i, a){
    cin>>A[i];
  }
  rep(i, b){
    cin>>B[i];
  }

  ll min_A = *min_element(A.begin(), A.end());
  ll min_B = *min_element(B.begin(), B.end());

  ll min_AB = min_A+min_B;

  //cout<<min_AB<<endl;
  ll x,y,c;
  rep(i,m){
    cin>>x>>y>>c;
    x--;y--;
    min_AB = min(min_AB, A[x]+B[y]-c);
  }
  
  cout << min_AB <<endl;
  
}




Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

using Graph = vector<vector<int>>;
vector<vector<int>> tsort(Graph &g) {
    int n = g.size(), k = 0;
    vector<int> indeg(n), que, nxt;
    for (int u = 0; u < n; u++) for (int v: g[u]) ++indeg[v];
    vector<vector<int>> dist(n);
    for (int v = 0; v < n; v++) if (indeg[v] == 0) que.emplace_back(v);
    while (!que.empty()) {
        for (int u: que) {
            dist[k].emplace_back(u);
            for (int v: g[u]) if (--indeg[v] == 0) nxt.emplace_back(v);
        }
        swap(que, nxt); nxt.clear(); k++;
    }
    if (*max_element(indeg.begin(), indeg.end()) != 0) return {};
    return dist.resize(k), dist;
}

int main() {
    int V, E; cin >> V >> E;
    Graph g(V);
    while (E--) {
        int s, t; cin >> s >> t;
        g[s].emplace_back(t);
    }
    for (auto &vec: tsort(g)) for (int v: vec) cout << v << endl;
    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define IINF 1e9

string lexi(string s, string t){

}

int main(void){
    string s,t;
    cin >> s >> t;
    vector<string> tmp;
    int l = s.size() - t.size() + 1;
    REP(i,max(0, l)){
        bool can = true;

        string t2 = s;
        REP(j,t.length()){
            if(i+j > s.size() - 1){
                can = false;
                break;
            }
            if(s[i+j] != '?' && s[i+j] != t[j]){
                can = false;
                break;
            }
            t2[i+j] = t[j];
        }
        if(can){
            FOR(k,0,s.length()){
                if(t2[k] == '?') t2[k] = 'a';
            }
            tmp.push_back(t2);
        }
    }
    sort(tmp.begin(),tmp.end());
    if(tmp.empty()) cout << "UNRESTORABLE" << endl;
    else cout << tmp[0] << endl;
    return 0;
}

Measured memory_bytes: 3628