akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pii pair< int, int >
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fr1(i, n) for (int i = 1; i <= n; ++i)
#define ss second
#define ff first
#define pb push_back

using namespace std;

int n, m;

const int N = 1e5 + 1;

int usd[N], arr[N], sz[N], par[N];
bool even[N];
vector< pii > adj[N];

int root (int x) {
	int tmp = x;
	while (arr[x] != x)
		x = arr[x];
	return arr[tmp] = x;
}

void merge (int x1, int x2, int idx) {
	int r1 = root (x1), r2 = root (x2);
	if (r1 == r2) return;
	adj[x1].push_back ({x2, idx});
	adj[x2].push_back ({x1, idx});
	if (sz[r2] > sz[r1]) swap (r1, r2);
	arr[r2] = r1;
	sz[r1] += sz[r2];
	return;
}

int dfs (int cur) {
	int rem = -1;
	if (!even[cur]) rem = cur;

	for (auto i : adj[cur]) {
		if (i.ff == par[cur]) continue;
		par[i.ff] = cur;
		int x = dfs (i.ff);
		if (x == -1) continue;
		usd[i.ss] ^= 1;
		if (rem == -1) {
			rem = x;
			continue;
		}
		rem = -1;
	}
	return rem;
}

void solve () {
	cin >> n >> m;

	if (m % 2) {
		int a, b;
		fr (j, m) {
			cin >> a >> b;
		}
		cout << "-1\n";
		return;
	}

	fr1 (i, n) {
		even[i] = 1;
		adj[i].clear ();
		arr[i] = i;
		sz[i] = 1;
		par[i] = -1;
	}
	vector< pii > edges;
	fr (i, m) {
		usd[i] = 0;
		int a, b;
		cin >> a >> b;
		even[b] ^= 1;
		merge (a, b, i);
		edges.pb ({a, b});
	}

	dfs (1);

	// fr (i, m) cout << usd[i] << " ";
	fr (i, m) {
		if (usd[i])
			cout << edges[i].ff << " " << edges[i].ss << endl;
		else
			cout << edges[i].ss << " " << edges[i].ff << endl;
	}
	cout << "\n";
	return;
}

int main () {
	ios_base::sync_with_stdio (false);
	solve ();
	return 0;
}


Measured memory_bytes: 15988
#include<stdio.h>
#define A 100

int main(){
  int tmp,flag=1,i,a[A],n,sw=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  
  while(flag==1){
    flag=0;

    for(i=n-1;i>0;i--){
      if(a[i]<a[i-1]){
	tmp=a[i];
	a[i]=a[i-1];
	a[i-1]=tmp;
	flag=1;
	sw++;
      }
    }
  }
  for(i=0;i<n-1;i++) printf("%d ",a[i]);
  printf("%d\n%d\n",a[i],sw);
  
  
  return 0;
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e3+5, M = 1e4+5;
int h, n, a[N], b[N];
int dp[M];
inline void update(int &a, int b)
{
    if (b == -1) return;
    if (a > b || a == -1) a = b;
}
int main(int argc, char const *argv[])
{
    cin >> h >> n;
    for (int i=1; i<=n; ++i) cin >> a[i] >> b[i];
    memset(dp, -1, sizeof dp);
    dp[h] = 0;
    for (int i=0; i<n; ++i)
    for (int j=h; j>=0; --j)
    {
        if (!~dp[j]) continue;
        update(dp[max(j-a[i+1], 0)], dp[j] + b[i+1]);
    }
    printf("%d\n", dp[0]);
    return 0;
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
#define comuse Comuse()
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll n,a,b;
  cin>>n>>a>>b;
  if(n*a<b){
    co(n*a);
  }
  else{
    co(b);
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
using namespace std;

bool prov(string a,string b, int i)
{
	int n=a.size();
	int m=b.size();
	bool y=1;
	for(int j=0;j<m;j++){
		if(a[i+j]!=b[j]&&a[i+j]!='?')	
			y=0;
	}
	return y;
}
typedef long long ll;

int main()
{
	string s0,t;
	bool tr[100];
	cin>>s0>>t;
	int n = s0.size();
	int m = t.size();
	bool x=0;
	for(int i=0;i<=n-m;i++){
		tr[100]=prov(s0,t,i);
		if(prov(s0,t,i)==1)
			x=1;
	}
	if(x==0){
		cout<<"UNRESTORABLE";
	}
	else{
		int min=0;
		for(int i=0;i<=n-m;i++){
			if(prov(s0,t,i)==1)
				min=i;	
		}
		for(int i=0;i<min;i++){
			if(s0[i]!='?')
				cout<<s0[i];
			else
				cout<<'a';
		}
		for(int i=0;i<m;i++){
			cout<<t[i];
		}
		for(int i=min+m;i<n;i++){
			if(s0[i]!='?')
				cout<<s0[i];
			else
				cout<<'a';
		}
	}
	return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  if(s.size()>t.size()) cout << "GREATER" << endl;
  else if(s.size()<t.size()) cout << "LESS" << endl;
  else if(s>t) cout << "GREATER" << endl;
  else if(s<t) cout << "LESS" << endl;
  else cout << "EQUAL" << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;

void main()
{
    auto input = readln.split.to!(int[]);
    auto N = input[0];
    auto M = input[1];

    ulong X;
    ( 2 ^^ M * (M * 1900 + (N - M) * 100) ).writeln;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P; 
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 200005;
//////////////////////////////


void solve()
{
	Int N, K, ans = LINF;
	cin >> N >> K;
	Int H[330];
	H[0] = 0;
	RREP(i, N) cin >> H[i];

	Int DP[330][330];
	REP(i, N + 1) {
		REP(j, N + 1) {
			DP[i][j] = LINF;
		}
	}

	DP[0][0] = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= i; ++j) {
			for (int k = j - 1; k<i; ++k) {
				DP[i][j] = min(DP[i][j], DP[k][j - 1] + max((Int)0, H[i] - H[k]));
			}
		}
	}

	for (int i = N - K; i <= N; ++i) ans = min(ans, DP[i][N - K]);
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 4392
N = int(input())
def prime(n,p):
  cnt = 0
  while n%p == 0:
    n //= p
    cnt += 1
  return cnt,n
ans = 0
for i in range(1,N+1,2):
  tmp = 1
  t = i
  for p in range(2,i):
    num,t = prime(t,p)
    tmp *= (num+1)
  if tmp == 8:
    ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;
const int N = 2002;
ll dp[N][N];

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

    vector<int> s(n+1), t(m+1);
    rep(i,n) cin >>s[i+1];
    rep(i,m) cin >>t[i+1];

    rep(i,N) dp[0][i] = dp[i][0] = 1;
    for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j){
        if(s[i]==t[j]) dp[i][j] = dp[i-1][j-1];
        dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + mod) % mod;
    }
    cout << dp[n][m] << endl;
    return 0;
}


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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;

bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}

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


signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        ll n;
        cin>>n;
        for(ll i=1;i<=n;i++){
            if(i*(i+1)/2>=n){
                cout<<i;
                return 0;
            }
        }
    }   
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h> 

int main(void)
{
  int n;
  int counter = 0;
  scanf("%d", &n);
  int num[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
    if ( num[i] % 2 == 0 ) {
      if ( num[i] % 3 == 0 || num[i] % 5 == 0 ) {
        counter++;
      }
    } else {
      counter++;
    }
  }
  if ( counter == n ) {
    printf("APPROVED");
  } else {
    printf("DENIED");
  }
  
}





Measured memory_bytes: 128
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
B = [0]
for i in A:
    B.append(B[-1] + i)
B_C = Counter(B)
ans = 0
for key, value in B_C.items():
    ans += value * (value-1) // 2
print(ans)



Measured memory_bytes: 41728
H,W = map(int,input().split())
a = [list(map(str,input().split())) for _ in range(H)]
ans = []
bar = ['#']*(W+2)
ans.append(bar)

for i in range(len(a)):
    item = ['#']
    for j in range(len(a[i])):
        item.append(a[i][j])
    item.append('#')
    ans.append(item)
ans.append(bar)

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


Measured memory_bytes: 3064
// Fuwa Fuwa Time!

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;

const int MAXM = (int) 1e5;

int n, m;

int a[MAXM + 5], ban[MAXM + 5];

inline void input()
{
	n = read<int>(), m = read<int>();
	for(int i = 1; i <= m; ++i) a[i] = read<int>();
}

const int N = 4;

struct matrix
{
	int a[N][N];

	inline matrix operator * (const matrix &rhs) const
	{
		matrix res;
		for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j)
		{
			res.a[i][j] = 0;
			for(int k = 0; k < N; ++k) (res.a[i][j] += (LL) this->a[i][k] * rhs.a[k][j] % MOD) %= MOD;
		}
		return res;
	}
};

inline matrix unit()
{
	matrix res;
	for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) res.a[i][j] = i == j;
	return res;
}

inline matrix fpm(matrix x, int y)
{
	matrix res = unit();
	for(; y; y >>= 1, x = x * x) if(y & 1) res = res * x;
	return res;
}

inline void solve()
{
	static matrix T, B;

	for(int S = 0; S < 4; ++S)
		for(int S0 = S; S0 < 4; S0 = (S0 + 1) | S)
		{
			++B.a[S][S0];
			++T.a[S][S0];
		}
	for(int S = 0; S < 4; ++S) ++T.a[3][S];

	static matrix S;

	S.a[0][0] = 1;
	int lst = 0;
	for(int i = 1; i <= m; ++i)
	{
		S = S * fpm(T, a[i] - lst) * B;
		lst = a[i] + 1;
	}
	S = S * fpm(T, n - lst);

	printf("%d\n", (S.a[0][3] + MOD) % MOD);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int a,b,c,d,i,n,count;
	
	while(scanf("%d\n", &n)==1) {
		count = 0;
		for(a=0;a<10;a++) {
			for(b=0;b<10;b++) {
				for(c=0;c<10;c++) {
					for(d=0;d<10;d++) {
						if(a+b+c+d==n) {
							count ++;
						}
					}
				}
			}
		}
		printf("%d\n", count);
	}	
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <time.h>  
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9) << flush;
//memset(a, 0, sizeof(a));
//--------------------------

int n;
ll a[200005];
map<ll, int> mp;

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

	ll ans = 0;
	ll sum = 0;

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

		if (mp.find(sum) != mp.end()) {
			ans += mp[sum];
			mp[sum]++;
		}
		else {
			mp[sum] = 1;
		}
	}

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


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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    ll n;
    cin >> n;
    map<string,ll> mp;
    for(int i = 0;i < n;i ++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s] ++;
    }

    ll ans = 0;
    for(auto p : mp){
        ll a = p.second;
        ans += a * (a-1) / 2;
    }

    cout << ans << endl;
}

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

using ll = long long;

const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N], l[N], r[N];

void solve(){
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++i){
        l[i] = max(l[i - 1], a[i]);
    }
    for(int i = n; i > 0; --i){
        r[i] = max(r[i + 1], a[i]);
    }
    for(int i = 1; i <= n; ++i){
        cout << max(l[i - 1], r[i + 1]) << "\n";
    }
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6272
#include<iostream>
#include<set>

using namespace std;

int main(){
    int K, N;
    int input;
    cin >> N >> K;
    
    set<int> set;

    for (int i=0; i < K; i++){
        cin >> input;
        set.insert(input);
    }

    while (1){
        if (set.find(N%10)!=set.end()){
            N++;
            continue;
        }
        if (set.find(N%100/10)!=set.end() && N>=10){
            N++;
            continue;
        }
        if (set.find(N%1000/100)!=set.end() && N>=100){
            N++;
            continue;
        }
        if (set.find(N%10000/1000)!=set.end() && N>=1000){
            N++;
            continue;
        }
        if (set.find(N%100000/10000)!=set.end() && N>=10000){
            N++;
            continue;
        }
        break;
    }
    cout << N << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll
#define Endl endl


signed main(){
    int N,p=0;string s;
    cin >> s;N=s.size();
    REP(i,N){if(s[i]=='p'){p++;}}
    cout << N/2 - p << endl;
    
    return 0;
}   


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--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 F			first
#define S			second

ll n, w[300001], e[300001];
string s;
 
int main(int argc, char **argv) {
	cin >> n >> s;
	w[0] = e[0] = 0;
	REP(i, n) {
		bool f = (s[i] == 'W');
		w[i+1] = w[i] + (f ? 1 : 0);
		e[i+1] = e[i] + (f ? 0 : 1);
	}
	ll res = n;
	REP(i, n) res = min(res, w[i]-w[0] + e[n]-e[i+1]);
	cout << res << endl;
	return 0;
}
 

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

void solve() {
    vector<string> S = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s; cin >> s;
    for(int i = 0; i < 7; ++i) {
        if(s == S[i]) {
            cout << 7 - i << '\n';
            return;
        }
    }
}

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


Measured memory_bytes: 256
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, b in ab)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(dp[H])


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

int main(){
    int n;
    cin >> n;
    int min_ = 2e9;
    int max_ = 1 - min_;
    for (int i = 0; i < n; i++) {
        int R;
        cin >> R;
        max_ = max(R - min_, max_);
        min_ = min(R, min_);
    }
    cout << max_ << endl;
    return 0;
}

Measured memory_bytes: 3072
# 絶対値が最も小さい数に向けて、両端から始め、その数より遠い側の数がマイナスなら入れ替えると言う動作を行う
# すると絶対値が最小の数以外は全て正になる
# あとは、絶対値が最小の数が正か負かを判断するのみ
# 絶対値が最小の数の符号は、全体のうちマイナスが奇数個なら負で、偶数個なら正

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

minus = 0
a_min = abs(a[0])
a_sum = 0

for x in a:
  if x < 0:
    minus += 1
    x = -x
  if x < a_min:
    a_min = x
  a_sum += x

if minus % 2 == 0:
  print(a_sum)
else:
  print(a_sum - 2 * a_min)

Measured memory_bytes: 14284
#define _USE_MATH_DEFINES

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <climits>
#include <ctime>

using namespace std;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;

void solve() {
	string A, B;
	getline(cin, A);
	getline(cin, B);
	int n = A.size();
	if (B == string(n, '0')) {
		cout << ((A == B) ? 0 : -1);
		return;
	}
	vector<int> r_cl(n, INT_MAX);
	vector<int> l_cl(n, INT_MAX);
	for (int i = 0; i < n; i++) {
		for (int l = 0; l < n; l++) {
			if (B[(i - l + n) % n] == '1') {
				l_cl[i] = l;
				break;
			}
		}
		for (int r = 0; r < n; r++) {
			if (B[(i + r) % n] == '1') {
				r_cl[i] = r;
				break;
			}
		}
	}
	B += B;
	int ans = INT_MAX;
	for (int start = 0; start < n; start++) {
		string C = B.substr(start, n);
		vector<pair<int,int>> psl({{0,0}}), psr({{0,0}});
		int cnt = 0;
		multiset<int> sl({0}), sr({0});
		for (int i = 0; i < n; i++) {
			if (A[i] != C[i]) {
				cnt++;
				if (l_cl[i] == 0 || r_cl[i] == 0)
					continue;
				psl.push_back({l_cl[i], r_cl[i]});
				psr.push_back({r_cl[i], l_cl[i]});
				sl.insert(l_cl[i]);
				sr.insert(r_cl[i]);
			}
		}
		sort(psl.begin(), psl.end());
		sort(psr.begin(), psr.end());
		ans = min(ans, cnt + n + min(start, n - start));
		for (int i = 0; i < psl.size(); i++) {
			int l = psl[i].first;
			int r = psl[i].second;
			sr.erase(sr.find(r));
			int new_ans = cnt;
			new_ans += l;
			if (!sr.empty()) {
				auto x = sr.end();
				x--;
				new_ans += *x + l;
				new_ans += min(abs(start - *x), n - abs(start - *x));
			} else {
				new_ans += min(abs(start - (n - l) % n), n - abs(start - (n - l) % n));
			}
			ans = min(ans, new_ans);
		}
		for (int i = 0; i < psr.size(); i++) {
			int r = psr[i].first;
			int l = psr[i].second;
			sl.erase(sl.find(l));
			int new_ans = cnt;
			new_ans += r;
			if (!sl.empty()) {
				auto x = sl.end();
				x--;
				new_ans += *x + r;
				new_ans += min(abs(start - (n - *x) % n), n - abs(start - (n - *x) % n));
			} else {
				new_ans += min(abs(start - r), n - abs(start - r));
			}
			ans = min(ans, new_ans);
		}
	}
	cout << ans;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll x;
  cin >> x;
  ll year = 0;
  ll ans = 100;
  while(ans < x){
    ans += ans / 100;
    year++;
  }
  cout << year << '\n';
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    vector<vector<int>> cnt(n, vector<int>(26));
    rep(i,n){
        for(int j = 0; j < s[i].size(); ++j){
            cnt[i][s[i][j]-'a']++;
        }
    }
    string ans = "";
    for(int i = 0; i < 26; ++i){
        char c = 'a'+i;
        int m = 100;
        for(int j = 0; j < n; ++j){
            m = min(m, cnt[j][i]);
        }
        rep(i,m) ans += c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
"""
N = int(input())
A, B = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(M)]
A = list(map(int,input().split()))
"""

N = int(input())
H = list(map(int,input().split()))

lst = []
pre = H[0]
cnt = 0
for i in range(1,N):
  if H[i] <= pre:
    cnt += 1
    pre = H[i]
  else:
    lst.append(cnt)
    cnt = 0
    pre = H[i]
else:
  lst.append(cnt)
   
print(max(lst))
  

Measured memory_bytes: 14224
import itertools
n,m = map(int,input().split())
routes = list(itertools.permutations([i for i in range(2,n+1)]))
nodes = {}
ans = 0
for i in range(1,n+1):
    nodes[i] = []
for _ in range(m):
    a,b = map(int,input().split())
    nodes[a].append(b)
    nodes[b].append(a)
for i in range(len(routes)):
    jud = 1
    if routes[i][0] not in nodes[1]:
        jud = 0
    for j in range(n-2):
        if routes[i][j+1] not in nodes[routes[i][j]]:
            jud = 0
    ans += jud
print(ans)


Measured memory_bytes: 9300
# x = 1
# y = 1
# z = 1

# n = (x ** 2) + (y ** 2) + (z ** 2) + (x * y) + (y * z) + (z * x)
# print(n)

val_list = [0] * 100000
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            val = (x ** 2) + (y ** 2) + (z ** 2) + (x * y) + (y * z) + (z * x)
            # print(n)
            # n_list.append(n)
            val_list[val] += 1
            
n = int(input())
for i in range(1, n + 1):
    print(val_list[i])

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

int main() {
 long long A,B,C,K;
  cin >> A >> B >> C >> K;
  int t=0;
  for (int i=1;i<=K;) {
    if (K<=A) {
      t += K;
      break;
    }
    if (A<=K) {
     t += A;
     i += A;
    }
    if (A < K && K <= A+B) {
      break;
    }
    if (A+B<K&&K<=A+B+C) {
      t -= K-A-B;
      break;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	s+='z';
	ll ans=0,cnt=0;
	for(ll i=0;i<s.size()-1;i++){
		if(s[i]=='A'){
			cnt++;
		}
		else if(s[i]=='B'&&s[i+1]=='C'){
			ans+=cnt;
			i++;
		}
		else{
			cnt=0;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>

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

ll N,M,Q;
ll A[200005];
ll ans[200005];
vector<ll> E[200005];
ll V[200005];
ll dp[200005];
stack<P> a;
P p;

 
void dfs(ll s){
    auto it = lower_bound(dp,dp+N, A[s]);
    ll k = distance(dp,it);
    
    a.push(P(k,dp[k]));
    dp[k] = A[s];
    auto itt = lower_bound(dp,dp+N, 10000000000000000);
    ll l = distance(dp,itt);
    ans[s] = l;
    
    V[s] = 1;
    for(int i=0;i<E[s].size();i++){
        if(V[E[s][i]]==0){
            dfs(E[s][i]);
        }
    }
    p = a.top();
    dp[p.first] = p.second;
    a.pop();
    
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N-1;i++){
        int u,v;
        cin >> u >> v;
        E[u-1].push_back(v-1);
        E[v-1].push_back(u-1);
    }
    for(int i=0;i<N+1;i++){
        dp[i] = 10000000000000001;
    }
    dfs(0);
    for(int i=0;i<N;i++){
        cout << ans[i] << endl;
    }
    
}


Measured memory_bytes: 37640
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



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

string s,t;

int main(){
    cin >> s;
    cin >> t;
    int cnt=0;
    rep(i,s.size()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;

return 0;
}

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



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

ll return_lcm(ll a, ll b){
    ll gcd = return_gcd(a, b);
    return a / gcd * b;
}

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<ll> t(n);
    rep(i,n) cin >> t[i];
    
    ll ans = 1ll;
    for(int i = 0 ; i < n; i++){
        ans = return_lcm(ans,t[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  // vector<int> X(5);
  // int x1, x2, x3, x4, x5;
  int N;
  cin >> N;

  map<string, int> M;
  M["AC"] = 0;
  M["WA"] = 0;
  M["TLE"] = 0;
  M["RE"] = 0;

  // vector<string> S(N);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    // S[i] = s;
    M[s] += 1;
  }

  // for (auto it = M.begin(); it != M.end(); it++) {
  //   cout << it->first << " x " << it->second << endl;
  // }
  cout << "AC x " << M["AC"] << endl;
  cout << "WA x " << M["WA"] << endl;
  cout << "TLE x " << M["TLE"] << endl;
  cout << "RE x " << M["RE"] << endl;

  return 0;
}


Measured memory_bytes: 3228
def solve(string):
    n, *ss = string.split()
    d = {}
    for s in map(lambda x: "".join(sorted(x)), ss):
        d[s] = 1 + d[s] if s in d.keys() else 1
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 27528
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  [n,m] <- getInts
  q <- getInt
  as <- getInts
  let goal = dropLastIncr $ lru m as
  -- print goal
  let g = S.fromList goal
  let rs = reverse $ filter (`S.member` g) as
  let result = if n * length goal > length rs
        then Nothing
        else (iterate (>>= dropGreedy goal) (Just rs)) !! n
  -- mapM_ print . take n $ iterate (>>= dropGreedy goal) (Just rs)
  putStrLn . yesNo $ isJust result

dropGreedy :: (Eq a) => [a] -> [a] -> Maybe [a]
dropGreedy [] xs = Just xs
dropGreedy _ [] = Nothing
dropGreedy (x:xs) (y:ys)
  | x == y  = dropGreedy xs ys
  | otherwise = (y :) <$> dropGreedy (x:xs) ys

lru m as = let
  lasts = accumArray min 1 (1,m) $ zip as [0,-1..]
  in  map snd . sort . map swap $ assocs lasts

dropLastIncr = reverse . foo . reverse  where
  foo xs = map snd . dropWhile (uncurry (>)) $ zip xs (tail xs)
 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 52092
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>

using namespace std;

int path[201][201];


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

	vector<int> r;
	for (int i = 0; i < R; i++) {
		int ri;
		cin >> ri;
		r.push_back(ri);
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i != j) path[i][j] = 1e9 + 1;
		}
	}

	for (int i = 0; i < M; i++) {
		int A, B, C;
		cin >> A >> B >> C;
		path[A][B] = path[B][A] = C;
	}

	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				if (path[i][j] > path[i][k] + path[k][j]) {
					path[i][j] = path[i][k] + path[k][j];
				}
			}
		}
	}

	sort(r.begin(), r.end());

	long long ans = numeric_limits<long long>::max();
	do {
		long long d = 0;
		for (int i = 0; i < r.size() - 1; i++) {
			d += path[r[i]][r[i+1]];
		}
		ans = min(ans, d);
	} while(next_permutation(r.begin(), r.end()));

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

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

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

// cout 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]; }
  return s;
}

int main() {
  int a, b;
  cin >> a >> b;
  int ans = (a - 1) * (b - 1);
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 888
import java.util.*;
public class Main {
	private static int a[][];
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	a = new int[3][3];
    	for (int i=0;i < 3; i++) {
    		a[0][i]= sc.nextInt();
		}
    	for (int i=0;i < 3; i++) {
    		a[1][i]= sc.nextInt();
		}
    	for (int i=0;i < 3; i++) {
    		a[2][i]= sc.nextInt();
		}
		int n = sc.nextInt();
    	for (int i=0;i < n; i++) {
    		mark(sc.nextInt());
		}
		if (bingo()) {
			System.out.println("Yes");

		}else{
			System.out.println("No");
		}
    }
    private static void mark(int m) {
    	for (int i=0;i < 3; i++) {
    		if (a[0][i]==m) {
    			a[0][i]=1;
    			return;
    		}
    	}
    	for (int i=0;i < 3; i++) {
    		if (a[1][i]==m) {
    			a[1][i]=1;
    			return;
    		}
    	}
    	for (int i=0;i < 3; i++) {
    		if (a[2][i]==m) {
    			a[2][i]=1;
    			return;
    		}
    	}
    }
    private static boolean bingo() {
    	if (a[0][0]==1 && a[0][1]==1 && a[0][2]==1 ){
    		return true;
    	}
    	if (a[1][0]==1 && a[1][1]==1 && a[1][2]==1 ){
    		return true;
    	}
    	if (a[2][0]==1 && a[2][1]==1 && a[2][2]==1 ){
    		return true;
    	}
    	if (a[0][0]==1 && a[1][0]==1 && a[2][0]==1 ){
    		return true;
    	}
    	if (a[0][1]==1 && a[1][1]==1 && a[2][1]==1 ){
    		return true;
    	}
    	if (a[0][2]==1 && a[1][2]==1 && a[2][2]==1 ){
    		return true;
    	}
    	if (a[0][0]==1 && a[1][1]==1 && a[2][2]==1 ){
    		return true;
    	}
    	if (a[2][0]==1 && a[1][1]==1 && a[0][2]==1 ){
    		return true;
    	}
    	return false;
    }
}





Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


string S;
int N, X,T;

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

	cin >> N >> X>>T;

	cout << ((N+(X-1)) / X)*T << endl;
	
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main(){
  
  int in[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  int innum = 0;
  
  scanf("%d",&innum);
  
  if(innum > 0 && innum <= 32){
	  printf("%d\n",in[innum-1]);
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
using namespace std;
string s[20];
int n,a,b,c,l[10],i,temp;
bool oka,okb,okc;
int main()
{
	cin>>a>>b>>c;
	if(a*c<=b)
	{
		cout<<c;
	}
	else
	{
		cout<<b/a;
	}
	return 0;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    vec<vec<usize>> a(3);
    for (usize i=0; i<3; i++) {
        std::string s;
        std::cin >> s;
        a.at(i).resize(s.length());
        std::transform(ALL(s), a.at(i).begin(), [](char c){ return c-'a'; });
    }
    usize now = 0;
    vec<usize> pos(3);
    while (true) {
        if (pos.at(now) == a.at(now).size()) {
            std::cout << (char)('A' + now) << '\n';
            return 0;
        }
        now = a.at(now).at(pos.at(now)++);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){    
    string S;
    int i=0;
    cin >> S;
    
    while(i != S.length()){
      if(i%2 == 0){
	if(S[i] == 'L'){
	  cout << "No" << endl;
	  return 0;
	}
	else i++;
      }
      else{
	if(S[i] == 'R'){
	  cout << "No" << endl;
	  return 0;
	}
	else i++;
      }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b,n;
cin>>a>>b>>n;
int r=n;
if(n%b==0)
    n-=1;

int ans=(a*n)/b-a*(n/b);
int x=(r/b)*b;
x-=1;
int val=(a*x)/b-a*(x/b);
ans=max(ans,val);
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {

  int N, A, B;
  int sum1, sum2;

  do {
    scanf("%d %d %d", &N, &A, &B);
  } while (N < 1 || N > 20 || A < 1 || A > 50 || B < 1 || B > 50);

  sum1 = N * A;
  sum2 = B;

  if (sum1 >= sum2) {
    printf("%d\n", sum2);
  } else {
    printf("%d\n", sum1);
  }

  return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int maxn = 2e5 + 10;
const int maxm = 1e4 + 10;
const ll mod = 998244353;

int main() {
    __;
    ll a, b;
    while (cin >> a >> b) {
        if ((a + b) % 2 == 0) {
            cout << (a + b) / 2 << endl;
        } else cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];
    long long sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<ll> vel;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll Lucas(int x){
    if(x == 0) return 2;
    if(x == 1) return 1;
    else return Lucas(x-1) + Lucas(x-2);
}
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N; cin >> N;
    vel L(87);
    L[0] = 2;
    L[1] = 1;
    rep2(i,N+1) L[i] = L[i - 1] + L[i - 2];
    cout << L[N] << endl;
    return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int x[3010];
int y[3010];
bool board[5010][5010];

int main(void){
	int n;
	while(cin >> n,n){
		
		rep(i,5010)rep(j,5010) board[i][j]=false;
		rep(i,n){
			cin >> x[i] >> y[i];
			board[x[i]][y[i]]=true;
		}
		int cmax=0;
		rep(i,n)rep(j,n){
			int dx=x[j]-x[i];
			int dy=y[j]-y[i];

			int x3=x[i]-dy;
			int y3=y[i]+dx;

			int x4=x[j]-dy;
			int y4=y[j]+dx;

			if(x3<0||5000<x3||y3<0||5000<y3||x4<0||5000<x4||y4<0||5000<y4)
				continue;

			if(board[x3][y3]&&board[x4][y4])
				cmax=max(cmax,dx*dx+dy*dy);
		}
		cout << cmax << endl;
	}
	return 0;
}

Measured memory_bytes: 25696
#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 n;

void dfs(string s)
{
    if (s.size() == n)
    {
        cout << s << endl;
        return;
    }
    int mx = 0;
    rep(i, s.size()) mx = max(mx, s[i] - 'a' + 1);
    for (int i = 0; i <= mx; i++)
    {
        string next = s;
        next += i + 'a';
        dfs(next);
    }
}

int main()
{
    cin >> n;
    dfs("a");
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
using namespace std;

int d[100000];
signed main() {
	int a, b; scanf("%d%d", &a, &b);
	int s = 0;
	for (int c = 0; c < a; c++) {
		scanf("%d", &d[c]);
		s = max(s, d[c]);
	}
	int g = 1 << 29;//(s,g]
	while (g-s>1) {
		int k = (s + g) / 2;
		int sum = 1;
		int n = 0;
		for (int i = 0; i < a; i++) {
			if (n + d[i] <= k) {
				n += d[i];
			}
			else {
				n = d[i];
				sum++;
			}
		}
		if (sum > b) {
			s = k;
		}
		else {
			sum = 1;
			int m = k - 1;
			int n = 0;
			for (int i = 0; i < a; i++) {
				if (n + d[i] <= m) {
					n += d[i];
				}
				else {
					n = d[i];
					sum++;
				}
			}
			if (sum > b) {
				printf("%d\n", k);
				return 0;
			}
			else {
				g = k;
			}
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define uid uniform_int_distribution <int>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int n, m;
	cin >> n >> m;
	vector <pair<int, pair<int, int>>> v[n + 1];
	for (int i = 0; i < m; i++)
	{
		int x, y, c;
		cin >> x >> y >> c;
		v[x].push_back({c, {x, y}});
	}
	priority_queue <pair<ll, pair<int, int>>> pq;
	for (auto g : v[1])
	{
		pq.push({-g.ff, {g.ss.ff, g.ss.ss}});
	}
	vector <ll> ans(n + 1, INF);
	ans[1] = 0;
	int p = 2;
	while(!pq.empty())
	{
		ll cost = -pq.top().ff;
		int l = pq.top().ss.ff;
		int r = pq.top().ss.ss;
		pq.pop();
		while(p <= r)
		{
			ans[p] = cost;
			for (auto g : v[p])
			{ 
				pq.push({-(cost + g.ff), {g.ss.ff, g.ss.ss}});
			}
			p++;
		}
	}
	if(ans[n] != INF)
		cout << ans[n];
	else
		cout << -1;
}


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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    ll N, S;
    void input() {
        cin >> N >> S;
    }

    bool check(ll b) {
        ll sum = 0;
        ll n = N;
        while (n > 0) {
            sum += n % b;
            n /= b;
        }
        return sum == S;
    }

    void solve() {

        if (N < S) {
            cout << -1 << endl;
            return;
        }

        if (N == S) {
            cout << N + 1 << endl;
            return;
        }

        ll Z = N - S;
        vector<ll> cand;
        for (ll x = 1; x * x <= N; x++) {
            if (Z % x != 0) continue;
            if (check(x + 1)) {
                cout << x + 1 << endl;
                return;
            }
            if (check(Z / x + 1)) {
                cand.push_back(Z / x + 1);
            }
        }
        sort(cand.begin(), cand.end());
        if (cand.empty()) {
            cout << -1 << endl;
        } else {
            cout << cand.front() << endl;
        }

    }
}

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



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

struct data {
	int w, price;

	data() { this -> w = this -> price = 0; }
	data(int w, int price) : w(w), price(price) {}
};

bool operator<(const data &a, const data &b) {
	return a.price > b.price;
}

data operator+(const data &a, const data &b) {
	data ret;

	ret.w = a.w + b.w;
	ret.price = a.price + b.price;

	return ret;
}

int main() {
	vector<data> v;

	v.push_back( data(2, 380) );
	v.push_back( data(3, 550) );
	v.push_back( data(5, 850) );

	v.push_back( data(2*5, 380*5*(100-20)/100) );
	v.push_back( data(3*4, 550*4*(100-15)/100) );
	v.push_back( data(5*3, 850*3*(100-12)/100) );

	int price[51]; fill(&price[0], &price[0]+51, -1);

	priority_queue<data> Q; Q.push( data(0, 0) );
	while ( !Q.empty() ) {
		data d = Q.top(); Q.pop();

		if (d.w > 50 || price[d.w] >= 0) continue;
		price[d.w] = d.price;

		for (int i = 0; i < v.size(); ++i)
			Q.push( d + v[i] );
	}

	int w;
	while (cin >> w, w)
		cout << price[w/100] << endl;
}

Measured memory_bytes: 1200