akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll x;   cin >> x;
    ll ans = 0;
    ans += (x/11)*2;
    if(x%11 <= 6 && x%11 > 0)   ans += 1;
    if(x%11 > 6)    ans += 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int[] n = cin.ArrayInt(5);
            int a = n[0] * 60 + n[1];
            int b = n[2] * 60 + n[3];
            int c = b - a;

            Console.WriteLine(c - n[4]);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 27224
import sys

input = sys.stdin.buffer.readline
r, c, k = map(int, input().split())


graph = [[0] * (c) for _ in range(r)]

for _ in range(k):
    d, e, f = map(int, input().split())
    graph[d - 1][e - 1] = f


infi = 10 ** 10
money = [[[-infi] * (c) for _ in range(r)] for _ in range(4)]
money[0][0][0] = 0
for i in range(r):
    for j in range(c):
        for t in range(4):
            m = money[t][i][j]
            delta = graph[i][j]
            if i < r - 1:
                ni = i + 1
                nj = j
                nt = 0
                money[nt][ni][nj] = max(money[nt][ni][nj], m)
                if t < 3:
                    money[nt][ni][nj] = max(money[nt][ni][nj], m + delta)

            if j < c - 1:
                ni = i
                nj = j + 1
                nt = t
                money[nt][ni][nj] = max(money[nt][ni][nj], m)
                if t < 3:
                    nt = t + 1
                    money[nt][ni][nj] = max(money[nt][ni][nj], m + delta)

ans = 0
if graph[r - 1][c - 1] > 0:
    for t in range(3):
        money[t][r - 1][c - 1] += graph[r - 1][c - 1]
for i in range(4):
    ans = max(money[i][r - 1][c - 1], ans)

print(ans)


Measured memory_bytes: 429224
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

	long ans = 0;
	for (int bit = 0; bit < (1 << (s.size() - 1)); bit++) {
		vector<int> v;
		for (int i = 0; i < s.size() - 1; i++) {
			if (bit & (1 << i)) {
				v.push_back(i);
			}
		}

		string s2 = s;
		vector<string> sub;
		if (v.size() == 0) {
			sub.push_back(s2);
		}
		else {
			int prev = 0;
			for (int i = 0; i < v.size(); i++) {
				int eraseN = v[i] + 1 - prev;
				sub.push_back(s2.substr(0, eraseN));
				s2.erase(0, eraseN);
				prev += eraseN;
			}
			sub.push_back(s2);
		}

		long sum = 0;
		for (int i = 0; i < sub.size(); i++) {
			sum += atol(sub[i].c_str());
		}

		ans += sum;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
#define YN(f) cout<<((f)?"Yes":"No")<<endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000; 

int main(){
	int n,a[100010],dim=0;
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	for(int i=0;i<1000000;i++){
		if(i<20){DEB(dim)END}
		if(a[dim]==2){
			cout<<i+1<<endl;
			return 0;
		}
		dim=a[dim]-1;
	}
	cout<<-1<<endl;
	return 0;
}

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

using namespace std;

constexpr char endl('\n');

long long abso(long long x) {
    return x > 0 ? x : -x;
}

using r_t = size_t;


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

    size_t x, y, z;
    cin >> x >> y >> z;

    swap(x, y);
    swap(x, z);

    cout << x << " " << y << " " << z << ::endl;
    

    return 0;
}


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

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= m; j++){
            if (m * i + n * j - 2 * i * j == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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


int selectionsort(int A[], int N) {

  int count = 0;
  for (int i = 0; i< N; i++) {

    int minj = i;

    for (int j = i; j < N; j++) {

      if (A[j] < A[minj]) minj = j;
    }

    swap(A[i], A[minj]);
    if (i != minj) count++;
  }
  
  for (int i = 0; i < N; i++) {
    if (i != N-1) cout << A[i] << " ";

    else cout << A[i] << "\n";
  }
  cout << count << "\n";
  
	      
}

int main() {

  int A[100];
  int N;

  cin >> N;

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

  selectionsort(A, N);
  return 0;
}

Measured memory_bytes: 1164
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    string s;
    cin >> s;
    int b = -1, e;
    for(int i=0;i<s.size();i++) {
        if(s[i]=='A' && b==-1)
            b = i;
        if(s[i]=='Z')
            e = i;
    }
    cout << e - b + 1 << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Edge
{
	int from;
	int to;
	ll cost;
};

bool calcShortest(vector<Edge>& list, int s, int t, int maxV, vector<ll>& d)
{
	for (auto i = 0; i < maxV; ++i)
	{
		d.push_back(LLONG_MAX);
	}
	d[s] = 0;

	auto isLoop = false;
	vector<bool> n(maxV);
	for (auto i = 0; i < 2 * maxV; ++i)
	{
		auto isUpdate = false;
		for (auto e : list)
		{
			if (d[e.from] < LLONG_MAX && d[e.to] > d[e.from] + e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
				isUpdate = true;

				if (i >= maxV)
				{
					n[e.to] = true;
				}
			}

			if (i >= maxV && n[e.from])
			{
				n[e.to] = true;
			}
		}
		if (!isUpdate)
		{
			break;
		}
	}

	return n[t];
}

int main()
{
	int N, M;
	cin >> N >> M;

	vector<Edge> list;
	for (auto i = 0; i < M; ++i)
	{
		int a, b;
		ll c;
		cin >> a >> b >> c;
		--a;
		--b;
		list.push_back({ a, b, -c });
	}

	vector<ll> d;
	if (calcShortest(list, 0, N - 1, N, d) != false)
	{
		cout << "inf" << endl;
	}
	else
	{
		cout << -d[N - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
#define maxx 1000010
long long l1,r1,l2,r2,num,mid;
long long a[1000010],b[1000010],c[1000010];
int main()
{
    long long t;
    scanf("%lld",&t);
    num=0;
    for(long long i=0; i<t; i++)
        scanf("%lld",&a[i]);
    for(long long i=0; i<t; i++)
        scanf("%lld",&b[i]);
    for(long long i=0; i<t; i++)
        scanf("%lld",&c[i]);
    sort(a,a+t);
    sort(b,b+t);
    sort(c,c+t);
    for(long long i=0; i<t; i++)
    {
        l1=0;
        r1=t-1;
        while(l1<=r1)
        {
            mid=l1+(r1-l1)/2;
            if(a[mid]<b[i])
                l1=mid+1;
            else
                r1=mid-1;
        }
        l2=0;
        r2=t-1;
        while(l2<=r2)
        {
            mid=l2+(r2-l2)/2;
            if(c[mid]<=b[i])
                l2=mid+1;
            else
                r2=mid-1;
        }
        num=num+(l1*(t-l2));
    }
    printf("%lld\n",num);
    return 0;
}


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

#define ll long long

void solve(){
    ll n,a,b;
    cin >> n >> a >> b;
    if (a == 0 || a == 0 && b == 0){
        cout << 0 << endl;
        return;
    }
    if (a + b > n){
        if (a >= n)
            cout << n << endl;
        else
            cout << a << endl;
        return;
    }
    ll last = n % (a + b);
    ll ans = (n / (a + b)) * a + min(last,a);
    cout << ans << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
  
namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
			while(true){
				string a=Console.ReadLine();
				if(a==null)break;
				var abc=a.Split(',').Select(double.Parse).ToArray();
				if(abc[1]/abc[2]/abc[2]>=25)
				Console.WriteLine(abc[0]);
				
				}
                
	    }
     }
}
    

Measured memory_bytes: 9360
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int H,N;
    cin>>H>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    ll sum=0;
    REP(i,N) sum+=A[i];
    if(H<=sum) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
vector<int> G[maxn];
int dfn[maxn],low[maxn];
int n,m,u,v,dep,ans;

void init()
{
    dep=ans=0;
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    for(int i=0;i<=n;i++) G[i].clear();
}

void Tarjan(int u,int fa)
{
    dfn[u]=low[u]=++dep;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(!dfn[v]){
            Tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]) ans++;
        }else if(v!=fa)
            low[u]=min(low[u],dfn[v]);
    }
}

int main()
{
    while(cin>>n>>m)
    {
        init();
        for(int i=0;i<m;i++){
            cin>>u>>v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        Tarjan(1,-1);
        cout<<ans<<endl;
    }
    return 0;
}


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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int ans = n / 1000;
	if ( ans * 1000 < n) 
		ans++;

	cout << ans * 1000 - n << endl;
}


Measured memory_bytes: 3652
n,x = gets.chomp.split(" ").map(&:to_i)

result = 0

while true do
  length = 2 ** (n + 2) - 3
  p_num = 2 ** (n + 1) - 1
  if n == 0
    result += 1
    break
  elsif x == 1 # 最下層
    break
  elsif x == length # 最上層
    result += p_num
    break
  elsif x == length / 2 + 1 # ちょうど真ん中
    result += (p_num / 2 + 1)
    break
  elsif x <= length / 2
    n -= 1
    x -= 1
  else
    result += (p_num / 2 + 1)
    n -= 1
    x -= length / 2 + 1
  end
end

puts result



Measured memory_bytes: 14348
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
scanf("%d%d%d%d",&A,&B,&C,&D);
if(A*B>C*D)
{
    printf("%d\n",(A*B));
   
}
else
if(A*B<C*D){
printf("%d\n",(C*D));
}
else
    printf("%d\n",(A*B));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

const int mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

void test_case(){
	int n, m , k; cin >> n >> m >> k;
	mint ans = 0;
	mint col = m;
	for(int x = n-1 ; x >= 0 ; --x){
		mint now = col;
		now *= c(n-1,x);
		if(x <= k)
			ans+=now;
		col *= m-1;
	}
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 6208
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    ll N;
    cin >> N;

    ll ans = N;
    for(ll i=1; i*i<=N; i++){
        if(N%i!=0) continue;
        ans = min(ans, i+N/i-2);
    }
    cout << ans << endl;
}

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

static const int ds = 6;

void dbigsort( int a[], int i0, int i1, int i2, int i3 ) {
	int ta[] = { a[i0], a[i1], a[i2], a[i3] };
	int max = ta[0];
	for( int i = 0; i < 4; i++ ) {
		if( max < ta[i] ) {
			max = ta[i];
		}
	}

	int t = 0;
	while( true ) {
		if( a[i0] == max ) {
			break;
		}
		t = a[i0];a[i0]=a[i1];a[i1]=a[i2];a[i2]=a[i3];a[i3]=t;
	}

	return;
}

bool dcomp( int a[], int b[] )
{
	for( int i = 0; i < ds; i++ ) {
		if( a[i] != b[i] ) {
			return false;
		}
	}

	return true;
}

int main()
{
	int dx[ds], dy[ds];

	for( int i = 0; i < ds; i++ ) {
		cin >> dx[i];
	}
	dbigsort( dx, 0, 1, 5, 4 );
	dbigsort( dx, 0, 3, 5, 2 );
	dbigsort( dx, 1, 2, 4, 3 );

	for( int i = 0; i < ds; i++ ) {
		cin >> dy[i];
	}
	dbigsort( dy, 0, 1, 5, 4 );
	dbigsort( dy, 0, 3, 5, 2 );
	dbigsort( dy, 1, 2, 4, 3 );

	cout << ( dcomp(dx,dy)?"Yes":"No" ) << endl;

	return 0;
}


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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<ll> a(N);
  vector<ll> m(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll rain = a[0];
  for (int j = 1; j < N; j++) {
    if (j % 2 == 1)
      rain -= a[(0 + j) % N];
    else
      rain += a[(0 + j) % N];
  }
  m[0] = rain;
  for (int i = 1; i < N; i++) {
    m[i] = (a[i - 1] - m[i - 1] / 2) * 2;
  }
  for (int i = 0; i < N; i++) {
    cout << m[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int n,m,A[15],B[101];

int mem[101][1<<15],used[101][1<<15];
int dfs(int idx,int sta,int sum){
  if(idx==m) return 0;
  if(used[idx][sta]++)return mem[idx][sta];
  int &res=mem[idx][sta]=abs(sum-B[idx])+dfs(idx+1,sta,sum);
  for(int i=0;i<n;i++)
    if((sta>>i)&1)res=min(res,dfs(idx,~((~sta)|(1<<i)),sum-A[i]));
  return res;
}

int main(){
  while(1){
  cin>>n>>m;
  if(!n&&!m)break;
  int sum=0;
  for(int i=0;i<n;i++) cin>>A[i],sum+=A[i];
  for(int i=0;i<m;i++) cin>>B[i];
  sort(A,A+n);
  sort(B,B+m,greater<int>());
  memset(used,0,sizeof(used));
  cout<<dfs(0,(1<<n)-1,sum)<<endl;
  }
  return 0;
}

Measured memory_bytes: 28840
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  int n,l;
  int mini = 1141514,wa = 0,st = 0;
  cin >> n >> l;
  for(int i=1;i<=n;i++){
    wa += (i + l -1);
  }
  for(int i=1;i<=n;i++){
    if(abs(i + l -1) < mini){
      mini = abs(i + l -1);
      st = i + l -1;
    }
  }
  cout << wa -st;
  return 0;
}


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

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        System.out.print(a/b+" ");
        System.out.print(a%b+" ");
        System.out.printf("%.5f\n",(double)a/b);
    }
}

Measured memory_bytes: 24708
#include<cstdio>
int n,m,i,j,k,k2,t,x,y,z,a[2505],v[2505],st[5005],en[5005],len[5005],last[2505],nxt[5005],st2[5005],en2[5005],last2[2505],nxt2[5005],find[10000005];
bool b[2505],f[2505];
void build(int x,int y,int z)
{
	k++,st[k]=x,en[k]=y,len[k]=z,nxt[k]=last[x],last[x]=k;
}
void build2(int x,int y)
{
	k2++,st2[k2]=x,en2[k2]=y,nxt2[k2]=last2[x],last2[x]=k2;
}
void go(int x)
{
	for (int i=last2[x];i;i=nxt2[i])
	if (!f[en2[i]])
	{
		f[en2[i]]=true;
		go(en2[i]);
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		build(x,y,z);
		build2(y,x);
	}
	f[n]=true;
	go(n);
	for (i=1;i<=n;i++)
	a[i]=-2e9;
	a[1]=0,x=y=find[1]=1,b[1]=true;
	while (x<=y)
	{
		b[find[x]]=false;
		for (i=last[find[x]];i;i=nxt[i])
		if (a[en[i]]<a[st[i]]+len[i]-t&&f[en[i]])
		{
			a[en[i]]=a[st[i]]+len[i]-t;
			if (!b[en[i]])
			b[en[i]]=true,y++,find[y]=en[i],v[en[i]]++;
			if (v[en[i]]>n)
			return printf("-1\n")&&0;
		}
		x++;
	}
	printf("%d\n",a[n]>0?a[n]:0);
	return 0;
}

Measured memory_bytes: 24960
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n = int(input())
if n % 111 == 0:
    print(n)
else:
    a = n//111
    print((a+1)*111)


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

using namespace std;

const int MOD = 998244353;

int addm(int a, int b)
{
	return (0LL + a + b) % MOD;
}

int mulm(int a, int b)
{
	return (1LL * a * b) % MOD;
}

int powm(int a, int n)
{
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return mulm(a, powm(mulm(a, a), n / 2));
	}
	else {
		return powm(mulm(a, a), n / 2);
	}
}

int invm(int a)
{
	return powm(a, MOD - 2);
}

class mod_factorial
{
public:
	mod_factorial(int n)
		: f(n + 1)
		, f_inv(n + 1)
	{
		f[0] = 1;
		for (int i = 1; i <= n; ++i) {
			f[i] = mulm(i, f[i - 1]);
		}

		f_inv[n] = invm(f[n]);
		for (int i = n - 1; i >= 0; --i) {
			f_inv[i] = mulm(i + 1, f_inv[i + 1]);
		}
	}

	int fact(int i) {
		return f[i];
	}
	int fact_inv(int i) {
		return f_inv[i];
	}

	int comb(int n, int r) {
		if (r < 0 || n < r) {
			return 0;
		}
		return mulm(f[n], mulm(f_inv[r], f_inv[n - r]));
	}

private:
	std::vector<int> f;
	std::vector<int> f_inv;
};

int main()
{
	int N, M, K;
	cin >> N >> M >> K;

	mod_factorial f(N + 1);

	int ans = 0;
	for (int i = 0; i <= K; ++i) {
		int tmp = M;
		tmp = mulm(tmp, f.comb(N - 1, i));
		tmp = mulm(tmp, powm(M - 1, N - i - 1));
		ans = addm(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4844
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        long n = long.Parse(ReadLine());

        // ad - bc == n
        long a = 1000000000L; // 10^9
        long d = n / a;
        long b = -1;
        long c = n % a;

        long x1 = 0;
        long y1 = 1;
        long x2 = x1 + a;
        long y2 = y1 + b;
        long x3 = x1 + c;
        long y3 = y1 + d;


        if (n == a * a)
        {
            WriteLine($"0 0 {a} 0 0 {a}");
            return;
        }

        WriteLine($"{x1} {y1} {x2} {y2} {x3} {y3}");
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 201000;
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    int ans = 0;
    int l = 0;
    int r = s.length() - 1;
    while(l < r){
        if (s[l] == s[r]){
            l++;
            r--;
        } else{
            if (s[l] == 'x'){
                ans++;
                l++;
            } else
            if (s[r] == 'x'){
                ans++;
                r--;
            } else
            if (s[l] != 'x' && s[r] != 'x'){
                cout << -1;
                return 0;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    vector<long long int> a(n),b(n),c(n-1);
    REP(i,n){
        cin>>a[i];
    }
    REP(i,n){
        cin>>b[i];
    }
    REP(i,n-1){
        cin>>c[i];
    }
    long long int result=0;
    REP(i,n){
        result+=b[a[i]-1];
        if(i>0){
            if(a[i]-a[i-1]==1){
                result+=c[a[i-1]-1];
            }
        }
        //cout << result << endl;
    }
    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 888
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    string s;
    cin>>s;
    string ans="No";
    for(ll i=0;i<s.size()-1;++i){
        if(s[i]=='A'){
            if(s[i+1]=='C'){
                ans="Yes";
                break;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
pss=[list(input().split())for _ in range(m)]

isAC=[False]*100005
cntWA=[0]*100005
ans=0

for i in range(m):
	num = int(pss[i][0])
	if isAC[num]:
		continue
	if pss[i][1] == "WA":
		cntWA[num]+=1
	else:
		ans+=cntWA[num]
		isAC[num]=True
print(sum(isAC),ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    int left = 0; int right = 0;
    int ans = 0;
    while (1){
        if (right >= n - 1) break;
        while (h[right + 1] <= h[right]) {
            right++;
            if (right >= n - 1) break;
        }
        ans = max(ans, right - left);
        left = right + 1;
        right = left;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

vector<int> prime(int N) {
    vector<int> pri;
    vector<bool> is_prime;
    is_prime    = vector<bool>(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    FOR(i, 2, N + 1) {
        if (is_prime[i]) {
            pri.push_back(i);
            FORSTEP(j, 2 * i, N + 1, i) is_prime[j] = false;
        }
    }
    return pri;
}

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

    int N;
    cin >> N;

    auto pri = prime(55555);
    int cnt = 0, n = 0;

    REP(i, pri.size() + 1) {

        if (cnt == N)
            break;
        if (pri[i] % 5 == 1) {
            cout << pri[i] << " ";
            cnt++;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, k;
string s;

signed main() {
	cin >> n >> s >> k;
	for (int i = 0; i < n; i++) {
		if (s[i] == s[k - 1])cout << s[i];
		else cout << '*';
	}
	cout << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h> 
typedef unsigned long long ll;
#define length 100000   //10万
#define kw_len 10
#define pi 3.14159265358979323846
ll factor[300];
ll memory[300]; 
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num){
    int i = 0,kosuu=0;
    while(*(factor+i) != 0){
        while(num % *(factor+i)==0){
            num /= *(factor+i);
            memory[*(factor+i)] +=1;
        }
        if(num==1)break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろ*/
int elast(ll number){    
    ll tmp=0;
    int flag=0;
    *factor = 2;
    for(int i=3;i <= number;i++){
        flag=0;
        for(int j=0;j <= tmp ;j++){
            if(i % (*(factor+j)) == 0){
                flag=1;
                break;
            }
        }
        if(flag)continue;
        tmp += 1;
        *(factor+tmp) = i;
    }
        return tmp+2;
}

int compare(const int*a,const int *b){
    if(*a<*b)
      return -1;
    else if(*a>*b)
      return 1;
    return 0;
}

ll nCr(int n,int r){
  ll val=1;
  int i;
  if(r==0)return 1;
  for(i=0;i<n-r;i++){
		val *= (n-i);
		val /= (i+1);
	}
  return val;
}

ll nPr(int n,int r){
  ll val=1;
  int i;
  for(i=0;i<r;i++){
    val *= (n-i);
  }
  return val;
}
/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/
int main(){
    double a,b,degree;
    double x,sum;
    scanf("%lf%lf%lf",&a,&b,&x);
    if((b-(x/a/a))<b/2){
    sum = atan(
        a / ((b-(x/a/a))*2)
    );
    }
    else{
        sum = atan(
            (x/a/b)/b*2
        );
    }
    degree = sum *180 / pi;
    printf("%lf",90.00000-degree);
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {

    int N;
    cin >> N;
    vector<int> W(N);
    rep(i,N){
        cin >> W[i];
    }
    int sum = accumulate(W.begin(),W.end(),0);
    int wk1 = 0;
    int wk2 = sum;
    int ans;
    rep(i,N){
        wk1+=W[i];
        wk2-=W[i];
        if(wk1 == wk2){
            ans = 0;
            break;
        }else if(wk1 > wk2){
            ans = min((wk1-wk2),(wk2+W[i]-wk1+W[i]));
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    ll N; cin >> N;
    vector<ll> A(N),sorted_A(N);

    rep(i,N){
        ll a; cin >> a;
        sorted_A[i] = a;
        A[i] = a;
    }
    sort(sorted_A.begin(),sorted_A.end(),greater<ll>());

    bool bl = (sorted_A[0] == sorted_A[1]);
    for(auto it : A){
        if(bl){
            cout << sorted_A[0] << endl;
        }else if(it != sorted_A[0]){
            cout << sorted_A[0] << endl;
        }else cout << sorted_A[1] << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (n);++i)

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;
    int dp[105][4][2] = {};
    dp[0][0][0] = 1;
    rep(i, n) rep(j, 4) rep(k, 2)
    {
        int nd = s[i] - '0';
        rep(d,10){
            int ni = i+1, nj = j, nk = k;
            if(d!=0)
                nj++;
            if(nj>K)
                continue;
            if(k==0){
                if(nd<d)
                    continue;
                if (nd > d)
                    nk = 1;
            }

            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* Author rumoisen */
/* created 2018/11/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    int n,a;
    cin>>n>>a;
    cout<<n*n-a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k,n;
	cin>>k>>n;
	int a[n];
	for(int i=0; i<n; i++)
		cin>>a[i];
	int m;
	m = a[0]-a[n-1]+k;
	for(int i=1; i<n; i++)
		m = max(m, a[i]-a[i-1]);
	cout<<k-m<<endl;	
	return 0;
};


Measured memory_bytes: 1024
N, M = map(int, input().split())

ks = [list(map(int, input().split())) for _ in range(M)]

p = list(map(int, input().split()))


def D2NC(D: int, N: int, link=False) -> list:
    """
    10進数表記の数字をN進数表記に変換する。
    (関数名は"Decimal to N_ary Converter"の略。)

    Parameters
    ----------
    D : 10進数表記で与えられた数字。
    N : 変換したい底。
    link : Trueにすると結果を文字列結合して返す。

    Returns
    -------
    res : 変換結果。デフォルトではリスト化して返す。
    """
    alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    res = []
    while D > 0:
        if D % N > 9:
            tmp = alp[D % N - 10]
            res.insert(0, str(tmp))
        else:
            res.insert(0, str(D % N))
        D //= N
    if not res:
        res.append('0')
    if link:
        res = ''.join(res)
    return res


digit = N

ans = 0
for i in range(2**N):
    switch = D2NC(i, 2, True).zfill(digit)
    idx = 0
    flg = 1
    for i in ks:
        ct = 0
        for j in i[1:]:
            if switch[j-1] == '1':
                ct += 1
        if ct % 2 != p[idx]:
            flg = 0
            break
        idx += 1
    if flg:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll S, ll W) {
  if (W >= S) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}
int main() {
  ll S;
  scanf("%lld", &S);
  ll W;
  scanf("%lld", &W);
  solve(S, W);
  return 0;
}


Measured memory_bytes: 3764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			int N = Integer.parseInt(br.readLine());
			String[] S = new String[N];
			int[] Sarray = new int[N];

			 S= br.readLine().split("\\s+");
			for(int x = 0; x < N; x++){
				Sarray[x] = Integer.parseInt(S[x]);
			}

			int Q = Integer.parseInt(br.readLine());
			String[] T = new String[Q];
			int temp = 0;
			int answer = 0;

			T = br.readLine().split("\\s+");
			for(int y = 0; y < Q; y++){
				temp = Integer.parseInt(T[y]);
				for(int k = 0; k < N; k++){
					if(temp == Sarray[k]){
						answer++;
						break;
					}
				}
			}

			System.out.println(answer);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}



Measured memory_bytes: 30800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  bool mul = false;
  cin >> N;
  
  for(int i = 1;i <= 9;i++){
    for(int j = 1;j <= 9;j++){
      if(N == i * j){
      mul = true;
      }
    }  
  }
  
  if(mul){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N, K  = map(int, input().split())
As = sorted(list(map(int, input().split())))
Fs = sorted(list(map(int, input().split())),reverse=True)
Xs = [a*f for a,f in zip(As,Fs)]
X_M = max(Xs)

def f(x):
    K_tmp = sum([max(0,a-x//f) for a,f in zip(As,Fs)])
    return K_tmp <= K

def  binarySearch(l,r,target):
    while r - l > 1:
        mid = (l+r)//2
        """計算を入れる"""
        # print(mid, guess)
        if f(mid):
            r = mid
        else:
            l = mid
    return r

print(binarySearch(-1,X_M,K))

Measured memory_bytes: 137464
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

first, second, third = 0, 0, 0
for i in p:
    if i <= a:
        first += 1
    if a+1 <= i <= b:
        second += 1
    if b+1 <= i:
        third += 1

print(min([first, second, third]))

Measured memory_bytes: 3064
#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 <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

main(){
  string hebi;
  int n;
  cin>>n;
  while(n--){
    cin>>hebi;
    bool a=true,b=true;
    if(hebi.size()<6 || hebi.size()%2){
      a=false;
      b=false;
    }
    rep(i,hebi.size()){
      if(i==0 && hebi[i]=='>')continue;
      if(i==1 && hebi[i]=='\'')continue;
      if(i==hebi.size()-1 && hebi[i]=='~')continue;
      else if(i>=2 && i<hebi.size()-1 && i!=hebi.size()/2 && hebi[i]=='=')continue;
      else if(i==hebi.size()/2 && hebi[i]=='#')continue;
      a=false;
    }

    rep(i,hebi.size()){
      if(i==0 && hebi[i]=='>')continue;
      if(i==1 && hebi[i]=='^')continue;
      if(i==hebi.size()-1 && hebi[i]=='~')continue;
      if(i==hebi.size()-2 && hebi[i]=='~')continue;
      else if(i%2==0 && hebi[i]=='Q')continue;
      else if(i%2==1 && hebi[i]=='=')continue;
      b=false;
    }

    if(a)puts("A");
    else if(b)puts("B");
    else puts("NA");
  }
}

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

int main() { 
  int n, T;
  cin >> n >> T;
  vector<int> v;
  while(n--){
  	int c, t;
    cin >> c >> t;
    if(t <= T){
    	v.push_back(c);	
    }
  }
  if(v.size() != 0){
  	cout << *min_element(v.begin(), v.end()) << endl;
  }else{
  	cout << "TLE" << endl;
  }
  return 0; 
}

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

 
	
	return 0;
}

Measured memory_bytes: 1156
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll D;
	cin >> D;

	ll N = 26;
	vector <ll> c(N);
	for (ll ii = 0; ii < N; ++ii){
		cin >> c[ii];
	}
	vector<vector<ll>> s(D, vector <ll> (N));
	for (ll ii = 0; ii < D; ++ii){
		for (ll jj = 0; jj < N; ++jj){
			cin >> s[ii][jj];
		}
	}

	//貪欲法
	vector <int> ans(D, 0);
	vector <int> last(N, -1);
	vector < set<int> > select(N);
	for (int ii = 0; ii < N; ++ii){
		select[ii].insert(-1);
	}
	for (ll d = 0; d < D; ++d){
		//d日目の最適解を選ぶ
		ll val = 0;
		ll idx = 0;
		for (int ii = 0; ii < N; ++ii){
			ll tmp = s[d][ii] + c[ii]*(d - last[ii]);
			if (tmp > val){
				val = tmp;
				idx = ii;
			}
		}
		ans[d] = idx;
		last[idx] = d;
		select[idx].insert(d);
	}

	//ランダムに値を変更する
	int trial = 1001001;
	for (int t = 0; t < trial; ++t){
		int d = rand() % D;
		int prevType = ans[d];
		int newType = rand() % N;
		while(prevType == newType) {
			newType = rand() % N;
		}
		ll dif = s[d][newType] - s[d][prevType];

		auto itr = upper_bound(select[newType].begin(), select[newType].end(), d);
		ll newDist = (itr != select[newType].end()) ? (*itr - d) : (D - d);
		auto itr2 = upper_bound(select[newType].rbegin(), select[newType].rend(), d);
		ll newVal = d - *itr2;
		dif += newVal * newDist;

		itr = upper_bound(select[prevType].begin(), select[prevType].end(), d);
		ll prevDist = (itr != select[prevType].end()) ? (*itr - d) : (D - d);
		itr2 = upper_bound(select[prevType].rbegin(), select[prevType].rend(), d);
		ll prevVal = d - *itr2;
		dif -= prevVal * prevDist;

		if (dif > 0){
			select[prevType].erase(d);
			select[newType].insert(d);
			ans[d] = newType;
		}
	}


	for (ll d = 0; d < D; ++d){
		cout << ans[d] + 1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 3724
#素因数分解
def prime_factorization(N):
    ans = []
    if N==1:
        return [[1,0]]
    a = 2
    count = 0
    t = N
    while a*a<=t:
        if N%a!=0:
            a = a + 1
            count = 0
            continue
        while N%a==0:
            count = count + 1
            N = N//a
        ans.append([a, count])
        a = a + 1
        count = 0
    if (N!=1):
        ans.append([N,1])
    return ans
e = 0
def dfs(N, n, sum):
    global e
    if N<sum:
        e = e - 1
        return
    e = e + 1
    dfs(N, n+1, sum+n)

N = int(input())
if N==1:
    print(0)
    exit()
L = prime_factorization(N)

ans = 0

for a,b in L:
   e = 0
   dfs(b, 1, 0)
   ans = ans + e
#print(L)
print(ans)

#print(dfs(2, 1, 0))

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
vector<int> V[MC];

int dfs(int p , int q){
	int g = 0;
	for(auto u : V[q]){
		if(u == p) continue;
		g ^= dfs(q,u)+1;
	}
	return g;
}

int main(){
	cin >> N;
	repp(i,1,N){
		int x,y;
		cin >> x >> y;
		V[x].PB(y);
		V[y].PB(x);
	}
	cout << (dfs(-1,1)?"Alice":"Bob") << endl;
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int G[707][707], vis[707], ok[2][1407], n, m;

bool dfs(int u, pi &ret, int c = 1) {
	vis[u] = c;
	ret.F++, ret.S += c == 1;
	for(int i=1;i<=n;i++) {
		if(G[u][i] == 0) continue;
		if(!vis[i]) {
			if(!dfs(i, ret, c ^ 3))
				return false;
		} else if(vis[i] == c) {
			return false;
		}
	}
	return true;
}

int main()
{
	IO_OP;
	
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i != j)
				G[i][j] = 1;
	for(int i=0;i<m;i++) {
		int u, v;
		cin >> u >> v;
		G[v][u] = G[u][v] = 0;
	}
	vector<pi> v;
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			pi p = {0, 0};
			if(!dfs(i, p)) {
				cout << -1 << endl;
				return 0;
			}
			v.PB(p);
		}
	}
	ok[0][0] = 1;
	for(pi p:v) {
		int x = p.S, y = p.F - p.S;
		for(int i=0;i<=n;i++) {
			ok[1][y+i] |= ok[0][i];	
			ok[1][x+i] |= ok[0][i];	
		}
		for(int i=0;i<=n;i++) {
			ok[0][i] = ok[1][i];
			ok[1][i] = 0;
		}
	}
	int ans = INF;
	for(int i=0;i<=n;i++) {
		if(ok[0][i]) {
			ans = min(ans, i*(i-1)/2+(n-i)*(n-i-1)/2);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 2176
n = int(input())
dic = {}
ans = 0
for i in range(n):
  li_1 = list(input())
  li_1.sort()
  word = "".join(li_1)
  if word in dic:
    dic[word] += 1
  else:
    dic[word] = 1
for key in dic:
  s = dic[key]
  ans += s*(s-1)//2
print(ans)
  

Measured memory_bytes: 17932
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(void){
    int n,m;
    cin >> n >> m;
    vector<long long> neg;
    vector<long long> pos;
    vector<long long> arr;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        if(temp < 0) neg.push_back(-1 * temp);
        else pos.push_back(temp);
        arr.push_back(temp);
    }

    long long result = 1000000000;

    for(int i = 0; i + m - 1 < n; i++){
        long long temp;
        long long cneg = 0;
        long long cpos = 0;

        if(arr[i] < 0) cneg = (arr[i] * - 1);
        if(arr[i + m - 1] > 0) cpos = arr[i + m - 1];

        if(cneg < cpos) temp = cneg * 2 + cpos;
        else temp = cpos * 2 + cneg;
        if(result > temp) result = temp;
    }

    cout << result << endl;
    return 0;
}



Measured memory_bytes: 2800