akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;
int		cnt;

int		main(void)
{
	int		S,W;
	cin >> S >> W;
	cout << (W >= S ? "unsafe" : "safe") << endl;
}


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

bool pairCompare(const pair<long long int, long long int> &p1, const pair<long long int, long long int> &p2)
{
    return p1.second > p2.second;
}

int main()
{
    long long int n, m;
    vector<long long int> a;
    vector<pair<long long int, long long int>> vp;
    cin >> n >> m;
    a.resize(n);
    vp.resize(m);
    for (long long int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    std::sort(a.begin(), a.end());
    for (long long int i = 0; i < m; i++)
    {
        cin >> vp[i].first >> vp[i].second;
    }
    std::sort(vp.begin(), vp.end(), pairCompare);
    /*
    for (long long int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
    for (long long int i = 0; i < m; i++)
    {
        cout << vp[i].first << " " << vp[i].second << endl;
    }
    */
    long long int c = 0, sum = 0;
    for (long long int i = 0; i < n && c < m; c++)
    {
        if (a[i] >= vp[c].second)
            break;
        for (; vp[c].first > 0; i++, vp[c].first--)
        {
            if (a[i] < vp[c].second)
                a[i] = vp[c].second;
            else
                break;
        }
    }
    for (long long int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    A, B, C, X, Y = map(int, input().split())
    answer = float("inf")
    for c in range(10 ** 5 + 1):
        a = X - c
        b = Y - c
        money = c * C * 2
        a = A * max(a, 0)
        b = B * max(b, 0)
        if answer > money + a + b:
            answer = money + a + b
    print(answer)


if __name__ == "__main__":
    main()


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

p = 10 ** 9 + 7

dx = 1
d0 = 0
d9 = 0
da = 0
for i in range(N):
    nx = dx * 8
    n0 = d0 * 9 + dx
    n9 = d9 * 9 + dx
    na = da * 10 + d0 + d9

    dx = nx % p
    d0 = n0 % p
    d9 = n9 % p
    da = na % p

print(da)


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


int main(){
	  int H,W;
	  cin >> H >> W;
	  int m[H+1][W+1];
	  for(int i=1; i<=H; i++)
			for(int j=1; j<=W; j++)
				  cin >> m[i][j];

	  int dp[H+1][W+1]={};

	  for(int i=1; i<=H; i++){
			for(int j=1; j<=W; j++){
				  if(m[i][j] == 1) dp[i][j] = 0;
			 	  else dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1])) + 1;
			}
	  }
	  
	  int ans = 0;
	  for(int i=1; i<=H; i++)
			for(int j=1; j<=W; j++)
				  ans = max(ans,dp[i][j]);
	  cout << ans*ans << endl;
	  
}

Measured memory_bytes: 18432
#include<cstdio>
#include<algorithm>
using namespace std;
 
int dp[10001];
int N,W;
int main() {
    scanf("%d%d",&N,&W);
 
    for(int i = 0;i < N;i++) {
        int v,w;
        scanf("%d%d",&v,&w);
        for(int j = w;j <= W;j++) {
            dp[j] = max(dp[j],dp[j - w] + v);
        }
    }
    printf("%d\n",dp[W]);
    return 0;
}


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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  map<char, int> cnt;
  string w;
  std::cin >> w;
  for (auto &c : w) {
    cnt[c]++;
  }
  bool ok = true;
  for (auto &p : cnt)
    if (p.se & 1)
      ok = false;
  if (ok)
    std::cout << "Yes"
              << "\n";
  else
    std::cout << "No"
              << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	ll n;
	ll sqn;
	ll a,b;
	ll ans=9999999;
	ll i=2;
	ll keta;
	a=1;
	b=1;
	
	cin>>n;
	sqn=sqrt(n);
	while(i<=sqn)
	{
		if(n%i==0)
		{
			a=i;
			b=n/i;
			keta=max((ll)log10(a),(ll)log10(b))+1;
			if(keta<ans)
				ans=keta;
		}
		i++;
	}
	if(ans==9999999)
	{
		a=n;
		b=1;
		ans = (ll)log10(a)+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int dayOfMonth[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	int i;
	int m, d, ans;
	while(1)
	{
		scanf("%d %d",&m, &d);
		if(m==0)break;

		ans = 4; // Thursday
		for(i=0; i<m-1; i++)
			ans = (ans+dayOfMonth[i])%7;
		ans = (ans+d-1)%7;

		switch(ans)
		{
		case 0: printf("Sunday");    break;
		case 1: printf("Monday");    break;
		case 2: printf("Tuesday");   break;
		case 3: printf("Wednesday"); break;
		case 4: printf("Thursday");  break;
		case 5: printf("Friday");    break;
		case 6: printf("Saturday");  break;
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int N;
    cin>>N;

    double ans;
    if (N % 2 == 0) ans = 1.0 / 2;
    else ans = (double)(N / 2 + 1) / N;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int m = ni();

    int[] h = na(n);

    boolean[] good = new boolean[n];
    Arrays.fill(good, true);
    for (int i = 0; i < m; i++) {
      int from = ni() - 1;
      int to = ni() - 1;

      if (h[from] >= h[to]) {
        good[to] = false;
      }
      if (h[from] <= h[to]) {
        good[from] = false;
      }
    }

    int cnt = 0;
    for (boolean b : good) {
      if (b)
        cnt++;
    }
    System.out.println(cnt);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

using namespace std;

struct data {
	long long sum;
	long long cos;
	long long dis;
};

int main(void) {
	int n;
	cin >> n;
	vector<data> v(2,{0,0,0});
	for (int i = 0; i < n; ++i) {
		long long a;
		cin >> a;
		v[0].sum += a;
		v[1].sum += a;
		for (int j = 0; j < 2; ++j) {
			v[j].sum += v[j].dis;
			v[j].dis = 0;
			if (v[j].sum == 0) {
				++v[j].cos;
				if (i%2 == j) {
					++v[j].dis;
				}
				else {
					--v[j].dis;
				}
			}
			else if ((i%2 == j) && (v[j].sum < 0)) {
				v[j].cos += -v[j].sum+1;
				v[j].dis += -v[j].sum+1;
			}
			else if ((i%2 != j) && (v[j].sum > 0)) {
				v[j].cos += v[j].sum+1;
				v[j].dis -= v[j].sum+1;
			}
		}
	}
	cout << min(v[0].cos,v[1].cos) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define is(s) freopen((const char*)(s),"r",stdin)
#define os(s) freopen((const char*)(s),"w",stdout)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define x first
#define y second

using namespace std;
int n,a;
pair<int,int>maxo[2]={mp(0,0),mp(0,0)},maxe[2]={mp(0,0),mp(0,0)};
vector<pair<int,int> >odd,even;
bool k;
int main()
{
	//is("input.txt");os("output.txt");
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	rep(i,n)
	{
		cin>>a;
		k=1;
		if(i%2==0)
		{
			rep(j,odd.size())
			if(a==odd[j].x)
			{
				odd[j].y++;
				k=0;
				break;
			}
			if(k) odd.pb(mp(a,1));
		}
		else
		{
			rep(j,even.size())
			if(a==even[j].x)
			{
				even[j].y++;
				k=0;
				break;
			}
			if(k) even.pb(mp(a,1));
		}
	}
	rep(i,odd.size())
	if(odd[i].y>maxo[0].y) maxo[0]=odd[i];
	rep(i,even.size())
	if(even[i].y>maxe[0].y) maxe[0]=even[i];
	if(maxo[0]==maxe[0]&&maxo[0].y==n/2)
	{
		cout<<n/2<<endl;
		return 0;
	}
	if(maxo[0].x!=maxe[0].x)
	{
		cout<<n-maxo[0].y-maxe[0].y<<endl;
		return 0;
	}
	rep(i,odd.size())
	if(odd[i].y>maxo[1].y&&odd[i].x!=maxo[0].x) maxo[1]=odd[i];
	rep(i,even.size())
	if(even[i].y>maxe[1].y&&even[i].x!=maxe[0].x) maxe[1]=even[i];
	cout<<n-maxo[0].y-maxe[0].y+min(maxo[0].y-maxo[1].y,maxe[0].y-maxe[1].y)<<endl;
	return 0;}


Measured memory_bytes: 1276
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll M,Q;


ll numofbits5(ll bits)
{
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

ll count(ll bits) {
	if (bits == 0)return 0;
	return count(bits >> 1) + (bits & 1);
}

int main() {
	bitset<64> N(0);
	cin >> Q;
	rep(i, Q) {
		int a;
		cin >> a;
		switch (a)
		{
		case 0:
		{
			ll b;
			cin >> b;
			cout << N.test(b)<<endl;
		}
			break;
		case 1:
		{
			ll b;
			cin >> b;
			N.set(b);
		}
			break;
		case 2:
		{
			ll b;
			cin >> b;
			N.reset(b);
		}
			break;
		case 3:
		{
			ll b;
			cin >> b;
			N.flip(b);
		}
			break;
		case 4:
			if (N.all())cout << 1 << endl;
			else cout << 0 << endl;
			break;
		case 5:
			if (N.any())cout << 1 << endl;
			else cout << 0 << endl;
			break;
		case 6:
			if (N.none())cout << 1 << endl;
			else cout << 0 << endl;
			break;
		case 7:
		{
			cout << N.count() << endl;
			break;
		}
		case 8:
			cout << N.to_ulong() << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
long long a[200005],b[200005];
long long s1,s2;
priority_queue<long long>q;
int cnt;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]<b[i])
		{
			s2+=b[i]-a[i];
			cnt++;
		}
		else if(a[i]>b[i])
		{
			s1+=a[i]-b[i];
			q.push(a[i]-b[i]);
		}
	}
	if(s2>s1)
	{
		cout<<"-1";
		return 0;
	}
	if(s2==0)
	{
		cout<<"0";
		return 0;
	}
	while(!q.empty())
	{
		long long x=q.top();
		q.pop();
		s2-=x;
		cnt++;
		if(s2<=0)
		{
			cout<<cnt;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 4e3 + 7;
int n;
char s[maxx];
int num[maxx];
vector <int> vec[maxx];
LL cnt[maxx];
bool vis[maxx];

LL chk(int a, int b, int c) {
	LL res = 0;
	for(int i = 0; i < vec[a].size(); i++) {
		for(int j = 1; vec[a][i] + 2 * j <= n; j++) {
			if(num[vec[a][i] + j] == b && num[vec[a][i] + 2 * j] == c) res++;
		}
	}
	return res;
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'B') num[i] = 1;
		else if(s[i] == 'G') num[i] = 2;
		else if(s[i] == 'R') num[i] = 3;
	}
	for(int i = 1; i <= n; i++) {
		vec[num[i]].push_back(i);
		cnt[num[i]]++;
	}
	LL ans = cnt[1] * cnt[2] * cnt[3];
	ans -= chk(1, 2, 3);
	ans -= chk(1, 3, 2);
	ans -= chk(2, 1, 3);
	ans -= chk(2, 3, 1);
	ans -= chk(3, 1, 2);
	ans -= chk(3, 2, 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3988
#include<stdio.h>
int min(int x, int y){return x > y ? y : x;}
int main(void){
    int i, j, k;
    int h, w;
    int c[10][10];
    int a[10], tmp;

    scanf("%d%d", &h, &w);
    for(i = 0; i < 10; i++){
        for(j = 0; j < 10; j++){
            scanf("%d", &c[i][j]);
        }
    }

    for(i = 0; i < 10; i++){
        a[i] = 0;
    }

    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            scanf("%d", &tmp);
            if(tmp == -1){
                continue;
            }else{
                a[tmp]++;
            }
        }
    }

    for(k = 0; k < 10; k++){
        for(i = 0; i < 10; i++){
            for(j = 0; j < 10; j++){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int ans = 0;
    for(i = 0; i < 10; i++){
        ans += a[i] * c[i][1];
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

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

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

const int mxN = 204;
V<> g[mxN];
V<> color;

bool dfs(int i, int col) {
    color[i] = col;
    for(auto v : g[i]) {
        if(color[v] != -1) {
            if(col == color[v]) return false;
            continue;
        }
        if(!dfs(v, 1 - col)) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VV<> dis(n, V<>(n, INF));
    rep(i, n) dis[i][i] = 0;
    rep(i, n) rep(j, n) {
        char c;
        cin >> c;
        int a = c - '0';
        if(a == 1) g[i].push_back(j), dis[i][j] = a;
    }
    color.assign(n, -1);
    if(!dfs(0, 0)) {
        cout << -1 << endl;
        return 0;
    }
    rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k]+dis[k][j]);
    int ans = 0;
    rep(i, n) rep(j, n) chmax(ans, dis[i][j]);
    cout << ans + 1 << endl;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, m, tmp1, tmp2;
    sc(n) sc(m)
    int road[n];
    fill(road, road+n, 0);
    for (int i = 0; i < m; i++){
        sc(tmp1) sc(tmp2)
        tmp1--; tmp2--;
        road[tmp1] += 1;
        road[tmp2] += 1;
    }
    for (int i = 0; i < n; i++){
        cout << road[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#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[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

/*int nCr(int n, int r) {
    int ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}*/

signed main() {
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  Vi a(n+1);
  int memo;
  
  rep(i,0,n){
    cin >> memo;
    a[i+1] = a[i] + memo;
  }
  map<int,int> kind;
  rep(i,0,n+1) {
    kind[a[i]]++;
  }
  int ans = 0;
  for (auto p : kind) {
    auto v = p.second;
    ans += v*(v-1)/2;
  }
  cout << ans << endl;
  return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define ll long long int
#define mod 1000000007

ll n;
int x,m;

void solve()
{
    cin>>n>>x>>m;
    
    vector<ll> ans;
    
    ans.push_back(x%m);
    
    ll sum = ans.front();
    
    ll i = 1;
    
    for(;i<m;i++)
    {
        ll x = pow(ans.back(),2);
        ll y = x%m;
        if(y==0)
        {
            cout<<sum;
            return;
        }

        sum += y;
        
        if(i==n-1)
        {
            cout<<sum;
            return;
        }
        
        ans.push_back(y);
        
        //cout<<y<<" ";
    }
    
    ll x = pow(ans.back(),2);
    ll y = x%m;
    if(y==0)
    {
        cout<<sum;
        return;
    }
    
    ll sum1 = 0;
    
    for(i = 0;i<ans.size();i++)
    {
        if(ans[i]==y)
        {
            break;
        }
        else
            sum1 += ans[i];
    }
    
    ll cyclelen = (m-i);
    
    ll cyclefac = floor((n-i)/double(cyclelen));
    
    ll rem =(n-i)%cyclelen;
    
    ll res = sum1 + (sum-sum1)*(cyclefac);
    
    
    for(ll j = i+1;j<i+1+rem;j++)
        res += ans[j-1];
    
    
    cout<<res;
    
    
}

int main()
{
    sync;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}







Measured memory_bytes: 4288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int ans = x < a ? 0 : 10;
		System.out.println(ans);
	}

}


Measured memory_bytes: 21588
#include<iostream>
#include<cstring>
using namespace std;
int pro(int now);
int ino(int now);
int poo(int now);
typedef struct{
  int p,l,r;
}node;
int pr[100001],in[100001],po[100001];
node tree[100001];
int main(){
  cin.tie(0);
  memset(tree,-1,sizeof(tree));
  int n,v,r,l;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>v;
    cin>>r;
    cin>>l;
    tree[v].r=r;
    tree[v].l=l;
    if(tree[v].r!=-1) tree[r].p=v;
    if(tree[v].l!=-1) tree[l].p=v;
  }
  int rt;
  for(int i=0;i<n;++i){
    if(tree[i].p==-1){
    rt=i;
    }
  }
  cout<<"Preorder"<<endl;
  pro(rt);
  cout<<endl;
  cout<<"Inorder"<<endl;
  ino(rt);
  cout<<endl;
  cout<<"Postorder"<<endl;
  poo(rt);
  cout<<endl;
  return 0;
}
int pro(int now){
  if(now==-1)return 0;
  cout<<" "<<now;
  pro(tree[now].r);
  pro(tree[now].l);
}    
int ino(int now){
  if(now==-1) return 0;
  ino(tree[now].r);
  cout<<" "<<now;
  ino(tree[now].l);
}
int poo(int now){
  if(now==-1) return 0;
  poo(tree[now].r);
  poo(tree[now].l);
  cout<<" "<<now;
}

Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl;
#define _GLIBCXX_DEBUG

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

  cout << n*800 - (n/15)*200 << endl;

}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll A, B;

int main() {
    cin >> A >> B;
    ll ans = 0;
    if(A > 12)
        ans = B;
    else if(A >= 6 && A <= 12)
        ans = B / 2;
    cout << ans << "\n";
}

Measured memory_bytes: 256
/*
Just Constraints are different than the other version
rest logic is similar
Constraints:
1<=n<=100
1<=wt<=10^9
1<=w[i]<=wt
1<=v[i]<=10^3
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n , w;
    cin>>n >> w;
    ll wei[n],val[n];
    for(int i =0; i< n;++i) {
    	cin>>wei[i] >> val[i];
    }
    long long  dp[n+1][100005]; //n+1 weight and 1001 value
    for(int i = 0; i <= n; ++i){
    	for(int j = 0; j<= 100000; ++j){
    		if(j == 0 )
    			dp[i][j] = 0;
    		else if( i == 0)
    			dp[i][j] = INT_MAX;
    		else if(val[i-1] > j )
    			dp[i][j] = dp[i-1][j];
    			else //note the difference of using min here and max in other version
    			dp[i][j]  = min(dp[i-1][j] , wei[i-1] + dp[i-1][j - val[i-1]]);
    		}
    	}
    	ll ans =0 ;
    	for(int i = 0; i <= 100000; ++i){
    		if(dp[n][i] <= w && dp[n][i] != INT_MAX)
    		    ans = i;
    	}
    	cout<<ans<<endl;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(100003);
  for(int i=0;i<n;i++){
    cin >> a[i];
    cnt[a[i]]++;
    cnt[a[i]+1]++;
    cnt[a[i]+2]++;
  }
  sort(cnt.begin(),cnt.end(),greater<int>());
  cout << cnt[0] << endl;
}

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

typedef struct {
	char name[12];
	int time, shift;
} process;

int q;

int cmp(const void *a, const void *b) {
	process *pa = (process *)a, *pb = (process *)b;
	return (pa->time - 1) / q - (pb->time - 1) / q;
}

// ???????????????????????????????????¨????????¢?????? O(n) ??§?§£????????????

int main(void) {
	int now = 0, N, i, j, maxGroup = 0, sum = 0;
	process *ps, **begins;
	int *counts;
	scanf("%d %d", &N, &q);
	ps = malloc(sizeof(process) * N);
	begins = calloc(50000/q, sizeof(process *));
	counts = calloc(50000/q, sizeof(int));
	for (i = 0; i < N; i++) {
		scanf("%s %d", ps[i].name, &ps[i].time);
		for (j = 0; j < (ps[i].time - 1) / q; j++)
			counts[j]++;
		ps[i].shift = counts[j];
		counts[j] = 0;
		if (begins[j] == NULL) begins[j] = &ps[i];
		if (j > maxGroup) maxGroup = j;
	}
	for (i = 0; i <= maxGroup; i++) {
		if (i > 0 && begins[i] != NULL) {
			begins[i]->shift += sum;
			sum = 0;
		}
		sum += counts[i];
	}
	qsort(ps, N, sizeof(process), cmp);
	for (i = 0; i < N; i++) {
		now += ps[i].shift * q + (ps[i].time % q == 0 ? q : ps[i].time % q);
		printf("%s %d\n", ps[i].name, now);
	}

}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }

struct Edge {
    int u, v, w;
};

int main() {
    int L; cin >> L;
    vector<Edge> edges;
    int N;
    for(N = 1; (1<<N) <= L; ++N) {}
    for(int i = 0; i < N - 1; ++i) {
        edges.push_back({i + 1, i + 2, (1 << i)});
        edges.push_back({i + 1, i + 2, 0});
    }
    int bit = 0;
    while(L > 0) {
        for(;((1 << bit) & L) == 0; ++bit) {}
        L -= (1 << bit);
        if(L > 0) edges.push_back({bit + 1, N, L});
    }
    cout << N << " " << sz(edges) << "\n";
    for(auto &e : edges) {
        cout << e.u << " " << e.v << " " << e.w << "\n";
    }
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

int main(void){
  int R, G;
  cin >> R >> G;
  cout << 2*G-R << endl;
}


Measured memory_bytes: 256
N,M=map(int,raw_input().split());C=[[0]*-~N for _ in range(N+1)];D=map(list,C);S=[raw_input()for _ in range(N)];r=0
for t in range(M-1):
	for i in range(1,N+1):
		for j in range(1,N+1):C[i][j]=C[i-1][j-1]+int(S[i-1][t]==S[j-1][t+1]);D[i][j]=min(D[i-1][j],D[i][j-1])+C[i][j]
	r+=D[N][N]
print r

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;
    ll tot=0;
    if(c==a) tot+=d-b;
    else{
        tot+=60-b;
        tot+=d;
        tot+=(c-a-1)*60;
    }
    cout<<tot-k<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    // time
    return 0;
}

Measured memory_bytes: 3640
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
li = []
for i in range(N):
    li.append(int(input()))
for i in range(3):
    for j in range(3):
        for k in range(N):
            if li[k] == A[i][j]:
                A[i][j] = -1
flag = 0

for i in range(3):
    if A[0][i] == A[1][i] == A[2][i] == -1:
        flag = 1
    if A[i][0] == A[i][1] == A[i][2] == -1:
        flag = 1
if A[0][0] == A[1][1] == A[2][2] == -1:
    flag = 1
if A[0][2] == A[1][1] == A[2][0] == -1:
    flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    l: f64,
  }

  puts!("{:.15}\n", (l / 3.0).powi(3));
}


Measured memory_bytes: 4352
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))

count = 0

for i in range(N):
    if len(a) <= 1:
        if a[0] == x:
            count += 1
        break
    
    n = min(a)
    if x < n:
        break
    
    x -= n
    a.pop(a.index(n))
    count += 1
    
print(count)

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

int main()
{
    string s;
    cin >> s;
    int a = 0;
    int z = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i=s.size()-1; i>=0; i--){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    cout << z-a+1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=3.141592654;
vector<int> v[100005];
int boom[100005];
int main()
{
    int n,m;
    cin>>n>>m;
    int a,b;
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    //for(int i=0;i<v[6].size();i++) cout<<v[6][i]<<endl;
    queue<int>q;
    q.push(1);
    int k=1;
    while(!q.empty())
    {
        int t=q.front();
        q.pop();
        for(int i=0; i<v[t].size(); i++)
        {
            if(boom[v[t][i]]==0)
            {
                boom[v[t][i]]=t;
                q.push(v[t][i]);
            }

        }
    }
    int i;
    for( i=2;i<=n;i++)
        if(boom[i]==0) break;
    if(i!=n+1)
        cout<<"No"<<endl;
    else
    {
        cout<<"Yes"<<endl;
        for(int j=2;j<=n;j++)
            cout<<boom[j]<<endl;
    }
    return 0;
}




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

using namespace std;

int main()
{
    string N;
    cin >> N;
    int sum = 0;

    for (int i = 0; i < N.length(); i++){
        sum = (sum + (N[i] - '0')) % 9;
    }
    if(sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3752
#include <stdio.h>

int main( void ) {

	int paper[10][10], x, y, size, n = 0, m = 0;

	for ( y = 0; y < 10; y++ ) { for ( x = 0; x < 10; x++ ) { paper[y][x] = 0; } }

	while ( scanf( "%d,%d,%d", &x, &y, &size ) != EOF ) {

		switch ( size ) {

			case 3:
				
				if ( y - 2 >= 0 ) { paper[y-2][x]++; }
				if ( x - 2 >= 0 ) { paper[y][x-2]++; }
				if ( x + 2 < 10 ) { paper[y][x+2]++; }
				if ( y + 2 < 10 ) { paper[y+2][x]++; }

			case 2:
				
				if ( y - 1 >= 0 && x - 1 >= 0 ) { paper[y-1][x-1]++; }
				if ( y - 1 >= 0 && x + 1 < 10 ) { paper[y-1][x+1]++; }
				if ( y + 1 < 10 && x - 1 >= 0 ) { paper[y+1][x-1]++; }
				if ( y + 1 < 10 && x + 1 < 10 ) { paper[y+1][x+1]++; }

			case 1:
				
				if ( y - 1 >= 0 ) { paper[y-1][x]++; }
				if ( x - 1 >= 0 ) { paper[y][x-1]++; }
				if ( x + 1 < 10 ) { paper[y][x+1]++; }
				if ( y + 1 < 10 ) { paper[y+1][x]++; }
				paper[y][x]++;
				break;

		}

	}

	for ( y = 0; y < 10; y++ ) {
		
		for ( x = 0; x < 10; x++ ) {
			
			if ( paper[y][x] == 0 ) { n++; }
			if ( paper[y][x] > m ) { m = paper[y][x]; }
		
		}
	
	}

	printf( "%d\n%d\n", n, m );

	return 0;

}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define rep(i,n,m) for(ll i = (n); i <(m); i++)
#define rrep(i,n,m) for(ll i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

class UnionFind
{
    public:
        const ll n;
        ll num_ok;
        vector<ll> parent;
        vector<ll> rank;
        vector<ll> sizes;
    
    UnionFind(ll _n): n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 0);
        sizes.assign(n, 1);
        num_ok = 0;
    }

    ll find(ll a)
    {
        if (parent[a] == -1) 
            return a;
        else
            return parent[a] = find(parent[a]);
    }

    void unite(ll a, ll b)
    {
        assert (0 <= a and a < n);
        assert (0 <= b and b < n);

        a = find(a);
        b = find(b);

        if (a == b) return;
        num_ok += (ll) sizes[a] * sizes[b];

        if (rank[a] == rank[b])
        {
            parent[a] = b;
            sizes[b] += sizes[a];
            ++rank[b];
        }
        else
        {
            if (rank[a] > rank[b]) swap(a, b);
            parent[a] = b;
            sizes[b] += sizes[a];
        }
    }
    bool is_same(ll a, ll b)
    {
        return find(a) == find(b);
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;

    vector<pii> edges;
    rep(i, 0, m)
    {
        ll a, b;
        cin >> a >> b;
        --a, --b;
        edges.emplace_back(a, b);
    }

    reverse(edges.begin(), edges.end());

    UnionFind ufind(n);
    vector<ll> ans;
    ll total = n * (n - 1) / 2;
    for (auto edge: edges)
    {
        ans.push_back(total - ufind.num_ok);
        ufind.unite(edge.first, edge.second);
    }
    reverse(ans.begin(), ans.end());
    for (auto a : ans)
        cout << a << endl;
    return 0;
}

Measured memory_bytes: 7024
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;


bool done[52][52];
int field[52][52];
int ofs[8][2] = {
  {0, 1},
  {1, 0},
  {-1, 0},
  {0, -1},
  {1, 1},
  {1, -1},
  {-1,-1},
  {-1, 1}
};

void paint(int y, int x)
{
  for (int i = 0; i < 8; ++i) {
    int nx = x + ofs[i][0];
    int ny = y + ofs[i][1];
    if (field[ny][nx] && !done[ny][nx]) {
      done[ny][nx] = true;
      paint(ny, nx);
    }
  }
}

int main() {
  int w, h;
  for(;;) {
    cin >> w >> h;
    if ((w|h) == 0) {
      break;
    }
    memset(field, 0, sizeof(field));
    memset(done, 0, sizeof(done));
    for (int i = 1; i <= h; ++i) {
      for (int j = 1; j <= w; ++j) {
        cin >> field[i][j];
      }
    }
    int cnt = 0;
    for (int i = 1; i <= h; ++i) {
      for (int j = 1; j <= w; ++j) {
        if (field[i][j] && !done[i][j]) {
          paint(i, j);
          ++cnt;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

const int N = 300010;
const int mod = 998244353;

long long mpow(long long a, long long b) {
	long long ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

long long fac[N], inv[N];

long long com(int n, int m) {
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main()
{
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	for (int i = 2; i < N; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mpow(fac[i], mod - 2) % mod;
	}

	long long ans = 0;
	long long n, a, b, k;
	cin >> n >> a >> b >> k;
	for (long long i = 0; i <= n && i * a <= k; i++) {
		if ((k - i * a ) % b) continue;
		long long j = (k - i * a) / b;
	    if (j > n) continue;
		ans = (ans + com(n, i) * com(n, j)) % mod;
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4992
import sys
import math
import random
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
def choice_contest(c, data_day, last, day, contest):
    contest -= 1
    #print(last)
    last = [i + 1 for i in last]
    # 今回開催するコンテストのlastを0にする
    last[contest] = 0
    #print(len(last))
    #print(last)
    # 不満度の計算
    d_satis = sum([last[i] * c[i] for i in range(26)])
    # i日目にcontestを選んだ場合の
    return [int(data_day[contest]) - d_satis, last]

def main():
    d = int(input())
    c = list(map(int,input().split()))
    data = [input().split() for _ in range(d)]
    last = [0] * 26
    ans = 0

    """
    hold_consets = [random.randrange(1, 26) for _ in range(d)]
    for i in range(d):
        s, last = choice_contest(c, data[i], last, i, contest = hold_consets[i])
        ans += s
    ans_hold_contest = hold_consets
    #print(ans)
    for _ in range(3):
        last_t = [0] * 26
        ans_t = 0
        hold_contest = [random.randrange(1, 26) for _ in range(d)]
        for i in range(d):
            s_t, last_t = choice_contest(c, data[i], last_t, i, contest = hold_contest[i])
            ans_t += s_t
        #print(ans_t)
        if ans < ans_t:
            ans = ans_t
            ans_hold_contest = hold_contest
    """
    for i in range(d):
        hold_contest = 1
        for j in range(26):
            last_t = [0] * 26
            if j == 0:
                s, last = choice_contest(c, data[i], last, i, contest = j + 1)
            else:
                s_t, last_t = choice_contest(c, data[i], last, i, contest = j + 1)
                if s < s_t:
                    s = s_t
                    last = last_t
                    hold_contest = j + 1
        print(hold_contest)
    #print(ans)

    return 0

if __name__ == "__main__":
    main()

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

int main(){   
	char a[1000];
	int b,c=0;
	scanf("%1001[^\n]",a);
	for(b=0;b<996;b++){
		if(a[b]=='p' && a[b+1]=='e' && a[b+2]=='a' && a[b+3]=='c' && a[b+4]=='h')c=1;
		if(a[b]=='a' && a[b+1]=='p' && a[b+2]=='p' && a[b+3]=='l' && a[b+4]=='e')c=2;
		if(c==1)a[b]='a',a[b+1]='p',a[b+2]='p',a[b+3]='l',a[b+4]='e',c=0;
		if(c==2)a[b]='p',a[b+1]='e',a[b+2]='a',a[b+3]='c',a[b+4]='h',c=0;
	}
	printf("%s\n",a);
	return 0;
}

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

using namespace std;

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

    long long ans(0);

    for(int i=1;i<=N;++i){
        if(i%3 == 0 or i%5 == 0) continue;
        ans += i;
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,m; cin>>n>>m;
	bool ac[n]; mset(ac,0);
	int p[n]; mset(p,0);
	
	forn(i,0,m){
		int x; cin>>x; x--;
		string v; cin>>v;
		if(v[0]=='A'){
			ac[x]=1;
		}
		else{
			if(!ac[x]) p[x]++;
		}
	}
	
	int cnt=0,pel=0;
	forn(i,0,n){
		if(ac[i]){
			cnt++;
			pel+=p[i];
		}
	}
	
	cout<<cnt<<" "<<pel<<'\n';
	return 0;
}


Measured memory_bytes: 768
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) (int)(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define ld long double
#define inf LONG_MAX
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = 1000000007;
using namespace std;

#define meta __FUNCTION__<<" : "<<__LINE__<<" "
#define tr1(x) cerr<<meta<<"| "<<#x<<" : "<<x<<" | "<<endl
#define tr2(x,y) cerr<<meta<<"| "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<endl
#define tr3(x,y,z) cerr<<meta<<"| "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl
#define tr4(w,x,y,z) cerr<<meta<<"| "<<#w<<" : "<<w<<" | "<<" "<<#x<<" : " <<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl
#define tr5(v,w,x,y,z) cerr<<meta<<"| "<<#v<<" : "<<v<<" | "<<" "<<#w<<" : "<<w<<" | "<<" "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl
#define tr6(u,v,w,x,y,z) cerr<<meta<<#u<<" : "<<u<<" | "<<" "<<#v<<" : "<<v<<" | "<<" "<<#w<<" : "<<w<<" | "<<" "<<#x<<" : "<<x<<" | "<<" "<<#y<<" : "<<y<<" | "<<" "<<#z<<" : "<<z<<" | "<<endl

template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
//Check N size twiceeeeeeeeeeeeeeeeee, and verify it

#define int ll
const int N = 2*1e5 + 10;

int x[N], y[N], n, h[N];
int check(int cx, int cy){
	int H = -1;
	for (int i = 0; i < n; ++i)
	{
		if(h[i] == 0)
			continue;
		int tt = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
		if(H == -1 or tt == H){
			H = tt;
		}else{
			return -1;
		}
	}

	for (int i = 0; i < n; ++i)
	{
		if(h[i] == 0){
			if(H - abs(x[i]-cx) - abs(y[i]-cy) > 0){
				return -1;
			}
		}
	}

	return H;
}

main(){_

	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>x[i]>>y[i]>>h[i];
	}

	for (int cx = 0; cx <= 100; ++cx)
	{
		for (int cy = 0; cy <= 100; ++cy)
		{
			int H = (check(cx, cy));
			if(H != -1){
				cout<<cx<<' '<<cy<<' '<<H;
				return 0;
			}
		}
	}

	assert(0);

	return 0;
}

Measured memory_bytes: 2304
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.nextInt()

  val mod = 1000000007
  def plus(a: Long, b: Long): Long = (a + b) % mod

  if (s < 3) {
    println(0)
  } else {
    val dp = Array.fill(s+1)(0L)
    val dpSum = Array.fill(s+2)(0L)
    dp(0) = 1
    dpSum(0) = 1

    for (i <- 1 until 3) {
      dp(i) = 0
      dpSum(i) = plus(dpSum(i-1), dp(i))
    }

    for (i <- 3 to s) {
      dp(i) = dpSum(i-3)
      dpSum(i) = plus(dpSum(i-1), dp(i))
    }

    println(dp(s))
  }
}


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

int main()
{
    int K,A,B;
    cin >> K;
    cin >> A >> B;
    if(A%K==0||B%K==0){
        cout << "OK" << endl;
    }else{
        int a_d=A/K;
        int b_d=B/K;
        if(b_d-1>=a_d){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }

    
}


Measured memory_bytes: 3632
#include<cstdio>
#include<set>

using namespace std;

set<int> s;

int check(int n){
	while(n > 0){
		if(s.find(n % 10) != s.end()) return 0;
		n /= 10;
	}
	return 1;
}

int main(){
	int n, k; scanf("%d %d", &n, &k);
	for(int i = 0; i < k; i++){
		int d; scanf("%d", &d);
		s.insert(d);
	}
	for(; !check(n); n++);
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 256