akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  vector<vector<int>>x(n,vector<int>(0));
  vector<vector<int>>y(n,vector<int>(0));
  rep(i,n){
    int t;
    cin>>t;
    rep(j,t){
      int tx,ty;
      cin>>tx>>ty;
      tx--;
      x[i].push_back(tx);
      y[i].push_back(ty);
    }
  }
  int ans=0;
  for(int bit=0;bit<(1<<n);++bit){
    int count=0;
    int tb=bit;
    while(tb>0){
      if(tb&1)count++;
      tb/=2;
    }
    bool b=1;
    rep(i,n){
      if(bit&(1<<i)){
      rep(j,x[i].size()){
        if(bit&(1<<x[i][j]) && y[i][j]==0){b=0;}
        if(!(bit&(1<<x[i][j])) && y[i][j]==1){b=0;}
      }
    }
  }
    if(b){ans=max(ans,count);}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC146A
{
    class Program
    {
        static void Main(string[] args)
        {
            String S;

            S = Console.ReadLine();

            if (S == "SUN")
                Console.WriteLine("7");

            else if (S == "MON")
                Console.WriteLine("6");


            else if (S == "TUE")
                Console.WriteLine("5");


            else if (S == "WED")
                Console.WriteLine("4");


            else if (S == "THU")
                Console.WriteLine("3");


            else if (S == "FRI")
                Console.WriteLine("2");


            else if (S == "SAT")
                Console.WriteLine("1");

            Console.ReadKey();


        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define ll long long

ll cube(ll x){
    return x*x*x*x*x;
}

int main(){
    ll x;
    scanf("%lld", &x);
    ll a, b;
    for (int i = 0; i <= 200; i++){
        for (int j = 0; j <= 200; j++){
            if (cube(i)-cube(j)==x){
                a = i, b = j;
                break;
            }
            if (cube(-i)-cube(j)==x){
                a = -i, b = j;
                break;
            }
            if (cube(i)-cube(-j)==x){
                a = i, b = -j;
                break;
            }
            if (cube(-i)-cube(-j)==x){
                a = -i, b = -j;
                break;
            }
        }
    }
    printf("%lld %lld\n", a, b);
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main()
{
    int n;cin >> n;
    vector<ll> a(n);rep(i,n)cin >> a[i];
    
    int flag = 0;
    rep(i,n)
    {
        if(a[i] == 0)flag = 1;

    }
    rep(i,n)
    if(flag == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    ll temp = 1;
    rep(i,n)
    {
       if(LINF/temp<a[i])
       {
           cout << -1 << endl;
           return 0;
       }
       temp *= a[i];
    }
    cout << temp << endl;

}

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

int main()
{
	bool f;
	int w,h,x,y;
	char t[128][128];

	while(cin >> h >> w, (h||w))
	{
		for(int i=0; i<h; i++)
		{
			cin >> t[i];
		}
	
		f=true;
		x=y=0;
		while(f)
		{
			switch(t[y][x])
			{
				case 0:
					cout << "LOOP" << endl;
					f=false;
					break;

				case '.':
					cout << x << " " << y << endl;
					f=false;
					break;

				case '>':
					t[y][x] = 0; x++;
					break;

				case '<':
					t[y][x] = 0; x--;
					break;

				case 'v':
					t[y][x] = 0; y++;
					break;

				case '^':
					t[y][x] = 0; y--;
					break;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#define ll long long int
using namespace std;

int main(){
    int n,m,denger_id;
    vector<int> a;
    vector<ll> step;

    cin>>n>>m;
    a.resize(m+1);
    for(int i=0; i<m; i++){
        cin>>a[i];
    }
    step.resize(n+1);
    for(int i=0; i<n+1; i++){
        step[i]=0;
    }

    step[0]=1;
    
    denger_id=0;
 

    for(int i=1; i<n+1; i++){
        if(i==a[denger_id]){
            denger_id++;
        }else if(i==1){
            step[i]=1;
        }else{
            step[i]=(step[i-1]+step[i-2])%1000000007;
        }
    }
    cout<<step[n]%1000000007<<endl;
    return 0;
}

Measured memory_bytes: 1408
using System; 
using System.Text;
using System.Collections.Generic; 
using System.Linq; 
using E = System.Linq.Enumerable; 
class Program {
    static void Main(string[] args) {
        //入力を受け取る
        var S  = Console.ReadLine();
        var K  = int.Parse(Console.ReadLine());
        
        var SS = new List<string>();
        for(int i = 0;i < S.Length;i++){
            for(int j = 1;j <= 5 && i+j <= S.Length;j++){
                var str = S.Substring(i,j);
                SS.Add(str);
            }
        }
        var ANS = SS.Distinct().ToArray();
        Array.Sort(ANS);   
        Console.WriteLine(ANS[K-1]);
     }
     
     
     }
     
     
                   


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

using namespace std;


int N, dp[3], c[3], dp2[3];

int main() {
    cin >> N;
    for (int i = 0; i < 3; ++i) dp[i] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) cin >> c[j];
        dp2[0] = max(dp[1] + c[1], dp[2] + c[2]);
        dp2[1] = max(dp[0] + c[0], dp[2] + c[2]);
        dp2[2] = max(dp[0] + c[0], dp[1] + c[1]);
        for (int j = 0; j < 3; ++j) dp[j] = dp2[j];
    }
    cout << max(dp[0], max(dp[1], dp[2])) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int lli;
#define MOD 1000000007
#define pi 3.1415926
using namespace std;


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    double x;
    cin >> x;
    cout << 2 * pi * x << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, T;
    cin >> N >> T;
    ll ti;
    ll res = 0;
    ll t_prev = -T;
    for(int i=0;i<N;i++){
        cin >> ti;
        res += min(T, ti - t_prev);
        t_prev = ti;
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=101;
char s[M];
int main()
{
	cin>>s;
	int len=strlen(s);
	for(int i=0;i<len;i++)
	{
		
		if(s[i]=='C')
		{
			for(int j=i+1;j<=len;j++)
			if(s[j]=='F')
			{
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,A,B; cin >> N >> A >> B;
    int ans=0;
    ans=N/(A+B)*A;
    ans+=min(A,N%(A+B));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#define FOR( i, l, r) for(int i = (l)    ; i <  (r); i++)
#define FOR1(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define REV( i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define REV1(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define INC( i, n) FOR( i, 0, n)
#define INC1(i, n) FOR1(i, 1, n)
#define DEC( i, n) REV( i, 0, n)
#define DEC1(i, n) REV1(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
char s1[101], s2[101];
int len;

void plus() {
	len++;
	s1[len] = s2[len] = '\0';
}

void minus() {
	len--;
	s1[len] = s2[len] = '\0';
}

void shift() {
	DEC(i, len) {
		s1[i + 1] = s1[i];
		s2[i + 1] = s2[i];
	}
}

int ask(int i, int p) {
	char as1[] = "..##";
	char as2[] = ".#.#";
	char r[4];
	
	s1[p] = as1[i];
	s2[p] = as2[i];
	
	printf("%s\n%s\n", s1, s2); fflush(stdout);
	
	scanf("%s", r);
	
	     if(r[0] == 'F') { return 0; }
	else if(r[0] == 'T') { return 1; }
	else                 { return 2; }
}

int main() {
	scanf("%d", &n);
	
	s1[0] = s2[0] = '\0';
	
	bool flag = true;
	while(len < n) {
		int res;
		plus();
		if(flag) {
			INC(i, 4) {
				res = ask(i, len - 1);
				if(res != 0) { break; }
			}
			if(res == 0) { flag = false; minus(); }
		} else {
			shift();
			INC(i, 4) {
				res = ask(i, 0);
				if(res != 0) { break; }
			}
		}
		if(res == 2) { break; }
	}
	
	return 0;
}


Measured memory_bytes: 596
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int x = sc.nextInt();
        out.println(x >= 30 ? "Yes" :"No");
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

int main() {
	int a[3];
	std::cin >> a[0] >> a[1] >> a[2];
	std::sort(a, a + 3);
	if (a[0] == a[1] && a[0] != a[2]) puts("Yes");
	else if (a[1] == a[2] && a[0] != a[2]) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a[101],n,i,flag=1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0)
			{
				flag=0;
			}
			
		}
	}
	if(flag)
	printf("APPROVED");
	else
	printf("DENIED");
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    
    for(int i = 0; i < n; i++){
        cin >> array.at(i);
    }
    int count = 0;
    for(int i = 1; i < n - 1; i++){
        if(array.at(i) != min(min(array.at(i-1),array.at(i)),array.at(i+1)) && array.at(i) != max(max(array.at(i-1),array.at(i)),array.at(i+1))){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
(defun read-string () ;スペース区切りstring入力
  (let* ((str (read-line)))
    (labels ((instring (instring-str rt)
               (let* ((pos (position #\Space instring-str :test #'char=)))
                 (if pos
                     (instring (subseq instring-str (1+ pos))
                               (cons (subseq instring-str 0 pos) rt))
                     (cons instring-str rt)))))
      (reverse (instring str nil)))))
(let* ((n (read))
       (playlist (mapcar (lambda (k) (list (first k) (parse-integer (second k))))
                         (loop :repeat n :collect (read-string))))
       (fd (read-line)))
  (princ (reduce #'+ (mapcar #'second (subseq playlist (1+ (position fd playlist :test #'string= :key #'first)))))))

Measured memory_bytes: 7392
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define pb push_back
using namespace std;
int n,ans,ave1;
float ave;


int b[110];
int main(){
	cin>>n;
	ans=0;
	
	for (int i=0;i<n;i++){
		cin >>b[i];
		ave+=b[i]*1.0/n;
	}
	ave1=int(ave+.5-(ave<0)); 
	for (int i=0;i<n;i++){
		ans +=(ave1-b[i])*(ave1-b[i]);
		
	}
	cout <<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;

    vector<tuple<ll,ll,ll>> v(n);
    rep(i,n){
        ll x,y,h;
        cin>>x>>y>>h;
        v[i] = make_tuple(x,y,h);
    }
    ll cx =0;
    ll cy =0;
    ll H = 0;

    if(n==1){
        cout<<cx<<" "<<cy<<" "<<H<<endl;
    }
    rep(i,101){
        rep(j,101){
            set <ll> se;
            rep(k,n){
                ll x,y,h;
                tie(x,y,h)=v[k];
                if(h==0)continue;
                se.insert(h+abs(x-i)+abs(y-j));
            }
            if(se.size()==1){
                H = *se.begin();
                bool dame=false;
                rep(k,n){
                    ll x,y,h;
                    tie(x,y,h)=v[k];
                    if(h != max(H-abs(x-i)-abs(y-j),0LL)){
                        dame = true;
                        break;
                    }
                }
                if(dame)continue;

                cx = i;
                cy = j;

                goto end;
            }
        }
    }
    end:
    cout<<cx<<" "<<cy<<" "<<H<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int gcd(int a,int b) {
    if (a % b == 0)
        return b;
    else
        return (gcd(b, a % b));
}
int main() {

    int k,total=0;
    cin >> k;
    for (int l = 1; l <= k;l++){
        for (int m = 1; m <= k;m++){
            for (int n = 1; n <= k;n++){
                total += gcd(gcd(l, m), n);
            } }
    }
    cout << total << endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	long long sum = 0;
	for(long long i = 1; i <= n; i++) if(i%3 != 0 && i%5 != 0) sum += i;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
N,K=map(int,input().split())
S=input()

cnt = 0
for i in range(0,len(S)):
    if i == len(S) - 1 and S[i] == "R":
        cnt = cnt
    elif i > 0 and  S[i-1] == "L" and S[i] == "L":
        cnt += 1
    elif S[i] == "R" and S[i+1] == "R":
        cnt += 1
    i += 1
print(min(cnt + 2 * K, N - 1))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll 	 long long
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{

ll x, k, d;

cin>>x>>k>>d;

x= abs(x);

if(x/d >= k) cout<<x-k*d<<endl;

else
{
	ll t= x/d;
	k-=t;
	x-=t*d;
	
	if(k%2) cout<<abs(x-d)<<endl;
	else cout<<x<<endl;
}

    return 0;
}

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

int main()
{
  int N ;
  cin>>N ;
  vector<int>A(N,0) ;
  for(int i=0;i<N-1;i++){
    int tmp ;
    cin>>tmp ;
    A.at(tmp-1)++ ;
  }
 
  for(int i=0;i<N;i++) cout<<A.at(i)<<endl ;
  
  return 0 ;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	double r;
	cin >> r;
	cout << acos(-1) * r * 2 << endl;
}
int32_t main() {
	BOLT;
	int t;
	t = 1;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3808
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;


int main(){

    int n;
    cin>>n;
    string str;
    cin>>str;

    for(auto c:str){
        if(c+n > 'Z') printf("%c", (c+n-'Z'-1)+'A');
        else printf("%c", c+n);
    }

    return 0;
}


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

int N;
string s, t;
bool bio[30];

bool work(int pos, char c) {
	for (char i = c; i <= 'z'; i++)
		if (!bio[i - 'a']) {
			t[pos] = i;
			bio[i - 'a'] = true;
			return true;
		}
	return false;
}

void init(int x) {
	memset(bio, false, sizeof bio);
	for (int i = 0; i < x; i++)
		bio[s[i] - 'a'] = true;
}
	
void go(int x) {
	init(x);
	
	t = s;
	if (x == N)
		t += ' ';
	
	if (!work(x, x == N ? 'a' : s[x] + 1))
		return;
	
	t.resize(x + 1);
	
	cout << t << endl;
	
	exit(0); 
}

int main() {
	cin >> s;
	
	N = s.size();
	for (int i = N; i >= 0; i--)
		go(i);  
		
	cout << -1 << endl;
	
	return 0;
}

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

int main(){
    ll N,D,A;
    cin >> N >> D >> A;
    vector<pair<ll,ll>> X(N);
    vector<ll> L(200100);
    rep(i,N){
        cin >> X[i].first >> X[i].second;
    }
    sort(X.begin(), X.end());
    ll cnt = 0;
    D *= 2;
    queue<pair<ll,ll>> que;
    ll total = 0;
    for(int i=0;i<N;i++){
        while(!que.empty() && que.front().first < X[i].first){
            total -= que.front().second;
            que.pop();
        }
        if(X[i].second > total){
            ll damage = X[i].second - total;
            ll num = (damage + A - 1) / A;
            cnt += num;
            total += num*A;
            que.push(make_pair(X[i].first + D, num*A));
        }
    }


    cout << cnt  << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define N 200005
//#define int long long 
using namespace std;
int n,m,t1,t2,a[N];
signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>t1){
			t2=t1;
			t1=a[i];
		}
		else if(a[i]>t2)t2=a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]==t1)printf("%d\n",t2);
		else printf("%d\n",t1);
	}
	return 0;
}

Measured memory_bytes: 2432
N, M, X = map(int, input().split())
Books = []
Skills = [0] * M
cost = 0
res = 10 ** 9

for i in range(N):
    Books.append(list(map(int, input().split())))

for bit in range(2 ** N):
    for i in range(N):
        if (bit >> i) & 1:
            for j in range(M):
                Skills[j] += Books[i][j+1]
            cost += Books[i][0]
    if all(a >= X for a in Skills):
        res = min(res, cost)
    cost = 0
    Skills = [0] * M

print(res if res != (10 ** 9) else -1)


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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };

using namespace std;

int ch(char a) {
	if (a == 'm') return 1000;
	if (a == ('c')) return 100;
	if (a == 'x')return 10;
	if (a == 'i') return 1;

}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(i, n) {
		string s1, s2;
		cin >> s1 >> s2;
		int x1=0, x2=0;
		int j = 0;
		while (j < s1.size()) {
			if (isdigit(s1[j])) {
				x1 += (s1[j]-'0')*ch(s1[j + 1]);
				j += 2;
			}
			else {
				x1 += ch(s1[j]);
				++j;
			}
		}
		j = 0;
		while (j < s2.size()) {
			if (isdigit(s2[j])) {
				x2 += (s2[j]-'0') * ch(s2[j + 1]);
				j += 2;
			}
			else {
				x2 += ch(s2[j]);
				++j;
			}
		}
		int x = x1 + x2;
		j = 1000;
		string s="";
		REP(i, 4) {
			char c;
			if (i == 0) c = 'm';
			else if (i == 1)c = 'c';
			else if (i == 2)  c = 'x';
			else if (i == 3) c = 'i';
			if (x / j == 1) {
				s += c;
				x -= x / j*j;
			}
			else if (x / j != 0) {
				s += to_string(x / j) + c;
				x -= x / j*j;
			}
			
			j /= 10;
		}
		cout << s << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3180
S = input()
n = len(S)
count = 0
for i in range(n):
    if i%2 ==0:
        if S[i]=='R' or S[i]=='U' or S[i]=='D':
            count += 1
        else:
            count += 0
    if i%2 == 1:
        if S[i]=='L' or S[i]=='U' or S[i]=='D':
            count += 1
        else:
            count += 0
if count == n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N, K, R, S, P;
char T[100005];
int ans;

map<char, int> score;

int main(void) {
    scanf("%d %d", &N, &K);
    scanf("%d %d %d", &R, &S, &P);
    scanf("%s", T);

    score['r'] = P; score['s'] = R; score['p'] = S;

    rep(i, 0, N) {
      if (i < K) ans += score[T[i]];
      else {
        if (T[i] != T[i-K]) ans += score[T[i]];
        else T[i] = '-';
      
      }

       
    }

    printf("%d\n", ans);

    return 0;
}



Measured memory_bytes: 384
s = input()

if not s[0] == "A":
    print('WA')
    exit()

clen = s[2:-1].count("C")
if clen != 1:
    print('WA')
    exit()

count=0
for ch in s:
    if not ('a' <= ch <= 'z'):
        count += 1
print('WA' if count-2!=0 else 'AC')

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

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++) cin >> s.at(i);
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++) cin >> t.at(i);
  vector<int> ret(N, 1);
  for (int i=0; i<N; i++) {
    for (int j=1; j<N-i; j++) {
      if (s.at(i)==s.at(i+j)) ret.at(i)++;
    }
    for (int k=0; k<M; k++) {
      if (s.at(i)==t.at(k)) ret.at(i)--;
    }
  }
  sort(ret.begin(), ret.end());
  int X = max(ret.at(N-1), 0);
  cout << X << endl;
}

Measured memory_bytes: 256
def merge(a, left, mid, right):
    """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """
    global cnt
    inf = 10 ** 9
    left_a = a[left:mid] + [inf]
    right_a = a[mid:right] + [inf]
    
    i, j = 0, 0

    for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1


def merge_sort(a, left, right):
    """ split list a[left:right-1] into two lists and merge
    """
    if left + 1 < right:
        mid = (left + right)//2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

n = int(input())
a = list(map(int, input().split()))
cnt = 0
merge_sort(a, 0, n)

print(' '.join(str(n) for n in a))
print(cnt)


Measured memory_bytes: 66784
#include <iostream>

using namespace std;

#define BUILD_NUM 4
#define FLOOR_NUM 3
#define ROOM_NUM  10

int main()
{
	int building[BUILD_NUM][FLOOR_NUM][ROOM_NUM] = {0};	// 各棟の情報用配列
	int infoNum;										// 入力する情報数
	int inBuild, inFloor, inRoom, inStay;				// 一時的に入力値を格納する変数
	
	// 情報数の入力
	cin >> infoNum;
	
	// 入力情報を配列に反映
	for(int i = 0; i < infoNum; i++)
	{
		cin >> inBuild;
		cin >> inFloor;
		cin >> inRoom;
		cin >> inStay;
		building[inBuild - 1][inFloor - 1][inRoom - 1] += inStay;
	}
	
	// 出力
	for(int i = 0; i < BUILD_NUM; i++)
	{
		for(int j = 0; j < FLOOR_NUM; j++)
		{
			for(int k = 0; k < ROOM_NUM; k++)
			{
				cout << " " << building[i][j][k];
				
				if(ROOM_NUM - 1 == k)
				{
					cout << endl;
				}
			}
		}
		if(BUILD_NUM - 1 != i)
		{
			cout << "####################" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3108
def shiritori(n, string_list):

    if len(string_list)!=len(set(string_list)):
        return False

    for i in range(1,n):
        if string_list[i-1][-1]!=string_list[i][0]:
            return False

    return True


def main():
    n = int(input())
    string_list = [input() for i  in range(n)]

    if shiritori(n, string_list):
        print('Yes')
    else :
        print('No')

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define read(n) scanf("%lld",&n)
#define write(x) printf("%lld\n",x)
#define F(i,n) for(int i = 0;i < n;i++)
#define ll long long
#define MX 105
#define MOD 1000000007
#define INF 1000000009
#define set_dp(dp) memset(dp,-1,sizeof(dp))
using namespace std;
ll n, k, a[MX], dp[MX][4], dp_ncr[MX][4];
char s[MX];
ll ncr(ll i, ll j){
	if(j > i) return 0;
	if(j == 0) return 1;
	if(dp_ncr[i][j] == -1)
		dp_ncr[i][j] = ncr(i - 1, j) + ncr(i - 1, j - 1);
	return dp_ncr[i][j];
}
ll solve(ll i, ll j){
	if(j < 0) return 0;
	if(i == -1) return j == 0;
	if(dp[i][j] == -1){
		ll ans = 0;

		if(a[i]){
			// place a zero
			ans += pow(9, j) * ncr(i, j);
			// place a non zero digit less than a[i]
			ans += (a[i] - 1) * (ll)pow(9, j - 1) * ncr(i, j - 1);
			// place a[i]
			ans += solve(i - 1, j - 1);
		}
		else{
			// place a zero
			ans += solve(i - 1, j);
		} 
			

		dp[i][j] = ans;

	}
	return dp[i][j];
}
int main(){

	set_dp(dp), set_dp(dp_ncr);

	scanf("%s", s);
	n = strlen(s);

	F(i, n) a[n - i - 1] = s[i] - '0';

	read(k);

	write(solve(n - 1, k));


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 10

int main(){

	int i,j,high[N], tmp;

	// input
	for(i=0;i<N;i++){
		scanf("%d", &high[i]);
	}

	// sort
	// pivot
	for(i=0;i<N-1;i++){
		// swap
		for(j=i;j<N;j++){
			// swap impl
			if(high[i] < high[j]){
				tmp = high[i];
				high[i] = high[j];
				high[j] = tmp;
			}
		}
	}

	for(i=0;i<3;i++){
		printf("%d\n", high[i]);
	}

	return 0;
}

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

using namespace std;

int mod = 1000000007;
int main(){
   long long N,K;
   cin >> N >> K;
   long long ans=0;
   for(long long i = K ; i <= N+1; i++){
      long long min = (i-1)*i/2;
      long long max = (2*N-i+1)*i/2;
      long long cnt = max-min+1;
      ans += cnt;
      //cout << cnt << endl;
      ans %= mod;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3632
from itertools import product
input = raw_input
h, w, k = map(int, input().split(" "))

mat = [list(input()) for i in range(h)]

n_black = 0
for line in mat:
    for elm in line:
        if elm == "#":
            n_black += 1

out = 0
for h_pattern in product((False, True), repeat=h):
    for w_pattern in product((False, True), repeat=w):
        #print(h_pattern, w_pattern)
        del_ = 0
        for hi, h_flag in enumerate(h_pattern):
            for wi, w_flag in enumerate(w_pattern):
                if h_flag or w_flag:
                    if mat[hi][wi] == "#":
                        del_ += 1
                        
        nokori = n_black - del_
        #print(nokori)
        if k == nokori:
            out += 1

print(out)

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

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

long long lcm(long long a, long b) {
	long long g = gcd(a, b);
	return a / g * b;
}

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

	long long ans = 1LL;
	long long t;

	for (int i = 0; i < n; ++i) {
		cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    ans = ''
    while 1:
        p,q = divmod(n,26)
        n = p-1 if q==0 else p
        if q==0:
            ans = 'z'+ans
        else:
            ans = chr(ord('a')-1+q)+ans
        if n==0:
            break
    print(ans)

main()


Measured memory_bytes: 9160
#include<bits/stdc++.h>
namespace ZDY{
    #pragma GCC optimize(3)
    #define il __inline__ __attribute__ ((always_inline))
    #define rg register
    #define ll long long
    #define ull unsigned long long
    #define db double
    #define sht short
    #define MB template <class T>il
    #define Fur(i,x,y) for(int i=x;i<=y;i++)
    #define Fdr(i,x,y) for(int i=x;i>=y;i--)
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define fcin ios::sync_with_stdio(false)
    #define l2(n) (int(log2(n)))
    #define inf 0x3f3f3f3f
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>y?x:y;}
    MB T MIN(T x,T y){return x<y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 100011
int n,L[N],R[N],f[N],v[N];
char ch[N];
int main(){
    in>>(ch+1);n=strlen(ch+1);
    Fur(i,1,n)L[i]=(ch[i]=='R')?i:L[i-1];
    Fdr(i,n,1)R[i]=(ch[i]=='L')?i:R[i+1];
    Fur(i,1,n){
        int t=f[i]=(ch[i]=='L')?L[i]:R[i];
        if((i-t)&1){
            if(ch[t]=='L')t--;
            else t++;
        }
        v[t]++;
    }
    Fur(i,1,n)out<<v[i]<<" ";
}


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

int main() {
  string s;
  cin>>s;
  int a=0;
  std::vector<int> v(26,0);
  for(int i=0;i<s.size();i++)v[(int)s[i]-97]++;
  for(int i=0;i<26;i++)if(v[i]%2!=0)a++;
  if(a==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
int main(void){
    int a,b;
    std::cin>>a>>b;
    if(a>b){
        std::cout<<"a > b"<<std::endl;
    }else if(a<b){
        std::cout<<"a < b"<<std::endl;
    }else{
        std::cout<<"a == b"<<std::endl;
    }
    return 0;
}



Measured memory_bytes: 3104
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <stdio.h>
//end of libraries ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define INF 3999999999999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll x  , a = 100 , ans;
int main(){
fcin;
	cin >> x;
	while( a < x ){
		a += (a/100);
		ans++;
	}
	cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    array<int,100> a;
    for(int i = 0; i < n; i++){
       cin >> a[i];
    }
    for(int i = 1; i <= n; i ++){
        int v = a[i];
        int j = i - 1;
        for(int k = 0; k < n; k++){
                cout << a[k];
                if(k < n -1)cout << " ";
        }cout <<endl;
        if(i == n)break;
        while(j >= 0 && a[j] > v){
             a[j + 1] = a[j];
             j--;
        }
        a[j + 1] =v;
    }
}


Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main() {
    string S; cin >> S;
    if (S[5] == '0' && (S[6] == '1' || S[6] == '2' || S[6] == '3' || S[6] == '4')) printf("%s\n", "Heisei");
    else printf("%s\n", "TBD");
}

Measured memory_bytes: 256
void main()
{
    long n = readln.chomp.to!long;

    long f = long.max;
    for (long i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            long a = i.log10.to!long + 1;
            long b = log10(n/i).to!long + 1;
            f = min(f, max(a, b));
        }
    }

    f.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
mod=10**9+7

from functools import lru_cache

@lru_cache()
def pow(N,K):
    if K==0:
        return 1
    elif K==1:
        return N
    if K%2==0:
        return (pow(N,K//2)*pow(N,K//2))%mod
    else:
        return (N*pow(N,K-1))%mod



def f(N,K,i):
    if table[K]>0 and i==1:
        return table[K]

    if K==i:
        return 1
    elif K==1:
        return 1

    if i==1:
        sigma=0
        for j in range(2,K+1):
            sigma+=f(N,K//j,1)
            sigma=sigma%mod
        retval=(pow(K,N)-sigma)%mod
        table[K]=retval
        return retval

    else:
        return f(N,K//i,1)%mod


def calc(N,K):
    retval=0
    for i in range(1,K+1):
        retval+=i*f(N,K,i)
        retval=retval%mod
    return retval

N,K=[int(i) for i in input().split(" ")]

table=[-1 for i in range(K+1)]
table[1]=1


print(calc(N,K))


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

using namespace std;
int main()
{
    int a;
    string s;
    cin>>a;
    cin>>s;
    if(a<3200)
    {
        cout<<"red"<<endl;
    }
    else
    {
        cout<<s<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long lint;
const lint N = 110, M = 1e5+100;
lint n, P, w[N], value[N];
pair<lint, lint>  dp[N][M];

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	scanf("%lld %lld", &n, &P);

	for (int i = 0; i < n; i++){
		scanf("%lld %lld", &w[i], &value[i]);
	}

	dp[0][0] = {1, 0};
	if (w[0] <= P) dp[0][value[0]] = {1, w[0]};

	for (int i = 1; i < n; i++){
		for (int j = 0; j < M; j++){
			if (dp[i - 1][j].first == 1){
				//cout << i << " " << j << endl;
			 	if (dp[i][j].first == 0 || dp[i][j].second > dp[i - 1][j].second)
			 		dp[i][j] = {1, dp[i - 1][j].second};
			}
			if (j - value[i] >= 0 && dp[i -1][j - value[i]].first == 1 && dp[i - 1][j - value[i]].second + w[i] <= P) {
				//cout << i << " " << j << endl;
				if (dp[i][j].first == 0 || dp[i][j].second > dp[i - 1][j - value[i]].second + w[i])
					dp[i][j] = {1, dp[i - 1][j - value[i]].second + w[i]};
			}
			if (j - value[i] == 0 && dp[i -1][0].first == 1 && dp[i - 1][0].second + w[i] <= P) {
				//cout << i << " " << j << endl;
				if (dp[i][j].first == 0 || dp[i][j].second > dp[i - 1][0].second + w[i])
					dp[i][j] = {1, dp[i - 1][0].second + w[i]};
			}
		}
	}

	lint ans = 0;

	for (int i = 0; i < M; i++)
		ans = max(ans, dp[n-1][i].first == 1 ? i : (lint)0);

	printf("%lld\n", ans);

	return 0; 
}

Measured memory_bytes: 49024
/*
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2331961#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2331969#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2331970#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2332101#2
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int bit_cnt(int a) {
	int ret = 0;
	while (a) {
		a &= a - 1;
		ret++;
	}
	return ret;
}

int dp[31][1 << 16];

int main() {
	while (true) {
		int n, c;	cin >> n >> c;
		if(n==0)	break;
		vint a(n, 0);
		rep(i, n) {
			rep(j, 16) {
				a[i] <<= 1;
				int in;	cin >> in;
				a[i] += in;
			}
		}
		vint b(c, 0);
		rep(i, c) {
			rep(j, 16) {
				b[i] <<= 1;
				int in;	cin >> in;
				b[i] += in;
			}
		}
		REP(i, n)	rep(j, 1 << 16)	dp[i][j] = 0;
		priority_queue<tuple<int, int, int> > pq;
		pq.push(mt(0, 0, 0));
		int ret = 0;
		while (!pq.empty()) {
			int point = 0, i = 0, state = 0;
			tie(i, point, state) = pq.top();	pq.pop();
			if (point < dp[i][state])	continue;
			if (i == n) {
				ret = max(ret, point);
				continue;
			}
			state |= a[i];
			rep(j, c) {
				int ns = state&(state^b[j]);
				int add = bit_cnt(state&b[j]);
				if (add + point > dp[i + 1][ns]) {
					dp[i + 1][ns] = add + point;
					pq.push(mt(i + 1, add + point, ns));
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    
    if (s == u) {
        cout << a - 1 << " " << b << endl;
    } else {
        cout << a << " " << b - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define inf 1e9
#define pi 3.1415926536
#define mod 1000000007
#define fr(i,a,b,in) for(int i=a;i<b;i+=in)
#define frn(i,a,b,dc) for(int i=a;i>=b;i-=dc)
#define test(t) int t; cin>>t; while(t--)
int main()
{
	fastio();
	int n;
	cin>>n;
	pair<int,int> p[n];
	fr(i,0,n,1) cin>>p[i].f>>p[i].s;
	int fl=0;
	fr(i,0,n-2,1){
		if(p[i].f==p[i].s && p[i+1].f==p[i+1].s && p[i+2].f==p[i+2].s){
			fl=1;
			break;
		}
	}
	if(fl) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<cstdio>
int n,a[100001];
long long S,T;
int main(){
	scanf("%d",&n);
	if(n==1) return 0*puts("YES");
	T=(long long)n*(n+1)/2;
	for(int i=1;i<=n;++i)
		scanf("%d",a+i), S+=a[i];
	if(S%T) return 0*puts("NO");
	S/=T;
	a[0]=a[n];
	for(int i=n;i>=1;--i)
		a[i]=a[i]-a[i-1];
	for(int i=1;i<=n;++i)
		a[i]-=S;
	int ok=1;
	for(int i=1;i<=n;++i)
		if(a[i]>0||a[i]%n) ok=0;
	puts(ok?"YES":"NO");
	return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int n,m;
    cin>>n>>m;
    if(n==1 or m==1) cout<<1<<endl;
    else cout<<(1LL*n*m+1)/2<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
typedef long long int ll;
using namespace std;

ll n;
ll a[3005];
ll dp[3005][3005];

ll go(ll s,ll e)
{
	if (s>e)
	return 0;
	if (s==e)
	return a[s];
	else if (dp[s][e]!=-1)
	return dp[s][e];
	else
	{
		ll x;
		x=max(a[s]-go(s+1,e),a[e]-go(s,e-1));
		dp[s][e]=x;
		return x;
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    for (int i=1;i<=n;i++)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<go(1,n)<<endl;

}


Measured memory_bytes: 70912
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 10000006
#define eps 1e-10
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
#define fir first
#define sec second
#define it_s_too_hard main
#define I_can_t_solve_it solve
//const long long inf=1LL<<62;
const double inf=1e9+9;
const int Mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
inline int dcmp(ld x){ if(fabs(x)<=eps) return 0; return x<0?-1:1;}
inline int scan(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline ll scan(ll x){
	int f=1;char ch=getchar();x=0;
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct Point{
	double x,y;
	Point(double x=0,double y=0):x(x),y(y) {}
	Point operator - (const Point &a)const { return Point(x-a.x,y-a.y);}
	Point operator * (const double &a)const{return Point(x*a,y*a);  }
	bool operator != (const Point &a)const{ return dcmp(x-a.x)!=0 || dcmp(y-a.y)!=0; }
	bool operator == (const Point &a)const{ return dcmp(x-a.x)==0 && dcmp(y-a.y)==0; }
	void read(){scanf("%lf%lf",&x,&y);}
};
double Dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
double dis(Vector a){
	return sqrt(Dot(a,a));
}
double Cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}
int dp[10000],vis[2000];
int n,g,ans;
int p[20],c[20],tp,ps,cp,st;
void I_can_t_solve_it(){
	ans=1000000;
	n=scan();g=scan();
	For(i,1,n) p[i]=scan(),c[i]=scan();
	tp=0;ps=0;cp=0;
	For(i,0,(1<<n)-1){
		tp=0;ps=0;cp=0;
		For(j,1,n)
			if((1<<(j-1))&i) tp+=p[j],ps+=p[j]*100*j+c[j];
		if(ps>=g) {ans=min(ans,tp);continue;}
		Fore(j,n,1){
			if((1<<(j-1))&i) continue;
			cp=j*(p[j]-1)*100;
			if(cp+ps>=g){
				st=g-ps;
				tp+=st/(j*100);
				if(st%(j*100)) tp++;
				ans=min(ans,tp);
				break;
			}
		}
	}
	cout<<ans<<endl;
}
int it_s_too_hard(){
	int t=1;
	For(i,1,t){
		I_can_t_solve_it();
	}
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 3580
n = int(input())
s = input()
cnt_w = [0]
for i in range(n):
    cnt_w.append(cnt_w[i] + (1 if s[i] == 'W' else 0))
cnt_w.append(cnt_w[n])
min_cnt = cnt_w[n-1]
for i in range(n):
    min_cnt = min(min_cnt, cnt_w[i] + (n - 1 - i) - (cnt_w[n] - cnt_w[i + 1]))
print(min_cnt)


Measured memory_bytes: 15520