akhauriyash/Code-Regression huggingface dataset:
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

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

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// (to, cost)
vector<pii> G[20];
int dp[1 << 15][15];

void solve() {
    int V, E; cin >> V >> E;
    rep(i,0,E) {
        int s, t, d; cin >> s >> t >> d;
        G[s].push_back(pii(t, d));
    }

    rep(i,0,1<<V) rep(j,0,V) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(bit,0,1<<V) rep(i,0,V) {
        for(auto x : G[i]) {
            if(bit >> x.first & 1) continue;
            int nbit = bit | (1 << x.first);
            chmin(dp[nbit][x.first], dp[bit][i] + x.second);
        }
    }
    int ans = (dp[(1<<V)-1][0] == INF ? -1 : dp[(1<<V)-1][0]);
    cout << ans << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 6908
#include <iostream>

using namespace std;

int main(){
	int N[2];
	
	cin >> N[0] >> N[1];
	unsigned long long map[2][64];
	
	for (int i = 0; i < 2; i++){
		for (int j = 0; j < N[i]; j++){
			char in[50];
			cin >> in;
			map[i][j] = 0;
			for (int k = 0; k < N[i]; k++){
				unsigned long long tmp = 1;
				if (in[k] == '#') map[i][j] = map[i][j] | (tmp<<k);
			}
		}
	}
	unsigned long long mask = 1;
	mask = (mask << N[1]);
	mask--;
	
	for (int i = 0; i <= (N[0] - N[1]); i++){
		for (int j = 0; j <= (N[0] - N[1]); j++){
			for (int k = 0; k < N[1]; k++){
				if (((map[0][i+k] & (mask << j)) != (map[1][k] << j))){break;}
				if (k == (N[1] - 1)) { cout << "Yes" << endl;  return 0; }
			}
		}
	}
	cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    int p[15], maxp = 0, sum = 0;
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &p[i]);
        maxp = max(maxp, p[i]);
        sum += p[i];
    }
    sum = sum - maxp + maxp / 2;
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod = 1e9+7;
int f[200005];
int mult(int x,int y){
    return ((x % mod) * (y % mod)) % mod;
}
int sub(int x,int y){
    int fi = x%mod;
    int yi = y%mod;
    fi-=yi;
    while(fi <0)
        fi+=mod;
    fi%=mod;
return fi;
}
int fastpow(int x,int y){
if(!y)return 1LL;
if(y == 1)  return x%mod;
int cur = fastpow(x,y/2);
cur%=mod;
cur = ((cur % mod) * (cur % mod))%mod;
if(y & 1)cur = ((cur % mod) * (x % mod) )%mod;
return cur;

}
int inverse(int x){
    return fastpow(x,mod-2);
}
int c(int x,int y){
    if(x < 0 || y < 0 || y > x)   return 0L;
    return mult(f[x],inverse(mult(f[y],f[x-y])));
}
int solv(int x,int y){
    int cur = 1,bot = 1;
    for(int i = 1; i<=y; i++,x--)
        cur = mult(cur,x),bot = mult(bot,i);
        bot = inverse(bot);
     return mult(cur,bot);
}
 main()
{
    int n,a,b;
    cin>>n>>a>>b;
    f[0] = 1;
    for(int i = 1; i<=2e5; i++)
        f[i] = ((f[i-1] % mod) * (i % mod))%mod;

    int ans = fastpow(2,n)- 1LL;
    ans%=mod;
    ans = sub(ans,solv(n,a));
    ans = sub(ans,solv(n,b));
    cout<<ans<<endl;

    return 0;
}


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

prime = [True] * 100001
like2017 = [0] * 100001
num = 0
for i in range(2, 100001):
  if prime[i]:
    for j in range(i*2, 100001, i):
      prime[j] = False
    if i != 2 and prime[(i+1)//2]:
      num += 1
  like2017[i] = num

for i in range(N):
  l, r = map(int, input().split())
  print(like2017[r] - like2017[l-1])

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

bool check(int n){
  while(n%2==0){
    n/=2;
  }
  while(n%3==0){
    n/=3;
  }
  while(n%5==0){
    n/=5;
  }
  if(n==1){
    return true;
  }else{
    return false;
  }
}

int main(){
  int m,n;
  while(1){
    cin>>m;
    if(m==0)break;
    cin>>n;
    int ans=0;
    for(int i=m;i<=n;i++){
      if( check(i) ){
        ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>

int main(void){
  int n, k=1;
  
  scanf("%d", &n);
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      if(i*j==n){
        k=0;
        break;
      }
    }
  }
  if(k) printf("No\n");
  else printf("Yes\n");
  
  return 0;
}

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

int main() {
  int r, g, b, rgb;
  cin >> r >> g >> b;
  rgb = r*100 + g*10 + b;
  if (rgb % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200100
using namespace std;
int a[N],id[N];
bool cmp(int i,int j){
	return a[i]<a[j];
}
int main(){
	set<int> del;
	int n;
	long long ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		id[i]=i;
	}
	sort(id,id+n,cmp);
	del.insert(-1);
	del.insert(n);
	for(int i=0;i<n;i++){
		int u=id[i],l=*(--del.lower_bound(u)),r=*del.upper_bound(u);
		del.insert(u);
		ans+=1LL*a[u]*(r-u)*(u-l);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11136
{你无权查看本记录 因为↓}

















































{你是傻逼
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
    SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBS
}



































{
    祝您一路顺风，半路失踪，回家发疯~~~~~~~~~~~~
}










































{再见了，SB，我们后会无期}



































{别以为我不知道是你YMJ！！！，喜欢看人家程序的**→_→}























































































var
 x,i,j:longint;
 a:array[0..5,0..5] of longint;
begin
 readln(a[1,1],a[1,2],a[2,2]);
 x:=a[2,2]*3;
 a[1,3]:=x-a[1,1]-a[1,2];
 a[3,1]:=x-a[1,3]-a[2,2];
 a[3,3]:=x-a[1,1]-a[2,2];
 a[2,1]:=x-a[1,1]-a[3,1];
 a[2,3]:=x-a[2,1]-a[2,2];
 a[3,2]:=x-a[1,2]-a[2,2];
 for i:=1 to 3 do
  begin
   for j:=1 to 3 do
    write(a[i,j],' ');
   writeln;
  end; 
end.

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef pair<pair<int,int>,bool> piib;

const ll N=1001;
const int MOD=1e9+7;

int a;

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

	//freopen("mosalah.in","r",stdin);

	#ifndef ONLINE_JUDGE
		//freopen("input.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	#endif // ONLINE_JUDGE

	cin >> a;
	cout << a+(a*a)+(a*a*a) << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  
  int sum;
  
  if(K>=N){
    sum = X*N;
  }
  
  else{
    sum=X*K+Y*(N-K);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
signed main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;

int n;
vector<int> a;

int main() {
	cin >> n;
	a.resize(n + 1);
	for (int i = 1; i < n + 1; i++) {
		cin >> a[i];
	}

	if (n % 2 == 0) {
		for (int i = n; i >= 1; i -= 2) {
			if (i != n) cout << " ";
			cout << a[i];
		}
		for (int i = 1; i < n; i += 2) {
			cout << " ";
			cout << a[i];
		}
	} else {
		for (int i = n; i >= 0; i -= 2) {
			if (i != n) cout << " ";
			cout << a[i];
		}
		for (int i = 2; i < n; i += 2) {
			cout << " ";
			cout << a[i];
		}	
	}
	cout << endl;
}


Measured memory_bytes: 3072
//
// Created by yamunaku on 2019/09/28.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int a,b,q;
    cin >> a >> b >> q;
    vl s(a),t(b);
    rep(i,a) cin >> s[i];
    rep(i,b) cin >> t[i];
    rep(i,q){
        ll x;
        cin >> x;
        int sidx=lower_bound(all(s),x)-s.begin();
        ll s1=LINF,s2=LINF;
        if(sidx<a){
            s2=s[sidx]-x;
        }
        if(sidx>0){
            s1=x-s[sidx-1];
        }
        int tidx=lower_bound(all(t),x)-t.begin();
        ll t1=LINF,t2=LINF;
        if(tidx<b){
            t2=t[tidx]-x;
        }
        if(tidx>0){
            t1=x-t[tidx-1];
        }
        cout << min(min(s1+t2+min(s1,t2),s2+t1+min(s2,t1)),min(max(s1,t1),max(s2,t2))) << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<map>
using namespace std;

class DisjointSet{
  public:
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }

    int findSet(int x){
        if(x != p[x]){
            // path compression
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n, k, l;
    cin >> n >> k >> l;

    DisjointSet road(n), train(n);

    int p, q, r, s;
    for(int i = 0; i < k; i++){
        cin >> p >> q;
        p--, q--;
        road.unite(p, q);
    }

    for(int i = 0; i < l; i++){
        cin >> r >> s;
        r--, s--;
        train.unite(r,s);
    }

    vector<int> ro(n), tr(n);
    for(int i = 0; i < n; i++)  ro[i] = road.findSet(i);
    for(int i = 0; i < n; i++)  tr[i] = train.findSet(i);

    map<int, map<int, int>> m;
    for(int i = 0; i < n; i++)  m[ro[i]][tr[i]]++;

    for(int i = 0; i < n; i++)  cout << m[ro[i]][tr[i]] << " \n"[i == n-1];
    
    return 0;
}

Measured memory_bytes: 30848
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n--){
    double x[4],y[4];
    for(int i=0;i<4;i++){
      cin >> x[i] >> y[i];
    }
    if(abs((x[3]-x[2])*(y[1]-y[0])-(x[1]-x[0])*(y[3]-y[2])) < 1e-10){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
const int N=1e5+5;
 
 
int pa[N];
int n,m;
 
ll szz[N];
ll ans[N];
struct edge{
    int u,v;
}edges[N];
 
int find(int x){
    if(pa[x]==x) return pa[x];
    else{
        pa[x]=find(pa[x]);
        return pa[x];
    }

}


 
int main(){
    IOS
    cin>>n>>m;
    int a,b;
    
    for(int i=1;i<=m;++i){
        cin>>edges[i].u>>edges[i].v;
 
    }
    //cout<<"hre"<<endl;
    
    for(int i=1;i<=n;++i){
        //raank[i]=0;
        pa[i]=i;
        szz[i]=1;
    }
    ans[m]=(ll)n*(ll)(n-1)/(ll)2;
    //cout<<"herew   df  "<<endl;
    for(int i=m;i>=1;--i){
 
          a=find(edges[i].u);
          b=find(edges[i].v);
          
         
          if(a==b){
               ans[i-1]=ans[i];
          }
          else{
               ans[i-1]=ans[i]-(szz[a]*szz[b]);
               szz[a]+=szz[b];
               pa[b]=a;
          }
          //cout<<szz[a]<<endl;
     
 
 
     }
     for(int i=1;i<=m;i++) 
         cout<<ans[i]<<endl;
      
    
     return 0;
}

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

using namespace std;
int x,y;


void solve(int *x, int *y){
    if(*x > *y){
        int temp = *x;
        *x = *y;
        *y = temp;
    }

    return;
}

int main(){
    while(1){
        cin >> x >> y;
        if((x | y) == 0){break;}
        solve(&x, &y);
        cout << x << " " << y << endl;
    }

    return 0;
}


Measured memory_bytes: 3040
n = int(input())
a = list(map(int, input().split()))

m = sum(a)/n
if int(m) == m:
  ans = 0
  for v in a:
    ans += (int(m)-v)**2
  print(ans)
else:
  x = int(m)
  y = int(m)+1
  X,Y = 0,0
  for v in a:
    X += (x-v)**2
    Y += (y-v)**2
  print(min(X,Y))

Measured memory_bytes: 3064
import itertools
N, Ma, Mb = map(int, input().split())
L = [[int(i) for i in input().split()] for _ in range(N)]

inf = N * 101
dp = [[[inf for _ in range(N*10+11)] for _ in range(N*10+11)] for _ in range(N+1)]

dp[0][0][0] = 0
cmb = itertools.product(range(N), range(N*10), range(N*10))
for i, j, k in cmb:
    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
    dp[i+1][j+L[i][0]][k+L[i][1]] = min(dp[i+1][j+L[i][0]][k+L[i][1]], dp[i][j][k] + L[i][2])
ans = inf
for i in range(1, N*10//max(Ma, Mb)):
    ans = min(ans, dp[N][i*Ma][i*Mb])

if ans == inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 106844
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1999;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

ll a[200005];
ll sum[200005], xorsum[200005];

int cnt(int i)
{
	int l = 1, r = i;
	while (l <= r)
	{
		int m = (l + r) >> 1;
		if (sum[i] - sum[m - 1] == (xorsum[i] ^ xorsum[m - 1]))r = m - 1;
		else l = m + 1;
	}
	return i - l + 1;
}
int main() {
	int n;
	scanf("%d", &n);
	fup(i, 1, n, 1)
	{
		scanf("%lld", a + i);
		sum[i] = sum[i - 1] + a[i];
		xorsum[i] = xorsum[i - 1] ^ a[i];
	}
	ll ans = 0;
	fup(i, 1, n, 1)
		ans += cnt(i);
	printf("%lld", ans);
}

Measured memory_bytes: 4992
h,w=map(int,input().split())
mx=10**18
for i in range(1,h):
  l=w//2
  s=[i*w,(h-i)*l,(h-i)*(w-l)]
  s.sort()
  mx=min(mx,s[2]-s[0])
  k=(h-i)//2
  t=[i*w,k*w,(h-k-i)*w]
  t.sort()
  mx=min(mx,t[2]-t[0])
for i in range(1,w):
  l=h//2
  s=[i*h,(w-i)*l,(w-i)*(h-l)]
  s.sort()
  mx=min(mx,s[2]-s[0])
  k=(w-i)//2
  t=[i*h,k*h,(w-k-i)*h]
  t.sort()
  mx=min(mx,t[2]-t[0])
print(mx)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  ll t1,t2;
  cin >> t1 >> t2;
  ll a1,a2;
  cin >> a1 >> a2;
  ll b1,b2;
  cin >> b1 >> b2;

  ll d1=(a1-b1)*t1;
  ll d2=d1+(a2-b2)*t2;


  if(d2>0){
    if(d1>0){
      cout << 0 << "\n";
    }
    else{
      if((-d1)%d2==0) cout << ((-d1)/d2)*2 << "\n";
      else cout << ((-d1)/d2)*2+1 << "\n";
    }
  }
  else if(d2<0){
    if(d1<0){
      cout << 0 << "\n";
    }
    else{
      if(d1%(-d2)==0) cout << (d1/(-d2))*2 << "\n";
      else cout << (d1/(-d2))*2+1 << "\n";      
    }    
  }
  else{
    cout << "infinity" << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[4][4];
int main()
{
    for(int i=1;i<=3;++i)
        for(int j=1;j<=3;++j)
        	cin>>a[i][j];
    if(a[1][2]+a[2][3]+a[3][1]+a[1][3]+a[2][1]+a[3][2]==(a[1][1]+a[2][2]+a[3][3])*2)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
X = N
quot_100 = X//100
X= X % 100
quot_10 = X // 10
X= X % 10
quot_1 = X

if (quot_100 == 7) or (quot_10 == 7) or (quot_1 == 7) :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

int main() {
  // code

  ll n, a, b;
  cin >> n >> a >> b;

  ll blocks = n / (a + b);
  ll lb = min(a, n % (a + b));

  cout << blocks * a + lb << endl;

  // codend
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=100010;
int s[maxn],c[maxn],f[maxn];
int main(){
	int n,r1;
	scanf("%d",&n);
	for(int i=1;i<n;++i)
		scanf("%d%d%d",&c[i],&s[i],&f[i]);
	for(int i=1;i<n;++i){
		r1=s[i]+c[i];
		for(int j=i+1;j<=n;++j){
			if(j==n){
				printf("%d\n",r1);
				continue;
			}
			if(r1<=s[j]){
				r1=s[j]+c[j];
				continue;
			}
			int qq=r1-s[j];
			int lq=qq/f[j];
			if(qq%f[j]==0)r1=s[j]+lq*f[j];
			else r1=s[j]+(lq+1)*f[j];
			r1+=c[j];
		}
	}printf("0\n");
	return 0;
}


Measured memory_bytes: 256
/* Coached by Dukkha */
#include <stdio.h>

#define N 100

int max(int a, int b) { return a > b ? a : b; }

int main() {
	static int ww[N], vv[N], dp[N + 1][N + 1][N * 3 + 1];
	int n, w_, w0, i, k, a, b, ans;

	scanf("%d%d", &n, &w_);
	for (i = 0; i < n; i++)
		scanf("%d%d", &ww[i], &vv[i]);
	w0 = ww[0];
	for (i = 0; i < n; i++)
		ww[i] -= w0;
	for (i = 0; i < n; i++) {
		int w = ww[i], v = vv[i];

		for (k = 0; k <= i; k++)
			for (a = 0; a <= n * 3; a++) {
				dp[i + 1][k][a] = max(dp[i + 1][k][a], dp[i][k][a]);
				if ((b = a + w) <= n * 3)
					dp[i + 1][k + 1][b] = max(dp[i + 1][k + 1][b], dp[i][k][a] + v);
			}
	}
	ans = 0;
	for (k = 1; k <= n; k++)
		if (w_ >= (long long) w0 * k)
			for (a = 0; a <= w_ - w0 * k && a <= n * 3; a++)
				ans = max(ans, dp[n][k][a]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 10368
import sys

M = 2019
S = sys.stdin.readline().rstrip()
N = len(S)

dmod = [0] * (N + 1)
amod = [0] * (N + 1)
tenmod = 1
prev_amod = 0
mcnt = [0] * 2019
ans = 0
for i in range(N, -1, -1):
    d = ord(S[i]) - ord("0") if i < N else 0
    dmod[i] = d * tenmod % M
    amod[i] = (dmod[i] + prev_amod) % M
    ans += mcnt[amod[i]]
    mcnt[amod[i]] += 1
    tenmod = tenmod * 10 % M
    prev_amod = amod[i]
print(ans)


Measured memory_bytes: 23012
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong h[100005];
llong mem[100005];

llong dfs(llong idx) {
    if (idx == n - 1) return 0;
    if (idx >= n) return (1ll << 30ll);
    if (mem[idx] != -1) return mem[idx];

    return mem[idx] = min(dfs(idx + 1) + llabs(h[idx] - h[idx + 1]),
                          dfs(idx + 2) + llabs(h[idx] - h[idx + 2]));
}

int main() {
    for (llong i = 0; i < 100005; i++) {
        mem[i] = -1;
    }
    
    cin >> n;
    for (llong i = 0; i < n; i++) {
        cin >> h[i];
    }

    cout << dfs(0) << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    string s;
    cin >> s;
    for (int i = 0; i < (int) s.size(); i++){
        if (s[i] == ',') cout << ' ';
        else cout << s[i];
    }
    cout << endl;
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3616
import sys
import math
import numpy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
 
p = int(readline())
if p % 2 == 1:
    print(0)
else:
    p //= 2
    ans = 0
    while p:
        p //= 5
        ans += p
    print(ans)


Measured memory_bytes: 21376
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int N;
vector<vint> G;
ll X[5010];
ll dp[1010][5010];

bool dfs(int v){

  for(int chi:G[v]){
    if(!dfs(chi))return false;
    ll tmp[5010];
    repeat(x,X[v]+1){
      tmp[x] = INF;
    }
    for(int x=0;x<=X[v];x++){
      if(x-X[chi]>=0)
      tmp[x] = min(tmp[x],dp[v][x-X[chi]]+dp[chi][X[chi]]);
      if(x-dp[chi][X[chi]]>=0)
      tmp[x] = min(tmp[x],dp[v][x-dp[chi][X[chi]]]+X[chi]);
      if(x>0){
        tmp[x] = min(tmp[x],tmp[x-1]);
      }
    }
    repeat(x,X[v]+1){
      dp[v][x] = tmp[x];
    }
  }
  return dp[v][X[v]] < INF;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  G.resize(N);
  repeat(i,N-1){
    int p;cin >> p;p--;
    G[p].push_back(i+1);
  }
  repeat(i,N){
    cin >> X[i];
  }
  cout << (dfs(0)? "POSSIBLE":"IMPOSSIBLE") << endl;
  //debugArray(dp[0],7);
  return 0;
}


Measured memory_bytes: 45184
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n+1];
   int cnt=0;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       if((i&1) && (a[i]&1))cnt++;
   }
   cout<<cnt<<endl;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K, A, B):
    if A >= B:
        return K + 1
    
    if K <= A - 1:
        return K + 1
    
    if B - A <= 2:
        return K + 1

    # print('-----', int(math.floor(K / 2)), (B-A))
    
    K -= A - 1
    ans = A
    ans += int(math.floor(K / 2)) * (B-A)
    ans += K % 2

    return ans


def main():
    # N = read_int()
    K, A, B = read_int_n()
    # A = [read_int_n() for _ in range(N)]
    print(slv(K, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7612
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    960 Hours of Solitude
    Quarantine_Day : 40
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<ll>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 200005

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

    ll n; cin>>n;
    vl v(n);
    REP(i, n) cin>>v[i];
    GSORT(v);
    ll a(0), b(0);
    REP(i, n){
        if(i & 1) b += v[i];
        else a += v[i];
    }
    cout<<abs(a - b)<<"\n";

    return 0;
}


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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")

long long combination(long long n, long long m){
	if(m == 0) return 1;
	if(m == 1) return n;
	// m = m>n-m?n-m:m;
	return combination(n,m-1)*(n-m+1)/m;
}

signed main(){
	cout<<fixed<<setprecision(7);
	
	int n, hoge[200] = {}, f = 0, t = 0, x = 0, o = 0, g = 0;
	
	cin>>n;
	
	for(int i = 1; i <= n; i++){
		int x = i;
		for(int j = 2; j * j <= i; j++){
			if(x%j == 0){//cout<<i<<" XX "<<j<<endl;
				while(x%j==0){
					x/=j;
					hoge[j]++;
				}
			}
		}
		if(x!=1)hoge[x]++;
	}
	
	// for(int i = 0; i <= 15; i++)cout<<i<<" "<<hoge[i]<<endl;
	
	for(int i = 0; i <= 100; i++){
		
		// if(hoge[i] >= 10) f += 2,t += 3;
		// else 
			// if(hoge[i] >= 8) f += 2, t += 2;
		// else 
			// if(hoge[i] >= 6) f+= 1, t += 2;
		// else 
		if(hoge[i] >= 74) o++;
		if(hoge[i] >= 24) x++;
		if(hoge[i] >= 14) g++;
		if(hoge[i] >= 4)f++,t++;
		else if(hoge[i] >= 2)t++;
	}
	
	// cout<<t<<" "<<f<<endl;
	
	if(f>=2&&t>=3)cout<<combination(f,2)*(t-2)+x*(t-1) + o + g*(f-1)<<endl;
	else cout<<0<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int i;
	cin>>s;
	for(i=0;i<s.size();i++)
		if(s[i]=='?')
			cout<<'D';
		else
			cout<<s[i];
	return 0;
}

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

int main(){
	string a,b;
	getline(cin,a);
	cin >>b;
	a=a+a;
	if(a.find(b)==-1)
	{cout <<"No"<<endl;}
	else{cout <<"Yes"<<endl;}
	return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

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

int main(){
  int n;
  cin >>n;
  vec<int> d(n);
  REP(i,n) cin >>d[i];

  sort(all(d));
  int ans=1;
  REP(i,n-1){
    if(d[i] != d[i+1]) ++ans;
  }

  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int mod = 1e9 + 7;
const int maxN = 23;
const int maxS = (1 << 20) + 7;

inline int pls(int x, int y) {return (x + y) % mod;}
inline int mns(int x, int y) {return pls(x, mod - y);}
inline int mul(int x, int y) {return 1LL * x * y % mod;}
inline void Add(int &x, int y) {x = pls(x, y);}
inline void Mul(int &x, int y) {x = mul(x, y);}
inline void Minus(int &x, int y) {x = mns(x, y);}

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m, K;
int lim[maxN][maxN];
int f[maxN][maxS];

inline int lb(int x) {return x & -x;}

inline int chg(int x, int p) {
	int t = x & ((1 << p) - 1); x >>= p;
	if (lb(x)) x ^= lb(x);
	x ^= 1;
	return x << p | t;
}

int main() {

	n = ri() - 1, m = ri(), K = ri();
	memset(lim, -1, sizeof lim);
	rep (i, 1, K) {
		int x = ri(), y = ri(), z = ri();
		lim[x][y] = z;
	}

	int mask = (1 << n) - 1;
	f[0][0] = 1;
	rep (i, 1, m) {
		rep (j, 1, n) {
			memset(f[i], 0, sizeof f[i]);
			rep (s, 0, mask) if (f[i-1][s]) {
				if (s >> (j-1) & 1) {
					if (lim[i][j] == 0) continue;
					Add(f[i][s], f[i-1][s]);
				}
				else {
					if (lim[i][j] != 1) Add(f[i][s], f[i-1][s]);
					if (lim[i][j] != 0) Add(f[i][chg(s, j-1)], f[i-1][s]);
				}
			}
			rep (s, 0, mask) f[i-1][s] = f[i][s];
		}
	}

	int res = 0;
	rep (s, 0, mask) Add(res, f[m][s]);
	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 88192
#include <bits/stdc++.h>  // ver1.9.7
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a.back()<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  int n;
  cin >> n;
  Vi a(n);
  rep(i,0,n) cin >> a[i];
  
  int now=-5,ct=0,ans = 0,pre;
  Vi L(2),R(2),pL(2),pR(2);
  rep(i,0,n){
    
    pre = now;
    pL = L,pR = R;
    ct = 0;    
    now = a[i];
    L = {1,0},R = {1,0};
    
    if(now-pre == 1) {L=pL;L[0]++;}
    else repreq(j,i-1,0){
      if(a[j] < now) L[ct]++;
      else {
        ct++;
        if(ct==1) L[ct]++;
        else break;
      }
    }
    
    ct = 0;
    if(pre-now == 1) {R=pR;R[0]--;}
    else repeq(j,i+1,n-1){
      if(a[j] < now) R[ct]++;
      else {
        ct++;
        if(ct==1) R[ct]++;
        else break;
      }
    }
    /*Vout(L);
    Vout(R);
    cout << endl;*/
    ans += (L[0]*R[1] + L[1]*R[0])*now;
  }
  
  cout << ans << endl;
  return 0;
}


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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;
typedef vector<string> vs;
typedef complex<int> P;

P d[4] = {
    P(0,1),
    P(0,-1),
    P(1,0),
    P(-1,0)
};

void f(vs& g, int i, int j){
    stack<P> s;
    s.push(P(i,j));
    char init = g[i][j];
    while(s.size()){
        P t = s.top();
        s.pop();

        int x = t.imag();
        int y = t.real();

        if(x<0 || y<0 || x>=g[0].size() || y>=g.size()) continue;
        if(g[y][x]==' ') continue;
        if(g[y][x]!=init) continue;

        g[y][x] = ' ';

        rep(i,4) s.push(t+d[i]);
    }
}

int main(){
    int h,w;
    while(cin>>h>>w, h|w){
        vs g(h);
        rep(i,h) cin>>g[i];

        int ans=0;
        rep(i,h)rep(j,w){
            if(g[i][j]!=' ') ans++;
            f(g,i,j);
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,A[100000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  int B[100000]={0};
  for (int i(0);i<N;i++){
    int x=(A[i]+N-1)/2;
    int y=N-1-x;
    if (x==y) B[x]++;
    else {
      B[min(x,y)]++;
      B[max(x,y)]++;
    }
  }
  ll ans(1);
  // for (int i(0);i<N;i++) cout << B[i] << " ";
  for (int i(0);i<N;i++){
    if (B[i]==0 || (B[i]==1&&i!=N/2)) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i(0);i<(N+1)/2;i++){
    ans*=B[i]; 
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  use_cio();
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll e = c * d / gcd(c, d);
  cin >> a >> b >> c >> d;
  cout << (b - a + 1) - (b / c - (a - 1) / c) - (b / d - (a - 1) / d) +
              (b / e - (a - 1) / e);
}


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

#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define MAXN 1000000000000000000UL

typedef long long ll;
int main(){
    unsigned long long mul = 1;
    int n; cin >> n;
    vector<unsigned long long> v(n); rep(i,n) cin >> v[i];
    rep(i,n){
        if(v[i]==0){ 
            cout << 0 << endl; 
            return 0;
        }
    }
    rep(i,n){
        if(MAXN / mul < v[i]){
            cout << "-1" << endl;
            return 0;
        }else mul = mul * v[i];
    }
    cout << mul << endl;
    return 0;
}

Measured memory_bytes: 4000
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int[][] A = new int[N][2];
		for(int i = 0; i < N; i++) {
			A[i][0] = sc.nextInt();
			A[i][1] = sc.nextInt();
		}
		Arrays.sort(A, (x,y) -> x[0]-y[0]);
		long ans = 0;
		int p = 0;
		PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
		for(int i = 1; i <= M; i++) {
			for(int j = p; j < N; j++) {
				if(A[j][0] <= i)
					pq.offer(A[j][1]);
				else {
					p = j;
					break;
				}
				if(j == N-1)
					p = N;
			}
			if(pq.size() > 0)
				ans += pq.poll();
		}
		System.out.println(ans);
	}

}

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

int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(abs(b-a)<=d && abs(c-b)<=d || abs(c-a)<=d){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, k, num[410], i, j, t, a;
    scanf("%d %d", &n, &k);
    for (i=0; i<n; i++) {
        num[i]=i+1;
    }
    for (i=0; i<k; i++) {
        scanf("%d", &t);
        for (j=0; j<t; j++) {
            scanf("%d", &a);
            num[a-1]=0;
        }
    }
    int cnt=0;
    for (i=0; i<n; i++) {
        if (num[i]!=0) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


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

int main()
{
	int a, b, c=-1;

   cin >> a >> b;

   if(a<10 && a>0 && b<10 && b>0){
		c=a*b;
   }

   cout << c << endl;
 

	return 0;
}

Measured memory_bytes: 256
Ns = input().split()
N = int(Ns[0])
D = float(Ns[1])
counter = 0

for i in range(N):
  line = input().split()
  x = float(line[0])
  y = float(line[1])
  
  if(x*x+y*y <= D*D):
    counter = counter + 1
    #print(x,y)

print(counter)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int n, m;
  cin >> n >> m;
  ll x[3][1005] = {};
  for (int i = 0; i < n; i++) cin >> x[0][i] >> x[1][i] >> x[2][i];
  ll res = 0;
  for (int bit = 0; bit < 8; bit++) {
    ll sum[1005] = {};
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) sum[i] += (bit>>j)&1 ? x[j][i] : -x[j][i];
    }
    sort(sum, sum+n);
    ll t = 0;
    for (int i = n-1; i >= n-m; i--) t += sum[i];
    res = max(res, t);
  }
  dump(res);
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type element struct {
	v    int
	prev *element
	next *element
}

func insert(v int, head *element) {
	// リストの先頭に追加する
	newelem := new(element)
	newelem.v = v
	newelem.prev = head      // 新たな要素のprevがheadを指すようにする
	newelem.next = head.next // 新たな要素のnextが現在のheadの次を指すようにする
	head.next.prev = newelem //
	head.next = newelem      // headのnextが新たな要素を指すようにする
}
func delete(v int, head *element, tail *element) {
	for elem := head; elem.next != nil; elem = elem.next {
		if elem.v == v { // 要素を見つけた
			elem.prev.next = elem.next
			elem.next.prev = elem.prev
			break
		}
	}
}
func deleteFirst(head *element) {
	elem := head.next
	elem.next.prev = head
	head.next = elem.next
}
func deleteLast(tail *element) {
	elem := tail.prev
	elem.prev.next = tail
	tail.prev = elem.prev
}
func showList(head *element, tail *element) {
	var wtr = bufio.NewWriter(os.Stdout)
	for elem := head.next; elem.next != nil; elem = elem.next {
		fmt.Fprint(wtr, elem.v)
		if elem.next != tail {
			fmt.Fprint(wtr, " ")
		}
	}
	fmt.Fprintln(wtr)
	_ = wtr.Flush()
}

type command struct {
	name string
	val  int
}

func main() {
	var head, tail element
	head.v = -1
	head.next = &tail
	head.prev = nil
	tail.v = -1
	tail.next = nil
	tail.prev = &head
	var n int
	fmt.Scan(&n)
	commands := make([]command, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range commands {
		sc.Scan()
		commands[i].name = sc.Text()
		if commands[i].name == "insert" || commands[i].name == "delete" {
			sc.Scan()
			commands[i].val, _ = strconv.Atoi(sc.Text())
		}
	}
	for i := 0; i < n; i++ {
		cmd := commands[i].name
		val := commands[i].val
		switch cmd {
		case "insert":
			insert(val, &head)
		case "delete":
			delete(val, &head, &tail)
		case "deleteFirst":
			deleteFirst(&head)
		case "deleteLast":
			deleteLast(&tail)
		}
	}
	showList(&head, &tail)
}



Measured memory_bytes: 121076
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int vecx[4]={0,1,0,-1};
int vecy[4]={1,0,-1,0};
int Map[101][101]={};
string MAP[101];
  int h,w;
    int cnt=1;
void dfs(int he,int wi){
  for(int i=0;i<4;i++){
    if(he+vecx[i]>=0&&he+vecx[i]<h&&wi+vecy[i]>=0&&wi+vecy[i]<w&&MAP[he][wi]==MAP[he+vecx[i]][wi+vecy[i]]&&Map[he+vecx[i]][wi+vecy[i]]==0){
      Map[he+vecx[i]][wi+vecy[i]]=cnt;
      dfs(he+vecx[i],wi+vecy[i]);
    }
  }
}
int main(){
  while(cin>>h>>w,h+w){
    cnt=1;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	Map[i][j]=0;
    for(int i=0;i<h;i++)
      cin>>MAP[i];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(Map[i][j]==0){
	  //cout<<"!"<<endl;
	  Map[i][j]=cnt;
	  dfs(i,j);
	  cnt++;
	}
      }
    }
    cout<<cnt-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 4104
import java.util.*;

public class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int L = sc.nextInt();
	List<String>list = new ArrayList<String>();
	for ( int i = 0; i < N; i++ ) {
	    String S = sc.next();
	    list.add(S);
	}
	Collections.sort(list);
	StringBuilder sb = new StringBuilder();
	for ( int i = 0; i < list.size(); i++ ) {
	    sb.append(list.get(i));
	}
	String s = sb.toString();
	System.out.println(s);
    }
}


Measured memory_bytes: 24912
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
template<class T> inline bool chmin(T &a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}

int SumDigit(int N){
	int _res = 0;
	while(N > 0){
		_res += (N % 10);
		N /= 10;
	}
	return _res;
}

int main(){
    int N;
    cin >> N;
    int a = 1, b = N - 1;
    int ans = INF;
    for(int i = 1; i < N; i++){
        int res = SumDigit(a) + SumDigit(b);
        chmin(ans, res);
        a++;
        b--;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

dp = [[0] * t for _ in range(n + 1)]

ans = 0
for i, (a, b) in enumerate(ab):
    for j in range(t):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j + a <= t - 1:
            dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b)
        else:
            ans = max(ans, dp[i][j] + b)

print(ans)


Measured memory_bytes: 118488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000000000000007
#define pii 3.14159265358979323846
int main()
{
	    // freopen("in.txt","r",stdin);
	    // freopen("out","w",stdout);
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	    ll t;t=1;
	    // cin >> t;
	    while(t--)
	    {
			ll n; cin >> n;
			
			vector<ll> a(n+1,0);
			rep(i,1,n)
			{
				ll k; cin >>k;
				a[k]++;
			}
           rep(i,0,a.size())
		   if(i==0)continue;
		   else
		   cout<<a[i]<<endl;
		}
}


Measured memory_bytes: 4724