akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n;
   cin >> n;
   vector<ll>s(n);
   ll ans = 0;
   rep(i,n)cin >> s[i];
   for(int sa = 1; sa <= n; sa++){
      ll sum = 0;
      int l = 0;
      int r = n - 1;
      set<int>st;
      while(l < n and r > 0){
         sum += s[l];
         st.insert(l);
         sum += s[r];
         if(st.count(r))break;
         st.insert(r);
         int a = r;
         if(a > sa and n - 1 - a > 0 and (n - 1 - a)%sa == 0){
            ans = max(ans, sum);
         }
         l += sa;
         r -= sa;
      }
   }
   cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
//typedef pair<int,int> P;

//少数点表示
//cout << std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans = 0;
    if(a%2 == 0 || b%2 == 0 || c%2 == 0){
        ans = 0;
    }else{
        ans = min({a*b,b*c,c*a});
    }

    cout << ans <<endl;

}

Measured memory_bytes: 256
s = list(input())
t = list(input())

ans = 0
if len(s) != len(t) - 1:
    ans = 1
else:
    for i in range(len(s)):
        if s[i] != t[i]:
            ans = 1

if ans == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8988
from collections import defaultdict
import sys
input=sys.stdin.readline
N=int(input())

s_dic=defaultdict(int)
for i in range(N):
  s=list(input().rstrip())
  s.sort()
  s_str="".join(s)
  s_dic[s_str]+=1
#print(s_dic)

answer=0
for val in s_dic.values():
  answer+=(val*(val-1))//2

print(answer)

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

int ans = 0, l = 0, r;
string s;

int main() {
	cin >> s;
	r = s.size() - 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 {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}


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

int main(){
    int n; cin>>n;
    int x[100],y[100],h[100];
    for(int i=-0;i<n;i++){
        cin>>x[i]>>y[i]>>h[i];
    }
    int H;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int k=0;k<n;k++){
                if(h[k])H=h[k]+abs(x[k]-i)+abs(y[k]-j);
            }
            bool flag=true;
            for(int k=0;k<n;k++){
                if(max(0,H-abs(x[k]-i)-abs(y[k]-j))!=h[k]){
                    flag=false;
                    break;
                }
            }
            if(flag)cout<<i<<" "<<j<<" "<<H<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <stdlib.h>
using namespace std;

int main(){
  string str;

  getline(cin,str);

  for(int i=0; i<str.size(); i++){
    if(islower(str[i])){
      cout << (char)toupper(str[i]);
    }else if(isupper(str[i])){
      cout << (char)tolower(str[i]);
    }else{
      cout << str[i];
    }
  }
  cout << endl;

}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

ll a, b, c;

int main()
{
    cin>>a>>b>>c;
    if (a + b > c) {
        Yes(false);
        return 0;
    }

    Yes(4 * a * b < (c - a - b) * (c - a - b));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int n;
cin >> n;
map<string,int> m;
rep(i,n){
    string s;
    cin >> s;
    m[s]++;
}
int mx=0;
for(auto e:m){
    int x = e.second;
    chmax(mx,x);
}

for(auto it=m.begin();it!=m.end();it++){
    if(it->second==mx)fin(it->first);
}

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 23808
import re
s = input()
odd = s[::2]
eve = s[1::2]
odd_re = re.compile(r"^[RUD]*$")
eve_re = re.compile(r"^[LUD]*$")
if odd_re.findall(odd) != [] and eve_re.findall(eve) != []:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
from collections import deque

def bfs(s):
    dist = [-1]*N
    q = deque([s])
    dist[s] = 0
    
    while q:
        v = q.popleft()
        
        for nv in adj_list[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N, u, v = map(int, input().split())
adj_list = [[] for _ in range(N)]
degree = [0]*N

for _ in range(N-1):
    Ai, Bi = map(int, input().split())
    adj_list[Ai-1].append(Bi-1)
    adj_list[Bi-1].append(Ai-1)
    degree[Ai-1] += 1
    degree[Bi-1] += 1
    
d1 = bfs(u-1)
d2 = bfs(v-1)
ans = 0

for i in range(N):
    if degree[i]==1 and d1[i]<d2[i]:
        ans = max(ans, d2[i]-1)
        
    if d1[i]==d2[i] and d1[i]+d2[i]==d1[v-1]:
        ans = max(ans, d1[i])
    
print(ans)

Measured memory_bytes: 62752
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 1e5 + 7;

int used[2 * N];
vector<int> g[2 * N];

void dfs(int cur, int &c1, int &c2, int c) {
	used[cur] = 1;
	if (c) c1++;
	else c2++;
	for (auto t : g[cur]) {
		if (!used[t]) {
			dfs(t, c1, c2, c ^ 1);;
		}
	}
}

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

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		y += N;
		g[x].push_back(y);
		g[y].push_back(x);
	}	
	int ans = 0;
	for (int i = 0; i < 2 * N; i++) {
		if (!used[i]) {
			int c1 = 0;
			int c2 = 0;
			dfs(i, c1, c2, 0);
			ans += c1 * c2;
		}
	}
	ans -= n;
	cout << ans << endl;
}


Measured memory_bytes: 12544
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	string s;
	while(cin >> s)
	{
		string ans;
		int sz=s.size();
		if(sz%2==1)
		{
			cout << "NA" << endl;
			continue;
		}
		for(int i=0;i<sz/2;i++)
		{
			int f=s[2*i]-'0',se=s[2*i+1]-'0';
			if(f<=0||f>6||se<=0||se>5)
			{
				cout << "NA" << endl;
				goto end;
			}
			if(f==6&&se>=2)
			{
				switch(se)
				{
					case 2:ans+='.';break;
					case 3:ans+='?';break;
					case 4:ans+='!';break;
					case 5:ans+=' ';break;
				}
			}
			else ans+='a'+(f-1)*5+se-1;
		}
		cout << ans << endl;
		end:;
	}
	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(void){
	ll n;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	int sum=0;
	int digits=log10(n)+1;
	//<<digits<<endl;
	if(1<digits) sum+=9;
	if(3<digits) sum+=900;
	if(5<digits) sum+=90000;
	if(digits==1) sum+=n;
	if(digits==3) sum+=n-99;
	if(digits==5) sum+=n-9999;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll h(n);
    rep(i, n){
        cin >> h[i];
    }
    h.emplace_back(0);
    ll ans = 0;
    rep(i, n){
        if(h[i] > h[i+1]){
            ans += h[i] - h[i+1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

template<typename T>
struct SegmentTree{
private:
    int N;
    vector<T> node;
    function<T(T, T)> F;
    T DEFAULT;
public:
    void init(int n, function<T(T, T)> f, T def){
        F = f;
        DEFAULT = def;
        N = 1;
        while(N < n) N = (N<<1);
        node.assign(2*N-1, DEFAULT);
    }
    T& operator [](int a){
        return node[a+N-1];
    }
    void update(int a, T x){
        a += N-1;
        node[a] = x;
        while(a > 0){
            a = (a-1)>>1;
            node[a] = F(node[(a<<1)+1], node[(a<<1)+2]);
        }
    }
    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return DEFAULT;
        if(a <= l && r <= b) return node[k];
        return F(query(a, b, (k<<1)+1, l, (l+r)>>1), query(a, b, (k<<1)+2, (l+r)>>1, r));
    }
};

int N;
vector<int> e[200000];
int A[200000];
vector<int> v;

multiset<int> st[200000];
int ans[200000];
int finalAns[200000];
SegmentTree<int> seg;
void solve(int n, int p){
    int idx = lower_bound(all(v), A[n]) - v.begin();
    ans[n] = seg.query(0, idx) + 1;
    st[idx].insert(ans[n]);
    seg.update(idx, *prev(st[idx].end()));
    finalAns[n] = seg.query(0, N);
    rep(i, e[n].size()){
        if(e[n][i] == p) continue;
        solve(e[n][i], n);
    }
    st[idx].erase(st[idx].find(ans[n]));
    if(st[idx].size() == 0) seg.update(idx, 0);
    else seg.update(idx, *prev(st[idx].end()));
}

signed main(){
    cin >> N;
    rep(i, N){
        cin >> A[i];
        v.pb(A[i]);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    rep(i, N-1){
        int u, v;
        cin >> u >> v;
        u--; v--;
        e[u].pb(v);
        e[v].pb(u);
    }
    seg.init(N, [](int a, int b){ return max(a, b); }, 0);
    solve(0, -1);
    rep(i, N) cout << finalAns[i] << endl;
}

Measured memory_bytes: 146888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int F=0;
  vector<string> SS(4);
  SS[0]+="SS";
  SS[1]+="SW";
  SS[2]+="WS";
  SS[3]+="WW";
  rep(q,4){
    F=0;
    rep(i,N-2){
      if(SS[q][i+1]=='S'){
        if(S[i+1]=='o'){
          if(SS[q][i]=='S') SS[q]+='S';
          else SS[q]+='W';
        }
        else{
          if(SS[q][i]=='S') SS[q]+='W';
          else SS[q]+='S';
        }
      }else{
        if(S[i+1]=='o'){
          if(SS[q][i]=='S') SS[q]+='W';
          else SS[q]+='S';
        }
        else{
          if(SS[q][i]=='S') SS[q]+='S';
          else SS[q]+='W';
        }
      }
    }
    if(SS[q][N-1]=='S'){
      if(S[N-1]=='o'){
        if(SS[q][0]==SS[q][N-2]) F++;
      }else{
        if(SS[q][0]!=SS[q][N-2]) F++;
      }
    }else{
      if(S[N-1]=='o'){
        if(SS[q][0]!=SS[q][N-2]) F++;
      }else{
        if(SS[q][0]==SS[q][N-2]) F++;
      }
    }
    if(SS[q][0]=='S'){
      if(S[0]=='o'){
        if(SS[q][N-1]==SS[q][1]) F++;
      }else{
        if(SS[q][N-1]!=SS[q][1]) F++;
      }
    }else{
      if(S[0]=='o'){
        if(SS[q][N-1]!=SS[q][1]) F++;
      }else{
        if(SS[q][N-1]==SS[q][1]) F++;
      }
    }
    if(F==2){
      cout<<SS[q]<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int numofbits(unsigned long long bits) {
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    unsigned long long flag = 0;
    int q, Q, a;
    cin >> Q;
    rep(i, Q) {
        cin >> q;
        if(q < 4) cin >> a;
        if(q == 0) { // test
            cout << (flag & (1ull << a) ? 1 : 0) << endl;
        } else if(q == 1) { // set
            flag |= (1ull << a);
        } else if(q == 2) { // clear
            flag &= ~(1ull << a);
        } else if(q == 3) { // flip
            flag ^= (1ull << a);
        } else if(q == 4) { // all
            cout << (flag == 0xffffffffffffffff) << endl;
        } else if(q == 5) { // any
            cout << (flag > 0) << endl;
        } else if(q == 6) { // none
            cout << (flag == 0) << endl;
        } else if(q == 7) { // count
            cout << numofbits(flag) << endl;
        } else if(q == 8) { // val
            cout << flag << endl;
        }
    }
}



Measured memory_bytes: 3160
n = int(input().rstrip())
p = list(map(int, input().rstrip().split()))

count = 0
for i in range(1,n-1):
  a = p[i-1]
  b = p[i]
  c = p[i+1]
  if (a<b and b<c) or (c<b and b<a):
    count+=1
print(count)

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

// --- DEBUG begin --- cut here ---
template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

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

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}
// --- DEBUG end --- cut here ---



int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N), B(N);
  for (ll i = 0; i < N; i++) {
    if (i % 2 == 0) cin >> A.at(i);
    else            cin >> B.at(i);
  }
  for (ll i = 0; i < N; i++) {
    if (i % 2 == 0) cin >> B.at(i);
    else            cin >> A.at(i);
  }
  ll K = (N+1) /2;
  ll cost = LLONG_MAX;
  for (ll x = 0; x < (1LL << N); x++) {
    if (__builtin_popcountll(x) != K) continue;
    vector<pair<ll, ll>> u, v, w;
    for (ll i = 0; i < N; i++) {
      if ((x >> i) & 1LL) u.emplace_back(A.at(i), i);
      else                v.emplace_back(B.at(i), i);
    }
    sort(u.begin(), u.end());
    sort(v.begin(), v.end());
    for (ll i = 0; i < K; i++) {
      w.push_back(move(u.at(i)));
      if (i < N/2) w.push_back(move(v.at(i)));
    }
    auto doit = [&]() -> void {
      for (ll i = 1; i < N; i++) if (w.at(i-1).first > w.at(i).first) return;
      ll cnt = 0;
      for (ll i = 0; i < N; i++) {
	for (ll j = i+1; j < N; j++) {
	  if (w.at(i).second > w.at(j).second) cnt++;
	}
      }
      cost = min(cost, cnt);
    };
    doit();
  }

  if (cost == LLONG_MAX) {
    cout << -1 << endl;
  }else {
    cout << cost << endl;
  }

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
     
    public class Main { //クラス名はMain
        public static void main(String[] args) {
            //コード
          int c1 = 0;	//偶数文字
          int c2 = 0;	//奇数文字
          Scanner sc = new Scanner(System.in);
    	  int n = sc.nextInt();
          //判定
          for(int i=1;i<=n;i++) {
           		if (Math.abs(i) % 2 == 0) {
                //偶数文字
                  c1++;
            }
            else {
              	//奇数文字
              	c2++;
           }
          }
           System.out.println(String.format("%.10f", (double)c2/(double)n));
        }
    }

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

using namespace std;


int main(){
  int n,x,y,z;
  cin>>n;
  cin>>x;

  bool a[101]={},b[101]={};
  for(int i=0,m;i<x;i++)
    cin>>m,a[m]=1;
  cin>>y;
  for(int i=0,m;i<y;i++)
    cin>>m,b[m]=1;
  
  int ans=0;
  
  cin>>z;
  
  for(int i=0,m;i<z;i++){
    cin>>m;
    int f=0;
    if(!a[m])f=1;
    if(b[m])f=1;
    ans+=f;
  }
  cout<<ans<<endl;  
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int A[100000 + 10];
int bit[40];

signed main(void) {
    int N, K;
    cin >> N >> K;
    rep(i, N) {
        cin >> A[i];
    }

    int ans = 0;
    for (int th=40; th>=-1; th--) {
        if (th >= 0 && (K&1LL<<th) == 0) { //bitが立ってない
            continue;
        } else { //bitが立っている→ここより上位のbitは全てKと同じで，ここのbitは0であるようなxについて考える
            int res = 0;
            for(int b=40; b>=0; b--) {
                int cnt_bit=0;
                rep(i, N) {
                    if ((A[i]&1LL<<b) > 0) { //bitが立っている
                        cnt_bit++;
                    }
                }
                if (b > th) { //上位bit→Kと同じにする
                    if ((K&1LL<<b) > 0) { //Kでbitが立っているなら
                        res += (1LL<<b) * (N-cnt_bit);
                    } else { //Kでbitが立っていないなら
                        res += (1LL<<b) * cnt_bit;
                    }
                } else if (b == th) { //閾のところ→bitは立てない
                    res += (1LL<<b) * cnt_bit;
                } else { //下位bit→都合のいいようにbitを変える
                    res += (1LL<<b) * max(cnt_bit, N-cnt_bit);
                }
            }
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define rep(i,m,n) for(int i=m;i<n;++i)
#define llrep(i,m,n) for(ll i=m;i<n;++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<ll>x, y, vans;

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		x.push_back(a);
		y.push_back(b);
	}
	ll ans = llinf;
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			ll xa = x[i], xb = x[j];
			vector<ll>v;
			v.assign(0, 0);
			int hoge = 0;
			rep(m, 0, n) {
				if (min(xa, xb) <= x[m] && x[m] <= max(xa, xb)){
					v.push_back(y[m]);
				}
			}
			ans = llinf;
			sort(all(v));
			if (v.size() < k) {
				continue;
			}
			rep(m, 0, v.size() - k + 1) {
				ans = min(ans, v[k - 1 + m] - v[m]);
			}
			vans.push_back(ans* abs(xa - xb));
		}
	}
	sort(all(vans));
	cout << vans[0] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			int m = in.nextInt();
			int s = in.nextInt()-1;
			int g1 = in.nextInt()-1;
			int g2 = in.nextInt()-1;
			if(n == 0) break;
			int[][] edge = new int[n][n];
//			int[][] root = new int[n][n];
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
//					root[i][j] = i;
					if(i==j) continue;
					edge[i][j] = 1000000;
				}
			}
			for(int i=0; i<m; i++){
				int b1 = in.nextInt()-1;
				int b2 = in.nextInt()-1;
				int c = in.nextInt();
				edge[b1][b2] = c;
			}
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					for(int k=0; k<n; k++){
						if(edge[j][k] > edge[j][i]+edge[i][k]){
							edge[j][k] = edge[j][i] + edge[i][k];
//							root[j][k] = i;
						}
					}
				}
			}
			int res = Integer.MAX_VALUE;
			for(int i=0; i<n; i++){
				res = Math.min(res, edge[s][i]+edge[i][g1]+edge[i][g2]);
			}
//			LinkedList<Integer> list = rooting(root, s, g1);
//			for(int i: list){
//				res = Math.min(res, edge[s][g1] + edge[i][g2]);
//			}
			
//			list = rooting(root, s, g2);
//			for(int i: list){
//				res = Math.min(res, edge[s][g2] + edge[i][g1]);
//			}
			
			System.out.println(res);
		}
	}
	
	public static LinkedList<Integer> rooting(
			int[][] root, int s, int t){
		LinkedList<Integer> res = new LinkedList<Integer>();
		refound(root, s, t, res);
		return res;
	}
	
	public static void refound(
			int[][] root, int s, int t
			, LinkedList<Integer> res){
		int center = root[s][t];
		if(s == center){
			res.add(t);
			return;
		}
		refound(root, s, center, res);
		refound(root, center, t, res);
	}
}

Measured memory_bytes: 62816
n, m = map(int, input().split())
white = [1]*n
white[0] = 0
red = [0] * n
red[0] = 1

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    if red[x] > 0:
        red[y] += 1
    else:
        white[y] += 1

    if white[x] > 0:
        white[x] -= 1
    else:
        red[x] -= 1


ans = n-red.count(0)
print(ans)


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

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  string S;
  cin >> N >> S >> K;
  char s = S[K-1];
  for (int i = 0; i < S.size(); ++i) {
    if(S[i] != s)
      S[i] = '*';
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n1,n2;
  cin>>n1>>n2;
  long int ma=(n1>n2)?n1:n2;
  int m=ma;
  while(1)
  {
  if(ma%n1==0 && ma%n2==0)
  {cout<<ma;break;}
  else ma=ma+m;}
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  int N, max = 0, min = 1000000000;
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    int A;
    scanf("%d", &A);
    if(max < A)
      max = A;
    if(A < min)
      min = A;
  }
  printf("%d\n", max-min);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int W;
	int H;
	int x;
	int y;
	int r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if ((x + r > W || x - r < 0) || (y + r > H || y - r < 0)){
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n,t;
    cin >> n >> t;
    vec(a,n);
    int k=a[0],ans=0;
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        if(k <= a[i]){
            ans += t;
            k = a[i]+t;
        }
        else{
            int x = a[i]-a[i-1];
            ans += x;
            k += x;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000005
typedef long long ll;
typedef pair <ll, ll> P;

int main() {
	ll h,w,cx,cy,dx,dy;
	cin >> h >> w >> cx >> cy >> dx >> dy;
	cx--;
	cy--;
	dx--;
	dy--;
	string s[h];
	for(ll i = 0; i < h; i++) cin >> s[i];
	deque <P> que;

	que.push_back(P(cx, cy));
	bool visited[h][w];
	ll d[h][w];
	for(ll i = 0; i < h; i++) {
		fill(visited[i], visited[i] + w, false);
		fill(d[i], d[i] + w, INF);
	}
	d[cx][cy] = 0;
	visited[cx][cy] = true;

	while(!que.empty()) {
		P p = que.front();
		ll X = p.first, Y = p.second;
		if(X == dx && Y == dy) {
			cout << d[X][Y] << endl;
			return 0;
		}
		visited[X][Y] = true;
		que.pop_front();
		for(ll i = -2; i < 3; i++)
			for(ll j = -2; j < 3; j++) {
				ll x = X + i, y = Y + j;
				if(x < h && x >= 0 && y < w && y >= 0 && s[x][y] == '.') {
					if(visited[x][y]) continue;
					if(abs(i) + abs(j) < 2) {
						que.push_front(P(x, y));
						d[x][y] = d[X][Y];
						visited[i][j] = true;
					} else {
						if(d[X][Y] + 1 < d[x][y]) {
							d[x][y] = d[X][Y] + 1;
							que.push_back(P(x, y));
						}
					}
				}
			}
	}

	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 14392
#include <iostream>
#include <cstdlib>
 
using namespace std;
 
int main(){
 int H, W, D,i,j,Q,n,k,l;
 cin >> H;
 cin >> W;
 cin >> D;
 int A[H*W+1][2];
 for (i=0;i<H;i++) {
  for (j=0;j<W;j++) {
   cin >> n;
   A[n][0]=i;
   A[n][1]=j;
  }
 }
 cin >> Q;
 int L[Q],R[Q];
 for (i=0;i<Q;i++) {
  cin >> L[i];
  cin >> R[i];
 }
 int S[D+1][H*W/D+1];
 for (k=1;k<D+1;k++) {
  int L=k;
  S[k][0]=0;
  for (l=1;D*l+L<H*W+1;l++) {
   S[k][l]=S[k][l-1]+abs(A[D*l+L][0]-A[D*(l-1)+L][0])+abs(A[D*l+L][1]-A[D*(l-1)+L][1]);
  }
 }
 for (i=0;i<Q;i++) {
  cout << S[(L[i]-1)%D +1][(R[i]-1)/D]-S[(L[i]-1)%D +1][(L[i]-1)/D] << endl;
 }
 return 0;
}

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

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

    ll N, Y;
    cin >> N >> Y;

    for(ll a = 0; a <= N; a++) {
        for(ll b = 0; b <= N - a; b++) {
            ll c = N - a - b;
            ll x = 10000 * a + 5000 * b + 1000 * c;
            if(x == Y) {
                cout << a << " " << b << " " << c << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int c[3][3];

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

  REP(i, 3) {
    REP(j, 3) {
      cin >> c[i][j];
    }
  }

  vector< int > b(3);
  REP(i, 3) {
    b[i] = c[0][i];
    // int b0 = c[0][0];
    // int b1 = c[0][1];
    // int b2 = c[0][2];
  }

  bool ok = true;
  FOR(i, 1, 3) {
    vector< int > p(3);
    REP(j, 3) {
      p[j] = c[i][j] - b[j];
    }
    if (!(p[0] == p[1] && p[1] == p[2])) {
      ok = false;
    }
  }

  OK(ok);

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int m,n,i,Q[1000],p,q,t;

void f(int a){Q[p++%1000]=a;}
int g(){return Q[q++%1000];}
int main()
{
	for(;scanf("%d%d",&n,&m),n;)
	{
		for(p=0;p<n;p++)
			Q[p]=p+1;
		for(q=0,i=1;n>1;i++)
		{
			t=g();
			if(i%m!=0)
				f(t);
			else
				n--;
		}
		printf("%d\n",g());
	}
	return 0;
}

Measured memory_bytes: 600
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include,/opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.string cimport string
from libcpp.vector cimport vector

cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cpdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class dsu_:
    cdef dsu *ptr
    def __cinit__(self, int n): self.ptr = new dsu(n)
    def __dealloc__(self): del self.ptr
    cpdef int merge(self,a,b): return self.ptr.merge(a,b)
    cpdef bool same(self,a,b): return self.ptr.same(a,b)
    cpdef int leader(self,a): return self.ptr.leader(a)
    cpdef int size(self,a): return self.ptr.size(a)
    cpdef vector[vector[int]] groups(self): return self.ptr.groups()

cdef extern from "/opt/atcoder-stl/atcoder/fenwicktree.hpp" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree()
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)
cdef class fenwick_tree_:
    cdef fenwick_tree[int] *ptr
    def __cinit__(self, int n): self.ptr = new fenwick_tree[int](n)  
    def __dealloc__(self): del self.ptr
    cpdef void add(self, int p, long x): self.ptr.add(p, x)
    cpdef long sum(self, int l, int r): return self.ptr.sum(l, r)

cdef extern from "/opt/atcoder-stl/atcoder/string.hpp" namespace "atcoder":
    vector[int] suffix_array(vector[int] s, int upper)
    vector[int] suffix_array(vector[long] s)
    vector[int] suffix_array(string s)
    vector[int] lcp_array(vector[long] s, vector[int] sa)
    vector[int] lcp_array(string s, vector[int] sa)
    vector[int] z_algorithm(vector[long] s)
    vector[int] z_algorithm(string s)
cpdef vector[int] suffix_array_u(vector[int] s, int upper): return suffix_array(s, upper)
cpdef vector[int] suffix_array_l(vector[long] s): return suffix_array(s)
cpdef vector[int] suffix_array_s(string s): return suffix_array(s)
cpdef vector[int] lcp_array_l(vector[long] s, vector[int] sa): return lcp_array(s, sa)
cpdef vector[int] lcp_array_s(string s, vector[int] sa): return lcp_array(s, sa)
cpdef vector[int] z_algorithm_l(vector[long] s): return z_algorithm(s)
cpdef vector[int] z_algorithm_s(string s): return z_algorithm(s)
"""

import os
try:
    from atcoder import *
except:
    open('atcoder.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')

s=list(map(ord,input()))
n=len(s)
sa=suffix_array_l(s)
print(n*(n+1)//2-sum(lcp_array_l(s,sa)))

Measured memory_bytes: 77800
N = int(input())
H = [int(i) for i in input().split()]
movemax = 0
count = 0
massr=0

for i in range(N-1):
    if H[i] >= H[i+1]:
        count += 1
        if count > movemax: movemax=count
    else:
        count = 0
print(movemax)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N; cin >> N;
    long long ans =1;
    for(int i=1;i<=N;i++){
        ans *= i;
        ans = ans%1000000007;
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;



int main() {
	fast;
	string s;
	cin >> s;
	if (s.back() != 's')s += 's';
	else s += "es";
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

const long long mod = 1e9 + 7;
long long pow2[100000 + 5];
long long sum_len[100000 + 5];
void init()
{
	pow2[0] = 1;
	sum_len[0] = 0;
	for (int i = 1; i < 100000 + 5; i++)
		pow2[i] = (pow2[i - 1] << 1) % mod;
	sum_len[1] = 2;
	for (int i = 2; i < 100000+5; i++)
		sum_len[i] = sum_len[i-1] * 3ll % mod;
	for (int i = 2; i < 100000 + 5; i++)
		sum_len[i] = (sum_len[i] + sum_len[i - 1]) % mod;
}

string str;
int a[100000 + 5];
int main()
{
	init();
	cin >> str;
	int len = str.length();
	for (int i = 0; i < len; i++)
		a[len - i - 1] = str[i] - '0';
	long long ans = 0;
	long long pre = 0;
	for (int i = len - 1; i >= 0; i--)
	{
		if (a[i])
		{
			ans = (ans + pow2[pre] * sum_len[i] % mod) % mod;
			pre++;
			ans = (ans + pow2[pre]) % mod;
		}
	}
	//if(a[0])ans = (ans + pow2[pre]) % mod;
	cout << (ans+1)%mod << endl;
	return 0;
}

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

bool dislike[10];

int isCorrect(int n) {
	int temp = n;
	while (temp) {
		int rem = temp % 10;
		if (dislike[rem]) {
			return false;
		}
		temp /= 10;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		int digit;
		cin >> digit;
		dislike[digit] = true;
	}

	for (int i = n; ; ++i) {
		if (isCorrect(i)) {
			cout << i;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <cstring>
using namespace std;

const int INF = 1<<28;
const int MAX_M = 31;
const int MAX_N = 8;

double dp[MAX_M][(1<<MAX_N)];
int g[MAX_M][MAX_M];
double ts[MAX_N];

int n, m, a, p, b;
void solve(int v, int tickets) {
    for (int i = 1; i <= m; i++) {
        if (g[v][i] != -1) {
            for (int j = 0; j < n; j++) {
                if (tickets & (1<<j)) {
                    if (dp[v][tickets] + g[v][i]/ts[j] < dp[i][tickets-(1<<j)]) {
                        dp[i][tickets-(1<<j)] = dp[v][tickets] + g[v][i] / ts[j];
                        solve(i, tickets-(1<<j));
                    }
                }
            }
        }
    }
}

int main() {
    while (cin >> n >> m >> p >> a >> b) {
        if (n == 0 && m == 0 && p == 0 && b == 0) break;
        for (int i = 0; i < n; i++) cin >> ts[i];
        memset(g, -1, sizeof(g));
        for (int i = 0; i < p; i++) {
            int x, y, z;
            cin >> x >> y >> z;
            g[x][y] = z;
            g[y][x] = z;
        }
        for (int i = 1; i <= m; i++)
            for (int j = 0; j < (1<<n); j++)
                dp[i][j] = INF;
        dp[a][(1<<n)-1] = 0;

        solve(a, (1<<n)-1);

        double min_cost = INF;
        for (int i = 0; i < (1<<n); i++)
            min_cost = min(min_cost, dp[b][i]);
        if (min_cost == INF) {
            printf("Impossible\n");
        } else {
            printf("%6f\n", min_cost);
        }
    }

    return 0;
}

Measured memory_bytes: 1312
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
char s1[10],s2[10];
int ans=0;
int main(){
    gets(s1);
    gets(s2);
	for(int i=0;i<3;i++){
		if(s1[i]==s2[i]) ans++; 
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
int32_t main()
{
    int n,k;
    cin>>n>>k;
    int h[n+1];
    h[0]=0;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    int c[n+1];
    for(int i=2;i<=n;i++)
    c[i]=1e9+7;
    //c[0]=0;
    c[1]=0;
    int t;
    for(int i=2;i<=n;i++)
    {
        for (int j=1;j<=std::min(k,i-1);j++)
        {
            t=c[i-j]+abs(h[i]-h[i-j]);
            if(c[i]>t)
            c[i]=t;
        }// c[i]=std::min(c[i-1]+abs(h[i-2]-h[i-1]),c[i-2]+abs(h[i-3]-h[i-1]));
    }
    cout<<c[n]<<endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
import java.math.*;
 
class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st, st2;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;

    public static void main(String[] args) throws Exception {
        st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        long M = Long.parseLong(st.nextToken());
        int[] A = new int[N];

        st = new StringTokenizer(br.readLine());
        TreeMap<Integer, Integer> d = new TreeMap<Integer, Integer>();

        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(A);

        for (int i = 0; i < N; i++) {
            if (!d.containsKey(A[i])) {
                d.put(A[i], i);
            }
        }

        // System.out.println(d);

        long[] acc = new long[N];
        for (int i = N-1; i >= 0; i--) {
            acc[i] = A[i];
            if (i != N-1) {
                acc[i] += acc[i+1];
            }
        }

        int a = 0;
        int b = A[A.length-1] * 2;

        while (a != b) {
            int mid = (a + b + 1) / 2;
            long totalCnt = 0;
            for (int i = 0; i < N; i++) {
                int target = mid - A[i];
                Integer higherKey = d.higherKey(target-1);
                if (higherKey != null) {
                    totalCnt += N - d.get(higherKey);
                }
            }
            if (totalCnt < M) {
                b = mid - 1;
            } else {
                a = mid;
            }
        }
        long ans = 0;
        for (int i = 0; i < N; i++) {
            if (M == 0) break;
            int target = a - A[i];
            Integer higherKey = d.higherKey(target);
            if (higherKey != null) {
                int nums = (int) (Math.min(N-d.get(higherKey), M));
                M -= nums;
                ans += (long) A[i] * nums;
                ans += acc[N - nums];
            }
        }
        ans += (M * a);

        pw.println(ans);

        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int a;
    public long b;

    Pair(int _a, long _b){
        a = _a;
        b = _b;
    }
 
    public String toString(){
        return a + " " + b;
    }

    public int compareTo(Pair p){
        if (b != p.b) return b < p.b ? -1 : 1;
        if (a != p.a) return a < p.a ? -1 : 1;
        return 0;
    }
}

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

int main(){
  int H,W;
  string S;
  cin >> H >> W;
    for(int i=0; i<W+2; i++){
      cout << "#";
    }
    cout << endl;
    for(int i=0; i<H; i++){
      cin >> S;
      cout << "#"<< S << "#" << endl;
    }
  for(int i = 0; i<W+2; i++){
    cout << "#";
  }
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int ans = 1;
  for(int i=0; i<N; i++){
    if(ans < K) ans *= 2;
    else ans += K;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
using namespace std;
const int INF = 2000000005;

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


Measured memory_bytes: 256
def withdrow(rest,num,cost):
    
    ans1 = float('inf')
    ans2 = float('inf')
    
    if rest < 24:
        return num + cost[rest]
    else:
        for i in range(1,10):
            if rest < 6**i:
                ans1 = withdrow(rest-6**(i-1), num+1,cost)
                break

    if rest < 24:
        return num + cost[rest]
    else:
        for i in range(1, 10):
            if rest < 9**i:
                ans2 = withdrow(rest-9**(i-1), num+1,cost)
                break

    return min(ans1, ans2)

N = int(input())

cost = [0,1,2,3,4,5,1,2,3,1,2,3,2,3,4,2,3,4,2,3,4,5,6,7]

ans = withdrow(N, 0, cost)
print(ans)

Measured memory_bytes: 3064
program main;
var
    i,j,k:longint;
    n:longint;
    sum:Int64;
begin
    readln(n);
    sum:=0;
    for i:=1 to n do if ((i mod 3) <> 0) and ((i mod 5) <> 0) then sum:=sum+i;
    writeln(sum);
end.

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

void fnInput(string& rsNumStr)
{
  cin >> rsNumStr;
}

int fnMinDiffChk(string sNumStr)
{
  const int cnnNum = 753;
  int nMinDiff = INT_MAX;

  for (int i = 0; i < sNumStr.size() - 2; i++)
  {
    int nNum = (sNumStr[i]     - '0') * 100 +
               (sNumStr[i + 1] - '0') * 10  + (sNumStr[i + 2] - '0');

    nMinDiff = min(nMinDiff, abs(nNum - cnnNum));
  }
  return nMinDiff;
}

int main()
{
  string sNumStr;

  fnInput(sNumStr);
  cout << fnMinDiffChk(sNumStr) << endl;

  return 0;
}

Measured memory_bytes: 256
/* bit 全探索 + 貪欲法。
コンプリートする問題の組み合わせを固定すれば、
残りはその他の問題のなかで得点の高い方から順に解いていけば良い。
*/

#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 15;
const int INF = 1<<29;

int main(){
    int D, G;
    int p[MAX_N], c[MAX_N];
    
    cin >> D >> G;
    for (int i = 0; i < D; i++) cin >> p[i] >> c[i];

    // bit 全探索
    int res = INF;
    // 全問コンプリートする点数の選択(bit の 1 のケタ)
    for (int bit = 0; bit < (1<<D); bit++){
        int score = 0;
        int solved = 0;
        
        for (int i = 0; i < D; i++){
            if (bit & (1<<i)){ // i 番目のフラグが立っている場合
                score += c[i] + 100 * (i + 1) * p[i];
                solved += p[i];
            }
        }

        if (score < G){ // 全問コンプリートだけでは目標に届かなかった
            for (int i = D - 1; i >= 0; i--){ // 得点の高い問題から順に解いていく
                if (bit & (1<<i)) continue; // コンプリートした問題は除く
                for (int j = 0; j < p[i]; j++){
                    if (score >= G) break;
                    score += 100 * (i + 1);
                    solved++;
                }
            }
        }

        res = min(res, solved);
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256