akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int a;
    cin >> a;
    cout << 3 * a * a << endl;
    return 0;
}


Measured memory_bytes: 256
#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 rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;

//Union-Find tree
struct UnionFind
{
	vector<ll> par;
	vector<ll> rank;
	vector<ll> siz;

	UnionFind(ll n) : par(n), rank(n), siz(n)
	{
		for (ll i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			siz[i] = 1;
		}
	}
	ll root(ll x)
	{
		if (par[x] == x) return x;
		else return par[x] = root(par[x]);
	}
	ll size(ll x)
	{
		return siz[root(x)];
	}
	void unite(ll x, ll y)
	{
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry)return;
		if (rank[rx] < rank[ry])swap(rx, ry);
		par[ry] = rx;
		siz[rx] += siz[ry];
		if (rank[rx] == rank[ry])rank[rx]++;
	}
	bool same(ll x, ll y)
	{
		return root(x) == root(y);
	}
};

void solve()
{
	int n, m, k; cin >> n >> m >> k;
	vector<int> friends(n, 0);
	vector<vector<int>> block(n);
	UnionFind uf(n);
	rep(i, m) 
	{
		int a, b; cin >> a >> b;
		a--;b--;
		friends[a]++;
		friends[b]++;
		uf.unite(a, b);
	}
	rep(i, k) 
	{
		int c, d; cin >> c >> d;
		c--;d--;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	rep(i, n)
	{
		int ans = uf.size(i)-friends[i]-1;
		for(auto e : block[i])
		{
			if(uf.same(i,e))ans--;
		}
		cout << ans << " ";
	}
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> s;
  map<string, int> mp;
  rep(i, n) {
    string a;
    cin >> a;
    s.push_back(a);
  }
  rep(i, n) mp[s[i]] = 0;
  rep(i, n) mp[s[i]]++;
  int k = 0;
  for(auto m : mp) {
    k = max(k, m.second);
  }
  sort(all(s));
  int p, q;
  p = q = 0;
  while (q < n) {
    while(q < n && s[p] == s[q]) q++;
    if(k == (q - p)) {
      out(s[p]);
    }
    p = q;
  }
  return 0;
}



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

using namespace std;

int main(int argc, char *argv[]) {
  string s;
  cin >> s;
  map<int, int> mp = {{0, 0}};
  int now = 0, ans = 0;
  for (auto c : s) {
    now ^= (1 << (c - 'a'));
    int x = 1e9;
    if (mp.count(now)) {
      x = mp[now] + 1;
    }
    for (int i = 0; i < 26; i++) {
      int t = (now ^ (1 << i));
      if (mp.count(t)) {
        x = min(x, mp[t] + 1);
      }
    }
    if (mp.count(now)) mp[now] = min(mp[now], x);
    else mp[now] = x;
    ans = x;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 184467440737095516;

ll n, m, x, y, dp[100005];
bool visited[100005];
vector<vector<ll> > v;
vector<ll> hub;

void dfs(ll a){
	visited[a] = 1;
	for (ll i = 0; i < v[a].size(); i++){
		dp[v[a][i]] = max(dp[v[a][i]], dp[a] + 1);
		hub[v[a][i]]--;
		if (hub[v[a][i]] == 0){
			dfs(v[a][i]);
		}
	}
}

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

	cin >> n >> m;
	v.resize(n + 1);
	hub.resize(n + 1, 0);
	while(m--){
		cin >> x >> y;
		v[x].push_back(y);
		hub[y]++;
	} 

	for (ll i = 1; i <= n; i++){
		if (!visited[i] && hub[i] == 0){
			dfs(i);
		}
	}

	ll maxi = 0;
	for (ll i = 1; i <= n; i++){
		maxi = max(maxi, dp[i]);
	}
	cout << maxi << '\n';
}
  

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

int main() {
	// your code
	string s;
	cin >> s;
	if(s.size() == 2){
		cout << s << endl;
		return 0;
	}else{
		cout << s[2] << s[1] << s[0] << endl;
	}
	
	return 0;
}

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

const int maxn = 2e5 + 3;
int n, m;
char a[maxn], b[maxn];

void addEdge(int u, int v) {
	if(u > v)
		std::swap(u, v);
	if(u == 1)
		a[v] = 1;
	if(v == n)
		b[u] = 1;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0, u, v; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addEdge(u, v);
	}
	for(int i = 1; i <= n; ++i)
	if(a[i] && b[i]) {
		puts("POSSIBLE");
		return 0;
	}
	puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)

vector<int> x, y, order;
double solve(int now, int next){
    double tx = x[next] - x[now];
    double ty = y[next] - y[now];
    return sqrt((double) tx*tx + ty*ty);
}

int main(){
    int n, cnt = 1; sc(n);
    double ans = 0.0;
    x.resize(n,0), y.resize(n,0);
    rep(i, 0, n) sc(x[i]), sc(y[i]);
    rep(i, 0, n) order.push_back(i);
    rep(i, 0, n-1) ans += solve(order[i], order[i+1]);
    while (next_permutation(order.begin(), order.end())){
        rep(i, 0, n-1) ans += solve(order[i], order[i+1]);
        cnt++;
    }
    cout << fixed << setprecision(15) << ans / cnt << endl;
    return 0;
}

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

int main(){
    int i;
    int a_hp, a_atk, t_hp, t_atk;

    cin >> t_hp >> t_atk >> a_hp >> a_atk;

    
    for(i = 0; ; i++){
        if(i%2 == 0){
            a_hp -= t_atk;
        }else{
            t_hp -= a_atk;
        }

        if(a_hp <= 0 || t_hp <= 0) break;
        
    }
    
    if(i%2 != 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
# 2019-11-26 17:11:55(JST)
import sys
from string import ascii_lowercase as alph
ind_alph = dict((char, ind) for ind, char in enumerate(alph))

def main():
    s, k = sys.stdin.read().split()
    s = list(s)
    k = int(k)
    n = len(s)

    i = 0
    while k:
        diff = (26 - ind_alph[s[i]]) % 26
        if diff <= k:
            s[i] = 'a'
            k -= diff
        if i == n - 1 and k:
                s[i] = alph[(ind_alph[s[i]] + k) % 26]
                k = 0
        i += 1

    print(''.join(s))

if __name__ == '__main__':
    main()


Measured memory_bytes: 4660
arr = [0,0,0,0]
lis = ["AC","WA","TLE","RE"]
for _ in range(int(input())):
  s = input()
  if s == "AC": arr[0] += 1
  elif s == "WA": arr[1] += 1
  elif s == "TLE": arr[2] += 1
  else: arr[3] += 1
for i in range(4):
  print(lis[i],"x",arr[i])

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

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

  int answer = 0;
  int plugs = 1;
  while (plugs < B) {
    plugs--;
    plugs += A;
    
    answer++;
  }

  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for ac in range(a + 1):
    for bc in range(b + 1):
        for cc in range(c + 1):
            if ac * 500 + bc * 100 + cc * 50 == x:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define NUM 100000

typedef struct pp{
    char name[100];
    int t;
} P;

void enqueue(P);
P dequeue(void);
void initialize(void);
int isEmpty(void);
int isFull(void);

int n,head = 0,tail = 0;
P Q[NUM];

int main()
{
    int q,total = 0;
    int i;
    P u;
    initialize();
    scanf("%d %d",&n,&q);
    
    for(i = 0;i < n;i++){
        scanf("%s %d",u.name,&u.t);
        enqueue(u);
    }
  
    while(isEmpty() != 1){
        u = dequeue();
        if(u.t > q){
            total += q;
            u.t -= q;
            enqueue(u);
        }
        else{
            total += u.t;
            printf("%s %d\n",u.name,total);
        }
    }
    return 0;
}

void initialize(void)
{
    head = tail = 0;
}

int isEmpty(void)
{
    return head == tail;
}

int isFull(void)
{
    return head == (tail+1) % (n+1);
}

void enqueue(P x)
{
    if(isFull()){
        printf("overflow\n");
        exit(1);
    }
    Q[tail] = x;
    if(tail == n) tail = 0;
    else tail++;
}

P dequeue(void)
{
    P x;
    if(isEmpty()){
        printf("underflow\n");
        exit(2);
    }
    x = Q[head];
    if(head+1 == n+1) head = 0;
    else head++;
    return x;
}



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

int main(){
    int n,m;
    cin >> n;
    set<int> st;
    cin >> m;
    map<int,int> mp;
    for(int i = 0; i < m; i++){
        int p;
        cin >> p;
        string s;
        cin >> s;
        if(s == "AC") st.insert(p);
        else {
            auto itr = st.find(p);
            if(itr == st.end()) mp[p]++;
        }
    }
    int pena = 0;
    for(auto p:st){
        pena += mp[p];
    }
    cout << st.size() << " " << pena << endl;
    return 0;
}

Measured memory_bytes: 12916
s = list(raw_input())
flag1 = True
flag2 = True
for i in range(len(s)):
	if s[i] == 'A' and flag1:
		startIndex = i
		flag1 = False
	if s[len(s) - i - 1] == 'Z' and flag2:
		endIndex = len(s) - i
		flag2 = False
	if not flag1 and not flag2:
		break

print endIndex - startIndex

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

int main () {
  int x, y;
  cin >> x >> y;
  if (y % 2 == 0) {
    if (y > 2 * x && y < 4 * x) cout << "Yes" << endl;
    else if (y == 2 * x || y == 4 * x) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  
}
  


Measured memory_bytes: 3636
import subprocess
import sys

code = r"""#include <iostream>
using namespace std;

int main() {
  int n; cin >> n;
  int need = (n + 1000 - 1) / 1000;
  cout << need * 1000 - n << '\n';
  
  return 0;
}
"""

with open("main.cc", "w") as f:
	f.write(code)
    
subprocess.Popen(['g++', '-std=c++2a', '-O2', "main.cc"]).communicate()
subprocess.Popen(['./a.out'], stdin=sys.stdin, stdout=sys.stdout).communicate()

Measured memory_bytes: 66364
// 1_abc140_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll gcd(ll a, ll b)
{
    if (b==0) return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    return a / gcd(a,b) * b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    ll ans = 1;
    rep(i,n)
    {
        ll input_num;
        cin >> input_num;
        ans = lcm(ans, input_num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){

	int h1, m1;
	int h2, m2;

	int k;
	cin >> h1 >> m1 >> h2 >> m2 >> k ;


	int ans;
	//4h2 - 22h1 = 
	if(h1 > h2){
		ans = 24 - h1 + h2;
	}else{
		ans = h2 - h1;
	}
	ans *= 60;
	if(m2 > m1){
		ans += m2 - m1;
	}else{
		//12 50 - 13 10
		ans -= 60;
		ans += 60 - m1 + m2; 
	}
	
	ans -= k;

	cout << ans ;
	
}


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

int main() {

    int n,m;

    cin >> n >> m;

    string a[n],b[m];

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

    for(int i=0; i<m; i++){
        cin >> b[i];
    }

    for(int i=0; i<n-m+1; i++){
        for(int j=0; j<n-m+1; j++){
            bool flag = true;
            for(int k=0; k<m; k++){
                for(int r=0; r<m; r++){
                    if(a[i+k][j+r] != b[k][r]){
                        flag = false;
                    }
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int P, Q, R;

int main()
{
  scanf( "%d%d%d", &P, &Q, &R );

  printf( "%d\n", std::min(P+Q, std::min(Q+R, P+R)));

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main() {
  int a, b, c, k;
  scanf("%d %d %d\n %d", &a, &b, &c, &k);
  int ans = a + b + c;
  int max = (a > b ? (a > c ? a : c) : (b > c ? b : c));
  ans += (max << k) - max;
  printf("%d\n", ans);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  unordered_map<int, int> A;
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A[a]++;
  }
  int ans = 0;
  for (auto a : A) {
    if (a.first < a.second) ans += a.second - a.first;
    else if (a.second < a.first) ans += a.second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4260
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

int main()
{
	int N,M;
	lint A[100010]={};
	vector<pair<lint,int>> bc;


	cin >> N >> M;
	for(int i=0;i<N;i++)
		cin >> A[i];
	for(int i=0;i<M;i++)
	{
		int B;
		lint C;
		cin >> B >> C;
		bc.push_back(make_pair(C,B));
	}

	sort(A,A+N);
	sort(bc.begin(),bc.end(),greater<pair<lint,int>>());

	int index=0;
	lint ans=0;
	for(auto itr=bc.begin();itr!=bc.end() && index<N;++itr)
	{
		for(int i=0;i<itr->second && index<N;i++,index++)
		{
			A[index]=max(A[index],itr->first);
			ans+=A[index];
		}
	}
	for(;index<N;index++)
		ans+=A[index];

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



Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define DEC(i, k) for (int i = (k); i >= 0; --i)
#define FORIT(i, c) for (__tyoeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define SZ(v) (int)((v).size())
#define MEMSET(v, h) memset((v), (h), sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())
#define ALL(c) (c).begin(), (c).end()

int m, n;
double probability[20][20];
double dp[2][(1 << 16) + 10];
double win[2][(1 << 16) + 10][20];

inline int bsf(int x) {
  __asm__("bsf %1, %0;" :"=r"(x) :"r"(x));
  return x;
}

int main() {
  scanf("%d %d", &m, &n);
  MEMSET(probability, 0);
  REP(cat, m) {
    REP(room, n) {
      scanf("%lf", &probability[cat][room]);
    }
  }

  MEMSET(dp, 0);
  MEMSET(win, -1);
  REP(S, 1 << m) {
    dp[n % 2][S] = 1.0;
  }
  REP(S, 1 << m) {
    REP(c, m) {
      win[n % 2][S][c] = 1.0;
    }
  }

  for (int i = n-1; i >= 0; --i) {
    int curr = i % 2;
    int prev = 1 - curr;
    FOR(S, 0, 1 << m) {
      dp[curr][S] = 0.0;
      REP(c, m) {
        if (S & (1 << c)) {
          dp[curr][S] = max(dp[curr][S], win[curr][S^(1<<c)][c]);
        }
      }
      REP(c, m) {
        if (S != 0) {
          win[curr][S][c] = probability[c][i] * win[prev][S][c]
            + (1.0 - probability[c][i]) * dp[curr][S];
        } else {
          win[curr][S][c] = probability[c][i] * win[prev][S][c];
        }
      }
    }
  }

  printf("%.9lf\n", dp[0][(1 << m) - 1]);
}

Measured memory_bytes: 0
#include <string>
#include<set>
#include <iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
main()
{
    long long int t,i,l;string x;
        long long c=1,c1=0;
        vector<string>v;vector<string>a;
    scanf("%lld",&t);
   for(i=0;i<t;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());a.push_back(v[0]);
    for(i=1;i<t;i++)
    {
       if(v[i]==v[i-1]){
            continue;
        }
        a.push_back(v[i]);
    }
    
    cout<<a.size()<<endl;
return 0;
    }

Measured memory_bytes: 21956
#include<bits/stdc++.h>
main(){while(true){int x[11000],n,i,j,k,l,m,y[11000],b,c,d,p[11000],w;scanf("%d", &n);
if(n==0){break;}
for(i=0;i<n;i++){scanf("%d", &y[i]);p[i]=x[i]=y[i];}c=0;d=0;m=n;d=m;w=99999;
for(i=0;i<n;i++){for(j=1;j<=3;j++){if(i>=1&&y[i-1]!=j&&y[i+1]!=j){goto z;}
p[i]=x[i]=j;b=1;d=n;
while(true){c=0;
for(k=0;k<m;k++){if(p[k]==p[k+1]){b++;}
else{if(b >= 4){
for(l=k+1;l<m;l++){p[l-b]=p[l];}
d -= b;c++;
for(l=d;l<m;l++){p[l]=0;}
}
b=1;}m=d;}
if(c==0){break;}
else{c=0;}}
w=std::min(w,m);x[i]=y[i];
for(k=0;k<n;k++){p[k]=y[k];}
z:;
}}printf("%d\n",w);}}

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

m = 1000000007
b = [-1,-1,-1]
ans = 1

for i in range(n):
    ans *= b.count(a[i]-1)
    ans%=m
    if ans ==0:
        print(0)
        exit()
    for j in range(3):
        if b[j]==a[i]-1:
            b[j]+=1
            break

print(ans%m)

Measured memory_bytes: 53132
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC081 D - Non-decreasing
// 2020.06.24

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> a(N);
  ll M = -1e9, m = 1e9;
  int Midx = 0, midx = 0;
  REP(i, N){
    cin >> a[i];
    M = max(M, a[i]);
    if(M == a[i]) Midx = i;
    m = min(m, a[i]);
    if(m == a[i]) midx = i;
  }
  if(m >= 0){
    cout << N-1 << endl;
    REP(i, N-1){
      cout << i+1 << " " << i+2 << endl;
    }
    return 0;
  }
  if(M <= 0){
    cout << N-1 << endl;
    REP(i, N-1){
      cout << N-i << " " << N-i-1 << endl;
    }
    return 0;
  }
  if(M >= abs(m)){
    cout << 2*N-1 << endl;
    REP(i, N){
      cout << Midx+1 << " " << i+1 << endl;
    }
    REP(i, N-1){
      cout << i+1 << " " << i+2 << endl;
    }
    return 0;
  }else{
    cout << 2*N-1 << endl;
    REP(i, N){
      cout << midx+1 << " " << i+1 << endl;
    }
    REP(i, N-1){
      cout << N-i << " " << N-i-1 << endl;
    }
    return 0;
  }
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static String S;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        S = sc.next();
        System.out.println( solve() );
    }

    static int solve() {
        int ans = 0;
        int i = 0;
        int j = S.length() - 1;
        while(i <= j) {
            char a = S.charAt(i);
            char b = S.charAt(j);

            if( a == b ) {
                i++;
                j--;

            } else if( a == 'x' ) {
                ans++;
                i++;

            } else if( b == 'x' ) {
                ans++;
                j--;

            } else {
                return -1;
            }
        }

        return ans;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



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

using namespace std;

typedef long long LL;

constexpr LL INF = 1e18;
LL dp[100001], dp2[100001];
LL N, T, E;
LL x[100001];

int main() {
    scanf("%lld %lld %lld", &N, &E, &T);
    for(int i = 1; i<=N; ++i) scanf("%lld", x+i);
    int now = 1;
    LL mn = -2*x[1];
    for(int i = 1; i<=N; ++i) {
        if( 2*(x[i] - x[1]) <= T ) {
            dp[i] = T;
            continue;
        }
        while( 2*(x[i]-x[now+1]) > T ) {
            mn = min(mn, dp[now]-2*x[now+1]);
            ++now;
        }
        dp[i] = min(dp[now]+T, mn+2*x[i]);
    }
    printf("%lld\n", dp[N]+E);
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	private static final double PING = 3.305785;

	public static void main(String[] args) {
		int am = sc.nextInt();
		int bm = sc.nextInt();

		double ans = ((double)am * (double)bm) / PING;

		System.out.println(ans);
	}

}

Measured memory_bytes: 26408
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, mid_index,right_index):
    global count
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list)
            
def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, mid_index,right_index)
    
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    global count
    count = 0
    merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)

Measured memory_bytes: 68996
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

bool check(vector<int> &b){
    vector<int>::iterator it;
    int i = 1;
    for(it = b.begin(); it != b.end(); it++){
        if(*it != i){
            return false;
        }
        i++;
    }
    return true;
}

int main(){
    int n;
    while(cin >> n,n){
        int i = 0;
        bool c;
        vector<int> b;
        vector<int>::iterator it;
        rep(i,n){
            int inp;
            cin >> inp;
            b.pb(inp);
        }
        for(i = 0; i <= 10000; i++){
            if(check(b)) break;
            b.pb(b.size() + 1);
            for(it = b.begin(); it != b.end(); it++) *it = *it - 1;
            for(it = b.begin(); it != b.end(); it++){
                if(*it == 0){
                    b.erase(it);
                    *it--;
                }
            }
        }
        if(i > 10000) cout << -1 << endl;
        else cout << i << endl;
    }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ss second
#define ff first 
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0)return (power((x*x)%M,n/2))%M;else return ((x%M)*power(x,n-1)%M);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
    for (ll i = 1; i <= n; i++){ 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll ncrmod(ll n, ll r, ll p){ 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
   return (ncrmod(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p;  
} 
ll modInverse(ll a,ll m) 
{ 
   ll m0 = m; 
   ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
       ll q = a / m; 
       ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
cin>>str;
stack<char>sec;
sec.push(str[0]);
for(int i=1; i<str.length(); i++){
if(sec.empty()){
sec.push(str[i]);
}
else if(str[i]=='1'){
if(!sec.empty()){
if(sec.top()=='0')
sec.pop();
else
sec.push(str[i]);
}else{
sec.push(str[i]);
}
}
else if(str[i]=='0'){
if(!sec.empty()){
if(sec.top()=='1')
sec.pop();
else
sec.push(str[i]);
}else{
sec.push(str[i]);
}
}
}
int n=str.length();
// cout<<sec.size()<<"\n";
cout<<n-(sec.size());
return 0;
}

Measured memory_bytes: 3796
s = input()

if s[0] == 'S':
    if s[1] == 'U':
        print(7)
    else:
        print(1)
elif s[0] == 'M':
    print(6)
elif  s[0] == 'T':
    if s[1] == 'U':
        print(5)
    else:
        print(3)
elif s[0] == 'W':
    print(4)
elif s[0] == 'F':
    print(2)

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

using namespace std;

const int NMAX = 100000 + 5;

int dp[NMAX];
vector <int> graph[NMAX];

void dfs(int node, int father) {
    for (auto it: graph[node])
        if (it != father) {
            dfs(it, node);
            dp[node] ^= dp[it];
        }
    if (father)
        ++ dp[node];
}

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

    for (int i = 1; i < N; ++ i) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    dfs(1, 0);
    if (dp[1])
        cout << "Alice\n";
    else
        cout << "Bob\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> coin(m);
    REP(i, m){
        cin >> coin.at(i);
    }
    vector<ll> minnum(n + 1, n);
    minnum.at(0) = 0;
    REP(i, n){
        for(ll c : coin){
            if(i + c <= n){
                minnum.at(i + c) = min(
                    minnum.at(i + c),
                    minnum.at(i) + 1
                );
            }
        }
    }
    cout << minnum.at(n) << endl;
    return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n),b(n),c(n);
	rep(i,n) cin >> a.at(i);
	rep(i,n) cin >> b.at(i);
	rep(i,n) cin >> c.at(i);
	sort(all(a));
	sort(all(b));
	sort(all(c));
	vector<ll> dp(n + 1);
	int j = 0;
	rep(i,n){
		while(j < n && a.at(j) < b.at(i)) j++;
		dp[i + 1] += j;
	}
	rep(i,n) dp[i + 1] += dp[i];
	j = 0;
	ll ans = 0;
	rep(i,n){
		while(j < n && b.at(j) < c.at(i)) j++;
		ans += dp[j];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2304
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Program
  {
    public static void Main()
    {
      var candidateBase = new[] { "the", "this", "that" };
      var candidates = new Dictionary<string, List<string>>(); 
      foreach (var candidate in candidateBase)
      {
        candidates[candidate] = new List<string>();
        foreach (var i in Enumerable.Range(0, 25))
          candidates[candidate].Add(Caesar(candidate, i));
      }

      string line;
      while ((line = Console.ReadLine()) != null)
      {
        var words = line.Split(' ');
        var rot = -1;
        foreach (var candidate in candidates)
        {
          if (words.Any(w => candidate.Value.Contains(w)))
          {
            foreach (var c in candidate.Value)
            {
              if (words.Contains(c))
              {
                rot = candidate.Value.IndexOf(c);
                break;
              }
              if (rot != -1)
                break;
            }
          }
          if (rot != -1)
            break;
        }
        Console.WriteLine(Caesar(line, -rot));
      }
    }

    static string Caesar(string str, int rot)
    {
      return new string(str.Select(c => Caesar(c, rot)).ToArray());
    }

    static char Caesar(char c, int rot)
    {
      if (c < 'a' || 'z' < c)
        return c;
      int tmp = (c - 'a') + rot;
      if (tmp < 0)
        tmp += 'z' + 1;
      else
        tmp = (tmp % 26) + 'a';
      return (char)tmp;
    }
  }
}

Measured memory_bytes: 5912
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
ll x, y;
ll a[1111][2];
int n;
ll ce(ll x, ll y)
{
	return (x-1)/y+1;
}
int main(void)
{
	cin>>n;
	int i;
	for(i=1 ; i<=n ; i++)
	{
		scanf("%lld %lld",&a[i][0],&a[i][1]);
	}
	x=1; y=1;
	for(i=1 ; i<=n ; i++)
	{
		ll mul=max(ce(x,a[i][0]),ce(y,a[i][1]));
		x=mul*a[i][0];
		y=mul*a[i][1];
	}
	cout<<x+y<<endl;
}

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

int main()
{
    string s;
    cin>>s;
    int n = s.size();
    int cnt= 0;
    for(int i = 0;i < n/2;++i){
        if(s[i] != s[n-i-1]) cnt++; 
    }
    printf("%d\n",cnt);
    return 0;
}

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


	
int main()
{
int n,l;cin>>n>>l;
int a[n],sum=0;
for(int i=0;i<n;i++)
	{a[i]=l+i;sum+=a[i];}
int min=a[0];
for(int i=1;i<n;i++)
	if(abs(min)>abs(a[i]))
		min=a[i];
sum-=min;
cout<<sum;
	
return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import deque
def inpl(): return tuple(map(int, input().split()))

N = int(input())
G = [[] for i in range(N+1)]
for _ in range(N-1):
    a, b = inpl()
    G[a].append(b)
    G[b].append(a)

F = ["" for i in range(N+1)]
S = ["" for i in range(N+1)]

visited = [False for i in range(N+1)]
Q = deque([(1, 0)])

while len(Q):
    m, d = Q.popleft()
    if visited[m]:
        continue
    else:
        F[m] = d
        visited[m] = True

    for nm in G[m]:
        Q.append((nm, d+1))

visited = [False for i in range(N+1)]
Q = deque([(N, 0)])

while len(Q):
    m, d = Q.popleft()
    if visited[m]:
        continue
    else:
        S[m] = d
        visited[m] = True

    for nm in G[m]:
        Q.append((nm, d+1))
    
black = 0    
for i in range(1, N+1):
    if F[i] <= S[i]:
        black += 1

if 2*black > N:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 30452
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))
(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))
(defmacro print-float (r)
  `(format t "~,9F~%" (coerce ,r 'double-float)))


;;本体
(defun main ()
  (let* ((n (read)) (l (read))
         (near0 (cond ((>= l 0) l)
                      ((<= (+ l (1- n)) 0) (+ l (1- n)))
                      (t 0))))
    (println
      (- (loop for i from l below (+ l n) sum i) near0))))

#-swank(main)


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

int main(){
  int h,w,k; cin >>h >>w >>k;
  string c[6];
  string copy[6], copy2[6];
  rep(i,h){ 
    cin >>c[i];
    copy[i] = c[i];
    copy2[i] = c[i];
  }
  int ans = 0;
  rep(s,1<<h){
    rep(i,h){
      if(s>>i&1) rep(j,w) c[i][j]='*';
      copy2[i] = c[i];
    }
    rep(t,1<<w){
      int cnt = 0;
      rep(j,w){
        if(t>>j&1){
          rep(i,h) c[i][j] = '*';
        }
      }
      rep(i,h){ 
        rep(j,w){
         if(c[i][j]=='#') cnt++; 
        }
        c[i] = copy2[i];
      }
      if(cnt==k) ans++;
    }
    rep(i,h) c[i]=copy[i];
  }
  cout << ans << endl;
  return 0; 
}


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

int main()
{
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	
	for (int i = 0; i < N; ++i)
	{
		int x;
		cin >> x;
		X = max(x, X);
	}
	
	for (int i = 0; i < M; ++i)
	{
		int y;
		cin >> y;
		Y = min(y, Y);
	}
	
	if (X < Y)
		cout << "No War\n";
	else
		cout << "War\n";
}


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

int main() {

    int n;
    cin >> n;

    vector<int> a(n),b(n);
    rep(i,n) {
        cin >> a[i];
        b[i] = a[i];
    }


    sort(b.begin(), b.end());

    for (int i = 0; i < n; i++) {
        bool f = false;
        for (int j = n-1; j >= 0; j--) {
            if (f || a[i] != b[j]) {
                cout << b[j] << endl;
                break;
            }
            else if (!f) {
                f = true;
            }
        }
    }
        
    return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define ll long long

using namespace std;
 
void solve() {
    ll n;
    cin >> n;

    ll ans = 0;
    for (int a = 1; a < n; ++a) {
        ll l = 1, r = n, m;
        while (l <= r) { 
            m = l + (r - l) / 2; 
      
            if (a * m < n && a * (m+1) >= n) 
                break;
             
            else if (a * m < n) 
                l = m + 1; 
      
            else
                r = m - 1; 
        }
        ans += m;
    }

    cout << ans << endl;
}

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

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

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
s = input()
length = len(s)
count = 0
count_large = 0
sep = s[2:length-1]


if s[0] == 'A':
    count += 1

if sep.count('C') == 1:
    count += 1

for i in range(length):
    if s[i].isupper():
        count_large += 1
        
if count_large == 2:
    count += 1

if count == 3:
    print('AC')
else:
    print('WA')


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

using namespace std;

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++) cin >> B[i];
	int count = 0;
	for (int i = 0; i < N; i++) {
		int sum = C;
		for (int j = 0; j < M; j++) {
			int A;
			cin >> A;
			sum += A * B[j];
		}
		if (sum > 0) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int sx = sc.nextInt(); int sy = sc.nextInt();
	int tx = sc.nextInt(); int ty = sc.nextInt();
	
	StringBuilder a = new StringBuilder();
	 a.append(move1(sx,tx,sy,ty)); 
	 a.append(move2(sx,tx,sy,ty)); 
	 a.append(move3(sx,tx,sy,ty)); 
	 a.append(move4(sx,tx,sy,ty)); 
     
	 
	 String ans = a.toString();
	 System.out.println(ans);
}

	static String move1 (int sx,int tx,int sy,int ty) {
	StringBuilder mm = new StringBuilder(); 

	for(int i=0; i<Math.abs(sx-tx);i++) {
		 mm.append("R");}
	for(int i=0; i<Math.abs(sy-ty);i++) {
		mm.append("U");}
	
		String m = mm.toString();
		 return m;
	}
	static String move2 (int sx,int tx,int sy,int ty) {
		StringBuilder mm = new StringBuilder(); 

		for(int i=0; i<Math.abs(sx-tx);i++) {
			 mm.append("L");}
		for(int i=0; i<Math.abs(sy-ty);i++) {
			mm.append("D");}
		
			String m = mm.toString();
			 return m;
		}
	static String move3 (int sx,int tx,int sy,int ty) {
		StringBuilder mm = new StringBuilder(); 
		 mm.append("D");
		for(int i=0; i<Math.abs(sx-tx)+1;i++) {
			 mm.append("R");}
		for(int i=0; i<Math.abs(sy-ty)+1;i++) {
			mm.append("U");}
		mm.append("L");
			String m = mm.toString();
			 return m;
		}
	static String move4 (int sx,int tx,int sy,int ty) {
		StringBuilder mm = new StringBuilder(); 
        mm.append("U");
		for(int i=0; i<Math.abs(sx-tx)+1;i++) {
			 mm.append("L");}
		for(int i=0; i<Math.abs(sy-ty)+1;i++) {
			mm.append("D");}
		mm.append("R");
			String m = mm.toString();
			 return m;
		}
	
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;

template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

void number(ll n)
{
	if(n==0) return;
	
	number((n-1)/26);
	cout<<(char)('a'+((n+25)%26));
}

void solve()
{
	ll n;
	cin>>n;
	
	number(n);
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
ll gcd(ll a, ll b){
  ll maxx = max(a, b);
  ll minn = min(a, b);
  ll rem;
  while(maxx%minn!=0){
    rem = maxx % minn;
    maxx = minn;
    minn = rem;
  }
  return minn;
}
ll lcm(ll a, ll b){
  return a/gcd(a,b)*b;
}
ll f(ll x, ll c, ll d){
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var (
	N      int
	a      []int
	answer int
)

func main() {
	readVariables()
	for i := 1; i < N; i++ {
		l, r := a[i-1], a[i-1]
		if i+1 < N {
			r = a[i+1]
		}
		c := false
		if a[i] == l {
			c = true
			for a[i] == l || a[i] == r {
				a[i]++
				a[i] %= N
			}
		}
		if c {
			answer++
		}
	}
	fmt.Println(answer)
}

func readVariables() {
	N = nextInt()
	a = make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt() % N
	}
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int l, r, ans, n;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d", &l, &r);
		ans += r - l + 1;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128