akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }
};


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    UnionFind UF(n);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        UF.unite(a[i], b[i]);
    }
    vector<int> root(n);
    for (int i = 0; i < n; i++) {
        root[UF.root(i)]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (root[i] != 0) {
            ans++;
        }
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define LL long long
#define Max 1000005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int a[Max];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    if(n%3==0){
        n/=3;
        if(a[0]==a[n-1] && a[2*n-1]==a[n] && a[2*n]==a[3*n-1] && (a[0]^a[n]^a[2*n])==0)
            printf("Yes\n");
        else
            printf("No\n");
    }else{
        if(a[0]==a[n-1] && a[n-1]==0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
    return 0;
}


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

class UnionFind {
 public:
  vector<int> parent;
  UnionFind(int n) { parent = vector<int>(n, -1); }
  int root(int a) {
    if(parent[a] < 0) return a;
    return parent[a] = root(parent[a]);
  }
  int size(int a) { return -parent[root(a)]; }
  bool connect(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b) return false;
    if(size(a) < size(b)) swap(a, b);
    parent[a] += parent[b];
    parent[b] = a;
    return true;
  }
  void reset() { fill(parent.begin(), parent.end(), -1); }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  UnionFind uni(n);
  for(int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    uni.connect(--x, --y);
  }
  int o = 0;
  for(int i = 0; i < n; i++)
    if(uni.root(i) == i) o++;
  cout << o << '\n';
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}



int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif



  ll n, m;
  cin >> n >> m;
  ll sum = 0;
  for (int i = 0; i < m; i++) {
    ll x;
    cin >> x;
    sum += x;
  }
  if (sum > n) {
    cout << "-1\n";
  }
  else {
    cout << n - sum << endl;
  }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
int main()
{
    ll H, W;
    cin >> H >> W;

    if (H == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    if (W == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    if (H % 2 == 1 & W % 2 == 1)
    {
        cout << H * W / 2 + 1 << endl;
    }
    else
    {
        cout << H * W / 2 << endl;
    }
}

Measured memory_bytes: 256
//ABC102-B
#include <stdio.h>
 
int main(){
	int N, i, A, Amax = 0, Amin = (int)(1e9);
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &A);
		if(A > Amax){
			Amax = A;
		}
		if(A < Amin){
			Amin = A;
		}
	}
	printf("%d\n", Amax - Amin);
	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    string s;
    cin >> s;
    int i = 0, j = s.size() - 1;
    while(s[i] != 'A'){
        i++;
    }
    while(s[j] != 'Z'){
        j--;
    }
    cout << j - i + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		int D = scanner.nextInt();
		scanner.close();
		int ans = (A * B >= C * D) ? A * B : C * D;
		System.out.println(ans);
	}

}


Measured memory_bytes: 35844
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<int> b(n-1);

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

    vector<int> a(n);
    a[0] = b[0];
    for (int i = 1; i <= n-2; i++) {
        a[i] = min(b[i], b[i-1]);
    }
    a[n-1] = b[n-2];
    int ans = 0;

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

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;
    string s1, s2; cin >> s1 >> s2;

    ll ans = 1;

    int pattern;
    int start;
    if (s1[0] == s2[0]) {
        ans *= 3;
        start = 1;
        pattern = 1;
    } else {
        ans *= 6;
        start = 2;
        pattern = 2;
    }

    for (int i = start; i < n; ++i) {
        if (s1[i] == s2[i]) {
            if (pattern == 1) {
                ans *= 2;
            } else {
                ans *= 1;
            }

            ans %= (ll)MOD;
            pattern = 1;
        } else {
            if (pattern == 1) {
                ans *= 2;
            } else {
                ans *= 3;
            }

            ans %= (ll)MOD;
            i++;
            pattern = 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
   int X,Y,Z;
   cin >> X >> Y >> Z;
    int x = X - Z*2;
    int m =0;
   for(int i = 1; i <= x / Y; i++){
       if(x >= i*Y + (i-1)*Z){
           m = max(m,i);
       }
   }
   cout << m << endl;
}

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

int n;
double p[3000+5];
double dp[3000+5][3000+5];

int main(){
	cin>>n;
	for(int i = 1;i<=n;i++)
		cin>>p[i];

	
	for(int i = 0;i<3000+5;i++)
		for(int j = 0;j<3000+5;j++)
			dp[i][j] = 0.0;

	dp[0][0] = 1.0;
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<i;j++){
			dp[i][j] += dp[i-1][j]*(1-p[i]);
			dp[i][j+1] += dp[i-1][j]*(p[i]);
		}
	}
	double ans = 0.0;
	for(int i = n;i>n/2;i--)
		ans += dp[n][i];

	cout<<fixed<<setprecision(10)<<ans<<endl;

}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;

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

    for(int i = 0; i < 1300; i++) {
        if((int)(i * 0.08) == A && (int)(i * 0.1) ==B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

}


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

int main() {
    string a, b;
    cin >> a >> b;
    string str = a + b;

    int S = atoi(str.c_str());

    for (int i=0; i<400; i++){
        if (S == i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    lint n;
    cin>>n;
    lint a=1,b=1;
    rep(i,n){
        lint x,y;
        cin>>x>>y;
        lint k=max((a-1)/x,(b-1)/y)+1;
        a=k*x;
        b=k*y;
    }
    cout<<a+b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){

  int n;
  cin >> n;

  int cnt = 0;
  REP2(i,1,n+1){
    string s = to_string(i);
    if(s.size()%2 == 1) cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using namespace std;

// unsigned euclidean_gcd(unsigned a, unsigned b) {
//   if(a < b) return euclidean_gcd(b, a);
//   unsigned r;
//   while ((r=a%b)) {
//     a = b;
//     b = r;
//   }
//   return b;
// }

int main(){
    int n;
    char s[101],t[101];
    cin >> n >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;


int main(){

    int x,y;
    cin >> x >> y;

    int ans = 0;

    if(x == 1){
        ans += 300000;
    }else if(x == 2){
        ans += 200000;
    }else if(x == 3){
        ans += 100000;
    }

    if(y == 1){
        ans += 300000;
    }else if(y == 2){
        ans += 200000;
    }else if(y == 3){
        ans += 100000;
    }

    if(x == 1 && y == 1) ans += 400000;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

string S;

typedef pair<string,string> PSS;

void DFS(int id, int stop, string A, string B, vector<PSS> &vec) {
  if (id == stop) {
    vec.PB(MP(A, B));
    return;
  }
  DFS(id + 1, stop, A + S[id], B, vec);
  DFS(id + 1, stop, A, B + S[id], vec);
}

int main() {
  int N;
  cin >> N;
  cin >> S;
  for (int i = N, j = 2 * N - 1; i < j; i++, j--)
    swap(S[i], S[j]);
  vector<PSS> v1, v2;
  DFS(0, N, "", "", v1);
  DFS(N, 2 * N, "", "", v2);
  sort(ALL(v1));
  ll ans = 0;
  for (const PSS &t : v2) {
    ans += upper_bound(ALL(v1), t) - lower_bound(ALL(v1), t);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 65260
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count,num;;
		String Pattern;
		List<Integer> S = new ArrayList<Integer>(Arrays.asList(0,0,0,0,0,0,0,0,0,0,0,0,0));
		List<Integer> H = new ArrayList<Integer>(Arrays.asList(0,0,0,0,0,0,0,0,0,0,0,0,0));
		List<Integer> C = new ArrayList<Integer>(Arrays.asList(0,0,0,0,0,0,0,0,0,0,0,0,0));
		List<Integer> D = new ArrayList<Integer>(Arrays.asList(0,0,0,0,0,0,0,0,0,0,0,0,0));
		count = sc.nextInt();

		for(int i=0; count>i; i++){
			Pattern = sc.next();
			num = sc.nextInt();
			switch (Pattern){
			case "S":
				S.set(num-1,num);
				break;
			case "H":
				H.set(num-1,num);
				break;
			case "C":
				C.set(num-1,num);
				break;
			case "D":
				D.set(num-1,num);
				break;
			default:
				break;
			}

		}
		numCheck("S",S);
		numCheck("H",H);
		numCheck("C",C);
		numCheck("D",D);
		

	}

	private static void numCheck(String P,List<Integer> Pattern) {
		for(int i =1; i<=13; i++) {
			int n = Pattern.indexOf(i);
			if(n == -1) {
				System.out.println(P+" "+i);
			}
		}

	}
}





Measured memory_bytes: 26444
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,m,X,Y,xmax=-INF,ymin=INF;
	cin >> N >> m >> X >> Y;
	vector<int> x(N), y(m);
	for (int i = 0; i <N; ++i) {
		cin >> x[i];
		xmax = max(x[i], xmax);
	}
	for (int i = 0; i < m; ++i) {
		cin >>y[i];
		ymin = min(y[i], ymin);
	}
	if (ymin > X&&ymin > xmax&&xmax < Y) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"



signed main()
{
    FAST;
    int t;
    t=1;
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        char a;
        cin>>a;
        if(a>='a' && a<='z')
        {
            cout<<'a'<<endl;
        }
        
        else
        {
            cout<<'A'<<endl;
        }
        
        
        
        
    }
        
    
    
    
    
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

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

	if (n == 1) { cout << m << endl; return 0; }

	int x = m / n;

	int ans = 1;

	for (int i = 2; i <= x; ++i) {
		if (m % i == 0) {
			ans = i;
		}
	}

	cout << ans << endl;





}

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

int main() {
    int h, w; cin >> h >> w;
    while (h != 0 && w != 0) {
        for (int height = 1; height <= h; ++height) {
            string rec = "";
            for (int width = 1; width <= w; ++width) {
                rec += "#";
            }
            cout << rec << endl;
        }
        cout << endl;
        
        cin >> h >> w;
    }
    return 0;
}


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

int main() {
  int x, y, t;
  while (cin >> x >> y) {
    if (x == 0 && y == 0) break;
    if (x > y) {
      t = y;
      y = x;
      x = t;
    }
    printf("%d %d\n", x, y);
  }
}


Measured memory_bytes: 3064
while True :
    q = int(input())
    if q == -1 :
        break
    
    n = 1
    x = q / 2
    while True :
        if abs(x**3 - q) < (0.00001 * q) :
            break
        x = x - (x**3 - q) / (3 * x**2)
    
    print('{:.6f}'.format(x))


Measured memory_bytes: 5664
words = input().split()
cards  = [int(x) for x in input().split()]
drop   = input()

if drop == words[0]:
    cards[0] -= 1
    print(str(cards[0]) + " " + str(cards[1]))
elif drop == words[1]:
    cards[1] -= 1
    print(str(cards[0]) + " " + str(cards[1]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long bitDP(bitset<13> b,long long now);
long long ene(long long a,long long b);
long long m,w;
long long mem[1<<12][13];
long long maxsb[20];
long long minsb[20];
main(){
  while(1){
    cin>>m>>w;
    if(m==0&&w==0) break;
    memset(mem,-1,sizeof(mem));
    if(m<=w){
      for(int i=0;i<m;i++){
	cin>>minsb[i];
      }
      for(int i=0;i<w;i++){
	cin>>maxsb[i];
      }
    }
    else{
      for(int i=0;i<m;i++){
	cin>>maxsb[i];
      }
      for(int i=0;i<w;i++){
	cin>>minsb[i];
      }
    }
    cout<<bitDP(0,0)<<endl;
  }
}
long long bitDP(bitset<13> b,long long now){
  if(now>=min(m,w)){
    return 0;
  }
  else if(mem[b.to_ulong()][now]!=-1) return mem[b.to_ulong()][now];
  long long ret=-10000000;
  bitset<13> bb(1);
  for(int i=0;i<max(m,w);i++){
    if((b&bb)==0){
      ret=max(ret,bitDP(b|bb,now+1)+ene(minsb[now],maxsb[i]));
    }
    bb=bb<<1;
  }
  return mem[b.to_ulong()][now]=ret;
}
long long ene(long long a,long long b){
  return llabs(a-b)*(llabs(a-b)-30)*(llabs(a-b)-30);
}

Measured memory_bytes: 3504
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)
	const x = parseInt(args[0][1], 10)
	const l = args[1].slice(0, n).map(arg => parseInt(arg, 10))
	const d = new Array(n + 1)

	d[0] = 0

	for (let i = 1; i <= n; i++) {
		d[i] = d[i - 1] + l[i - 1]
	}

	let cnt = 0

	for (let i = 0; i < d.length; i++) {
		if (d[i] <= x) cnt++
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

const int MAX_N = 1000003, mod = 1000003;
int fact[MAX_N];

int power(int base, int n) {
	int res = 1;
	for (; n != 0; n /= 2) {
		if (n & 1) res = 1ll * res * base % mod;
		base = 1ll * base * base % mod;
	}
	return res;
}

int inv(int x) {
	return power(x, mod - 2);
}

int main() {
	fact[0] = 1;
	for (int i = 1; i < MAX_N; i++)
		fact[i] = 1ll * fact[i - 1] * i % mod;

	auto solve = [&](int x, int n) -> int {
		if (MAX_N < x + n || x == 0) return 0;
		return 1ll * fact[x + n - 1] * inv(fact[x - 1]) % mod;
	};
	int T, n, x, d;
	std::cin >> T;
	for (int kase = 1; kase <= T; kase++) {
		std::cin >> x >> d >> n;
		if (d == 0) {
			std::cout << power(x, n) << "\n";
			continue;
		}
		int dn = power(d, n);
		int m = 1ll * x * inv(d) % mod;
		std::cout << 1ll * dn * solve(m, n) % mod << '\n';
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int sum;
	
	while (cin >> sum, sum) {
		for_(i,0,9) {
			int sub;
			cin >> sub;
			sum -= sub;
		}
		
		cout << sum << endl;
	}
}

Measured memory_bytes: 1160
// https://atcoder.jp/contests/abc161/tasks/abc161_f

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#if DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const ll N_MAX = 1e12;

ll N;

int count(ll k) {
  ll n = N;
  if (n % k == 1) return 1 + ((n - 1) / k > k);
  while (n % k == 0) n /= k;
  return n % k == 1;
}

int main() {
  cin >> N;

  int ans = 0;
  for (ll k = 2; k * k <= N; k++) {
    ans += count(k);
  }
  ans += 1 + (N > 2);

  cout << ans << endl;
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif
const int maxr=3003;
double dp[maxr][maxr];
double ways(double arr[],ll ind,ll size,ll count){
	if(ind==size){
		if(count>=size/2+1){
			return 1;
		}
		return 0;
	}
	double &ans=dp[ind][count];
	if(ans>-1){
		return ans;
	}
	ans=0;
	ans+=ways(arr,ind+1,size,count+1)*(arr[ind]);
	ans+=ways(arr,ind+1,size,count)*(1-arr[ind]);
	return ans;
}
//
int main()
{
	GO
	//fioe();
	ll n;
	cin>>n;
	double arr[n+3];
	for(ll i=0;i<maxr;i++){
		for(ll j=0;j<maxr;j++){
			dp[i][j]=-1;
		}
	}
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	double ans=ways(arr,0,n,0);
	printf("%0.10f",ans);
	time();
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll

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

const ll LLINF = (1LL<<60);

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }

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

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    string s, t;
    cin >> s >> t;

    int ans = LLINF;
    function<void(int,int,string)> dfs = [&](int idx, int cost, string str) {
      if(idx == n || str == t) { chmin(ans, cost); return; }
      // idx番目をstr[idx]->t[idx]にもっていくのにかかるコスト
      int diff = (t[idx]-str[idx]+10)%10;
      // [idx, i] を回転させる
      FOR(i, idx, str.size()) {
        str[i] = ((str[i]-'0') + diff)%10 + '0';
        dfs(idx+1, cost+(diff==0?0:1), str);
      }
    };

    dfs(0, 0, s);
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3104
import sys
import collections


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
ans_dic = collections.Counter(list(input()))
for _ in range(N-1):
    c = collections.Counter(list(input()))
    for k, v in ans_dic.items():
        if k in c:
            if ans_dic[k] > c[k]:
                ans_dic[k] = c[k]
        else:
            ans_dic[k] = 0

ans = []
for k, v in ans_dic.items():
    for _ in range(v):
        ans.append(k)

ans.sort()
print(''.join(ans))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N)
	cin >> A[i];
	SORT(A);
	vector<ll> B(N);
	B[N / 2] = A[0];
	int l = 1, r = N - 1;
	int i = N / 2, j = N / 2;
	while (true) {
		if (i - 1 >= 0) {
			--i;
			B[i] = A[r];
		}
		if (j + 1 == N) break;
		++j;
		B[j] = A[r - 1];
		r -= 2;
		if (i - 1 >= 0) {
			--i;
			B[i] = A[l];
		}
		if (j + 1 == N) break;
		++j;
		B[j] = A[l + 1];
		l += 2;
	}
	vector<ll> C(N);
	C[N / 2] = A[N - 1];
	l = 0, r = N - 2;
	i = j = N / 2;
	while (true) {
		if (i - 1 >= 0) {
			--i;
			C[i] = A[l];
		}
		if (j + 1 == N) break;
		++j;
		C[j] = A[l + 1];
		l += 2;
		if (i - 1 >= 0) {
			--i;
			C[i] = A[r];
		}
		if (j + 1 == N) break;
		++j;
		C[j] = A[r - 1];
		r -= 2;
	}
	ll b = 0, c = 0;
	REP(i, N - 1) {
		b += abs(B[i + 1] - B[i]);
		c += abs(C[i + 1] - C[i]);
	}
	cout << max(b, c) << endl;

	return 0;
}

Measured memory_bytes: 2176
import * as readline from "readline";

const rl = readline.createInterface({
    input: process.stdin,
});

const lines = [];
rl.on("line", (line) => {
    lines.push(line);
});
rl.on("close", () => {
    console.log(main(lines.slice(1)));
});

// const input1 = ['acornistnt', 'peanutbomb', 'constraint'];
// const input1 = ['aaa', 'aaa', 'bbb'];
// const input2 = ['oneplustwo', 'ninemodsix'];
// const input3 = ['abaaaaaaaa', 'oneplustwo', 'aaaaaaaaba', 'twoplusone', 'aaaabaaaaa'];

// test(1, main(input1));
// test(0, main(input2));
// test(4, main(input3));

function main(lines) {
    const ss = lines.map(line => sort(line)).sort();

    const counts = [];
    let cnt = 1;
    for (let i = 0; i < ss.length - 1; i++) {
        if (ss[i] === ss[i + 1]) {
            cnt++;
        } else {
            counts.push(cnt);
            cnt = 1;
        }
    }
    counts.push(cnt);

    return counts.reduce((acc, cnt) => {
        if (cnt > 1) {
            acc += combi2(cnt);
        }
        return acc;
    }, 0);

    // 0. aaaab
    // 1. aaaab
    // 2. bbbcc
    // 3. bbbcc
    // 4. bbbcc

    // [2, 3]

    // 2C2 + 3C2
    // 2C2 = (2 * 1) / (2 * 1) = 1
    // 3C2 = (3 * 2) / (2 * 1)
    // 5C2 = (5 * 4) / (2 * 1)
}

function combi2(num) {
    return num * (num - 1) / 2;
}

function range(from, to) {
    const result = [];
    for (let i = from; i < to; i++) {
        result.push(i);
    }
    return result;
}

function sort(text) {
    return text.split('').sort().join('');
}

function test(expected, actual) {
    console.log(expected === actual ? 'OK' : 'NG: expected: %d, actual: %d',  expected, actual);
}

Measured memory_bytes: 51264
use proconio::input;


fn pow(a: u64, b: u64) -> u64 {
  let m = 1_000_000_007u64;
  if b == 0  { return 1; }
  if b % 2 == 1 {
    return a * pow(a, b-1) % m;
  } else {
    let r = pow(a, b/2);
    return r * r % m;
  }
}

fn main() {
  input! {
    n: u64, 
    k: u64,
  }
  let m = 1_000_000_007u64;
  let mut v: Vec<u64> = Vec::<u64>::with_capacity((k+1) as usize);
  for i in 0..k+1 { v.push(0); }
  let mut res: u64 = 0;

  for i in (1..k+1).rev(){
    v[i as usize] = pow(k / i, n);
    let mut j: usize = i as usize*2 as usize;
    while j <= k as usize {
      v[i as usize] = (v[i as usize] + m - v[j]) % m;
      j += i as usize;
    }
    res += v[i as usize] * i as u64 % m;
    res %= m;
  }
  println!("{}", res);
}

Measured memory_bytes: 2748
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int count = 0;
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[][] map = new int[n][n];
			
			boolean up = true;
			int y = 0;
			int x = 0;
			for(int i=1;i<=n*n;i++){
				
				map[y][x] = i;
				if(up==true){
					if(x==n-1){
						y++;
						up = false;
					}else if(y==0){
						x++;
						up = false;
					}else{
						x++;
						y--;
					}
				}else{
					if(y==n-1){
						x++;
						up = true;
					}else if(x==0){
						y++;
						up = true;
					}else{
						x--;
						y++;
					}
				}
				
			}
			count++;
			System.out.println("Case " + count + ":");
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					System.out.printf("%3d", map[i][j]);
				}
				System.out.println();
			}
			
			
		}
	}	
}

Measured memory_bytes: 19304
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,r;
string s,s1,s2;
vl v,a;
//vl vis,d;
ll dp[4000][4000];
ll sg(int x,int y){
    if(dp[x][y]!=inf*inf)return dp[x][y];
    if(x==y)return v[x];
    dp[x][y]=a[y+1]-a[x]-min(sg(x+1,y),sg(x,y-1));
    //cout<<x<<" "<<y<<" "<<dp[x][y]<<el;
    return dp[x][y];
}

int main() {
    IOS;
    cin>>n;
    v.resize(n);cin>>v;
    fo(i,4000)fo(j,4000)dp[i][j]=inf*inf;
    a.assign(n+1,0);
    fo(i,n)a[i+1]=a[i]+v[i];
    fo(i,n)kv+=v[i];
    cout<<2*sg(0,n-1)-kv;
    return 0;
}



Measured memory_bytes: 125440
n = gets.to_i
taro = 0
hanako = 0
n.times do |i|
  tc, hc = gets.split(" ")
  case (tc <=> hc)
  when -1
    hanako += 3
  when 0
    taro += 1
    hanako += 1
  when 1
    taro += 3
  end
  puts [taro, hanako].join(" ") if (i == (n-1))
end

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int>V(2*M);
  for ( int i = 0 ; i < 2*M ; i++ )
    cin >> V.at(i);
  for ( int j = 0 ; j < N ; j++ ) {
    int count = 0;
    for ( int j2 = 0 ; j2 < 2*M ; j2++ ) {
      if ( V.at(j2) == j + 1)
        count++;
    }  
  cout << count << endl;      
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <complex>

using namespace std;

#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10010];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

struct UFT{	//O(loga(n))
	int n;
	vi d, r;
	UFT(int n) : n(n), d(n, -1), r(n, 0){};
	int root(int i){
		if(d[i] < 0) return i;
		return d[i] = root(d[i]);
	}
	bool same(int x, int y){
		return root(x) == root(y);
	}
	bool unite(int x, int y){
		x = root(x);
		y = root(y);
		if(x == y) return false;

		if(r[x] < r[y]) swap(x, y);
		else if(r[x] == r[y]) r[x]++;
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	int size(int i){
		return -d[root(i)];
	}
};

int ans = 0;
int h, w, c;
int d[10][10];
bool isOutOfRange(int x, int y){
	return x < 0 || x >= w || y < 0 || y >= h;
}
int dx[] ={-1,0,1,0};
int dy[] ={0,-1,0,1};

void calc(int clr, int n, UFT uft){
	rep(y, h) rep(x, w){
		if(!uft.same(0, y * w + x)) continue;
		rep(i, 4){
			int nx = x + dx[i], ny = y + dy[i];
			if(isOutOfRange(nx, ny)) continue;
			if(d[ny][nx] == clr) uft.unite(0, ny * w + nx);
		}
	}
	if(n < 4) rep(i, 6) calc(i+1, n+1, uft);
	if(clr == c) ans = max(ans, uft.size(0));
}

int main(){
	while(1){
		h = in.nextInt(), w = in.nextInt(), c = in.nextInt();
		//cout<<h<<" "<<w<<" "<<c<<endl;
		if(h == 0 && w == 0 && c == 0) break;
		rep(i, h) rep(j, w) d[i][j] = in.nextInt();
		UFT uft(h * w);
		ans = 0;
		rep(y, h) rep(x, w){
			rep(i, 4){
				int nx =x +dx[i], ny = y + dy[i];
				if(isOutOfRange(nx, ny)) continue;
				if(d[y][x] == d[ny][nx]) uft.unite(y*w + x, ny*w+nx);
			}
			//if(d[y][x] == c) ans = max(ans, uft.size(y * w + x));
		}
		rep(i, 6) calc(i+1, 0, uft);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>//万能头
	
	using namespace std;
	string st;
	int s,P;
	int main()
	{
		cin>>st;
		for(int i=0;i<st.length();i++)
		{
			if(s==0)
			{
				if(st[i]==67)P=1;
				else if(P==1&&st[i]==70)P=2,s=1;
			}
			else break;
		}
		if(P==2)cout<<"Yes\n";
		else cout<<"No\n";
		
		return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second

using namespace std;
typedef long long ll;
bool ok[10];

bool OK(int n){
    while(n > 0){
        if(ok[n % 10]) return false;
        n /= 10;
    }
    return true;

}
int main()
{
    int n, k;
    cin >> n >> k;

    fr(i, 0, k){
        int d;
        cin >> d;
        ok[d] = true;
    }

    while(!OK(n)) n ++;
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] firstLine = scanner.nextLine().split("\\s+");
        int N = Integer.parseInt(firstLine[0]), K = Integer.parseInt(firstLine[1]), Q = Integer.parseInt(firstLine[2]);
        int[] players = new int[N];

        for (int i = 0; i < Q; i++)
            players[scanner.nextInt() - 1]++;

        for (Integer p : players) {
            if (p + K - Q <= 0) System.out.println("No");
            else System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 57252
A,B,C = map(int,input().split())
lists = [A,B,C]
K = int(input())
X = 0
for i in range(K):
    X = max(lists) * 2
    for j in range(len(lists)):
        if lists[j] == max(lists):
            lists[j] = X
print(sum(lists))

Measured memory_bytes: 3060
N = int(raw_input())
A = map(int, raw_input().split())

A = list(sorted(A, reverse=True))
ans = 1
is_before = False
count = 0
for i in range(N-1):
    if not is_before:
        if A[i] == A[i+1]:
            ans = ans * A[i]
            is_before = True
            count = count + 1
    else:
        is_before = False

    if count>1:
        print ans
        exit()

print 0



Measured memory_bytes: 11296
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/* the recursive version can't go to 2e5 */

const int inf = 1e9;
const int maxn = 1e6;
int n,dp[maxn][2]; string s;

bool isW(const int i)
{ return s[i] == '.'; }
bool isB(const int i)
{ return !isW(i); }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n >> s) {
        s = '.' + s; n++;
        FOR(i,1,n) FOR(j,0,2) {
            dp[i][j] = inf;
            if (j) {
                dp[i][j] = min(dp[i][j], dp[i-1][0]+isW(i));
                dp[i][j] = min(dp[i][j], dp[i-1][1]+isW(i));
            }
            else {
                dp[i][j] = min(dp[i][j], dp[i-1][0]+isB(i));
            }
        }
        const int ans = min(dp[n-1][0], dp[n-1][1]);
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 2128
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,k;
const int MAX_N = 100000;
bool card[MAX_N+10];
int main(){
	while(cin>>n>>k,n||k){
		memset(card,0,sizeof(card));
		for(int i = 0;i < k;i++){
			int x;
			cin>>x;
			card[x] = true;
		}
		int a = 0,b,res = 1;
		while(!card[++a]);//初めに現れる数字を探す
		b = a;
		while(card[++b]);//連続でなくなるまでbを進める
		if(card[0]){//空白のカードがあるならば
			while(card[++b]);
		}
		while(b<=n){
			res = max(res,b-a);
			while(card[++a]);
			while(a < n&&!card[++a]);
			b = a;
			while(b <=n&&card[++b]);
			if(card[0]){
				while(b <=n&&card[++b]);
			}
		}
		res =max(res,b-a);
		cout <<res<<endl;
	}

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  ll ans = 0;
  rep(i, 60) {
    int s = 0;
    rep(j, N) s ^= A[j] >> i & 1;
    if (s == 1) {
      ans += 1LL << i;
      rep(j, N) A[j] &= ~(1LL << i);
    }
  }
  vector<ll> bases;
  sort(range(A), greater<>());
  for (ll x : A) {
    for (ll y : bases) x = min(x, x ^ y);
    if (x != 0) bases.push_back(x);
  }
  ll s = 0;
  for (ll x : bases) s = max(s, s ^ x);
  cout << ans + s * 2 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  int D, T, S;
  cin >> D >> T >> S;
  if (D <= T * S) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<iostream>
using namespace std;
static const int N=1000;

int main( void ){
  int M[N][N];
  int n,m,l,k;
 
  cin >> n;

  for( int i = 0 ; i < n ; i++ ){
    for( int j = 0 ; j < n ; j++ ){
      M[i][j];
    }
  }
  for( int i = 0 ; i < n ; i++ ){
    cin >> m >> l;
    m--;
    for( int j = 0 ; j < l ; j++ ){
      cin >> k;
      k--;
      M[m][k] = 1;
    }
  }
  for( int i = 0 ; i < n ; i++ ){
    for( int j = 0 ; j < n ; j++ ){
      if( j ) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体

vector<string> split(const string &s, char delim) {
	vector<string> elems;
	string item;
	for (char ch : s) {
		if (ch == delim) {
			if (!item.empty())
				elems.push_back(item);
			item.clear();
		} else {
			item += ch;
		}
	}
	if (!item.empty())
		elems.push_back(item);
	return elems;
}

int main() {
	IOS();
	ll a;
	string s;
	cin >> a >> s;
	ll c = stol(split(s, '.').at(0) + split(s, '.').at(1));
	ll d = a * c / 100;
	dump(d);
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll> hash(100001);
  ll a,b;
  for(i=0;i<n;i++){
    cin>>a>>b;
    hash[a]+=b;
  }

  for(i=0;i<100001;i++){
    buf+=hash[i];
    if(buf>=k)break;
  }
  cout<<i<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int main(){
    int cnt5=0;
    int cnt7=0;
    rep(i,3){
        int a; cin >> a;
        if (a==5) cnt5++;
        else cnt7++;
    }
    
    if (cnt5==2 && cnt7==1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256