akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#define ll long long
#define N 200005
using namespace std;
int n,x,y;ll sum;
struct pi{
	ll a,b;
	pi(){};
	pi(ll _a,ll _b){
		a=_a;b=_b;
	}
}tmp[N];
vector<pi>h[N];
struct pl{int l,r,lv,rv;}s[N];
void add(int a,int b,int c){
	if(s[a].l==0) s[a].l=b,s[a].lv=c;
	else s[a].r=b,s[a].rv=c;
}
bool cmp(const pi &A,const pi &B){return A.a<B.a||A.a==B.a&&A.b<B.b;} 
void dfs(int a,int fa,ll v,int w){
	if(s[a].l==0){h[a].push_back(pi(w,w));return;}
	else dfs(s[a].l,a,v,s[a].lv),dfs(s[a].r,a,v,s[a].rv);
	if(h[s[a].l].size()>h[s[a].r].size()) swap(s[a].l,s[a].r),swap(s[a].lv,s[a].rv);
	if(h[s[a].l].size()==0) return;
	int l=0,top=0;
	for(int i=0;i<h[s[a].l].size();i++){
		while(l<h[s[a].r].size()&&h[s[a].r][l].a+h[s[a].l][i].b<=v) l++;
		if(l!=0) top++,tmp[top]=pi(h[s[a].l][i].a+w,h[s[a].r][l-1].b+w);
	}
	int tip=top;
	for(int i=1;i<=tip;i++)
		if(tmp[i].a!=tmp[i].b) top++,tmp[top]=pi(tmp[i].b,tmp[i].a);
	sort(tmp+1,tmp+1+top,cmp);
	if(top!=0) h[a].push_back(tmp[1]);
	for(int i=2;i<=top;i++)
		if(tmp[i].b<h[a][h[a].size()-1].b) h[a].push_back(tmp[i]);
}
int main()
{
	//freopen("cc.in","r",stdin);
	//freopen("cc.out","w",stdout);
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&x,&y),add(x,i,y),sum+=y;
	ll l=0,r=min(sum,(ll)1e10);
	while(l+1<r){
		ll mid=(l+r)/2;
		for(int i=1;i<=n;i++) h[i].clear();
		dfs(1,0,mid,0);
		if(h[1].size()!=0) r=mid;else l=mid;
	}
	for(int i=1;i<=n;i++) h[i].clear();
	dfs(1,0,l,0);if(h[1].size()!=0) r--;else l++;
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 32936
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            double[] s = ReadLine().Split(' ').Select(double.Parse).ToArray();

            double ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                ans += 1 / s[i];
            }
            WriteLine(1/ans);

        }
    }
}


Measured memory_bytes: 13268
import math
a,b,h,m = map(int, input().split())

deg_a = 30 * (h + m / 60)
deg_b = m * 6

theta = abs(deg_a - deg_b)
theta = min(360 - theta, theta)
out = math.pow(math.pow(a,2) + pow(b,2) - 2 * a * b * math.cos(theta * math.pi / 180.0), 0.5);

print(out)


Measured memory_bytes: 9564
x = int(input())
if x < 600:
    print(8)
elif x < 800:
    print(7)
elif x < 1000:
    print(6)
elif x < 1200:
    print(5)
elif x < 1400:
    print(4)
elif x < 1600:
    print(3)
elif x < 1800:
    print(2)
else:
    print(1)



Measured memory_bytes: 61624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(ll i=l;i<r;i++)
#define rrep(i,l,r) for(ll i=(r)-1;i>=l;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define range(i) i.begin(),i.end()
#define sum(i) accumulate(range(i),0)
struct start { start() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }start;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head, Tail&&... tail) {
	cin >> head;
	in(move(tail)...);
}
template <class T>
inline void out(T t) {
	cout << t << '\n';
}
template <class Head, class... Tail>
inline void out(Head head, Tail... tail) {
	cout << head << ' ';
	out(move(tail)...);
}
template <class T>
inline void out(vector<T> a){
    rep(i,0,a.size()-1)cout<<a[i]<<' ';
    out(a.back());
}



int main() {
    string s;
    in(s);
    if(s[0]-'A'){
        out("WA");
        return 0;
    }
    if(s[1]>'z'||s[1]<'a'){
        out("WA");
        return 0;
    }
    int C=0;
    rep(i,2,s.size()-1){
        if(s[i]=='C')C++;
        else if(s[i]<'a'||s[i]>'z'){
        out("WA");
        return 0;
        }
    }
    if(s.back()>'z'||s.back()<'a'){
        out("WA");
        return 0;
    }
    out(C-1?"WA":"AC");
} 









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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) (n)*(n)

using namespace std;
typedef long long ll;

int main() {
    FAST;

    ll n;
    cin>>n;

    if(n>=400 && n<=599)cout<<"8"<<endl;
    else if(n>=600 && n<=799)cout<<"7"<<endl;
    else if(n>=800 && n<=999)cout<<"6"<<endl;
    else if(n>=1000 && n<=1199)cout<<"5"<<endl;
    else if(n>=1200 && n<=1399)cout<<"4"<<endl;
    else if(n>=1400 && n<=1599)cout<<"3"<<endl;
    else if(n>=1600 && n<=1799)cout<<"2"<<endl;
    else if(n>=1800 && n<=1999)cout<<"1"<<endl;



    return 0;
}




Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
  int H,W;
  while (true) {
    cin >> H >> W;
    if(H == 0 && W == 0)break;
    for(int i=0; i < H; ++i){
      for(int j=0; j < W ;++j){
        if((i+j) % 2 == 0) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
N = int(input())
A = [int(x) for x in input().split()]
x = [0]*N
for i in range(N):
  x[0] += ((-1)**i)*A[i]
for i in range(1,N):
  x[i] = -x[i-1]+2*A[i-1]
for i in range(N):
  print(x[i],end=" ")
print()

Measured memory_bytes: 20712
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n,k;
  cin>>n>>k;
  long double a[n];
  long double maxa=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    maxa=max(maxa,a[i]);
  }
  long double lb=0, ub=maxa;
  for(int i=0;i<100;i++){
    long double mid=(lb+ub)/2.0;
    ll num=0;
    for(int j=0;j<n;j++){
      ll temp=(ll)(a[j]/mid);
      if((long double)temp*mid==a[j]){
        num+=temp-1;
      }
      else num+=temp;
    }
    if(num<=k) ub=mid;
    else lb=mid;
  }
  cout<<(ll)(lb+0.9999999999)<<endl;
  return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int cnt[MAXN], bb[MAXN];

void solve(){
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	REPN(i, 1, n){
		cnt[i] = 1;
	}
	bb[1] = 1;
	REP(i, 0, m){
		scanf("%d%d", &x, &y);
		cnt[x]--;
		cnt[y]++;
		if (bb[x]){
			bb[y] = 1;
			if (cnt[x] == 0){
				bb[x] = 0;
			}
		}
	}
	int ans = 0;
	REPN(i, 1, n){
		ans += bb[i];
	}
	printf("%d\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

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

int main(void){
    int x,n,i,j,ans;
    ans = 1000;
    cin >> x >> n;

    vector<int> p(n);
    vector<int> list(110);

    for(i=0; i<n; i++){
        cin >> p.at(i);
    }

    for(i=0; i<=101; i++){
        list.at(i) = abs(x-i);
        for(j=0; j<n; j++){
            if(i == p.at(j)){
            list.at(i) = 1000;
            }
        }
        ans = min(list.at(i),ans);
    }

    for(i=0; i<=101;i++){
        if(list.at(i) == ans){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int N;
	cin >> N;
	vector<double> x(N);
	vector<string> u(N);
	double otoshidama = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> u[i];
		if (u[i] == "JPY") {
			otoshidama += x[i];
		}
		else {
			otoshidama += x[i] * 380000;
		}
	}

	cout << otoshidama;

	return 0;
}

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

int main() {
	int n, h, w; cin >> n >> h >> w;
	int ans = 0;
	for (int i = 0; i < n; i ++) {
		int a, b; cin >> a >> b;
		if (a >= h && b >= w) ans ++;
	}
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N ()
#define ll long long
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;

bool MOP2;
int main(){
	int n;
	double ans=0.0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int res;
		scanf("%d",&res);
		ans+=1.0/res;
	}
	printf("%.6lf\n",1.0/ans);
	return 0;
}
 





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

int main()
{
    int h, w, n;
    cin >> h >> w >> n;

    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    vector<int> ans(h * w);

    ll cnt = 0;
    rep(i, n)
    {
        rep(j, a.at(i))
        {
            ans.at(cnt + j) = i + 1;
        }

        cnt += a.at(i);
    }

    rep(i, h)
    {
        if (i % 2 == 0)
        {
            rep(j, w)
            {
                cout << ans.at(i * w + j) << " ";
            }
        }
        else
        {
            for (int j = w - 1; j >= 0; j--)
            {
                cout << ans.at(i * w + j) << " ";
            }
        }

        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3672
#include<iostream>
using namespace std;
int main(){
  int N, M, C;
  cin >> N >> M >> C;
  int B[21];
  int A[21];
  for(int i = 0; i < M; ++i) cin >> B[i];
  int count = 0, ans = 0;
  for(int j = 0; j < N; ++j){
    for(int i = 0; i < M; ++i){
    cin >> A[i];
    ans += A[i]*B[i];
    }
    ans += C;
    if( ans > 0) ++count;
    ans = 0;
  }
  cout << count <<endl;
    return 0;
}

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

int main()
{
	int N, D;

	cin >> N >> D;

	int ans;
	if (N % (D * 2 + 1) == 0)
	{
		ans = N / (D * 2 + 1);
	}
	else
	{
		ans = N / (D * 2 + 1) + 1;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, L;
    cin >> N >> L;

    vector<int> arr;
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        int cur = L + i - 1;
        sum += cur;
        arr.push_back(cur);
    }

    int minsub = INT_MAX;
    int ans = 0;
    for (int j = 0; j < N; j++) {
        int cur = arr[j];
        int leftsum = sum - cur;
        int cursub = abs(sum - leftsum);
        if (minsub > cursub) {
            minsub = cursub;
            ans = leftsum;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(all(a));

    // よい集合が存在しないとき
    if(sum < k) {
        out(n);
        re0;
    }

    // 以下よい集合は存在する。

    // まずa[i]が必要かどうかは
    // 「要素の総和がk-a[i]以上k未満のa[i]を含まない部分集合が存在するならa[i]は必要。そうでなければ不必要」
    // と判定できる。

    // 次に解の単調性 「a[i] < a[j]のとき、a[j]が不必要 ⇒ a[i]も不必要」 を示す。
    // 仮定より要素の総和がk-a[j]以上k未満のa[j]を含まない部分集合は存在しない。
    // つまりa[j]を含まない部分集合の要素の総和はk-a[j]未満またはk以上。
    // k-a[j] < k-a[i] より要素の総和がk-a[i]以上k未満のa[i]もa[j]も含まない部分集合は存在しない。
    // a[j]を含む部分集合の要素の総和はk未満またはk+a[j]以上なので、
    // a[j]を含むがa[i]は含まない部分集合の要素の総和はk-a[i]未満またはk+a[j]-a[i]以上。
    // k < k + (a[j] - a[i]) より要素の総和がk-a[i]以上k未満のa[j]を含むがa[i]は含まない部分集合は存在しない。
    // 以上よりa[j]を含むかどうかによらずa[i]は不必要。
    
    // 判定問題「a[x]は不必要か？」を二分探索で解く
    ll left = -1;
    ll right = n;
    while(right - left > 1) {
        ll x = (left + right)/2;
        vector<vector<bool>> dp(n+1, vector<bool>(k+1, false));  // dp[i+1][j] : a[i]までで総和をjにできるならtrue
        dp[0][0] = true;
        rep(i, n) {
            exrep(j, 0, k) {
                if(dp[i][j]) {
                    dp[i+1][j] = true;
                }
                if(i == x) {
                    continue;
                }
                if(j >= a[i] && dp[i][j - a[i]]) {
                    dp[i+1][j] = true;
                }
            }
        }
        bool noneed = true;
        exrep(j, max(0LL, k-a[x]), k-1) {
            if(dp[n][j]) {
                noneed = false;
            }
        }
        if(noneed) {
            left = x;
        }
        else {
            right = x;
        }
    }

    out(right);
    re0;
}

Measured memory_bytes: 3660
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int M1, D1, M2, D2;
	boolean result = false;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		M1 = Integer.parseInt(tokens[0]);
		D1 = Integer.parseInt(tokens[1]);
		tokens = in.readLine().split(" ");
		M2 = Integer.parseInt(tokens[0]);
		D1 = Integer.parseInt(tokens[1]);

	}

	void calc() {
		if (M1 != M2) {
			result = true;
		}
	}

	void showResult() {
		System.out.println(result ? 1 : 0);
	}
}


Measured memory_bytes: 21204
#include <stdio.h>

int main() {

	int i, j, k, n, x, count = 0;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		for (i = 1; i <= n - 2; i++) {
			for (j = i + 1; j <= n - 1; j++) {
                for (k = j + 1; k <= n; k++) {
					//printf("%d + %d + %d = %d\n", i, j, k, i + j + k);
					if (i + j + k == x) count++;
				}
			}
		}
		printf("%d\n", count);
		count = 0;
	}

}


Measured memory_bytes: 2092
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    #a, b, c = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    cnt = 0
    while not (A[0] == A[1] and A[0] == A[2]):
        A = sorted(A)
        if A[2] - A[0] >=2:
            A[0] += 2
        else:
            A[0] += 1
            A[1] += 1
        cnt += 1

    print(cnt)


resolve()

Measured memory_bytes: 38256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
int pw(int a, int b) {
    int c = 1;
    for (int i = 0; i  < b;i ++) {
        c = (1LL * c * a) % mod;
    }
    return c;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    ll f = pw(10, n);
    f -= 2LL * pw(9, n);
    f += pw(8, n);
    f %= mod;
    if (f < 0) f += mod;
    cout << f;
    return 0;
}


Measured memory_bytes: 3508
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String mozi = scan.next();

		System.out.println(mozi.substring(2,3).equals(mozi.substring(3,4)) && mozi.substring(4,5).equals(mozi.substring(5,6))?"Yes":"No");

		scan.close();

	}

}


Measured memory_bytes: 25044
n = int(input())

count = 1
ans = []
dict = {}

for i in range(n):
    s = input()
    if s in dict:
        dict[s] += 1
        count = max([count,dict[s]])
    else:
        dict[s] = 1

for k in dict:
    if dict[k]==count:
        ans.append(k)

ans.sort()

for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 32096
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        A[i]--;
    }

    set<int> used;
    vector<int> perm;
    int now = 0;
    while (used.count(now) == 0) {
        perm.push_back(now);
        used.insert(now);
        now = A[now];
    }

    int s = find(ALL(perm), now) - perm.begin();
    /*
    cerr << s << endl;
    for (int i = 0; i < (int)perm.size(); i++) {
        cerr << perm[i];
    }
    cerr << endl;
    */
    if (K <= s) {
        cout << perm[K] + 1 << endl;
        return 0;
    } else {
        K -= s;
        K %= (int)perm.size() - s;
        cout << perm[s + K] + 1 << endl;
        return 0;
    }
}


Measured memory_bytes: 13884
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int r = sc.nextInt();
			int c = sc.nextInt();
			if(r==0 && c==0)
				break;
			
			int[][] field = new int[r][c];
			for(int i=0;i<r;i++){
				for(int j=0;j<c;j++){
					field[i][j] = sc.nextInt();
				}
			}
			
			solve(r, c, field);
		}
	}

	private void solve(int r, int c, int[][] field) {
		int[][] reverseField = new int[r][c];
		for(int i=0;i<field.length;i++){
			for(int j=0;j<field[i].length;j++){
				reverseField[i][j] = 1-field[i][j];
			}
		}
		
		int res = 0;
		int[][] curField = new int[r][c];
		for(int i=0;i<(1<<r);i++){
			for(int j=0;j<r;j++){
				if((i>>j)%2==0)
					curField[j] = reverseField[j];
				else
					curField[j] = field[j];

			}
			res = Math.max(res, calcFineOsenbei(curField));
		}
		System.out.println(res);
	}

	private int calcFineOsenbei(int[][] field){
		int res = 0;
		for(int i=0;i<field[0].length;i++){
			int rowCount = 0;
			for(int j=0;j<field.length;j++){
				rowCount += field[j][i];
			}
			res += Math.max(rowCount, field.length-rowCount);
		}
		return res;
	}
}

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

struct Pair
{
    long A;
    long B;
    Pair(long A2, long B2)
    {
        A=A2;
        B=B2;
    }
    bool operator<(const Pair &another) const
    {
        if(A==another.A){
            return B < another.B;
        }else{
            return A< another.A;
        }
    }
};

int main()
{
    long N,M;
    std::cin >> N >> M;
    std::vector<Pair> AB;
    for(long i=0; i<N; i++){
        long tempA,tempB;
        std::cin >> tempA >> tempB;
        AB.push_back(Pair(tempA,tempB));
    }
    std::sort(AB.begin(),AB.end());
    long result=0;
    for(long i=0; i<N; i++){
        if(AB[i].B<M){
            result+=AB[i].A*AB[i].B;
            M-=AB[i].B;
        }else{
            result+=AB[i].A*M;
            M=0;
        }
        if(M==0){
            break;
        }
    }
    std::cout << result << std::endl;
    return 0;
}

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

const long long INF = (long long) 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = accumulate(a.begin(), a.end(), 0ll);
  long long ans = INF;
  long long cur = 0ll;
  for (int i = 0; i < n; i++) {
    cur += a[i];
    ans = min(ans, abs(sum - cur - cur));
  }
  cout << ans << '\n';
  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) (n)*(n)

using namespace std;
typedef long long ll;

int main() {
    FAST;

    string s;
    cin>>s;
    ll n=s.size();
    if(s[n-1]=='s')
    {
        cout<<s<<"es"<<endl;
    }
    else
    {
        cout<<s<<"s"<<endl;
    }


    return 0;
}






Measured memory_bytes: 3648
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}



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

int main(){
      int n;cin >> n;
      int arr[n + 10];
      int ans = 0;
      for(int i = 0;i < n;i++)cin >> arr[i];
      for(int i = 1;i < n - 1;i++){
            if((arr[i] > arr[i - 1] && arr[i] < arr[i + 1]) ||
            (arr[i] < arr[i - 1] && arr[i] > arr[i + 1]))ans++;
      }
      cout << ans;
}

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

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

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

	int sum = 0;

	for (int i = 0;i < 4;i++){
		int tmp; cin >> tmp;
		sum += tmp;
	}

	cout << sum/60 << endl << sum%60 << endl;

	return 0;

}



Measured memory_bytes: 3124
;;; Utils

(defmacro read-numbers-to-list ()
  `(read-from-string
    (concatenate 'string "(" (read-line) ")")))


(defmacro read-line-to-array (dimension)
  (if (< dimension 0)
      (error "invalid arguments for dimension.")
      `(make-array ,dimension :initial-contents (read-numbers-to-list))))

(defmacro read-line-to-char-list ()
  `(concatenate 'list (read-line)))

(defmethod make-cumlative-sum ((sequence list))
  (labels ((inner (sequence &optional (acc '(0)))
             (if (null sequence)
                 (reverse acc)
                 (inner (rest sequence) (cons (+ (first sequence)
                                                 (first acc))
                                              acc)))))
    (inner sequence)))





(defmethod princ-for-each-line ((sequence list))
  (labels ((inner (sequence)
             (if (null sequence)
                 nil
                 (progn
                   (fresh-line)
                   (princ (first sequence))
                   (inner (rest sequence))))))
    (inner sequence)))

(defmethod princ-for-each-line ((sequence array))
  (dotimes (i (length sequence))
    (fresh-line)
    (princ (aref sequence i))))



;;; Write code here

(defun count-difference (str1 str2)
  (assert (= (length str1) (length str2)))
  (labels ((inner (s1 s2 &optional (cnt 0))
             (cond
               ((null s1) cnt)
               ((char-equal (first s1) (first s2))
                (inner (rest s1) (rest s2) cnt))
               (t
                (inner (rest s1) (rest s2) (1+ cnt))))))
    (inner str1 str2)))



(defun solve (bigger smaller)
  (let ((b-len (length bigger))
        (s-len (length smaller)))
    (labels ((inner (bigger smaller &optional (ans 10001) (cnt 0))
               (if (= cnt (1+ (- b-len s-len)))
                   ans
                   (progn
                     (if (<= (count-difference (subseq bigger 0 s-len) smaller)
                             ans)
                         (setf ans (count-difference (subseq bigger 0 s-len) smaller)))
                     (inner (rest bigger) smaller ans (1+ cnt))))))
      (inner bigger smaller))))




(defun main ()
  (let ((str1 (read-line-to-char-list))
        (str2 (read-line-to-char-list)))
    (format t "~a~%" (solve str1 str2))))

(main)


Measured memory_bytes: 32948
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

map<pair<ll, ll>, ll> color;

int main() {
    ll n; cin >> n;
    vector<P> r, b;
    rep(i, 0, n){
        ll a, b; cin >> a >> b;
        r.push_back({a, b});
    }
    rep(i, 0, n){
        ll c, d; cin >> c >> d;
        b.push_back({c, d});
    }
    sort(ALL(r));
    sort(ALL(b));
    ll ans = 0;
    rep(i, 0, n){
        ll bx = b[i].fi, by = b[i].se;
        ll pay = -1;
        ll px = -1, py = -1;
        rep(j, 0, n){
            ll rx = r[j].fi, ry = r[j].se;
            if(color[{rx, ry}]) continue;
            if(rx >= bx || ry >= by ) continue;
            if(ry > pay){
                pay = ry;
                px = rx, py = ry;
            }
        }   
        if(pay == -1) continue;
        color[{px, py}] = 1;
        ans++;
    }
    co(ans);


    return 0;
}


Measured memory_bytes: 256
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    
const int N = 2e5+5;

ll dp[N];

const ll INF = 1e18+5;

//dp[i] = max possible sum of beauties if last flower taken is ith

int n;
ll T[2*N];

void build(){
    for(int i = n-1; i >= 0; --i){
        T[i] = max(T[i<<1], T[i<<1 | 1]);
    }
}

void modify(int p, ll val){
    for(T[p+=n]= val; p > 1; p >>= 1){
        T[p>>1] = max(T[p],T[p^1]);
    }
}

ll query(int l, int r){
    ll res = 0;
    for(l += n, r += n; l < r; l >>= 1, r >>= 1){
        if(l&1)res= max(res,T[l++]);
        if(r&1)res= max(res, T[--r]);
    }
    return res;
}



int main(){
   IOS

    cin>>n;

   vi h(n), a(n);

   for(int & x : h)cin>>x, x--;
   for(int & x : a)cin>>x;


    for(int flower  = 0; flower < n; flower++){ 
        ll best = query(0, h[flower]);
        dp[h[flower]] = best + a[flower];
        modify(h[flower], dp[h[flower]]);
    }

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


    cout<<ans<<"\n";
    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }

int main() {
    int n, cnt;
    cin >> n;
    cnt = n;
    vector<pair<int, int>> all;
    for (int i = 0; i < n; i++) {
        int a, b;
        pair<int, int> tmp;
        cin >> a >> b;
        tmp.first = a - b;
        tmp.second = a + b;
        all.push_back(tmp);
    }
    sort(all.begin(), all.end(), cmp);
    for (int i = 0; i < n - 1; i++) {
        if (all[i].second > all[i + 1].first) {
            all[i + 1].second = all[i + 1].first = all[i].second;
            --cnt;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 1400
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
i64 dp[303][303][303]; // day, unvis, size of 0 unit

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i <= M; ++i) {
		for (int j = 0; j <= N; ++j) {
			for (int k = 0; k <= N; ++k) {
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][N - 1][1] = 1;
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j <= N; ++j) {
			for (int k = 0; k <= N; ++k) if (dp[i][j][k]) {
				ADD(dp[i + 1][j][N - j], k * dp[i][j][k]);
				if (j > 0) ADD(dp[i + 1][j - 1][k], j * dp[i][j][k]);
				ADD(dp[i + 1][j][k], (N - k - j) * dp[i][j][k]);
			}
		}
	}
	printf("%lld\n", dp[M][0][N]);
	return 0;
}


Measured memory_bytes: 215936
N = int(input())
if N == 1:
    print(1)
    exit()
xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
items = list(set(d_list))
s = 1
for item in items:
    c = d_list.count(item)
    if c > s:
        s = c
print(N - s)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define up(i,a,b) for(int i=a;i<=b;i++)
#define down(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>b;i--)
#define self (*this)
#define pb push_back
#define cntbit(x) __builtin_popcountll(x)
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<ll,int> pli;

const int maxn=1e3+7;
const int maxb=5e3+7;
const ll mod=777777777;
const int inf=1e9+7;
const ll linf=1e16+7;
const double esp=1e-6;

int n,m,res=1;

inline void Enter(){
    cin>>n>>m;
}

inline void Solve(){
    for(int d=1;1ll*d*d<=1ll*m;d++){
        if(m%d) continue;
        if(d<=m/n) res=max(res,d);
        if(m/d<=m/n) res=max(res,m/d);
    }
    cout<<res;
}

inline void Main(){
    Enter();
    Solve();
}

inline void Execution_Time_Calculator(const bool &Allow){
    auto start = chrono::steady_clock::now();
    Main();
    if(not Allow) return;
    auto end=chrono::steady_clock::now();
    cerr<<"\n\nIn milliseconds: "
        <<chrono::duration_cast<chrono::milliseconds>(end-start).count();
    cerr<<'\n' << "In seconds: "<<fixed<<setprecision(3)
        <<(double)chrono::duration_cast<chrono::milliseconds>(end-start).count()/1000<<'\n';
}

inline void Input_Output_From_File(const bool &Allow){
    if(not Allow) return;
    #define task "TEST"
    freopen(task".INP","r",stdin);
    freopen(task".OUT","w",stdout);
}

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

    Input_Output_From_File(0);
    Execution_Time_Calculator(1);

    return 0;
}


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

int main(){
    int k;
    cin >> k;
    rep(i,k) cout << "ACL";
    cout << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    ll p[n], cnt0 = 0, cnt2 = 0, cnt4 = 0;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        ll cnt = 0;
        while (a % 2 == 0) {
            a /= 2;
            cnt++;
        }
        p[i] = cnt;
        if (cnt >= 2) cnt4++;
        else if (cnt == 1) cnt2++;
        else cnt0++;
    }
    if (cnt4 >= cnt0 || (cnt2 == 0 && cnt4 + 1 >= cnt0)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String abc = sc.next();
        char ONE = '1';
        int cnt = 0;
        for (char s : abc.toCharArray()) {
            if(ONE == s) {
                cnt++;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a<c&&b>c){
        cout << "Yes" << endl;
        return 0;
    }
    if(a>c&&b<c){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int shiro = 0;
  int kuro = 0;
  for( int i = 0; i < N; i++ ){
    cin >> S.at(i);
    if( S.at(i) == '.' ) shiro++;
    else kuro++;
  }
  
  int ans = shiro;
  int maekuro = 0;
  for( int i = 0; i < N; i++ ){
    if( S.at(i) == '.' ){ //もしi=白だったら
      shiro--;
    }else{ //もしi=黒だったら
      maekuro++;
    }
    if( shiro + maekuro < ans ) ans = shiro + maekuro;
   }
  cout << ans << endl;
}

Measured memory_bytes: 640
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,b) for(ll i=(b)-1; i>=a; --i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scanv(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#define square(x) x*x
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------

struct P {
    double x,y;
};

int n;
vector<P> p;

double dist(P a,P b){
    double dx = a.x-b.x;
    double dy = a.y-b.y;
    return (dx*dx+dy*dy);
}
double f(double x,double y){
    double res = 0;
    rep(i,n){
        res = max(res,dist((P){x,y},p[i]));
    }
    return res;
}
double g(double x){
    double  l=0,r=1000;
    rep(i,80){
        double c1 = (l*2+r)/3;
        double c2 = (l+r*2)/3;
        if(f(x,c1) > f(x,c2)) l = c1; else r = c2;
    }
    return f(x,l);
}

void input(){
}
void src(){
    cin>>n;
    p.resize(n);
    rep(i,n) cin>>p[i].x>>p[i].y;

    double l=0,r=1000;
    rep(i,80){
        double c1 = (l*2+r)/3;
        double c2 = (l+r*2)/3;
        if(g(c1) > g(c2)) l = c1; else r = c2;
    }
    double ans = sqrt(g(l));
    printf("%.10f",ans);
    return;
}    
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
}

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

//?????????
#pragma region MACRO 
#define putans(x)   cout << (x) << endl
#define dputans(x) std::cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //???????????????????????????????????????????????????
std::ifstream ifs("data.txt");
#define p ifs >>
#else //?????£????????????????????§?????????????????????
#define p cin >>
#endif
#pragma endregion

//???????????°??????????????´
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef????????????????????????????¶????????????§?????????
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//??????????????°(???????????????????????§??????)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

ll power(ll m,ll n, ll mod = MOD ){
	ll ans = 1;
	ll mbin = m;
	for (ll i = 1 ; i <= n; i *= 2) {
		if ((n & i) != 0) {
			ans *= mbin; ans %= mod;
		}
		mbin = (mbin * mbin) % mod;
	}
	return ans;
}

int main() {
	int m, n; p m >> n;
	ll k = power(m, n);
	putans(k);
	return 0;
}

/*
#define i(x) int x; scanf("%d",&x);
#define l(x) ll x; scanf("%lld",&x);
#define d(x) double  x; scanf("%lf",&x);
*/
//??????????£?????????°???
//https://www23.atwiki.jp/akitaicpc/pages/65.html

Measured memory_bytes: 3104
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


int main(void){
  string T;
  cin >> T;
  ll N = 0, W = 0, S = 0, E = 0;
  rep(i, T.size()){
    if(T[i] == 'N') N++;
    if(T[i] == 'W') W++;
    if(T[i] == 'S') S++;
    if(T[i] == 'E') E++;
  }
  if(((N + S) && !(N * S)) || ((W + E) && !(W * E))) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
# B - Greedy Takahashi
a,b,k = map(int,input().split())
if a < k:
    k -= a
    a = 0  
    if b < k:
        b = 0
        print(a,b)
    else:
        print(a,b-k)
else:
    print(a-k,b)

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

int main()
{
    int N;
    cin >> N;
    vector<int> blocks(N, 0);
    for (int i; i < N; i++) {
        cin >> blocks.at(i);
    }

    int count = 0;
    int current_index = 0;
    int current_num = 1;

    for (int i; i < N; i++)
    {
        if (blocks.at(i) == current_num) {
            current_num++;
            continue;
        }
    }
    int ans;
    if (current_num == 1) {
        ans = -1;
    } else {
        ans = N - (current_num - 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define chkmin(x,y) x=min(x,y)
#define ll long long
using namespace std;
const int Md=1000000007;
int n,m,k,tim,top=0,low[55],dfn[55];
bool vis[55];
ll mi[210],ans=1,fac[210],ifac[210],inv[210];
struct edge
{
  int t;bool vis;
  edge *nx,*rev;
}*con[55],*st[110];

void ins(int x,int y)
{
  edge *p=new edge;
  p->t=y; p->vis=0; p->nx=con[x]; con[x]=p;
}

ll ksm(ll a,int b)
{
	ll r=1;
	for(;b;b>>=1)
	{
		if(b&1)r=r*a%Md;
		a=a*a%Md;
	}
	return r;
}

int gcd(int x,int y)
{
	return y?gcd(y,x%y):x;
}

void tarjan(int v,edge *fro)
{
  dfn[v]=low[v]=++tim;
  for(edge *p=con[v];p;p=p->nx)
    if(!p->vis&&!p->rev->vis)
    {
      st[++top]=p;p->vis=p->rev->vis=1;
      if(!dfn[p->t])
      {
        tarjan(p->t,p);
        chkmin(low[v],low[p->t]);
        if(low[p->t]>=dfn[v])
        {
          bool cir=1;int cnt=0;ll cal=0;
          for(int i=top;st[i+1]!=p;cnt++,i--)
            if(vis[st[i]->t]) cir=0;
            else vis[st[i]->t]=1;       
          if(cir)
          {
            for(int i=0;i<cnt;i++)  
              cal=(cal+mi[gcd(cnt,i)])%Md;
            cal=cal*inv[cnt]%Md;   
          }
          else cal=fac[cnt+k-1]*ifac[cnt]%Md*ifac[k-1]%Md;
          ans=ans*cal%Md;
          for(;st[top+1]!=p;top--) vis[st[top]->t]=0;
        }
      }
      else chkmin(low[v],dfn[p->t]);
    }
}

int main()
{
  scanf("%d%d%d",&n,&m,&k);
  mi[0]=1;
  for(int i=1;i<=m;i++) mi[i]=mi[i-1]*k%Md;
  fac[0]=1;
  for(int i=1;i<=m+k;i++) fac[i]=fac[i-1]*i%Md;
  ifac[m+k]=ksm(fac[m+k],Md-2);
  for(int i=m+k-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%Md;
  for(int i=1;i<=m+k;i++) inv[i]=ifac[i]*fac[i-1]%Md;            
  for(int i=1;i<=m;i++)
  {
    int x,y;
    scanf("%d%d",&x,&y);
    ins(x,y);ins(y,x);
    con[x]->rev=con[y]; con[y]->rev=con[x];
  }
  for(int i=1;i<=n;i++)
    if(!dfn[i]) tarjan(i,NULL);
  printf("%lld",ans); 
  return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x:x[1], reverse=True)

D = [0]*N
cnt = 0
for bc in BC:
    if cnt == N: break
    b, c = bc[0], bc[1]
    for _ in range(b):
        if cnt == N: break
        D[cnt] = c
        cnt += 1

ans = 0
for i in range(N):
    ans += max(A[i], D[i])
print(ans)


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

main()
{
int A,B,C,D, a[1000],b[1000],c[1000],n,aaa,k,i,r=0,rr=0,d1,dd=0,d2,d3,ck=0,m,j,aa,bb,cc;
//char cr[1000];
//scanf("%lld",&n);
//cin>>A>>B>>C>>D;
cin>>n;

for(i=1;i<=n;i++){

        for(j=1;j<=n;j++){

            for(k=1;k<=n;k++){
                aa=i;
                bb=j;
                cc=k;


        int x,y,z;
   // cout<<a[i]<<b[i]<<c[i]<<endl;




    if((aa<bb)&&(aa<cc)){
        x=aa;
    }
    else if((bb<aa)&&(bb<cc)){
        x=bb;
    }
    else{
        x=cc;
    }
  vvv:  if((aa%x==0)&&(bb%x==0)&&(cc%x==0)){
            y=x;

        dd=dd+y;
        x=123456;
    }

   if(x!=123456){
    x=x-1;
   }
    if(x!=123456)goto vvv;



}

}}

  cout<<dd;
//printf("%lld",dd);

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int n;
string s;
ll ans = 0;
void dfs(int x, string v) {
  if (x == n) {
    istringstream stream(v);
    string vv;
    while (getline(stream, vv, '+')) {
      ans += stol(vv);
    }
    return;
  }
  if (x < n - 1)
    dfs(x + 1, v + s[x] + "+");
  dfs(x + 1, v + s[x]);
}

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

  cin >> s;
  n = s.size();
  dfs(0, "");
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int max=0,all=0;
	int a[105];
	int n;
	int i,j,k;
	cin>>all>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(max<a[i])max=a[i];
	}
	all-=max;
	max=max-all-1;
	if(max>0){
		cout<<max<<endl;
	}else{
		cout<<"0"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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


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

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		ANS("Bad")
	}
	else {
		ANS("Good")
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int N;
    double T,A;

    cin >> N >> T >> A;

    double near = 100000;
    int p;

    for(int i = 0; i < N; i++){
        double h;
        cin >> h;

        if(A - T + h*0.006 < 0){
            if(near > -(A - T + h*0.006)){
                near = -(A - T + h*0.006);
                p = i+1;
            }
        }else{
            if(near > A - T + h*0.006){
                near = A - T + h*0.006;
                p = i+1;
            }
        }
    }

    cout << p << endl;

    return 0;
}

Measured memory_bytes: 256