akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
#include <queue>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  //std::cout << std::fixed << std::setprecision(10);
  ull n, m;
  cin >> n >> m;

  vector<vector<ull>> s = {};
  each(i, m) {
    ull k;
    cin >> k;
    vector<ull> sws = {};
    each(j, k) {
      ull sw;
      cin >> sw;
      sws.push(sw);
    }
    s.push(sws);
  }

  vector<ull> p;
  each(i, m) {
    ull tmp;
    cin >> tmp;
    p.push(tmp);
  }

  ull result = 0;
  for (ull bit=0; bit < (1 << n); bit++) {
    //cout << std::bitset<10>(bit) << endl;

    ull okcount = 0;
    each(i, m) {

      ull lighting = 0;
      each(ii, s[i].size()) {
        if (bit & (1 << (s[i][ii] - 1))) {
          lighting++;
        }
      }

      //cout << "lighting:[" << lighting << "]  cond:[" << p[i] << "] compare:[" << (lighting%2) << "=" << p[i] << "," << ((lighting % 2) == p[i] ? "true" : "false")  <<"]" << endl;

      if ((lighting % 2) == p[i]) {
        okcount++;
      }
    }

    if (okcount == m) {
      result++;
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
int h, w;
int n;
int a, b;
long long ans[11];
map<P, int>mp;
int main() {
	cin >> h >> w >> n;
	rep(i, n) {
		cin >> a >> b;
		for (int j = max(2, a - 1);j <= min(h - 1, a + 1);j++) {
			for (int k = max(2, b - 1);k <= min(w - 1, b + 1);k++) {
				mp[{j, k}]++;
			}
		}
	}
	for (auto x : mp) {
		ans[x.second]++;
	}
	ans[0] = (long long)(h-2) * (w-2) - mp.size();
	rep(i, 10)cout << ans[i] << endl;
	getchar();getchar();
	return 0;
}

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

int main() {

	 unsigned long long int n, a, b, x, y, ans;

	cin >> n >> a >> b;

	x = n / (a + b);
	y = n % (a + b);

	if (y >= a) ans = a * (x + 1);
	else ans = a * x + y;

	cout << ans;

	return 0;
}





Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    v = i_list()

    fd = {}
    sd = {}
    for i,k in enumerate(v):
        if i%2==0:
            fd[k] = fd.get(k,0) + 1
        else:
            sd[k] = sd.get(k,0) + 1

    a = max(fd, key=fd.get)
    b = max(sd, key=sd.get)
    c = max(fd.values())
    d = max(sd.values())

    if a != b:
        print(n - c - d)
    else:
        fd[a] = 0
        sd[b] = 0
        e = max(fd.values())
        f = max(sd.values())
        z = max(c+f , d+e)
        print(n-z)


if __name__=="__main__":
    main()


Measured memory_bytes: 99720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;
int MOD = 1e9 + 7;

int N,Q;
vector<vector<ll> > G(200010);
vector<ll> cost(200010);
vector<bool> visited(200010,false);

void dfs(int v, int pv){
    visited[v] = true;
    if(v != 0)cost[v]+=cost[pv];
    for(auto nv: G[v]){
        if(visited[nv] == false) dfs(nv, v);
    }
}

int main(){
    cin >> N >> Q;
    
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    
    rep(i,Q){
        int a,b; cin >> a >> b;
        a--;
        cost[a] += b;
    }

    dfs(0,0);
    rep(i,N-1) cout << cost[i] << " ";
    cout << cost[N-1] << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = input[0], m = input[1];
            var graph = new List<int>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<int>();
            for (int i = 0; i < m; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int a = input[0] - 1, b = input[1] - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            var sign = new int[n - 1];
            for (int i = 0; i < n - 1; i++) sign[i] = -1;
            var queue = new Queue<int>();
            queue.Enqueue(0);
            while (queue.Any())
            {
                int now = queue.Peek();
                queue.Dequeue();
                foreach (var r in graph[now])
                {
                    if (r == 0 || sign[r - 1] != -1) continue;
                    sign[r - 1] = now;
                    queue.Enqueue(r);
                }
            }
            if (sign.Any(x => x == -1))
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
                Console.WriteLine(string.Join("\n", sign.Select(x => x + 1)));
            }
        }
    }
}

Measured memory_bytes: 53004
#include <iostream>

void print(int n, int a[]) {
    std::cout << a[0];
    for (int i = 1; i < n; i += 1) {
        std::cout << " " << a[i];
    }
    std::cout << std::endl;
}

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

    int A[100];
    for (int i = 0; i < N; i += 1) {
        std::cin >> A[i];
    }

    print(N, A);

    for (int i = 1; i < N; i += 1) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j -= 1;
        }
        A[j + 1] = v;

        print(N, A);
    }

    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    bool prime[250010] = {1,0,0};
    int p[250010];
    int n = 0;
    range(i,2,250010){
        for(int j = i + i; j <= 250010; j+= i){
            prime[j] = true;
        }
    }
    rep(i,250010){
        if(prime[i] == false) n++;
        p[i] = n;
    }
    while(cin >> n, n){
        cout << p[n * 2] - p[n] << endl;
    }
}

Measured memory_bytes: 2388
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int m,f,r;

bool input(){
  cin >>m >>f >>r;
  if (m == -1) if (f == -1) if (r == -1) return false;
  return true;
}

void solve(){
  if (m == -1 || f == -1) cout <<"F" <<endl;
  else if (m + f >= 80) cout <<"A" <<endl;
  else if (m + f >= 65) cout <<"B" <<endl;
  else if (m + f >= 50) cout <<"C" <<endl;
  else if (m + f >= 30) cout <<(r >= 50 ? "C" : "D") <<endl;
  else cout <<"F" <<endl;
}

int main() {
  while (input()) solve();
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
   ll N;
   cin >> N;
   vector<ll> A(N),B(N);
   rep(i,N) cin >> A[i] >> B[i];
   ll ans = 0;
   rrep(i,N){
      A[i] += ans;
      if(A[i] % B[i] == 0) continue;
      ans += B[i] - (A[i] % B[i]);
   }
   cout << ans << endl;
}


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

ll func(ll a,ll x){
  ll ans = 0;
  if(a > -1){
    ans = a/x +1;
  }
  
  return ans;
}

int main() {
  long long  a,b,x;
  cin >> a >> b >> x;
  long long ans;
  ans = func(b,x) - func(a-1,x);
   
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
$h = [];
$mindiff = PHP_INT_MAX;
fscanf(STDIN, "%d %d", $N, $K);

for($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d", $h[$i]);
}

sort($h);

for($m = 0; $m <= $N - $K; $m++) {
    $diff = $h[$m + $K - 1] - $h[$m];
    if ($mindiff > $diff) {
        $mindiff = $diff;
    }
    if ($diff == 0) {
        break;
    }
}

echo $mindiff . "\n";

Measured memory_bytes: 12792
A,B=map(int,input().split())
S=input()

if str.isdecimal(S[0:A]) and S[A]=="-" and str.isdecimal(S[A+1:]):
    #print(str.isdecimal(S[0:A]))
    #print(S[A]=="-")
    #print(str.isdecimal(S[A+1:]))
    #print(S[A+2:])
    
    print("Yes")
else:
    #print(str.isdecimal(S[0:A]))
    #print(S[A])
    #print(str.isdecimal(S[A+1:]))
    #print(S[A+1:])
    
    print("No")

Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--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; }
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;
int A[100005];

unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

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

  cin >> N;
  rep(i, N){
    if (GetDigit(i+1)%2 == 0){
      A[i+1] = A[i];
    }else{
      A[i+1]=A[i]+1;
    }
  }

  cout << A[N] << endl;
  return 0;
}

Measured memory_bytes: 640
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std;
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mod            1000000007
 
void solve()
{
    ll n;

    cin>>n;

    ld tt=0,x;

    F(i,n)
    {
        cin>>x;

        tt+=(1.00/x);
    }

    cout<<(1.00/tt);
}
 
signed main(){
 
    fast;
 
    ll t=1;
 
    //cin>>t;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
cnt = [0]*(10**5+1)
for i in range(0,N):
    cnt[a[i]] += 1

ans = 0
for i in range(10**5-1):
    ans = max(ans, cnt[i]+cnt[i+1]+cnt[i+2])

print(ans)

Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int d,t,s;
  cin >> d >> t >> s;
  if (t*s >= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};

int main() {
	int n;
	scanf("%d",&n);
	vector<ll> l(n+1);
	l[0]=2LL;
	l[1]=1LL;
	REP(i,2,n+1) l[i]=l[i-1]+l[i-2];
	printf("%ld",l[n]);
}

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

int main(){
  int N;
  cin >> N;
  int ans = 0;
  int A = 0, B = 0, BA = 0;
  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    for(size_t j = 1; j < s.length(); ++j){
      if(s[j-1] == 'A' and s[j] == 'B') ++ans;
    }
    if(s[0] == 'B' and s.back() == 'A') ++BA;
    else if(s[0] == 'B') ++B;
    else if(s.back() == 'A') ++A;
  }
  int t = -1;
  while(1){
    //cerr << A << " " << B << " "<< BA << endl;
    if(t < 0){
      if(A){
        t = 0;
        --A;
      }else if(BA){
        t = 0;
        --BA;
      }
    }
    if(t < 0) break;
    t = -1;
    if(BA){
      t = 1;
      --BA;
    }else if(B){
      t = 0;
      --B;
    }
    if(t >= 0) ++ans;
    if(not t) t = -1;
  }
  cout << ans << endl;
}


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

int main(void){
    int n;
    string s;
    cin >> n;
    cin >> s;

    int t = n / 2;
    if(n % 2 == 0 && s.substr(0, t) == s.substr(t, t)) cout << "Yes" << endl;
    else cout << "No" << endl;
      
    return 0;
}

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

int n,m;
vector<int> g[100005];
int dp[100005];
int visited[100005];
int mx=0;

void dfs(int node){

	if(visited[node])
		return;	

	visited[node]=1;	
	dp[node]=0;
	for(auto child:g[node]){
		dfs(child);
		dp[node]=max(dp[node],dp[child]+1);
	}
	mx=max(mx,dp[node]);
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		int from,to;
		cin>>from>>to;
		g[from].push_back(to);
	}
	for(int i=1;i<=n;++i)
		if(!visited[i])
			dfs(i);
	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            if('a'<=c&&c<='z'){
                System.out.print(Character.toUpperCase(c));
            }else{
                if('A'<=c&&c<='Z'){
                System.out.print(Character.toLowerCase(c));
                }else{
                    System.out.print(c);
                }
            }
        }
        System.out.println();
        sc.close();
    }    
}


Measured memory_bytes: 26828
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vll abc(3);
    REP(i,3) cin >> abc[i];
    ll ans=LLINF;
    REP(i,3){
        if(abc[i]%2==0){
            cout << 0 << endl;
            return 0;
        }
        ans = min(ans,abc[(i+1)%3]*abc[(i+2)%3]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[-len(dreamer) :] == dreamer:
            S = S[: -len(dreamer)]
        if S[-len(eraser) :] == eraser:
            S = S[: -len(eraser)]
        if S[-len(dream) :] == dream:
            S = S[: -len(dream)]
        if S[-len(erase) :] == erase:
            S = S[: -len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()



Measured memory_bytes: 3188
#include<stdio.h>
int main(void) {
	int i, a[6],x=0,y=0,z=0,o=0;
	for (i = 0; i < 6; i++) {
		scanf("%d", &a[i]);
		if (a[i] == 1)
			x++;
		else if (a[i] == 2)
			y++;
		else if (a[i] == 3)
			z++;
		else
			o++;
	}
	if (x <= 2 && y <= 2 && z <= 2 && o <= 2)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xtoy = {}
ytox = {}
for x, y in xy:
    if x not in xtoy:
        xtoy[x] = []
    xtoy[x].append(y)
    if y not in ytox:
        ytox[y] = []
    ytox[y].append(x)
ret = 0
while len(xtoy) > 0:
    x = next(iter(xtoy))
    xs = set()
    ys = set()
    xs.add(x)
    q = [(x, None)]
    while len(q) > 0:
        (xx, yy) = q.pop(0)
        if xx is not None:
            for y in xtoy.pop(xx):
                if y not in ys:
                    ys.add(y)
                    q.append((None, y))
        if yy is not None:
            for x in ytox.pop(yy):
                if x not in xs:
                    xs.add(x)
                    q.append((x, None))
    ret += len(xs) * len(ys)
print(ret - n)


Measured memory_bytes: 90072
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323


void solve()
{
       ll n;
       cin>>n;
       vector<ll>a(n);
       rep(i,0,n) cin>>a[i];
       ll ans=0;
       ll dp[n+1][2]; // dp[i][0] = ans till i when i-1 multiplied by -1, dp[i][0] = ans otherwise
       dp[0][0]=0, dp[0][1]=0;
       dp[1][0]=-1*a[0], dp[1][1]=a[0];
       for(int i=2; i<n; i++)
       {
              // dp[i][0] = cur multiplied by -1
              dp[i][0] = max(dp[i-1][0]+a[i-1], dp[i-1][1]-a[i-1]);
              dp[i][1] = max(dp[i-1][1]+a[i-1], dp[i-1][0]-a[i-1]);
       }
       dp[n][1] = max(dp[n-1][1]+a[n-1], dp[n-1][0]-a[n-1]);
       cout<<dp[n][1]<<endl;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    vector<int> v(n,0);
    v[1]=abs(ar[1]-ar[0]);
    for(int i=2;i<n;i++)
    {
        int m=INT_MAX;
        for(int j=1;j<=k && i-j>=0 ;j++)
            m=min(v[i-j]+abs(ar[i]-ar[i-j]),m);
        v[i]=m;
        //cout<<min(v[i-1]+abs(ar[i]-ar[i-1]),v[i-2]+abs(ar[i]-ar[i-2]))<<" ";
    }
    //cout<<endl;
    cout<<v[n-1];
}


Measured memory_bytes: 1024
using System;

namespace AtCoder
{
    class A_PlacingMarbles_081
    {
        public static void Main()
        {
            var input = Console.ReadLine().ToCharArray();
            var count = 0;
            if (input[0] == '1') { ++count; }
            if (input[1] == '1') { ++count; }
            if (input[2] == '1') { ++count; }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
# 1..n でnと違いに素なものの個数
# エラトステネスの逆っぽい
n = int(input())


def prime_divide(n):
    res = []
    i = 2
    while True:
        if n % i == 0:
            res.append(i)
            n //= i
        else:
            i += 1
            if i > n ** (0.5):
                break
    if n != 1:
        res.append(n)
    return res


def euler_fai(n):
    # root n まで見て残っているならそれはOK
    # 個数のみ保持するので何個消したかを残しておけば良い
    # n <= 10**9
    total = n  # 1...n のtotal
    lis = list(set(prime_divide(n)))
    l = len(lis)
    # bit全探索で1...2**n-1 まで探すと良い
    for i in range(1, 2 ** l):
        cum = 1  # 累積
        cnt = 0
        for j in range(l):
            if i >> j & 1:
                # bitが立っている。
                cum *= lis[j]
                cnt += 1
        if cnt % 2:  # 奇数個なら-
            total -= n // cum
        else:
            total += n // cum
    return total


print(euler_fai(n))



Measured memory_bytes: 5644
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
class UnionFind{
private:
    std::vector<int> par;
    std::vector<int> rank;
public:
    void init(int N){
        par.resize(N);
        rank.resize(N);
        for(int a = 0;a < N;a++)
        {
            par[a]=-1;
            rank[a]=0;
        }
    }
    int root(int a)
    {
        if(par[a] < 0)return a;
        else return par[a] = root(par[a]);
    }
    void connect(int a,int b)
    {
        a = root(a);
        b = root(b);
        if(a==b)return;

        if(rank[a] < rank[b]){
            par[a] = b;
        }else{
            par[b] = a;
            if(rank[a] == rank[b])rank[a]++;
        }
    }
    bool check(int a,int b){
        a = root(a);
        b = root(b);
        if(a == b)return true;
        else return false;
    }
};
int main(){
    CIN(N);CIN(K);
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    LL ruiseki[N+10];
    ruiseki[0]=0;
    REP(a,N){
        ruiseki[a+1]=ruiseki[a]+vec.at(a);
    }
    LL ruiseki2[N+10];
    ruiseki2[0]=0;
    REP(a,N){
        ruiseki2[a+1] = ruiseki2[a]+max(vec.at(a),0);
    }
    LL ans = 0;
    REP(a,N-K+1){
        ans = max(ans, ruiseki2[a] + max(ruiseki[a+K] - ruiseki[a],0LL) + ruiseki2[N] - ruiseki2[a+K]);
    }
    COUT(ans);    return 0;
}


Measured memory_bytes: 2296
n=int(input())
l1=[]
l=[int(i) for i in input().split()]
from collections import deque 
l1=deque()
if n%2==0:
   # l1=[]
    p=0 
    for i in l:
        if p==0:
            l1.append(i)
        else:
            l1.appendleft(i)
        p=1-p 
    print(*l1)
else:
   # l1=[]
    p=0 
    for i in l:
        if p==0:
            l1.appendleft(i)
        else:
            l1.append(i)
        p=1-p 
    print(*l1)

Measured memory_bytes: 98744
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

vector<vector<LL>> dp(63, vector<LL>(4, -1));
LL L, R;

void setdp(){
	dp.assign(63, vector<LL>(4, -1));
}

//3free 0 nofree 1 d free 2 u free

LL func(int p, int free){
	if(p==-1)return 1;
	if(p==0){
		if(free==3){
			return 3;
		}
		if(free==0){
			if((R&1)&&(L&1))return 1;
			if((R&1)&&(~L&1))return 3;
			if((~R&1)&&(L&1))return 0;
			if((~R&1)&&(~L&1))return 1;
		}
		if(free==1){
			if(R&1)return 3;
			if(~R&1)return 1;
		}
		if(free==2){
			if(L&1)return 1;
			if(~L&1)return 3;
		}
	}
	if(dp[p][free]>=0)return dp[p][free];
	LL res = 0;

	if(free==3){
		res += 3 * func(p-1, 3);
		res %= MOD;
	}
	if(free==0){
		if((R&BIT(p))&&(L&BIT(p)))res +=  func(p-1, 0);
		if((R&BIT(p))&&(~L&BIT(p)))res += func(p-1, 0) + func(p-1, 2) + func(p-1, 1);
		if((~R&BIT(p))&&(~L&BIT(p)))res += func(p-1, 0);
		res %= MOD;
	}
	if(free==1){
		if(R&BIT(p))res += func(p-1, 3) + 2 * func(p-1, 1);
		if(~R&BIT(p))res += func(p-1, 1);
		res %= MOD;
	}
	if(free==2){
		if(L&BIT(p))res += func(p-1, 2);
		if(~L&BIT(p))res += 2 * func(p-1, 2) + func(p-1, 3);
		res %= MOD;
	}
	return dp[p][free] = res;
}

int getplace(LL x){
	for(int i=0;;++i){
		x>>=1;
		if(!x)return i;
	}
}

int main(){
	cin >> L >> R;
	if(L==R){
		cout << 1 << endl;
		return 0;
	}
	LL ans = 0;
	//1 d 2 u
	for(int i=0;;++i){
		if(R<BIT(i))break;
		int free = 3;
		if(L>=2*BIT(i))continue;
		if(getplace(L)==i){
			free ^= 1;
		}
		if(getplace(R)==i){
			free ^= 2;
		}
		ans += func(i-1, free);
		ans %= MOD;
		setdp();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2010,M=4e6+10;int n;
const ll inf=1e16;
struct path{int y,nxt;ll w,cost;}g[M];int h[N],tot=1;
void add(int x,int y,ll w,ll cost){
	g[++tot]=(path){y,h[x],w,cost};h[x]=tot;
	g[++tot]=(path){x,h[y],0,-cost};h[y]=tot;
}
namespace SPFA{
	int S,T,pre[N],q[M],ql,qr;bool vis[N];ll dis[N];
	ll spfa(){
		for(int i=0;i<=T;i++)dis[i]=-inf;
		q[ql=qr=1]=S;dis[S]=0;vis[S]=1;pre[S]=0;
		while(ql<=qr){
			int x=q[ql++];vis[x]=0;
			for(int i=h[x];i;i=g[i].nxt)if(g[i].w&&dis[g[i].y]<g[i].cost+dis[x]){
				pre[g[i].y]=i;dis[g[i].y]=g[i].cost+dis[x];
				if(!vis[g[i].y])q[++qr]=g[i].y,vis[g[i].y]=1;
			}
		}
		if(dis[T]==-1)return 0;
		ll s=0,w=inf;
		for(int p=T,i=pre[T];p!=S;p=g[i^1].y,i=pre[p]){
			w=min(w,g[i].w);s+=g[i].cost;
		}
		for(int p=T,i=pre[T];p!=S;p=g[i^1].y,i=pre[p]){
			g[i].w-=w;g[i^1].w+=w;
		}return w*s;
	}
	ll solve(){
		ll ans=0,ret;while(ret=spfa())
		ans+=ret;
		return ans;
	}
}
int r[N][3],b[N][3],S,T;
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d",&n);T=SPFA::T=2*n+5;
	for(int i=1;i<=n;i++)for(int j=0;j<3;j++)scanf("%d",&r[i][j]);
	for(int i=1;i<=n;i++)for(int j=0;j<3;j++)scanf("%d",&b[i][j]);
	for(int i=1;i<=n;i++)add(S,i,r[i][2],0),add(i+n,T,b[i][2],0);
	for(int i=1;i<=n;i++){
		add(i,n*2+1,inf,r[i][0]+r[i][1]);
		add(i,n*2+2,inf,-r[i][0]+r[i][1]);
		add(i,n*2+3,inf,r[i][0]-r[i][1]);
		add(i,n*2+4,inf,-r[i][0]-r[i][1]);

		add(n*2+1,i+n,inf,-b[i][0]-b[i][1]);
		add(n*2+2,i+n,inf,b[i][0]-b[i][1]);
		add(n*2+3,i+n,inf,-b[i][0]+b[i][1]);
		add(n*2+4,i+n,inf,b[i][0]+b[i][1]);
	}
	printf("%lld\n",SPFA::solve());
}

Measured memory_bytes: 2432
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Repeat ACL
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int k;
  scanf("%d", &k);

  while (k--) printf("ACL");
  putchar('\n');
  return 0;
}


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

using namespace std;

int nbpierres;
int taillesaut;
int pierres[100000];
int bestscore[100000];

signed main()
{
    ios::sync_with_stdio(false);
    cin>>nbpierres>>taillesaut;
    for(int i = 0 ; i < nbpierres ; i ++)
    {
        cin>>pierres[i];
    }
    for(int i = nbpierres-1 ; i >=0 ; i--)
    {
        int mini = 1<<30;
        for(int j = 1 ; (i+j<nbpierres && j<taillesaut+1) ; j++)
        {
            mini = min(mini,bestscore[i+j]+abs(pierres[i]-pierres[i+j]));
        }
        bestscore[i]=(mini == 1<<30 ? 0 : mini);
    }
    cout<<bestscore[0];
}


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)3e5 + 7;

string a,t,s;
int u[N],l;

main () {
      cin >> a;

      if (a == "zyxwvutsrqponmlkjihgfedcba") {
            cout << "-1";
            return 0;
      }

      for (int i = 0; i < a.size(); i ++)
            u[a[i]] = 1;

      if (a.size() < 26) {
            cout << a;
            for (int j = 'a'; j <= 'z'; j ++) {
                  if (!u[j]) {
                        cout << char(j);
                        return 0;
                  }
            }
      }
      else {
            s = a;
            next_permutation(a.begin(),a.end());

            for (int i = 0; i < a.size(); i ++) {
                  cout << a[i];
                  if (a[i] > s[i]) {
                        return 0;
                  }
            }
      }
}


Measured memory_bytes: 256
a, b = (int(i) for i in input().split())  

x = [input() for i in range(a)]
y = [input() for i in range(b)]

h = a - b + 1
w = len(x) - len(y) + 1
res = "No"

for i in range(h):
  for ii in range(w):
    if all([y[z] == x[i+z][ii:ii+len(y)] for z in range(b)]):
      res = "Yes"
      break

print(res)


Measured memory_bytes: 3064
//by sdfzchy
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int inf=(1<<30),N=100010;
LL n,m;
inline int in()
{
	char ch=getchar();
	int f=1,tmp=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {tmp=(tmp<<1)+(tmp<<3)+(ch-'0');ch=getchar();}
	return tmp*f;
}

int main()
{
//	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
	scanf("%lld",&n);
	m=sqrt(1.0*n);
	printf("%lld\n",m*m);
	return 0;
}


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

using namespace std;

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

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

  cout << 2*(n-1) << endl;

  for (int i = 0; i < n; i++) {
    if (i != mx) {
      cout << mx + 1 << ' ' << i + 1 << endl;
      a[i] += a[mx];
    }
  }

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

  for (int i = 0; i < n; i++) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}


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

int main() {
  int a[3];
  for (int i = 0; i < 3; i++) cin >> a[i];
  int count5 = 0;
  int count7 = 0;
  for (int i = 0; i < 3; i++) {
    if (a[i] == 5) count5++;
    if (a[i] == 7) count7++;
  }
  
  if (count5 == 2 && count7 == 1) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int N = 2e5 + 10 , OO = 1e9 + 2, Max = 50 + 10;
const ll  MOD = 998244353 ;
int dp[N] , a[N];
int dx[100] ;
int main() {
    int n , k ;
    cin >> n >> k ;
    for(int i = 1;i<=n;++i) cin >> a[i] , dp[i] = OO;
    for(int i = 1;i<=k;++i) dx[i - 1] = i;
    dp[1] = 0 ;
    for(int i = 1;i<=n;++i) {
        for(int j =0;j < k;++j) {
            int nx = i + dx[j];
            if(nx <=n)
                dp[nx] = min(dp[nx],dp[i] + abs(a[nx] - a[i]));
        }
    }
    cout << dp[n] << endl;

}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine();
        var c = new int[26];
        for(int i = 0; i < n.Length; i++)
        {
            c[n[i] - 'a']++;
        }
        var isEven = true;
        for(int i = 0; i < 26; i++)
        {
            if(c[i] % 2 != 0)
            {
                isEven = false;
                break;
            }
        }
        WriteLine(isEven ? "Yes" : "No");
    }
}



Measured memory_bytes: 17328
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for c in range(C+1):
    for b in range(B+1):
        for a in range(A+1):
            temp = a * 500 + b * 100 + c * 50
            if X == temp:
                ans += 1

print(ans)

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

using namespace std; 

#define endl "\n"



long long int divisors[1000006]={0};
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
    long long int n,i,j,x=0;
    cin>>n;
 
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; j += i)
            ++divisors[j];
 
    long long ans = 0;
    for(i=1;i<n;i++)
    {
        x=n-i;
       ans+=divisors[x];
       //ans+=ceil(n/i)-1;
    }
    
    cout<<ans<<endl;
   
  
     return 0;
}

Measured memory_bytes: 11428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793

string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
	string w;
	cin >> w;
	vector<int>res(abc.size());
	for (int i = 0; i < abc.size(); i++) {
		res[i] = count(w.begin(), w.end(), abc[i]);
	}
	for (int i = 0; i < res.size(); i++) {
		if (res[i] % 2 != 0) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
/************************************
 * ???????????¢?´¢??§??¶?????°?????°??????????????°?????? *
 ************************************/

#include <iostream>
#include <queue>
#include <map>

#define LAND '1'  //??? char???
#define SEA  '0'   //??? char???

using namespace std;

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

/*8??????*/
int dx[] = {1,1,0,-1,-1,-1, 0, 1};
int dy[] = {0,1,1, 1, 0,-1,-1,-1};

bool input(vector< vector<char> > &m);
void delete_island(vector< vector< char > > &m, int x, int y);
void output(vector< vector< char> > m);


int main(){
  int w, h;
    
  while(cin >> w >> h, w && h){
    vector< vector< char > > m(h+2, vector<char>(w+2));
    input(m);
    
    int island = 0;
    for(int y = 0; y < m.size(); y++){
      for(int x = 0; x < m[y].size(); x++){
	if(m[y][x] == LAND){
	  delete_island(m,x,y);
	  island++;
	}
      }
    }
    cout << island << endl;
  }
}


bool input(vector< vector<char> > &m){
  for(int y = 0; y < m.size(); y++){
    for(int x = 0; x < m[y].size(); x++){
      if(y == 0 || x == 0 ||
	 y == m.size()-1 || x == m[y].size()-1){
	m[y][x] = SEA;
      }else{
	if(!(cin >> m[y][x])) return false;
      }
    }
  }
  return true;
}


 void delete_island(vector< vector< char > > &m, int x, int y){
   queue< pair< int, int > > q;
   q.push(make_pair(x,y));

   while(!(q.empty())){
     pair<int, int> cur = q.front();
     q.pop();
     if(m[cur.second][cur.first] == LAND){
       m[cur.second][cur.first] = SEA;
       for(int i = 0; i < sizeof(dx)/sizeof(int); i++){
	 q.push(make_pair(cur.first+dx[i],cur.second+dy[i]));
       }
     }
   }
}

void output(vector< vector< char> > m){
  for(int y = 0; y < m.size()-1; y++){
    for(int x = 0; x < m[y].size()-1; x++){
      cout << m[y][x] << " ";
    }
    cout << endl;
  }
  cout << endl;
}

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

 
int main(){
  long N;
  cin >> N;
  long val = 0;
  long facter = 10;
  if(N%2 == 1){
    cout << "0" <<endl;
    exit(0);
  }
  while(1){
    if(facter > N) break;
    else{
      val = val + N/facter;
      facter = facter * 5;
    }
  }
  cout << val << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

const int INF = 1e9;

int main() {
    int r, c;
    while (cin >> r >> c && r && c) {
        string a[r];
        for (int i = 0; i < r; i++) for (int j = 0, k; j < c; j++) {
            cin >> k;
            a[i] += to_string(k);
        }
        ll ans = 0;
        for (int bit = 0; bit < (1 << r); bit++) {
            ll sum = 0;
            for (int j = 0; j < c; j++) {
                ll cnt = 0;
                for (int i = 0; i < r; i++) {
                    if ((bit & (1 << i)) && (a[i][j] == '0')) cnt++;
                    else if (!(bit & (1 << i)) && (a[i][j] == '1')) cnt++;
                }
                sum += max(cnt, r - cnt);
            }
            ans = max(ans, sum);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3328
#include<stdio.h>
int main(void)
{
	int N,i,s;
	int k[10000];
	int flg;
	
	
	scanf("%d",&N);
	
	while(N!=0){
		flg=0;
		s=0;
		for(i=1;i<=N;i++){
			scanf("%d",&k[i]);
			s++;
			if(k[i]>=2){
				flg=1;
				
			}
			else if(k[i]==0){
				s--;
			}
			
		}
		s=s+1;
		
		
		if(flg==1){
	
			printf("%d\n",s);
			
		}
		if(flg==0){
			printf("NA\n");
		}
		scanf("%d",&N);
	}
	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

vector<vector<pair<ll,ll>>> edge(100050);
vll d(100050);

void dijkstra(ll s){
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
    fill(all(d),INF);
    d[s]=(ll)0;
    q.push(mp(0,s));
    while(q.size()){
        auto p=q.top();q.pop();
        auto v=p.second;
        if(d[v]<p.first)continue;
        for(auto e:edge[v]){
            if(d[e.first]>d[v]+e.second){
                d[e.first]=d[v]+e.second;
                q.push(mp(d[e.first],e.first));
            }
        }
    }
}

int main(){
    int n;cin>>n;
    ll a,b,c;
    rep(i,n-1){
        cin>>a>>b>>c;
        edge[a].push_back(mp(b,c));
        edge[b].push_back(mp(a,c));
    }
    int q,k;cin>>q>>k;
    dijkstra(k);
    int x,y;
    vll ans(q);
    rep(i,q){
        cin>>x>>y;
        ans[i]=d[x]+d[y];
    }
    rep(i,q)cout<<ans[i]<<endl;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define E 2.71828182845905
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define PI 3.14159265
#define mem(x) memset(x,0,sizeof(x));
using namespace std;
vector<int> ad[100005]; 
int mxd[100005];
bool vis[100005];

void dfs(int v){
	vis[v]=1;
	int mx=0;
	rep(i,0,sz(ad[v])){
		if(!vis[ad[v][i]])
			dfs(ad[v][i]);
		mx=max(mx,mxd[ad[v][i]]);
	}
	if(sz(ad[v])==0)
		mxd[v]=0;
	else
		mxd[v]=mx+1;
}
void sol() {
	int n,m;
	cin>>n>>m;
	rep(i,0,m){
		int x,y;
		cin>>x>>y;
		ad[x].pb(y);
	}
	mem(mxd);
	mem(vis);
	int ans=INT_MIN;
	rep(i,1,n+1)
	{
		if(!vis[i])
			dfs(i);
		ans=max(ans,mxd[i]);
	}
	cout<<ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
 	//cin>>t;
 	while(t--){	
	sol();
 	}
}

Measured memory_bytes: 8320
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int h,m,hm[200][200]={0},j,n,a[40000];
    scanf("%d%d%d",&h,&m,&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int p=0,q=0,number=0;
    for(int i=0;;i++)
    {
        if(i==3)
            i=0;
        if(i==0)
        {
            for(;;)
            {
                hm[p][q++]=number+1;
                a[number]--;
                if(a[number]==0)
                    number++;
                if(q>=m)
                {
                    q--;
                    p++;
                    break;
                }
            }
        }
        if(i==1)
        {

            for(;;)
            {
                hm[p][q--]=number+1;
                a[number]--;
                if(a[number]==0)
                    number++;
                if(q<0)
                {
                    q++;
                    p++;
                    break;
                }
            }
        }

        if(p>=h)
            break;
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<m;j++)
        {
            printf("%d",hm[i][j]);
            if(j!=m-1)
                printf(" ");
        }
        if(i!=h-1)
            printf("\n");
    }

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
//const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);


const ll MOD = 998244353;

const int MAXN = 301000;

vl fact(MAXN);
vl rfact(MAXN);

ll mod_pow(ll x, ll p, ll M = MOD) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a * x%M;
		x = x * x%M;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll M = MOD) {
	return mod_pow(a, M - 2, M);
}

void set_fact(ll n, ll M = MOD) {
	fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
	for (ll i = 2; i <= n; i++) {
		fact[i] = i * fact[i - 1] % M;
		rfact[i] = mod_inverse(fact[i], M);
	}
}

ll nCr(ll n, ll r, ll M = MOD) {
	ll ret = fact[n];
	ret = (ret*rfact[r]) % M;
	ret = (ret*rfact[n - r]) % M;
	return ret;
}

int main() {
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	set_fact(n + 10);
	vector<pll> pos;
	rep(i, n + 1) {
		if ((k - i * a) % b == 0) {
			ll x = i, y = (k - i * a) / b;
			if (in(x,0,n + 1) && in(y,0,n+1)) {
				pos.push_back(pll(x, y));
			}
		}
	}
	ll ans = 0;
	rep(i,pos.size()){
		ll temp = 1;
		ll x = pos[i].first, y = pos[i].second;
		temp *= nCr(n, x);
		temp %= MOD;
		temp *= nCr(n, y);
		temp %= MOD;
		ans += temp;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 10864