akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,i;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    int max = a.at(0);
    int maxi = 0;
    int premax = a.at(0);
    for(i = 1;i < n;++i){
        if(a.at(i) >= max){
            premax = max;
            max = a.at(i);
            maxi = i;
        }else{
            if(a.at(i) > premax){
                premax = a.at(i);
            }
        }
    }
    if(maxi == 0){
        premax = a.at(1);
        for(i = 2;i < n;++i){
            if(a.at(i) >= premax){
                premax = a.at(i);
            }
        }
    }
    for(i = 0;i < n;++i){
        if(i != maxi){
            cout << max << endl;
        }else{
            cout << premax << endl;
        }
    }
    return 0;
}

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

int main() {
	// your code goes here
	int mod;
	cin>>mod;
	if(mod%2==0 || mod%5==0){
		cout<<"-1\n";
		return 0;
	}
	int i = 1;
	int curR = 7%mod;
	while(curR%mod!=0){
		curR = ((curR * (10%mod))%mod + 7%mod)%mod;
		i++;
	}
	cout<<i<<"\n";
	return 0;
}

Measured memory_bytes: 3632
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    int x;
    cin>>x;
    if(x>=30){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}




Measured memory_bytes: 3596
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

x1,y1,x2,y2=get_f
puts (((x1-x2)**2+(y1-y2)**2)**0.5).round(5)


Measured memory_bytes: 6940
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
long long int resp;
int me[maxn],md[maxn],v[maxn];
int main(){
	int n;
	scanf("%d",&n);
	v[0]=-1;v[n+1]=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&v[i]);
	}
	stack<int> sd,se;
	sd.push(0);
	se.push(n+1);
	for(int i=1;i<=n;i++){	
		while(v[sd.top()]>v[i]){
			sd.pop();
		}
		md[i]=sd.top();
		sd.push(i);
	}
	for(int i=n;i>=1;i--){	
		while(v[se.top()]>v[i]){
			se.pop();
		}
		me[i]=se.top();
		se.push(i);
	}
	for(int i=1;i<=n;i++){
		long long int e,d;
		e=i-me[i];
		d=md[i]-i;
		resp+=(v[i]*e*d);
	}
	cout<<resp;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll modpow(ll a, ll n, ll m){
  ll res = 1;
  while(n > 0){
    if(n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

int main(){
  ll n; cin >> n;
  ll a[100005];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  if(n%2==0){
    bool flag = true;
    for(int i=0;i<n/2;i++){
      if(a[2*i] != a[2*i+1]){
        flag = false;
        break;
      }
    }
    if(flag) cout << modpow(2,n/2,MOD) << endl;
    else cout << 0 << endl;
  }else{
    bool flag = true;
    if(a[0] != 0){
      flag = false;
    }
    for(int i=0;i<n/2;i++){
      if(a[2*i+1] != a[2*i+2] || a[2*i+1] * a[2*i+2] == 0 || flag == false){
        flag = false;
        break;
      }
    }
    if(flag) cout << modpow(2,n/2,MOD) << endl;
    else cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
import numpy as np
N, M = (int(i) for i in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
money = 0
for a, b in AB:
    if M == 0:
        break
    elif M >= b:
        M -= b
        money += a*b
    elif M < b:
        money += a*M
        M = 0
print(money)

Measured memory_bytes: 36852
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

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


int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static int n;
	static int[] c, work;
	static boolean[] exist;
	static long[] rem;
	static List<List<Integer>> list;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		sa = br.readLine().split(" ");
		c = new int[n];
		work = new int[n];
		exist = new boolean[n];
		for (int i = 0; i < n; i++) {
			int col = Integer.parseInt(sa[i]) - 1;
			c[i] = col;
			exist[col] = true;
		}

		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			list.get(b).add(a);
		}
		br.close();

		rem = new long[n];
		dfs(0, -1, 0);
		for (int i = 0; i < n; i++) {
			long val = n - work[i];
			rem[i] += val * (val + 1) / 2;
		}
		long total = (long) n * (n + 1) / 2;

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; i++) {
			if (exist[i]) {
				pw.println(total - rem[i]);
			} else {
				pw.println(0);
			}
		}
		pw.flush();
	}

	static void dfs(int x, int p, int inSize) {
		int size = inSize;
		for (int next : list.get(x)) {
			if (next != p) {
				int befnext = work[c[next]];
				int befcur = work[c[x]];
				dfs(next, x, befnext);
				int total = work[c[next]] - befnext;
				long val = total - (work[c[x]] - befcur);
				rem[c[x]] += val * (val + 1) / 2;
				size += total;
			}
		}
		size++;
		work[c[x]] = size;
	}
}


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

using namespace std;

int main(){
    double x1, y1, x2, y2, x3, y3, x4, y4;
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        x1 -= x2; y1 -= y2; x3 -= x4; y3 -= y4;
        cout << (abs(x1*y3-y1*x3) < 1e-10?"YES":"NO") << endl;
    }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int N = 2e5;
ll v[N], n, m, c, p;
bool check(int i) {
	int n1 = upper_bound(v, v + n, v[i]) - v;
	if (n - n1 < p)
		return true;
	else {
		int n2 = upper_bound(v, v + n, v[i] + m) - v;
		if (n - n2 >= p)
			return false;

		ll s = m * (p - 1 + n1);
		for (int j = n1; j <= n - p; j++)
			s += min(m, v[i] + m - v[j]);
		if (s >= m * c)
			return true;
		else
			return false;
	}
	return true;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> m >> c >> p;
	for (int i = 0; i < n; i++)
		cin >> v[i];
	sort(v, v + n);
	int ans, s = 0, e = n - 1;
	while (s <= e) {
		int mid = s + (e - s) / 2;
		if (check(mid)) {
			ans = mid;
			e = mid - 1;
		}
		else
			s = mid + 1;
	}
	cout << n - ans;
	return 0;
}


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

int main(){
    long long N;
    cin >> N;
    long long L[N+1];
    long long i,j,k;
    for(i=1; i<=N; i++){
        cin >> L[i];
    }
    long long ans=0;
    for(i=1; i<=N; i++){
        for(j=i+1; j<=N; j++){
            for(k=j+1; k<=N; k++){
                if(L[i]==L[j]) continue;
                if(L[j]==L[k]) continue;
                if(L[k]==L[i]) continue;
                if(L[i]>=L[j]+L[k]) continue;
                if(L[j]>=L[k]+L[i]) continue;
                if(L[k]>=L[i]+L[j]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3692
#include <stdio.h>

char a[111][111];

int main(void)
{
	int W, B, n = 100, i, j;

	scanf("%d %d" ,&W, &B);

	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
            a[i][j] = (i <= n / 2 ? '.' : '#');

    for (i = 1; i <= (B - 1) / (n / 2); i++)
		for (j = 1; j <= n / 2; j++)
            a[i * 2 - 1][j * 2 - 1] = '#';
	for (j = 1; j <= (B - 1) % (n / 2); j++)
		a[i * 2 - 1][j * 2 - 1] = '#';

	for (i = 1; i <= (W - 1) / (n / 2); i++)
		for (j = 1; j <= n / 2; j++)
            a[(n + 1) - (i * 2 - 1)][j * 2 - 1] = '.';
	for (j = 1; j <= (W - 1) % (n / 2); j++)
		a[(n + 1) - (i * 2 - 1)][j * 2 - 1] = '.';

	puts("100 100");
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
			printf("%c" ,a[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 128
import heapq
n,m=map(int,input().split())
t=[[] for _ in range(m+1)]
for i in range(n):
    a,b=map(int,input().split())
    if a>m:
        continue
    t[a].append(b)
ans=0
h=[]
for l in t:
    for i in l:
        heapq.heappush(h,-i)
    if h:
        ans-=heapq.heappop(h)
print(ans)

Measured memory_bytes: 24348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int mod = 998244353;
inline int add(int u, int v) {
  return u + v >= mod ? u + v - mod : u + v;
}
inline int sub(int u, int v) {
  return u >= v ? u - v : u - v + mod;
}
inline int mul(ll u, int v) {
  return u * v % mod;
}

const int N = 303, M = 1000;
int choose[M][M];

inline int partition(int n, int k) {
  return choose[n + k - 1][k - 1];
}

int ways[N][N][N]; // ways[i][j][f] = last i, j moves, f free ones

int solve(VI& ones, int k) {
  const int n = ones.size();
  if (n == 0) return 1;

  ways[n][0][0] = 1;
  for (int i = n; i >= 1; i--) {
    const int len = ones[i - 1];
    for (int j = 0; j <= k; j++) {
      for (int f = 0; f < N; f++) {
        ways[i - 1][j][f] = ways[i][j][f];
      }
    }
    for (int j = 0; j <= k; j++) {
      for (int f = N - 2; f >= 0; f--) {
        ways[i - 1][j][f] = add(ways[i - 1][j][f], ways[i - 1][j][f + 1]);
      }
    }
    for (int j = 0; j <= k; j++) {
      for (int cur = 1; cur <= len && j + cur <= k; cur++) {
        for (int f = 0; f + cur < N; f++) {
          ways[i - 1][j + cur][f + cur] = add(ways[i - 1][j + cur][f + cur], ways[i][j][f]);
        }
      }
    }
  }

  int ans = 0;
  for (int j = 0; j <= k; j++) {
    for (int f = 0; f < N; f++) {
      ans = add(ans, ways[0][j][f]);
    }
  }

  return ans;
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  string s; cin >> s;
  int k; cin >> k;
  vector<int> ones;
  int f = 0;
  bool seen = false;
  for (char c: s) {
    if (c == '1') {
      f++;
    }
    if (c == '0') {
      if (seen) {
        ones.push_back(f);
      }
      f = 0;
      seen = true;
    }
  }
  if (f > 0 && seen) {
    ones.push_back(f);
  }

  for (int n = 0; n < M; n++) {
    choose[n][0] = choose[n][n] = 1;
    for (int r = 1; r < n; r++) {
      choose[n][r] = add(choose[n - 1][r], choose[n - 1][r - 1]);
    }
  }

  k = min(k, 300);
  cout << solve(ones, k) << endl;

  return 0;
}


Measured memory_bytes: 61132
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
 
using ld = long double;
using ll = long long;
using ii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vii = vector <ii>;
using vpll = vector<pll>;


int main(){
 
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  int k;
  cin >> k;
  int cur = 7;
  for(int i=1;i<=1e6;i++){
    if(cur%k == 0){
      cout << i << endl;
      return 0;
    }
    cur *= 10;
    cur += 7;
    cur %= k;
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 3620
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003;
int n;
vector<pair<int, int> > g[maxN];

long long ans;
int siz[maxN], f[maxN], rt, minSiz;
void dfs(int x, int fa, int pre) {
    siz[x] = 1;
    for (pair<int, int> y : g[x])
        if (y.first != fa)
            dfs(y.first, x, y.second), siz[x] += siz[y.first], f[x] = max(f[x], siz[y.first]);
    ans += 2ll * min(siz[x], n - siz[x]) * pre;
    f[x] = max(f[x], n - siz[x]);
    if (minSiz > f[x])
        minSiz = f[x], rt = x;
}

int main() {
    int i, x, y, z, tmp = 1e9;
    n = read();
    for (i = 1; i < n; ++i)
        x = read(), y = read(), z = read(),
            g[x].push_back(make_pair(y, z)), g[y].push_back(make_pair(x, z));
    minSiz = n, dfs(1, 0, 0);
    for (pair<int, int> y : g[rt]) {
        tmp = min(tmp, y.second);
        if (f[rt] == f[y.first]) {
            printf("%lld\n", ans - y.second);
            return 0;
        }
    }
    ans -= tmp;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
  double l;
  cin >> l;
  la a=l*l*l;
  cout << setprecision(10) << a/27 << endl;
}

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

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

    int k=m*2+1;
    // first part
    for ( int l=1,r=m; l<r; l++,r-- ) {
        cout << l << ' ' << r << '\n';
    }
    for ( int l=m+1,r=k; l<r; l++,r-- ) {
        cout << l << ' ' << r << '\n';
    }
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main(){
    int a,b,c,n;
    int i=0;
    cin >> n;
    while(i<n){
        cin >> a >> b >> c;
        if( ((a*a+b*b)==c*c) || ((b*b+c*c)==a*a) || ((a*a+c*c) == b*b)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll t;
ll chk[10][10];
int main()
{
    ll a,b,c,d,e,f,i,j;
    cin>>a;
    ll m,n;
    for(i=1;i<=a;i++)
    {
        b=i;
        f=0;
        while(b>0)
        {
            c=b%10;
            if(f==0)m=c;
            f++;
            b/=10;
            if(b==0)n=c;
        }
        //cout<<m<<' '<<n<<endl;
        chk[n][m]++;
    }
    f=0;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {

            f+=(chk[i][j]*chk[j][i]);
        }
    }
    cout<<f<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b, ans;
	cin >> a >> b;

	ans = a + b;
	if (ans < a - b)
		ans = a - b;
	if (ans < a*b)
		ans = a * b;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		char c[] = s.toCharArray();
		boolean ans = false;
		for (int i = 0; i <= s.length() + 3; i++) {
			turn(c);
			s = new String(c);

			if (s.equals(t)) {
				ans = true;
			}
		}
		if (ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	public static void turn(char c[]) {
		char ten = c[c.length - 1];
		for (int i = c.length - 1; i > 0; i--) {
			c[i] = c[i - 1];
		}
		c[0] = ten;

	}
}

Measured memory_bytes: 21716
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
#define mod 998244353
void update(int tree[],int start,int end,int point,int val,int index)
{
	if(point>end||point<start)
	   return ;
	if(start==end)
	{
		tree[index]=val;
		return ;
	}
	else
	{
		int mid=(start+end)/2;
		update(tree,start,mid,point,val,2*index);
		update(tree,mid+1,end,point,val,2*index+1);
		tree[index]=tree[2*index]+tree[2*index+1];
	}
}
int sum_query(int tree[],int start,int end,int left,int right,int index)
{
	if(left>end||start>right)
	  return 0;
    if(start>=left&&end<=right)
      return tree[index];
    else
    {
		int mid=(start+end)/2;
		int x=sum_query(tree,start,mid,left,right,2*index);
		int y=sum_query(tree,mid+1,end,left,right,2*index+1);
		return x+y;
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int mat[k][2];
	int j;
	for(j=0;j<k;j++)
	{
		cin>>mat[j][0]>>mat[j][1];
	}
	int tree[4*n+1]={0};
	int dp[n];
	dp[n-1]=1;
	update(tree,0,n-1,n-1,1,1);
	for(j=n-2;j>=0;j--)
	{
		int here=0;
		int i;
		for(i=0;i<k;i++)
		{
			int l=mat[i][0];
			int r=mat[i][1];
			l+=j;
			r+=j;
			int temp=sum_query(tree,0,n-1,l,r,1);
			here+=temp;
			here%=mod;
		}
		dp[j]=here;
		update(tree,0,n-1,j,here,1);
	}
	cout<<dp[0]<<endl;
}


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

int main()
{
	char str[200];

	while (cin >> str){
		for (int i = 0; str[i] != '\0'; i++){
			if (str[i] == '@'){
				for (int j = 0; j < str[i + 1] - '0'; j++){
					cout << str[i + 2];
				}
				i += 2;
			}
			else {
				cout << str[i];
			}
			
		}
		cout << endl;
	}
	return (0);
}

Measured memory_bytes: 1132
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,m,c=gsmi
b=gsmi
a=n.times.map{gsmi}

a.each do |i|
  sum = 0
  m.times do |j|
    sum+=i[j]*b[j]
  end
  sum+=c
  cnt+=1 if sum>0
end

puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

typedef pair<int, int> P;
char maze[50][50];
int d[50][50];
int sx, sy, gx, gy;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int H, W;

int bfs() {
	queue<P> que;
	REP(i, H) {
		REP(j, W) {
			d[i][j] = INF;
		}
	}
	que.push(P(sx, sy));
	d[sx][sy] = 0;

	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == gx && p.second == gy)break;
		REP(i, 4) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			//cout<<nx<<" "<<ny<<endl;
			if (0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF) {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gx][gy];
}

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

	
	cin >> H >> W;
	vector<string> S(H);
	int wcnt = 0;
	REP(i, H) {
		REP(j, W) {
			cin >> maze[i][j];
			if (maze[i][j] == '.')wcnt++;
		}
	}
	sx = 0;
	sy = 0;
	gx = H - 1;
	gy = W - 1;
	if (wcnt - bfs() - 1 < 0) {
		cout << -1 << endl;
		return 0;
	}
	cout << wcnt - bfs()-1 << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main(void)
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) {
		cin>>a[i];
	}
	sort(a,a+n);
	cout<<a[n-1]-a[0]<<endl;
}

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

using namespace std;

#define b 3
#define n2 9

const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};
const char dir[4]={'u','l','d','r'};

struct puzzle{
    int f[n2];
    int space;
    string path;
    bool operator < (const puzzle &p)const {
        for(int i=0;i<n2;i++){
            if(f[i]==p.f[i]){
                continue;
            }
            return f[i]>p.f[i];
        }
        return false;
    }
};

bool istarget(puzzle p)
{
    for(int i=0;i<n2;i++){
        if(p.f[i]!=(i+1)){
            return false;
        }
    }
    return true;
}

string bfs(puzzle s)
{
    queue<puzzle>q;
    map<puzzle,bool>V;
    puzzle u,v;
    s.path="";
    q.push(s);
    V[s]=true;
    while(!q.empty()){
        u=q.front();
//        for(int i=0;i<n2;i++){
//            cout<<u.f[i]<<" ";
//        }
//        cout<<endl;
        q.pop();
        if(istarget(u)){
            return u.path;
        }
        int sx=u.space/b;
        int sy=u.space%b;
//        cout<<sx<<" "<<sy<<endl;
        for(int r=0;r<4;r++){
            int tx=sx+dx[r];
            int ty=sy+dy[r];
            if(tx<0||ty<0||tx>=b||ty>=b){
                continue;
            }
            v=u;
            v.space=tx*b+ty;
            swap(v.f[v.space],v.f[u.space]);
            if(!V[v]){
                V[v]=true;
                v.path+=dir[r];
                q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main()
{
    puzzle in;
    for(int i=0;i<n2;i++){
        scanf("%d",&in.f[i]);
        if(in.f[i]==0){
            in.f[i]=n2;
            in.space=i;
        }
    }
    string ans=bfs(in);
    cout<<ans.size()<<endl;
    return 0;
}
/*
1 3 0
4 2 5
7 8 6
*/



Measured memory_bytes: 30704
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N;cin>>N;
    int A[110];
    for(int i=0;i<N;i++)cin>>A[i];
    sort(A,A+N);
    cout<<A[N-1]-A[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import sys

stdin = sys.stdin

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

n = ni()
co = []
for i in range(n):
    co.append(na())
    co[-1][1] += co[-1][0]
co.sort(key=lambda x: x[0])


class Segtreermq:
    def __init__(self, n):
        self.H = 1
        while self.H < n:
            self.H *= 2
        self.M = self.H * 2
        self.vals = [999999999999] * self.M

    def update(self, pos, v):
        self.vals[self.H+pos] = v
        x = self.H+pos>>1
        while x >= 1:
            self.vals[x] = min(self.vals[2*x], self.vals[2*x+1])
            x>>=1

    def min(self, l, r):
        ret = 999999999999999
        if l >= r:
            return ret
        while l != 0:
            f = l&-l
            if l+f > r:
                break
            v = self.vals[(self.H+l)//f]
            if v < ret:
                ret = v
            l += f

        while l < r:
            f = r & -r
            v = self.vals[(self.H+r)//f-1]
            if v < ret:
                ret = v
            r -= f
        return ret

xs = [_[0] for _ in co]

st = Segtreermq(n)
for i in range(n-1,-1,-1):
    ind = bisect.bisect_left(xs, co[i][1])
    reach = max(co[i][1], -st.min(i, ind))
    st.update(i, -reach)
    co[i][1] = reach

mod = 998244353
stack = []
dp = [0] * n
for i in range(n-1,-1,-1):
    val = 1
    while len(stack) > 0 and co[stack[-1]][1] <= co[i][1]:
        val = val * dp[stack[-1]] % mod
        stack.pop(-1)
    dp[i] = (val + 1) % mod
    stack.append(i)

ans = 1
for s in stack:
    ans = ans * dp[s] % mod
print(ans)


Measured memory_bytes: 106792
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;
use std::io;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        m: usize,
        bd: [[usize1]; n],
    }
    let mut cnt = vec![0; m];
    for ref row in bd.iter() {
        for &c in row.iter() {
            cnt[c] += 1;
        }
    }
    println!("{}", cnt.iter().filter(|&x| *x == n).count());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
std::string A, B;
 
void calcSum(int&, int&);
void throughTree(int&, std::string&);
int64_t calcNum(int&, std::string&);
 
int main()
{
    std::cin >> A >> B;
    int a_i{}, b_i{};
    calcSum(a_i, b_i);
    putchar('\n');
 
    return 0;
}
 
void calcSum(int& a_i, int& b_i)
{
    a_i++; b_i++;
    putchar('(');
    if (A[a_i] != ')' && B[b_i] != ')')
        calcSum(a_i, b_i);
    else if (A[a_i] != ')')
        throughTree(a_i, A);
    else if (B[b_i] != ')')
        throughTree(b_i, B);
    a_i++; b_i++;
    putchar(')');
 
    putchar('[');
    std::cout << std::to_string(calcNum(a_i, A) + calcNum(b_i, B));
    putchar(']');
 
    a_i++; b_i++;
    putchar('(');
    if (A[a_i] != ')' && B[b_i] != ')')
        calcSum(a_i, b_i);
    else if (A[a_i] != ')')
        throughTree(a_i, A);
    else if (B[b_i] != ')')
        throughTree(b_i, B);
    a_i++; b_i++;
    putchar(')');
 
    return;
}
 
void throughTree(int& s_i, std::string& str)
{
    if (str[s_i] == ')') return;
    s_i++;
    throughTree(s_i, str);
    s_i++;
 
    calcNum(s_i, str);
 
    s_i++;
    throughTree(s_i, str);
    s_i++;
 
    return;
}
 
int64_t calcNum(int& s_i, std::string& str)
{
    s_i++;
    int64_t ret{};
    while (str[s_i] != ']')
    {
        ret = 10 * ret + str[s_i] - '0';
        s_i++;
    }
    s_i++;
    return ret;
}


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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  string a, b;
  cin>>a>>b;
  int n = a.length();
  int m = b.length();

  int dp[n+1][m+1];

  for(int i = 0; i <= n; i++){
    dp[i][0] = 0;
  }

  for(int i = 0; i <= m; i++){
    dp[0][i] = 0;
  }

  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(a[i-1] == b[j-1])
        dp[i][j] = 1 + dp[i-1][j-1];
      else
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  // cout<<dp[n][m]<<"\n";

  // for(int i = 0; i <= n; i++){
  //   for(int j = 0; j <= m; j++){
  //     cout<<dp[i][j]<<" ";
  //   }cout<<"\n";
  // }

  string ans="";
  int i = n;
  int j = m;

  while(j>0 && i>0){
      if (a[i-1] == b[j-1]) 
      { 
          ans += a[i-1];
          i--; j--; 
      } 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
  };
  reverse(ans.begin(), ans.end());
  cout<<ans;

  return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   ll a;
   string b;
   cin>>a>>b;

   int ran=b.size()+2;
   rep(i, b.size()) if(b[i]=='.') ran=i+2+1;
   ll b100=0;
   for(int i=0; i<ran; i++){
      if(b[i]!='.'){
         b100*=10;
         if(i<b.size()) b100+=(b[i]-'0');
      }
   }

   cout << a*b100/100 << endl;
   return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  string S;
  cin>>S;

  char memo='X';
  ll ans=0;
  for(int i=0;i<N;i++){
    if(memo!=S[i]){
      ans++;
      memo=S[i];
    }
  }

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
        ll rel = abs(a-b);
        if(rel+w*t<=v*t) cout<<"YES";
        else cout<<"NO";
    }   
}



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


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

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000000007;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) {}
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) {}
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

int main(void) {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  mint pa = mint(a) / 100;
  mint pb = mint(b) / 100;
  mint pc = mint(c) / 100;

  mint res = 0;
  REP(i, n) {
    mint p = POW(pa / (pa+pb), n) * POW(pb / (pa+pb), i) * CMB(n-1+i, i); // 勝敗数がn:iになる確率
    mint e = mint(n+i) / (pa+pb); // その時の試合数の期待値
    res += p * e;
    // cerr << p << " " << e << " " << res << endl;
  }
  REP(i, n) {
    mint p = POW(pb / (pa + pb) , n) * POW(pa / (pa + pb), i) * CMB(n-1+i, i); // 勝敗数がi:nになる確率
    mint e = mint(n+i) / (pa+pb); // その時の試合数の期待値
    res += p * e;
    // cerr << p << " " << e << " " << res << endl;
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 1400
import sys


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def check(n):
    C = ["0", "1", "2", "3", "4", "5", "6", "8", "9"]
    for c in C:
        if c in str(n):
            return False
    return True


def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        return
    if K % 5 == 0:
        print(-1)
        return
    if K % 7 == 0:
        L = 9 * K // 7
    else:
        L = 9 * K
    cnt = 1
    amari = 10 % L
    while True:
        if amari == 1:
            print(cnt)
            return
        amari = amari * 10 % L
        cnt += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
void solve(){
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int x;
    cin>>x;
    x--;
    cout<<a[x];
}
    
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

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

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

char s[4];

int main() {
  scanf("%s", s);
  int count = 0;
  REP(i,3) if (s[i] == '1') ++count;
  printf("%d\n", count);
  return 0;
}

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

int main()
{
int p1=0,p2=0;
for(int i=0;i<4;i++){
int t;
cin>>t;
p1+=t;
}
for(int i=0;i<4;i++){
int t;
cin>>t;
p2+=t;
}
cout<<max(p1,p2)<<endl;
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    string days[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for (int i = 0; i < 7; i++) {
        if (s.compare(days[i]) == 0)
            cout << 7 - i << endl;
    }

	return 0;
}

Measured memory_bytes: 3600
//It's time to be who I am, rather than who I am supposed to be.
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int inf = 1e12;
const int N = 105;
const int W = 1e5 + 5;

int n, total, weight[N], value[N], dp[N][W];

int solve(int item, int remain){
	if(remain < 0)
		return -inf;
	if(remain == 0 || item == 0)
		return 0;

	int &ans = dp[item][remain];
	if(ans != 0)
		return ans;

	int take = value[item] + solve(item - 1, remain - weight[item]);
	int dont_take = solve(item - 1, remain);
		
	ans = max(take, dont_take);

	return ans;
}

int32_t main(){ 
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);


	cin >> n >> total;
	for(int i = 1; i <= n; i++)
		cin >> weight[i] >> value[i];

	cout << solve(n, total) << '\n';
    
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b;
    cin>>a>>b;
    int xd = 0;
    int ans = max(xd, a-2*b);
    cout<<ans;
}

Measured memory_bytes: 256
S = input()
l = len(S)
cnt = 0
if (S[0] == "A"):
    for i in range(2, l - 1):
        if (S[i] == "C"):
            cnt += 1

    if (cnt == 1):
        f = True
        for i in range(len(S)):
            if (S[i] != "A") and (S[i] != "C"):
                if (S[i].isupper()):
                    f = False
                    break
        if (f):
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a,b,v;
int rev(int n){
    int m=0;
while(n>0){
    m=m*10+n%10;
    n/=10;
}
return m;
}
bool ispal(int n){
    int m =rev(n);
if(n==m)
    return 1;
else
    return 0;
}

int main(){
scanf("%d %d",&a,&b);
int cnt=0;
for(int i=a;i<=b;++i){
    if(ispal(i))
        ++cnt;

}
printf("%d",cnt);


}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
int main(){
	int h,w;
	while(scanf("%d%d",&h,&w),(h|w)){
		bool field[16][100010] = {{0}};
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				int a;
				scanf("%d",&a);
				field[i][j] = a == 1;
			}
		}
		int ans = 0;
		for(int i = 0; i < (1 << h); i++){
			bool board[16][100010];
			for(int j = 0; j < h; j++){
				if(i & (1 << j)){
					for(int k = 0; k < w; k++){
						board[j][k] = !field[j][k];
					}
				}
				else{
					for(int k = 0; k < w; k++){
						board[j][k] = field[j][k];
					}
				}
			}
			for(int j = 0; j < w; j++){
				int black = 0,white = 0;
				for(int k = 0; k < h; k++){
					if(board[k][j]) black++;
					else white++;
				}
				if(black > white){
					for(int k = 0; k < h; k++){
						board[k][j] = !board[k][j];
					}
				}
			}
			int cnt = 0;
			for(int j = 0; j < h; j++){
				for(int k = 0; k < w; k++){
					if(!board[j][k])cnt++;
				}
			}
			ans = max(ans,cnt);
		}
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
vector<int> G[200100];
vector<int> rG[200100];
bool used[200100];
vector<int> vec;
int cmp[200100];
int sz[200100];
int loop_idx;
vector<int> loop;
vector<int> root_val;
void add_edge(int a,int b){
	G[a].pb(b);
	rG[b].pb(a);
}
void dfs(int v){
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]])dfs(G[v][i]);
	}
	vec.pb(v);
}
void rdfs(int v,int k){
	used[v]=true;
	cmp[v]=k;
	sz[k]++;
	for(int i=0;i<rG[v].size();i++){
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
}
void find_loop(int v,int k){
	used[v]=true;
	loop.pb(v);
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]]&&cmp[G[v][i]]==k)find_loop(G[v][i],k);
	}
}
void print(vector<int> &vect){
	for(int i=0;i<vect.size();i++){
		cout << vect[i];
		if(i+1<vect.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int rec(int v){
	vector<int> s;
	for(int i=0;i<G[v].size();i++){
		if(cmp[G[v][i]]==loop_idx)continue;
		s.pb(rec(G[v][i]));
	}
	sort(all(s));
	s.erase(unique(all(s)),s.end());
	for(int i=0;i<s.size();i++){
		if(s[i]!=i)return i;
	}
	return (int)s.size();
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		int p;
		cin >> p;
		p--;
		add_edge(p,i);
	}
	for(int i=0;i<N;i++){
		if(!used[i])dfs(i);
	}
	reverse(all(vec));
	int k=0;
	memset(used,false,sizeof(used));
	int l=-1;
	for(int i=0;i<vec.size();i++){
		if(!used[vec[i]]){
			rdfs(vec[i],k);
			if(sz[k]>1){
				l=vec[i];
				loop_idx=k;
			}
			k++;
		}
	}
	memset(used,false,sizeof(used));
	find_loop(l,loop_idx);
	for(int i=0;i<loop.size();i++){
		root_val.pb(rec(loop[i]));
		if(root_val.back()==-1){
			cout << "IMPOSSIBLE" << endl;
			return 0;
		}
	}
	//print(root_val);
	vector<int> tmp = root_val;
	int M = root_val.size();
	for(int i=M-1;i>0;i--){
		if(tmp[(i+1)%M]==tmp[i])tmp[i]++;
	}
	if(tmp[0]!=tmp[1]){
		cout << "POSSIBLE" << endl;
		return 0;
	}
	tmp = root_val;
	tmp[0]++;
	for(int i=M-1;i>0;i--){
		if(tmp[(i+1)%M]==tmp[i])tmp[i]++;
	}
	if(tmp[1]==tmp[0]-1){
		cout << "POSSIBLE" << endl;
		return 0;
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 32880
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);

		int m = s.nextInt();
		for (int x = 0; x < m; x++) {
			int moneyb = s.nextInt();
			int year = s.nextInt();
			int n = s.nextInt();

			int[] moneya = new int[n];
			int max = 0;

			for (int y = 0; y < n; y++) {
				int rate = s.nextInt();
				double rate_per_year = s.nextDouble();
				int fee = s.nextInt();

				if (rate == 0) {
					moneya[y] = SimpleInterester(moneyb, year, rate_per_year,
							fee);
				} else {
					moneya[y] = CompoundInterester(moneyb, year, rate_per_year,
							fee);
				}
			}

			for (int k = 0; k < n; k++) {
				if (max < moneya[k])
					max = moneya[k];
			}
			System.out.println(max);
		}
		s.close();
	}

	public static int CompoundInterester(int moneyc, int y, double rpy, int fee) {
		for (int i = 0; i < y; i++) {
			int b = (int) (moneyc * rpy);
			moneyc = moneyc + b - fee;
		}
		return moneyc;
	}

	public static int SimpleInterester(int moneys, int y, double rpy, int fee) {
		int b = 0;
		for (int i = 0; i < y; i++) {
			b += (int) (moneys * rpy);
			moneys = moneys - fee;
		}
		moneys += b;
		return moneys;
	}

}

Measured memory_bytes: 42008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int m, m2, b; cin >> m >> m2 >> b;
    if(m>=b) {
        cout << 0 << endl;
    }
    else if(m+m2<b) {
        cout << "NA" << endl;
    }
    else {
        cout << b-m << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i+=1)
using namespace std;

int main() {
  int K,X;
  cin >>K>>X;
  if(X-(K-1)>=-1000000 && X+K-1<=1000000) {
    for(int i =X-(K-1); i<=X+K-1; i+=1) {
      cout<<i<<" ";
    }
  }
  else if(X-(K-1)<=-1000000) {
    for(int i=-1000000; i<=X+K-1; i+=1) {
      cout<<i<<" ";
    }
  }
  else if(X-(K-1)>=1000000) {
    for(int i=X-(K-1); i<=1000000; i+=1) {
      cout<<i<<" ";
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vpll flag, D; vll path;
//***********//
int main() {
	string S, T;
	cin >> S >> T;
	N = S.length();
	for (i = 0; i < N; i++) {
		if (S[i] != T[i]) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3920
#include <stdio.h>
#include <string.h>
int main(void){
	char S[200];
	scanf("%s",S);
	int i=0;
	int len = strlen(S);
	while(len != i){
		//printf("S[%d] = %c\n",i,S[i]);
		if(i%2 == 0){
			if(S[i] != 'R' && S[i] !='U'&&S[i] != 'D'){
				printf("No");
				return 0;
			}
		}
		if(i%2 == 1){
			//printf("i = %d && S[i] = %c\n",i,S[i]);
			if(S[i] != 'L' && S[i] !='U'&&S[i] !='D'){
				printf("No");
				return 0;
			}
		}
		i++;
	}
	printf("Yes");
	return 0;
}



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

int main(){
    int N; cin >> N;
    int a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    int b[100010] = {};

    for(int i = 0; i < N; i++){
        if(a[i] != 0) b[a[i]-1]++;
        b[a[i]]++;
        b[a[i]+1]++;
    }
    int maxV = 0;
    for(int i = 0; i < 100000; i++){
        maxV = max(b[i], maxV);
    }
    cout << maxV << endl;
    



    return 0;
}

Measured memory_bytes: 1024