akhauriyash/Code-Regression huggingface dataset:
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int A, B, C, K;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        K = sc.nextInt();
    }

    void solve(PrintWriter out) {
        int ans = Math.min(A, K);
        int k = Math.max(0, K - A);
        k = Math.max(0, k - B);
        out.println(ans - k);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 32648
# problem B

A = []
for i in range(1,4):
    x = map(int,input().split())
    A.append(list(x))

N = int(input())

b = []
for i in range(1,N+1):
    y = int(input())
    b.append(y)

    
for i in A:
    for j in range(0,3):
        i[j] = (i[j] in b)


tate = []
yoko = []
naname = []

for i in range(0,3):
    tate.append(A[0][i]*A[1][i]*A[2][i])
for i in range(0,3):
    yoko.append(A[i][0]*A[i][1]*A[i][2])
    

naname.append(A[0][0]*A[1][1]*A[2][2])
naname.append(A[0][2]*A[1][1]*A[2][0])

ans = sum(tate)+sum(yoko)+sum(naname)
if ans == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 200

int solve(int,int);
int A[MAX],n;

int main(void){
  int B[MAX],i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&B[i]);
    if(solve(0,B[i])) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int solve(int x,int y){
  if(A[x] == y) return 1;
  if(x+1 == n) return 0;
  if(solve(x+1,y-A[x]) || solve(x+1,y)) return 1;
  return 0;

}

Measured memory_bytes: 580
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 18] * N
dp[0] = 0

for i in range(N):
    for j in range(K):
        if i > j:
            cost = abs(h[i] - h[i - j - 1])
            if dp[i - j - 1] + cost < dp[i]:
                dp[i] = dp[i - j - 1] + cost

print(dp[-1])


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

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

int main(){

  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0)break;
    int t[200],h[200],st=0,sh=0;
    rep(i,n){
      cin >> t[i];
      st+=t[i];
    }
    rep(i,m){
      cin >> h[i];
      sh+=h[i];
    }
    int ai=0,aj=0,min=10000000;
    rep(i,n){
      rep(j,m){
	sh+=t[i]; sh-=h[j];
	st+=h[j]; st-=t[i];
	if(st==sh && t[i]+h[j] < min){
	  ai=i; aj=j; 
	  min =  t[i]+h[j];
	}
	sh-=t[i]; sh+=h[j];
	st-=h[j]; st+=t[i];
      }
    }
    if(min == 10000000) cout << "-1\n";
else    cout << t[ai] << " " << h[aj] << endl;
  }
  }

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1000000007;

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

    if(K <= A){
        cout << K << endl;
    }else if(K <= A + B){
        cout << A << endl;
    }else{
        cout << A - (K - (A + B)) << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<string, int> counter;
    while (n--) {
        string s;
        cin >> s;
        counter[s]++;
    }
    cout << "AC" << " x " << counter["AC"] << endl;
    cout << "WA" << " x " << counter["WA"] << endl;
    cout << "TLE" << " x " << counter["TLE"] << endl;
    cout << "RE" << " x " << counter["RE"] << endl;
}


Measured memory_bytes: 3628
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = input_int_list()
    print(max(A) - min(A))
    return


if __name__ == "__main__":
    main()


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

void solve() {
    int a, b, c; cin >> a >> b >> c;
    c -= a;
    if (b >= c && c >= 0) cout << "YES";
    else cout << "NO";
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define vi vector<int>
#define pi pair<int,int>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define ll long long 

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod=1e9+7;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
	int add(int a,int b)
	{
		a+=b;
		if(a>=mod)a-=mod;
		return a;
		}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
		return res;
	}



void solve()
{
int n,m;
cin>>n>>m;
string a[n];
for(int i=0;i<n;i++)
{
	
		cin>>a[i];
		
		
	}
int dp[n][m]={0};
for(int i=0;i<n;i++)for(int j=0;j<m;j++)dp[i][j]=0;
dp[0][0]=1;
for(int i=0;i<n;i++)
{
	for(int j=0;j<m;j++)
	{
		if(i==0&&j==0)continue;
		if(i>0&&a[i][j]=='.')dp[i][j]=add(dp[i][j],dp[i-1][j]);
		if(j>0&&a[i][j]=='.')dp[i][j]=add(dp[i][j],dp[i][j-1]);
		}
	}	
	cout<<dp[n-1][m-1];
}
	
	
int main()
{   ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		}
	
	
	}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vl v(n);
	rep(i,n)cin>>v[i];
	ll ans=0,sum=0;
	rep(i,k)sum+=v[i];
	chmax(ans,sum);
	rep(i,n-k){
		sum+=v[i+k];
		sum-=v[i];
		chmax(ans,sum);
	}
	fcout(8);
	puta(((ans+k))/2.0);
}


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

#define sl1(a)  scanf("%lld",&a)

int main(){
    long long n,ans=0ll;
    sl1(n);
    for (long long  i=1;i<n;i++)  ans+=(n-1)/i;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3792
#include <string>
#include <iostream>
using namespace std;
int main()
{
  string S;
  int n=0;
  for(int i=0;i<4;i++){
    cin>>S[i];
    if(S[i]=='+'){n++;}
    if(S[i]=='-'){n--;}
  }
cout<<n<<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
const ll N= 1e5+7;
ll l, n , r ,t ,k , ans , x , y , a, b, c ,d,sum , cntr, now , xnum;
int arr[N];
vector<ll>v;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    cout << v[n/2] - v[(n/2)-1] <<"\n";
    return 0;
}


Measured memory_bytes: 1400
W,H,N = map(int,raw_input().split())
A = 0
x,y = map(int,raw_input().split())
for i in range(N-1):
	X,Y = map(int,raw_input().split())
	dx,dy = X-x,Y-y
	A += max(abs(dy),abs(dx)) + max(0,min(1,-dx*dy))*min(abs(dy),abs(dx))
	x,y = X,Y
print A

Measured memory_bytes: 4240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Standard_Deviation
{
    class Program
    {
        static void Main(string[] args)
        {
            List<double> result = new List<double>();

            while (true)
            {
                int num = -1;

                num = int.Parse(Console.ReadLine());

                if (num == 0)
                {
                    break;
                }

                string[] input = Console.ReadLine().Split(' ');

                List<int> scores = new List<int>();

                for (int i = 0; i < input.Length; ++i)
                {
                    scores.Add(int.Parse(input[i]));
                }

                int sum = 0;

                foreach (int item in scores)
                {
                    sum += item;
                }

                double avg = (double)sum / num;

                double s = 0;

                foreach (int item in scores)
                {
                    s += Math.Pow(item - avg, 2);                    
                }

                result.Add(Math.Sqrt(s / num));
            }

            foreach (double item in result)
            {
                Console.WriteLine(item);
            }

            
        }
    }
}



Measured memory_bytes: 17904
#include <iostream>

using namespace std;

int main()
{
   int Cats , Unknown , Wanted ;

   cin >> Cats >> Unknown >> Wanted ;

   if(Wanted > Cats + Unknown || Wanted < Cats){ cout << "NO" ;}
   else if (Wanted <= (Cats + Unknown)){cout << "YES";}

    return 0;
}


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

#define ll long long
#define ar array

int n, W, dp[100001];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	fill(dp+1, dp+100001, 1e9+1);
	cin >> n >> W;
	for (int i=0, w, v; i<n; ++i) {
		cin >> w >> v;
		for (int i=100000; i>=v; --i)
			dp[i]=min(dp[i], dp[i-v]+w);
	}
	int ans=0;
	for (int i=1; i<=100000; ++i) if (dp[i]<=W) ans=i;
	cout << ans;
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 4028
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}



ll mp[Max+10];

bool  factor(ll n)
{
    if(n%2==0 && mp[2])return false;

    if(n%2==0)mp[2]=1;

    while(n%2==0)n/=2;


     for(ll i=3; i<=sqrt(n); i+=2)
     {
         if(n%i==0 && mp[i])return false;

         else if(n%i==0)
         {
             mp[i]++;

             while(n%i==0)n/=i;
         }
     }

     if(n>1 && mp[n])return false;

     mp[n]++;

     return true;

}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,q,l,r,ans=0;

     cin>>n;

     ll ara[n+2];

     bool flag=true;

     m=1;

     for(i=0; i<n; i++)
     {
         cin>>ara[i];

       if(i==0)m=ara[i];

       m=__gcd(ara[i],m);


         if(flag)
         {
             flag=factor(ara[i]);
         }



     }

     if(flag)cout<<"pairwise coprime"<<endl;

     else if(m==1)
        cout<<"setwise coprime"<<endl;

     else cout<<"not coprime"<<endl;



}



Measured memory_bytes: 12048
def choose(n, r, mod = 10 ** 9 + 7)
  fact2(n - r + 1, n, mod) \
    * modpow(fact2(1, r, mod), mod - 2, mod) \
    % mod
end

# 分割統治法を使用
def fact2(l, r, mod = 10 ** 9 + 7)
  return 1 if l == 0 || r == 0
  return r if l == r
  return l * r % mod if r - l == 1
  half = (l + r) / 2
  (fact2(l, half, mod) % mod) \
    * (fact2(half + 1, r, mod) \
    % mod) \
    % mod
end

def modpow(n, p, mod = 10 ** 9 + 7)
  res = 1
  while p > 0
    if p & 1 == 1
      res = (res * n) % mod
    end
    n = (n ** 2) % mod
    p >>= 1
  end
  res
end
# require 'pry'
MOD = 10 ** 9 + 7
N, A, B = gets.split.map(&:to_i)
# binding.pry
puts (((modpow(2, N, MOD) + (MOD - 1)) \
  % MOD \
  + (MOD - choose(N, A, MOD))) \
  % MOD \
  + (MOD - choose(N, B, MOD))) \
  % MOD

Measured memory_bytes: 1788
def convolve(a, b):
    def fft(f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2
 
    def ifft(f):
        d = 1
        while d < n:
            v = pow(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2
 
    p, g = 998244353, 3
    n0, n1 = len(a), len(b)
    n = 1 << (max(n0, n1) - 1).bit_length() + 1
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)
    w = pow(g, (p - 1) // n, p)
    invw = pow(w, p-2, p)
    fft(a), fft(b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(a)
    invn = pow(n, p - 2, p)
    return [a[i] * invn % p for i in range(n0 + n1 - 1)]

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print(*convolve(A, B))

Measured memory_bytes: 203012
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
 
int main(){
    int W,H;
    while(cin >> W >> H && W){
        string cmd;
        int x=0,y=0,d=0;
        while(cin >> cmd , cmd != "STOP"){
            if(cmd[0]=='F'){
                int val; cin >> val;
                rep(i,val)x += dx[d] , y += dy[d];
            }else if(cmd[0] == 'B'){
                int val; cin >> val;
                rep(i,val)x += dx[(d+2)%4] , y += dy[(d+2)%4];
            }else if(cmd[0] == 'R'){
                d = (d+1)%4;
            }else if(cmd[0] == 'L'){
                d = (d+3)%4;
            }
            if(x<0)x=0;
            if(x>=W)x = W-1;
            if(y<0)y=0;
            if(y>=H)y = H-1;
        }
        cout << x+1 << " " << y+1 << endl;
    }
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define ld long double
#define iii tuple<int, int, int>


char ss[10][10];

string bin(int n) {

    stack<int> st;

    string s = "";

    while(n) {
        st.push(n%2);
        n/=2;
    }

    while(!st.empty()) {
        s += to_string(st.top());
        st.pop();
    }

    return s;
}


int main() {

    int r, c, x;
    scanf("%d %d %d", &r, &c, &x);

    for(int i=1; i<=r; ++i) {
        for(int j=1; j<=c; ++j) {
            scanf(" %c", &ss[i][j]);
        }
    }

    int ans = 0;

    int row = (1<<r) - 1;
    int col = (1<<c) - 1;

    for(int a=0; a<=row; a++) {
        for(int b=0; b<=col; b++) {

            string s = bin(a);
            string t = bin(b);

            if((int)s.length() < r) {
                while((int)s.length() < r) {
                    s = '0' + s;
                }
            }
            if((int) t.length() < c) {
                while((int) t.length() < c) {
                    t = '0' + t;
                }
            }

            int temp = 0;

            for(int i=1; i<=r; i++) {
                if(s[i-1] == '0') continue;

                for(int j=1; j<=c; j++) {
                    if(t[j-1] == '0') continue;

                    if(ss[i][j] == '#') temp++;
                }
            }

            if(temp == x) {
                ans++;
            }
        }
    }

    printf("%d\n", ans);
}



Measured memory_bytes: 3772
#include <cstdio>
using namespace std;
 
int main()
{
    int i,d;
    while (scanf("%d",&d)!=EOF){
        int sum=0;
        for (i=d;i<=600-d;i+=d) sum+=i*i*d;
        printf("%d\n",sum);
    }
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	string w[7] = {"SUN", "SAT", "FRI", "THU", "WED", "TUE", "MON"};
	int ans;
	for (int i = 0; i < 7; i++) {
		if (s == w[i]) {
			ans = i;
		}
	}
	if (ans == 0) {
		ans = 7;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, m, l = [int(s) for s in input().split()]
A = []
B = []
C = [[0 for i in range(l)] for i in range(n)]

for i in range(n):
    A.append([int(s) for s in input().split()])
for i in range(m):
    B.append([int(s) for s in input().split()])

for i,row in enumerate(C):
    for j in range(len(row)):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]


for row in C:
    print(' '.join([str(i) for i in row]))

Measured memory_bytes: 8916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  string S,ans="No";
  cin>>S;
  if(S[1]=='9'||S[0]=='9')
    ans="Yes";
  cout<<ans;
  }


Measured memory_bytes: 256
n,x,y = [int(n) for n in input().split()]


ans = [0] * (n-1)

for i in range(n-1):
    for j in range(i+1,n):
        a=j-i
        b=abs((y-1)-j)+abs(i-(x-1))+1
        ans[min(a,b)-1]+=1
for i in ans:
	print(i)        


Measured memory_bytes: 3572
n,q=map(int, input().split())
s=input()
lst=[list(map(int, input().split())) for i in range(q)] 
acwa=[0]*(n)
a=0
ac=0
for i in range(n):
  if(s[i]=="A"):
    a=1
  elif(s[i]=="C"):
    if(a==1):
      ac+=1
    a=0
  else:
    a=0
  acwa[i]=ac
for i in lst:
  ans=acwa[i[1]-1]-acwa[max(i[0]-2,0)]
  if(acwa[i[0]-1]!=acwa[max(i[0]-2,0)]):
    ans-=1
  print(ans)


Measured memory_bytes: 30704
#include <stdio.h>
int main(void){
    int a, b, p, m;
    scanf("%d %d", &a, &b);
    p = 1;
    m = 0;
    while (p < b)
    {
        p += (a - 1);
        m += 1;
    }
    printf("%d\n", m);
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n, k int
	var h int
	fmt.Scanf("%d %d", &n, &k)
	out := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h)
		if h >= k {
			out++
		}
	}
	fmt.Println(out)
}


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

using namespace std;

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

  string S;
  cin >> S;
  int count[2] = {0, 0};
  for (auto c: S) count[c-'A']++;
  if (count[0] && count[1]) cout << "Yes" << endl;
  else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int main()
{
	int h, w;
	cin >> h >> w;
	int d[11][11];
	rep(i, 10)rep(j, 10) cin >> d[i][j];
	rep(k, 10)rep(i, 10)rep(j, 10)
	{
		if(d[i][j]>d[i][k]+d[k][j])
		{
			d[i][j]=d[i][k]+d[k][j];	
		}
	}
	int x;
	int ans=0;
	rep(i, h*w)
	{
		cin >> x;
		if(x!=-1) ans+=d[x][1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long x = 1;
        for(long i=1; i<=a; i++) {
            x = (long) (i * x %(Math.pow(10, 9)+7));
        }
        System.out.println(x);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include<functional>

int main()
{
	long long int N = 0, K = 0,  ans = 0;

	std::cin >>N >> K;

	std::vector<long long int> H(N);
	for (long long int i = 0; i < N; i++){
		std::cin >> H[i];
	}

	if (K >= N){
		std::cout << 0 << std::endl;
		return 0;
	}

	std::sort(H.begin(), H.end(), std::greater<int>());
	for (int i = K; i < N; i++)
	{
		ans += H[i];
	}

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

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  str s,t="";
  cin>>s;
  rep(i,SZ(s)){
    if(i+1<SZ(s)&&s[i]=='B'&&s[i+1]=='C')t+='D',i++;
    else t+=s[i];
  }
  int cnt=0,res=0;
  for(auto&c:t){
    if(c=='A')cnt++;
    else if(c=='D')res+=cnt;
    else cnt=0;
  }
  out(res);
  
  
  
  return 0;
}



Measured memory_bytes: 916
// * template

#include <bits/stdc++.h>
#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

template<class T, class U> inline void fill_array(T &e, const U &v) { e = v; }
template<class T, class U, size_t s> inline void fill_array(T (&a)[s], const U &v) {for(auto&e:a)fill_array(e,v);}
template<class T, class U, size_t s> inline void fill_array(array<T, s> &a, const U &v) {for(auto&e:a)fill_array(e,v);}
template<class T, class U> inline void fill_array(vector<T> &a, const U &v) {for(auto&e:a)fill_array(e,v);}

struct range {
	typedef int Int;
	struct iter {
		Int i;
		const Int s;
		iter(const Int &i_, const Int &s_):i(i_), s(s_) {}
		bool operator!=(const iter &r) const { return s > 0 ? i < r.i : i > r.i; }
		const Int &operator*() const { return i; }
		iter &operator++() { i += s; return *this; }
	};
	const Int f, l, s;
	range(const Int &f_, const Int &l_, const Int &s_):f(f_), l(l_), s(s_) {}
	range(const Int &f_, const Int &l_):f(f_), l(l_), s(1) {}
	range(const Int &num):f(0), l(num), s(1) {}
	iter begin() const { return iter(f, s); }
	iter end() const { return iter(l, s); }
};

// *solve

typedef complex<double> point;
#define X real()
#define Y imag()

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	for(int w, h, n; cin >> w >> h >> n && w;) {
		const int n2 = n + n;

		vector<point> strawberries;
		strawberries.reserve(n2);
		for(const int i : range(n2)) {
			int x, y;
			cin >> x >> y;
			strawberries.emplace_back(x, y);
		}

		vector<double> event{0.0, static_cast<double>(h)};
		vector<point> points(strawberries);
		points.emplace_back(w, 0);
		points.emplace_back(w, h);

		for(const int i : range(n2 + 2)) {
			for(const int j : range(i + 1, n2 + 2)) {
				point p1 = points[i];
				point p2 = points[j];

				if(p1.X == p2.X) continue;
				if(p1.X > p2.X) swap(p1, p2);

				const double a = (p2.Y - p1.Y) / (p2.X - p1.X);
				const double b = p1.Y - a * p1.X;
				if(0 <= b && b <= h) event.emplace_back(b);
			}
		}

		const auto calc = [&](const double y) {
			vector<double> vec;
			for(const auto &p : strawberries) {
				vec.emplace_back((p.Y - y) / p.X);
			}
			sort(begin(vec), end(vec));
			const double y1 = max(0.0, min<double>(h, y + vec[n - 1] * w));
			const double y2 = max(0.0, min<double>(h, y + vec[n] * w));
			return y2 - y1;
		};

		double S = 0.0;
		sort(begin(event), end(event));
		for(const int i : range(1, event.size())) {
			const double len = event[i] - event[i - 1];
			S += len * calc(event[i] - len / 2);
		}

		cout << S / (h * h) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1424
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define endl "\n" // interactive problem
#define int long long

const int N = (int)(5e5) + 322;
const int inf = (int)(1e9) + 123;
const int mod = (int)(1e9) + 7;
const double EPS = 1e-9;

int n, a[N];
unsigned long long allxor;

const int LOG_A = 62;

int basis[LOG_A + 1];

void insertVector(int mask) {
    for (int i = LOG_A - 1; i >= 0; i--) {
        if ((mask & 1ll << i) == 0) continue;

        if (!basis[i]) {
            basis[i] = mask;
            return;
        }

        mask ^= basis[i];
    }
}

signed main() {
    cin.tie(0);
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        allxor ^= a[i];
    }
    //cout << allxor << endl;
    int change = 0;
    for(int i = 0; i < LOG_A; ++i) {
        if (!((allxor >> i) & 1ll)) {
            change |= (1ll << i);
        }
    }
    for(int i = 1; i <= n; ++i) {
        a[i] &= change;
        insertVector(a[i]);
    }
    unsigned long long ans = 0;

    for (int i = LOG_A - 1; i >= 0; i--) {
        if (!basis[i]) continue;

        if (ans & 1ll << i) continue;

        ans ^= basis[i];
    }

    cout << ans * 2ll + allxor << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

using namespace std;
int main (){
    int w,h,n;
    cin >> w >> h >> n;
    int x[n],y[n],a[n];

    int left  =0;
    int right =w;
    int top   =h;
    int bottom=0;

    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> a[i];
        if     (a[i]==1) left  =max(left,x[i]);
        else if(a[i]==2) right =min(right,x[i]);
        else if(a[i]==3) bottom=max(bottom,y[i]);
        else             top =min(top,y[i]);
    }
    cout << max(0,(right-left))*max(0,(top-bottom)) << "\n";
}

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

using namespace std;

//aとbを比較して、aに小さいほうを入れる。bのほうが小さければtrueを戻す
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}

//aとbを比較して、aに大きいほうを入れる。bのほうが大きければtrueを戻す
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}

const long long mod = 1e9+7;
int main(void){
  int N,M;
  cin >> N >> M;

  vector<bool> oks(N+1,true);
  for(int i = 0; i < M; i++){
    int temp;
    cin >> temp;
    oks[temp] = false;
  }

  vector<long long> dp(N+1, 0);
  dp[0] = 1;
  for(int now = 0; now < N; now++){
    for(int next = now+1; next <= min(N, now+2); next++){
      if(oks[next]){
        dp[next] += dp[now];
        dp[next] %= mod;
      }
    }
  }
//for(auto i: dp)cout << i << endl;
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int to;
	int cost;
};

typedef pair<int,int> P;
int V;

const int MAX_V = 5000;

vector<edge> G[MAX_V];
vector<edge> G2[MAX_V];
int d[MAX_V];
const int INF = 100000000;

int prevv[MAX_V];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d,d+MAX_V,INF);
  fill(prevv,prevv+MAX_V,-1);
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first)
      continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
	d[e.to] = d[v] + e.cost;
	que.push(P(d[e.to],e.to));
	// ツつサツづ個ノツーツドツづ鳴づ個催短ツ仰猟猟」ツ経ツ路ツづーツ記ツ録ツつオツづつィツつュ
	prevv[e.to] = v;
      }
    }
  }
}
void dijkstra2(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d,d+MAX_V,INF);
  fill(prevv,prevv+MAX_V,-1);
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first)
      continue;
    for(int i = 0; i < G2[v].size(); i++){
      edge e = G2[v][i];
      if(d[e.to] > d[v] + e.cost){
	d[e.to] = d[v] + e.cost;
	que.push(P(d[e.to],e.to));
	// ツつサツづ個ノツーツドツづ鳴づ個催短ツ仰猟猟」ツ経ツ路ツづーツ記ツ録ツつオツづつィツつュ
	prevv[e.to] = v;
      }
    }
  }
}

int main(){

	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0)){
		for(int i = 0; i < n; i++){
			int from,to,money,time;
			cin>>from>>to>>money>>time;
			edge e;
			e.to=to;
			e.cost=money;
			G[from].push_back(e);
			e.to=from;
			G[to].push_back(e);

			e.cost=time;
			G2[to].push_back(e);
			e.to=to;
			G2[from].push_back(e);

		}
		int k;
		cin>>k;
		for(int i = 0; i < k; i++){
			int s,g,r;
			cin>>s>>g>>r;
			if(r==0){
				dijkstra(s);
				cout<<d[g]<<endl;
			}
			else{
				dijkstra2(s);
				cout<<d[g]<<endl;
			}
		}
		for(int i = 0; i < MAX_V; i++){
			G[i].clear();
			G2[i].clear();
		}
	}


	return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    for ( int i = 0; i < N; i++ ) {
        if ( s.substr(i) == t.substr(0, N-i)) return N + i;
    }
    return 2*N;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def reachable(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, None)):
        for j in range(n):
            if dp[i][j] == True:
                dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i != -1:
        x -= i
        i += 1
    else:
        i = len(s)
        x -= i

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s + 'T', i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 != 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1

    if reachable(xsteps, abs(x)) == True and reachable(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 65780
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = 0;
    'outer: for i in 1..s.len() / 2 {
        for j in 0..i {
            if s[j] != s[j + i] {
                continue 'outer;
            }
        }
        ans = i
    }
    println!("{}", ans * 2);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	long H[110000];
	int s = 0;
	cin >> H[0];
	for (int i = 1; i < N; i++) {
		cin >> H[i];
		if (H[i - 1] < H[i]) {
			H[i]--;
			continue;
		}
		if (H[i - 1] > H[i]) {
			s = 1;
			break;
		}
	}
	if (s == 1)cout << "No";
	else cout << "Yes";

}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 100005

int main(void){
 	ll n,k;
 	cin>>n>>k;
	if(k%2 == 1){
 		ll nya = n/k;
 		cout<<nya*nya*nya<<endl;
 	}else{
  		ll nya = n/k;
  		ll nyb = (n+k/2)/k;
 		cout<<nya*nya*nya + nyb*nyb*nyb<<endl;	
 	}

	return 0;
}

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

int main()
{
	int a,b,c;
	char op;
	while(1)
	{
		scanf("%d %c %d", &a, &op, &b);
		if (op== 63 )
		break;
		else if (op == 43)
		c=a+b;
		else if (op == 45)
		c=a-b;
		else if (op == 42)
		c=a*b;
		else if (op == 47)
		c=a/b;
		printf("%d\n", c);
	}

	return 0;
}


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

int H,W;
vector<vector<int> > field;
void dfs(int h,int w){
    field[h][w]=0;
    for(int dh=-1;dh<=1;++dh){
        for(int dw=-1;dw<=1;dw++){
            int nh=h+dh,nw=w+dw;
            if(nh<0 || nh>=H || nw<0 || nw>=W)continue;
            if(field[nh][nw]==0)continue;
            dfs(nh,nw);
        }
    }
}

int main(){
    while(cin>>W>>H){
        if(H==0 || W==0)break;
        field.assign(H,vector<int>(W,0));
        for(int h=0;h<H;h++)for(int w=0;w<W;w++)cin>>field[h][w];
        int count=0;
        for(int h=0;h<H;h++){
            for(int w=0;w<W;w++){
                if(field[h][w]==0)continue;
                dfs(h,w);
                ++count;
            }
            
        }
        cout<<count<<endl;
    }
}


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

 
int main() {
    int n;
    cin>>n;
    deque<int> q;
    //nが偶数の時
    if(n%2==0){
        rep(i,n/2){
            int a,b;
            cin>>a>>b;
            q.push_back(a);
            q.push_front(b);
        }
        rep(i,n)cout<<q[i]<<" ";
    }else{//nが奇数の時
        int a0;
        cin>>a0;
        q.push_back(a0);
        rep(i,n/2){
            int a,b;
            cin>>a>>b;
            q.push_back(a);
            q.push_front(b);
        }
        rep(i,n)cout<<q[i]<<" ";
    }   
}

Measured memory_bytes: 3072
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

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



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

int main(){
    string a,b;
    cin >> a >> b;
    
    ll n = a.size();
    ll m = b.size();
    
    if(n>m) cout << "GREATER";
    else if (n<m) cout << "LESS";
    
    if(n==m){
        
        if(a==b){
            cout << "EQUAL";
            return 0;
        }
        
        for(int i = 0; i < n; i++){
            if(a[i]-'0'> b[i]-'0'){
                cout << "GREATER";
                return 0;
            }
            else if(a[i]-'0'<b[i]-'0'){
                cout << "LESS";
                return 0;
            }
        }
    }
}


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

int main() {
	int a[6],l=1,k;
	for(int i=1;i<=5;i++) {
		cin >> a[i];

	}
	cin >> k;
            for(int i=1;i<=5;i++) {
                for(int j=i+1;j<=5;j++) {
                if(abs(a[i]-a[j]) <= k) continue;
                else {cout << ":(" << endl; return 0;}
                }
            }
            cout << "Yay!" << endl;

}


Measured memory_bytes: 256
N,M = map(int,input().split())
lst = list(map(int,input().split()))
def wake(n,m,li):
    li2 = []
    li.sort()
    for i in range(m-1):
        cur = li[i+1]-li[i]
        li2.append([cur,i])
    li2.sort(key=lambda x: x[0],reverse = True)
    li3 = [x[0] for x in li2[n-1:]]
    return sum(li3)
if N >= M:
    ans = 0
else:
    ans = wake(N,M,lst)
print(ans)

Measured memory_bytes: 21584
#include "bits/stdc++.h"
using namespace std;

int main(){

    char ch1,ch2;
    cin >> ch1 >> ch2;
    
    swap(ch1,ch2);
    if(ch2 == 'D'){
        
        if(ch1 == 'H'){
            
            cout << 'D';
        }
        else{
            
            cout << 'H';
        }
    }
    else{
        
        cout << ch1;
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> v(N);
  rep(i,K){
    int d;
    cin >> d;
    rep(j, d){
      int A;
      cin >> A;
      v.at(A-1) = true;
    }
  }
  int num = 0;
  rep(i, N){
    if(!v.at(i)) num++;
  }
  cout << num << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        int x;
        cin >> x;
        A.at(i) = x - i - 1;
    }
    sort(A.begin(), A.end());
    
    int b = A.at(N / 2);
    int64_t ans = 0;
    for (int i = 0; i < N; i++){
        ans += abs(b - A.at(i));
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;

class Fenwick {
private:
  vector <long long> f;
public:
  void init(int n) {
    f.assign(n, 0);
  }
  void update(int pos, int delta) {
    for (; pos < sz(f); pos = (pos | (pos + 1))) {
      f[pos] += delta;
    }
  }
  long long sum(int pos) {
    long long res = 0;
    for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
      res += f[pos];
    }
    return res;
  }
  long long sum(int l, int r) {
    return sum(r) - sum(l - 1);
  }
};

int n, m, qn;
vector <int> t[MAXN];
vector < pair<int, int> > q[MAXN];
int ans[MAXN];
Fenwick f;

int main() { 

  scanf("%d %d %d", &n, &m, &qn);
  f.init(n);

  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--; r--;
    t[l].push_back(r);
    f.update(r, 1);
  }

  for (int i = 0; i < qn; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--; r--;
    q[l].push_back({r, i});
  }

  for (int i = 0; i < n; i++) {
    if (i > 0) {
      for (int r : t[i - 1]) {
        f.update(r, -1);
      }
    }
    for (auto p : q[i]) {
      ans[p.second] = f.sum(i, p.first);
    }
  }

  for (int i = 0; i < qn; i++) {
    printf("%d\n", ans[i]);
  }

  return 0;
}


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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();


        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        String ret = "";

        for(int i = 0; i < n; ++i){
            ret += s[i];
            ret += t[i];

        }


        System.out.println(ret);
        // write your code here
    }
}


Measured memory_bytes: 23124