akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int n,k;
int main(){
	cin>>n>>k>>s;
	s+=string(s.rbegin(),s.rend());
	if(k>20)cout<<string(n,*min_element(s.begin(),s.end()))<<'\n';else{
		while(k--){
			string t(s,0,n);
			reverse(t.begin(),t.end());
			for(int i=1;i<=n;++i){
				string p(s,i,n);
				reverse(p.begin(),p.end());
				if(p<t)t=p;
			}
			s=string(t.rbegin(),t.rend())+t;
		}
		s.erase(0,n);
		cout<<s<<'\n';
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int n = in();
	while (n--) {
		vector<int> D(8);
		for (int &d: D)
			d = gcu() - '0';
		gcu();
		sort(D.begin(), D.end());
		static auto f = [](int acc, int d) {return acc * 10 + d;};
		out(accumulate(D.rbegin(), D.rend(), 0, f) -
			accumulate(D.begin(), D.end(), 0, f), '\n');
	}
}


Measured memory_bytes: 2508
#include<cstdio>
#include<algorithm>
using namespace std;
int N,K,Ans;
int main(){
	scanf("%d%d",&N,&K);
	for(int i=1,x;i<=N;i++){
		scanf("%d",&x);
		if(x>=K)Ans++;
	}
	printf("%d\n",Ans);
}

Measured memory_bytes: 128
/**/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF=99999999999999;
const int inf=999999999;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if((c>=a&&c<=b)||(c>=b&&c<=a))
		cout<<"Yes\n";
	else
		cout<<"No\n";

	return 0;
}

/*
    summary:
*/

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

int main(void){
    int N, K, R, S, P;
    string T;

    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    vector<bool> ifWon(K, false);

    int Point = 0;
    for(int i=0; i<N; i++){
        if(i>=K){
            if((T[i]==T[i-K])&&(ifWon[i%K])){
                ifWon[i%K]=false;
                continue;
            }
        }
        switch(T[i]){
            case 'r':
                Point += P;
                ifWon[i%K] = true;
                break;
            case 's':
                Point += R;
                ifWon[i%K] = true;
                break;
            case 'p':
                Point += S;
                ifWon[i%K] = true;
                break;
        }
    }

    cout << Point << endl;

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int ans=0, anscopy=999;
  
  for (int i=0; i<s.size()-2; ++i) {
    int num= (s.at(i)-'0')*100+(s.at(i+1)-'0')*10+(s.at(i+2)-'0');
    ans= abs(num-753);
    if (ans<=anscopy) anscopy=ans;
  }
  cout << anscopy;
}

Measured memory_bytes: 256
#include "iostream"
#include "cmath"

using namespace std;

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

int main() {
  long a, b;
  scanf("%ld %ld", &a, &b);
  long ans;
  ans = a*b/gcd(a, b);
  printf("%ld", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>  
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

bool sortinrev(const pair<ll,string> &a,  
               const pair<ll,string> &b) 
{ 
       return (a.first > b.first); 
}
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}
 
bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll n;
        cin >> n;
        
        ll sum=0;
        rep(i,1,n+1)
        {
           if(i%3!=0 && i%5!=0)
               sum+=i;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, m; cin >> n >> m;
    bool fg = true;
    map<int, int> mp;
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        mp[a]++; mp[b]++;
    }
    for(auto m: mp){
        if(m.second%2 == 1) fg = false;
    }

    if(fg) cout << "YES" << ln;
    else cout << "NO" << ln;
}


Measured memory_bytes: 4352
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
count=0
for i in range(n):
  x-=a[i]
  if x>=0 and i<n-1:
      count+=1
  elif x==0 and i==n-1:
      count+=1
  
print(count)

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, ret = 0;
    cin >> n;
    for (int i=1; i<=n; i++) {
        int a;
        cin >> a;
        ret += (i % 2 && a % 2);
    }
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
char j[1001];
char o[1001];
using namespace std;
int main(){
    char a;
    int i=0,jj=0,k;
    while(true){
        a=getchar();
        if(a>='a' && a<='z'){
            i++;
            j[i]=a;
        }
        else break;
    }
    while(cin>>a){
        jj++;
        o[jj]=a;
    }
    for(k=1;k<=1000;k++){
        if(k<=i) cout<<j[k];
        if(k<=jj) cout<<o[k];
    }
    cout<<endl;
    return 0;
}

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

int main(){
  int d;
  string a[4] = {"Christmas", "Christmas Eve", "Christmas Eve Eve", "Christmas Eve Eve Eve"};
  
  
  cin >> d;
  
  if(d == 25){
    cout << a[0] << endl;
  } else if(d == 24){
    cout << a[1] << endl;
  } else if(d == 23){
    cout << a[2] << endl;
  } else if(d == 22){
    cout << a[3] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    bool b=true;
    int cnt=0;
    if (n==1) {
            cout << "No" << endl;
            return 0;
        } 
   if (n >1){ 
    for (int i=0; i < n/2; i++){
      
        if (n%2==1) {
            cout << "No" << endl;
             b=false;
             break;
        } 
        else if (s[i]!=s[i+n/2]){
             cout << "No" << endl;
             b=false;
             break;
        }
    }
   }
    if (b) cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int n,a[5];

string s;

int main(){
    scanf("%d",&n);

    for(int i=1;i<=n;++i){
        cin>>s;
        if(s=="AC") a[1]++;
        if(s=="WA") a[2]++;
        if(s=="TLE") a[3]++;
        if(s=="RE") a[4]++;
    }

    printf("AC x %d\n",a[1]);
    printf("WA x %d\n",a[2]);
    printf("TLE x %d\n",a[3]);
    printf("RE x %d\n",a[4]);
}

Measured memory_bytes: 3808
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

//辺を表す構造体(行先、容量、逆辺)
struct edge{ll to,cap,rev;};

const ll max_n=10000;

vector<edge> G[max_n];
bool used[max_n];//dfsで既に調べたかのフラグ
ll level[max_n];
ll iter[max_n];

void add_edge(ll from,ll to,ll cap){
    G[from].push_back((edge){to,cap,(ll)G[to].size()});
    G[to].push_back((edge){from,0,(ll)G[from].size()-1});
}

void bfs(ll s){
    memset(level,-1,sizeof(level));
    queue<ll> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        ll v=que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e=G[v][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

ll dfs(ll v,ll t,ll f){
    if(v==t) return f;
    for(ll &i=iter[v];i<G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(ll s,ll t){
    ll flow=0;
    for(;;){
        bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        ll f;
        while((f=dfs(s,t,INF))>0){
            flow+=f;
        }
    }
}


int n,k;
bool can[max_n][max_n];

void solve(){
    ll s=n+k;
    ll t=s+1;
    rep(i,n){
        add_edge(s,i,1);
    }
    rep(i,k){
        add_edge(n+i,t,1);
    }
    rep(i,n){
        rep(j,k){
            if(can[i][j]){
                add_edge(i,n+j,1);
            }
        }
    }
    cout<<max_flow(s,t)<<endl;
}

int main(){
    cin>>n;
    k=n;
    V<P> r(n),b(n);
    rep(i,n){
        int a,t;
        cin>>a>>t;
        r[i]=P(a,t);
    }
    rep(i,n){
        int c,d;
        cin>>c>>d;
        b[i]=P(c,d);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(r[i].ft<b[j].ft&&r[i].sc<b[j].sc){
                can[i][j]=1;
            }
        }
    }
    solve();
}

Measured memory_bytes: 1280
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>


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


int main() {
    int n;
    cin >> n;
    vector<ll>a(n);
    vector<string>s(n);
    rep(i, n) {
        stringstream ss;
        cin >> a[i];
        ss << static_cast<bitset<32>>(a[i]);
        s[i] = ss.str();
    }
    int cnt[32] = { 0 };
    rep(i, n) {
        rep(j, 32) {
            if (s[i][j] == '1')cnt[j]++;
        }
    }
    rep(i, n) {
        int tmp[32], tmp2[32] = { 0 };
        string ans(32,'0');
        rep(j, 32) {
            if (s[i][j] == '1') {
                tmp[j] = cnt[j] - 1;
                tmp2[j]++;
            }
            else tmp[j] = cnt[j];
        }
        rep(j, 32) {
            tmp2[j] *= n;
            tmp[j] *= (n - 1);
            if ((max(tmp2[j], tmp[j]) - min(tmp2[j], tmp[j])) % 2 == 1) {
                ans[j] = '1';
            }
            else ans[j] = '0';
           
        }
        ll anst = stoi(ans, 0, 2);
        cout << anst << endl;
    }

    
    return 0;
}

Measured memory_bytes: 21580
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int n,x,t;
	cin >> n >> x >> t;
	int ans = 0;
	int cnt = 0;
	while(cnt < n){
		ans += t;
		cnt += x;
	}
	cout << ans << endl;


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://abc174.contest.atcoder.jp/tasks/abc174_b
// rm -r -f test;oj d https://atcoder.jp/contests/abc176/tasks/abc176_a

Measured memory_bytes: 3596
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans=0;
int main(){
	cin>>n; 
	for (ll i=1;i*i<=n;i++)
		if (n%i==0){
			ll t=n/i;
			if(t-i<2) break;
			ans+=t-1;
		}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;
int w[222222], b[222222];
signed main() {
	int n;
	string s;
	cin >> n >> s;
	bool can = true;
	rep(i, n) {
		if (s[i] == '#') {
			b[i + 1] = 1;
			can = false;
		}
		else {
			w[i + 1] = 1;
		}
	}
	rep(i, n + 1) {
		w[i + 1] += w[i];
		b[i + 1] += b[i];
	}
	if (can) {
		cout << 0 << endl;
		return 0;
	}
	int ans = inf;
	rep(i, n + 1) {
		ans = min(ans, b[i] + w[n] - w[i]);
	}
	cout << ans << endl;
}


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


string s, t;
using State = string::iterator;
int atom(State& it);
int term(State& it);
int form(State& it);

int atom(State& it) {
  auto c = *it;
  assert(c >= 'a' && c <='d');
  it++;
  return t[c - 'a'] - '0';
}
int term(State& it) {
  auto c = *it;
  ++it;
  if(c == '+') {
    return form(it) | form(it);
  }
  else if(c == '*') {
    return form(it) & form(it);
  }
  else if(c == '^') {
    return form(it) ^ form(it);
  }
  assert(false);
}
int form(State& it) {
  auto c = *it;
  if(c == '[') {
    ++it;
    int tmp = term(it);
    ++it;
    return tmp;
  }
  assert(c >= 'a' && c <= 'd');
  return atom(it);
}

string conv(int x) {
  string s = to_string(x);
  if(s.size() < 4) {
    s = string(4 - s.size(), '0') + s;
  }
  return s;
}

int main() {
  while(cin >> s) {
    if(s == ".") break;
    cin >> t;
    auto it = s.begin();
    int x = form(it);
    int cnt = 0;
    rep(i, 10000) {
      it = s.begin();
      t = conv(i);
      int y = form(it);
      if(x == y) cnt++;
    }
    cout << x << " " << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 3216
using System;

namespace AtCoderABC129D
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;

            string[] s = Console.ReadLine().Split(' ');

            int H = int.Parse(s[0]);
            int W = int.Parse(s[1]);

            int[][] X = new int[H][];
            int[][] Y = new int[H][];

            bool[][] A = new bool[H][];

            for (int i = 0; i < H; i++)
            {
                A[i] = new bool[W];
                X[i] = new int[W];
                Y[i] = new int[W];

                char[] c = Console.ReadLine().ToCharArray();

                for(int j=0;j<W;j++)
                {
                    A[i][j] = (c[j] == '.');
                }
            }

            int count =0;

            for(int i=0;i<H;i++)
            {
                for(int j=0;j<W;j++)
                {
                    if(A[i][j])
                    {
                        count++;
                    }
                    else
                    {
                        for(int k=0;k<count;k++)
                        {
                            X[i][j - k - 1] = count;
                        }

                        count = 0;
                    }
                }

                for (int k = 0; k < count; k++)
                {
                    X[i][W - k - 1] = count;
                }

                count = 0;
            }

            for (int j = 0; j < W; j++)
            {
                for (int i = 0; i < H; i++)
                {
                    if (A[i][j])
                    {
                        count++;
                    }
                    else
                    {
                        for (int k = 0; k < count; k++)
                        {
                            Y[i -k -1][j] = count;
                        }

                        count = 0;
                    }
                }

                for (int k = 0; k < count; k++)
                {
                    Y[H - k - 1][j] = count;
                }

                count = 0;
            }

            for(int i=0;i<H;i++)
            {
                for(int j=0;j<W;j++)
                {
                    if (X[i][j] + Y[i][j] -1 > ans)
                        ans = X[i][j] + Y[i][j]-1;

                }
            }

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 53688
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(K);
    ll A[N+2]={0};
    ll pref=0;
    FORI(i,1,N+2)
    {
        pref+=i-1;
        pref%=MOD;
        A[i]=((i*N)%MOD-pref+MOD)%MOD;
        A[i]=(A[i]-pref+1+MOD)%MOD;
    }
    ll ans=0;
    FORI(i,K,N+2)
    {
        ans=(ans+A[i])%MOD;
    }
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 5348
def main(s):
    pattern1 = ["0" if i % 2 == 0 else "1" for i in range(len(s))]
    pattern2 = ["1" if i % 2 == 0 else "0" for i in range(len(s))]
    dist1 = 0
    dist2 = 0
    for i in range(len(s)):
        if s[i] != pattern1[i]:
            dist1 += 1
        if s[i] != pattern2[i]:
            dist2 += 1

    return min(dist1, dist2)


s = input()
# s = "000"  # 1
# s = "10010010"  # 3
# s = "0"  # 0
print(main(s))


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

int n, a;
vector<pair<int, int>> students;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        students.push_back(make_pair(a, i));
    }
    sort(students.begin(), students.end());
    for (int i = 0; i < n; i++)
    {
        cout << students[i].second << " ";
    }
    cin >> n;
}

Measured memory_bytes: 1780
'use strict'
const range = (start, end) => {
  const list = [];
  for (let i = start; i <= end; i++ ) {
    list.push(i);
  }
  return list;
}


const main = (input) => {
  const args = input.split(' ');
  const K = parseInt(args[0], 10);
  const X = parseInt(args[1], 10);

  let min = X-K+1
  if(min<-1000000) {
    min = -1000000
  }
  const max = X+K-1
  if(max>10000000) {
    max = 1000000
  }
  const result = range(min,max)
  result.forEach((num) => {console.log(num)})

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

Measured memory_bytes: 9264
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1000000007;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    ll ans=0;
    for (int i=1;i<N;++i){
        ans+=(N-1)/i;
    }

    cout << ans << '\n';
}

Measured memory_bytes: 3652
/*Obada*/
#include <bits/stdc++.h>

using namespace std ;

int main()
{
    int num1 , num2 , num3 , sum ;
    cin >> num1 >> num2 >> num3 ;

    sum = num1 + num2 + num3 ;

    if (sum >= 22)

        cout << "bust" ;

    else

        cout << "win" ;

        return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

long long d[300020];
bool visited[300020];

typedef struct{
    int to, head, next;
    long long cost;
} edge;

edge tree[300020];

void dfs(int v, int p, long long cost){
    d[v] = cost;
    visited[v] = true;

    for(int e = tree[v].head; e != -1; e = tree[e].next){
        if(!visited[tree[e].to]){
            if(tree[e].to == p){
                continue;
            }
            dfs(tree[e].to, v, tree[e].cost + cost);
            visited[tree[e].to] = false;
        }
    }
}

int main(void){

    int N;

    scanf("%d", &N);

    for(int i = 0; i < N; i++){
        tree[i].head = -1;
    }

    int a[N], b[N];
    long long c[N];
    int m = 0;

    for(int i = 0; i < N-1; i++){
        scanf("%d%d%lld", &a[i], &b[i], &c[i]);
        a[i]--, b[i]--;
        tree[m].next = tree[a[i]].head;
        tree[a[i]].head = m;
        tree[m].to = b[i];
        tree[m].cost = c[i];
        m++;
        tree[m].next = tree[b[i]].head;
        tree[b[i]].head = m;
        tree[m].to = a[i];
        tree[m].cost = c[i];
        m++;
    }

    int Q, K;

    scanf("%d%d", &Q, &K);

    dfs(K-1, -1, 0);

    int x[Q], y[Q];

    for(int i = 0; i < Q; i++){
        scanf("%d%d", &x[i], &y[i]);
    }

    for(int i = 0; i < Q; i++){
        printf("%lld\n", d[x[i]-1] + d[y[i]-1]);
    }

    return 0;
}

Measured memory_bytes: 16860
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

string s;
int k;

int main() {
	cin >> s >> k;
	lp(s.size() - 1) {
		if (s[i] != 'a') {
			if ('z' - s[i] < k) {
				k -= 'z' + 1 - s[i];
				s[i] = 'a';
			}
		}
	}
	k %= 26;
	s[s.size() - 1] += k - 26;
	if (s[s.size() - 1] < 'a')s[s.size() - 1] += 26;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
N, M = [int(n) for n in input().split()]

# node:connected
graph = {node:set() for node in range(1,N+1)}

for _ in range(M):
    A, B = [int(n) for n in input().split()]
    graph[A].add(B)
    graph[B].add(A)

to_visit = set(range(2,N+1))
level = 0

posts = {}

while to_visit:
    # base
    if level == 0:
        levels = {0:{1:None}}
        current_level = {1}
    
    # loop
    else:
        prevs = levels[level-1]
        levels[level] = {}
        for prev in prevs:
            for nbr in graph[prev]:
                if nbr in to_visit:
                    levels[level][nbr] = prev
                    posts[nbr] = prev
                    to_visit.remove(nbr) 
    
    level += 1

print('Yes')
for i in range(2,N+1):
    print(posts[i])

Measured memory_bytes: 90536
L,R = map(int,input().split())

ans = float('inf')

if R - L + 1 >= 2019:
    ans = 0
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min(ans, (i*j)%2019)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	int a, b;
	int count = 0;
	bool ans = false;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a == b) {
			count++;
		}
		else {
			count = 0;
		}
		if (count == 3) {
			ans = true;
		}
	}

	if (ans == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;


long long sub_mod(long long a,long long b){
	long long re;
	if(a%mod < b%mod){
		re = (a%mod)+mod - (b%mod);
	}
	else{
		re = (a%mod) - (b%mod);
	}
	return re;
}

long long mod_pow(long long a, long long n, long long p) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return res;
}

long long div_mod(long long a,long long b){
	long long w = mod_pow(b,mod-2,mod);
	long long re = a*w%mod;
	return re;
}

long long int ncr(int n,int a){
	long long ko = 1;
	long long haha = 1;
	for(int i = 0; i < a; i++){
		ko = ko * (n-i) % mod;
		haha = haha * (i+1) % mod;
	}
	return div_mod(ko,haha);
}
int main(void)
{
	int n,a,b;
	cin>>n>>a>>b;
	long long ans = mod_pow(2,n,mod);
	ans = ans - 1;
	ans = sub_mod(ans,ncr(n,a));
	ans = sub_mod(ans,ncr(n,b));
	
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair <int, int>
using namespace std;
int n, m;
pair <int, int> a[100005];
int main() {
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        cin >> a[i].fi >> a[i].se;
    }
    sort (a, a+n);
    priority_queue <int> pq;
    int cur = 0;
    int ans = 0;
    for (int i=1; i<=m; i++) {
        while (a[cur].fi <= i && cur < n) {
            pq.push(a[cur].se);
            cur++;
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1660
const input = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');
const meta = input[0];
const a = input[1];
const b = input[2];
const c = input[3];

const metaD = meta.trim().split(' ').map(i => parseInt(i));
const X = metaD[0];
const Y = metaD[1];
const Z = metaD[2];
const K = metaD[3];
const A = a.trim().split(' ').map(i => parseInt(i)).slice(0,X).sort((a,b)=>b-a);
const B = b.trim().split(' ').map(i => parseInt(i)).slice(0,Y).sort((a,b)=>b-a);
const C = c.trim().split(' ').map(i => parseInt(i)).slice(0,Z).sort((a,b)=>b-a);

const result = [];
const queue = new Map();
queue.set('0,0,0', A[0]+B[0]+C[0]);

const done = {};

const addToQueue = (p,x,y,z) => {
    const d = `${x},${y},${z}`;
    if (!queue.has(d) && !done[d] && A[x] && B[x] && C[x]) {
        queue.set(d,p);
    }
}

const queueMax = () => {
    var key = '';
    var value = 0;
    queue.forEach((v,k)=> {
        if (v>value) {
            value = v;
            key = k;
        }
    });
    return [key,value];
}

Array.from(Array(K)).forEach(() => {
    const largest = queueMax();
    result.push(largest[1]);
    queue.delete(largest[0]);
    const xyz = largest[0].split(',').map(i=>parseInt(i));
    const x = xyz[0];
    const y = xyz[1];
    const z = xyz[2];
    done[largest[0]] = true;
    addToQueue(A[x+1]+B[y]+C[z],x+1,y,z);
    addToQueue(A[x]+B[y+1]+C[z],x,y+1,z);
    addToQueue(A[x]+B[y]+C[z+1],x,y,z+1);
});

console.log(result.join('\n'));

Measured memory_bytes: 11736
#include<iostream>
#include<vector>

using namespace std;

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

int h, w, n;

vector<string> fall(vector<string> v) {
  rep (iii, h) rep (i, h - 1) rep (j, w) {
    if (v[h - i - 1][j] == '.') swap(v[h - i - 1][j], v[h - i - 2][j]);
  }
  return v;
}

bool valid(vector<string> v) {
  vector<string> next = v;
  bool del = false;
  rep (i, h) rep (j, w - n + 1) rep (c, 26) {
    bool ok = true;
    rep (k, n) if (v[i][j + k] != 'A' + c) {
      ok = false;
      break;
    }
    if (ok) {
      del = true;
      rep (k, n) next[i][j + k] = '.';
    }
  }
  rep (i, h - n + 1) rep (j, w) rep (c, 26) {
    bool ok = true;
    rep (k, n) if (v[i + k][j] != 'A' + c) {
      ok = false;
      break;
    }
    if (ok) {
      del = true;
      rep (k, n) next[i + k][j] = '.';
    }
  }
  if (!del) {
    rep (i, h) rep (j, w) if (v[i][j] != '.') return false;
    return true;
  }
  return valid(fall(next));
}

int main() {
  cin >> h >> w >> n;
  vector<string> vs(h);
  rep (i, h) cin >> vs[i];
  rep (i, h) rep (j, w - 1) {
    vector<string> v = vs;
    swap(v[i][j], v[i][j + 1]);
    v = fall(v);
    if (valid(v)) {
      cout << "YES" << endl;
      return 0;
    }
  }  
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 1424
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
      string s,t,u;
      int a,b;
      cin>>s>>t>>a>>b>>u;
      if(s == u)a--;
      if(t == u)b--;
      cout<<a<<" "<<b;
    }


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

#define fr first
#define sc second

using namespace std;

const int N = 3e5 + 7;

int a[N];
pair<int, int> b[N];
int c[N];

main()
{
    int n, r, l;

    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        b[i].fr = a[i];
        b[i].sc = i;
    }

    sort(b + 1, b + n + 1);

    for (int i = 1; i <= n; i++)
    {
        c[b[i].sc] = i;
    }

    l = n / 2;
    r = n / 2 + 1;

    for (int i = 1; i <= n; i++)
    {
        int ans;
        if (c[i] <= l)
        {
            ans = b[r].fr;
        }
        else
        {
            ans = b[l].fr;
        }
        printf("%d\n", ans);
    }
}




Measured memory_bytes: 6144
using System;
using System.Linq;
//using System.Collections.Generic;

class Test
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int m = int.Parse(Console.ReadLine());
        int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int i = 0;
        while (true)
        {
            if (A[i] > B[i])
            {
                Console.WriteLine(0);
                break;
            }
            else if (A[i] < B[i])
            {
                Console.WriteLine(1);
                break;
            }
            else if (A.Length > i + 1 && B.Length > i + 1) i++;
            else if (B.Length == i + 1)
            {
                Console.WriteLine(0);
                break;
            }
            else
            {
                Console.WriteLine(1);
                break;
            }
        }
    }
}




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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  rep(i,m) cin >> s.at(i) >> c.at(i);
  
  bool flag=1;
  
  if(n == 1){
  for(int i = 0; i <= 9; i++){
    flag = 1;
    rep(j,m){
    if(s.at(j) != 1) {flag=0; continue;}
    if(c.at(j) != i) {flag=0; continue;}
    }
    if(flag==1) {cout << i << endl; break;}
  }
  }

  if(n==2){
    for(int i = 10; i <= 99; i++){
      flag = 1;
      rep(j,m){
        if(s.at(j) == 3) {flag=0; continue;}
        if(s.at(j) == 2 && i%10 != c.at(j)) {flag=0; continue;}
        if(s.at(j) == 1 && i/10 != c.at(j)) {flag=0; continue;}
      }
        if(flag==1) {cout << i << endl; break;}
    }
  }


    if(n == 3){
    for(int i = 100; i <= 999; i++){
      flag = 1;
      rep(j,m){
        if(s.at(j) == 3 && (i%10) != c.at(j)) {flag=0; continue;}
        if(s.at(j) == 2 && (i%100)/10 != c.at(j)) {flag=0; continue;}
        if(s.at(j) == 1 && (i/100) != c.at(j)) {flag=0; continue;}
      }
        if(flag==1) {cout << i << endl; break;}
    }
  }
  
  if(flag == 0) cout << -1 << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main(){
  int N, K, l[51], ans = 0;

  cin >> N >> K;
  for(int i = 0; i < N; i++) cin >> l[i];

  sort(l, l+N);

  for(int i = N-1; N-K-1 < i; i--) ans += l[i];

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
# まだ解いてない配点を nokori として持つ
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})


d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();

    int max=Math.max(a+b,a+a-1);
        max=Math.max(max,b+b-1);

    System.out.println(max);
  }
}


Measured memory_bytes: 23124
#include<stdio.h>
  
static const int MAX = 100;
 
int main(){
    
  int M[MAX][MAX];
  int n, u, k, v;
  int i, j;
  
  scanf("%d", &n);
    
  for (i = 0; i < n; i++){
    for (j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }
    
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
      
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      M[u-1][v-1] = 1;
    }
  }
    
  for (i = 0; i < n; i++ ){
    for (j = 0; j < n; j++ ){
      if (j) printf(" ");
      printf("%d",M[i][j]);
      if(j == n-1){
    printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    rep(j, n) {
        ll u = a + (n-1-j)*c - j*d;
        ll v = a - j*c + (n-1-j)*d;
        if(u <= b && b <= v) {
            cout << "YES" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll MAXN = 1000000;

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

    const auto solve = [&]()
    {
        ll x = 0;

        rep (i, MAXN)
        {
            x = 10 * x + 7;
            x %= K;

            if (x == 0) { return i + 1; }
        }

        return -1LL;
    };

    cout << solve() << endl;

    return 0;
}


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

const int mod=2;
typedef valarray<int> vec;
typedef valarray<vec> mat;

mat mul(mat a,mat b){
	int m=a.size();
	mat c(vec(0,m),m);
	rep(i,m)rep(j,m) rep(k,m) c[i][j]^=(a[i][k]&b[k][j]);
	return c;
}
mat power(mat a,int n){
	int m=a.size();
	mat b(vec(0,m),m);
	rep(i,m) b[i][i]=1;
	while(n){
		if(n&1) b=mul(b,a);
		a=mul(a,a);
		n>>=1;
	}
	return b;
}
inline int pivoting(mat &a,int k,int &c){
	int n=a.size(),m=a[0].size(),p=k,ret=0;
	for(;c<m;++c){
		int cmax=a[k][c];
		range(i,k+1,n){
			if(a[i][c]){
				p=i,ret=1;
				cmax=a[i][c];
			}
		}
		if(cmax) break;
	}
	if(k!=p) swap(a[k],a[p]);
	return ret;
}
int forward(mat &a){
	int n=a.size(),m=a[0].size(),ret=0,c=0;
	rep(i,n-1){
		ret+=pivoting(a,i,c);
		if(a[i][c]==0) break;
		range(j,i+1,n){
			int coef=a[j][c];
			range(k,c,m) a[j][k]^=(coef&a[i][k]);
		}
	}
	return ret;
}
vec back(mat &a){
	int n=a.size(),m=a[0].size();
	vec x(0,n);
	for(int i=n-1;i>=0;i--){
		int sum=0;
		if(i+1<n) range(j,i+1,n) sum^=(a[i][j]&x[j]);
		x[i]=a[i][i]&(a[i][m-1]^sum);
	}
	rep(i,n) cout << (i?" ":"") << x[i];
	cout << endl;
	return x;
}
int answer(mat &a){
	int n=a.size(),m=a[0].size();
	int arank=0,brank=0;
	rep(i,n)rep(j,m-1) if(a[i][j]) arank=i+1;
	rep(i,n)rep(j,m) if(a[i][j]) brank=i+1;
	if(arank!=brank) return 0;
	if(arank<n) return 2;
	return 1;
}

int main(void){
	int n,t;
	cin >> n;
	mat a(vec(0,n),n),b(vec(0,n+1),n);
	rep(i,n)rep(j,n) cin >> a[i][j];
	rep(i,n) cin >> b[i][n];
	cin >> t;

	a=power(a,t);
	rep(i,n)rep(j,n) b[i][j]=a[i][j];

	forward(b);
	int ans=answer(b);
	if(ans==0)
		puts("none");
	else if(ans==1)
		vec x=back(b);
	else
		puts("ambiguous");
	return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
const int N=6,nC=324;
int n,C,L[N];
int f[1<<N-1][nC];
unsigned long long ans;
int main(){
    scanf("%d%d",&n,&C);
    for(int i=0;i<n;++i)scanf("%d",L+i);
    sort(L,L+n);
    int tot=0;
    do{
        ++tot;
        memset(f,0,sizeof f);
        f[0][n*L[n-1]]=1; 
        for(int i=1;i<=n*C;++i)if(i%n){
            const int id=i%n-1,t=min(i+L[id]*n,n*C);
            for(int S=0;S<1<<n-1;++S)
            if(!(S>>id&1))
            for(int k=i;k<=n*C;++k)
            f[S|1<<id][max(k,t)]+=f[S][k];
        }
        ans+=f[(1<<n-1)-1][n*C];
    }while(next_permutation(L,L+n-1));
    printf("%.16g\n",1.*ans/tot/pow(C,n-1));
    return 0;
}

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

int main() {
  int N,X;
  cin >> N >> X;
 
  vector<int> A(N);
  for(int i = 0;i < N;i++){
    cin >> A.at(i);
  }
  int sum = 0;
  int count = 0;
  
  for(int i = 0;i<N;i++){
      sum += A.at(i);
      count++;
    if(sum > X){
      count--;
      break;
    }
  }
  
  cout << count + 1 << endl;
}

Measured memory_bytes: 256