akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin >> S;
	int64_t ret = 0, n = S.size();
	for(int i=0; i < 1<<n-1; ++i){
		int64_t sum_i_pattern = 0;
		int st = 0;
		for(int j=0; j<n-1; ++j){
			if (i>>j & 1){
				sum_i_pattern += stol(S.substr(st, j + 1 - st));
				st = j + 1;
			}
		}
		if(st < n) sum_i_pattern += stol(S.substr(st, n - st));
		ret += sum_i_pattern;
	}
	cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a * b % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repr(i, a, n) for (ll i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

ll sol(ll n) {
  if (n < 0)
    return 0;
  int r = n % 4;
  if (r == 0)
    return n;
  if (r == 1)
    return 1;
  if (r == 2)
    return n + 1;
  if (r == 3)
    return 0;
  return -1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  ll a, b;
  cin >> a >> b;
  cout << (sol(a - 1) ^ sol(b)) << endl;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#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(){
    int a, b;
    cin >> a >> b;
    int k = abs(a+b)/2;
    if(abs(a-k)==abs(b-k)){
        cout << k << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


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

using namespace std;


bool comp(const string &s, const string &t)
{
    return s + t < t + s;
}

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

    string s;
    vector<string> v;
    for(int i=0; i < n; i++) {
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end(), comp);

    for(int i = 0; i < n; i++) {
        cout << v[i];
    }
    cout << endl;

    return 0;
}


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

const int mod = 1e9 + 7;

const int maxn = 3005;
int n, q;
int a[maxn];

int dp[maxn][maxn], tmp[maxn][maxn];

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

const int inv = (mod + 1) / 2;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> q;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            if(a[i] > a[j]){
                dp[i][j] = 1;
            }else{
                dp[i][j] = 0;
            }
        }
    }
    int power = 1;
    for(int i = 1;i <= q;i++){
        int x, y;
        cin >> x >> y;
        for(int j = 1;j <= n;j++){
            tmp[j][x] = dp[j][x];
            tmp[j][y] = dp[j][y];
            tmp[x][j] = dp[x][j];
            tmp[y][j] = dp[y][j];
        }
        for(int j = 1;j <= n;j++){
            if(j == x or j == y)
                continue;
            dp[j][x] = dp[j][y] = 1LL * inv * (tmp[j][y] + tmp[j][x]) % mod;
            dp[x][j] = dp[y][j] = 1LL * inv * (tmp[x][j] + tmp[y][j]) % mod;
        }
        dp[x][y] = dp[y][x] = 1LL * inv * (tmp[x][y] + tmp[y][x]) % mod;
        power = power * 2 % mod;
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        for(int j = i + 1;j <= n;j++){
            dp[i][j] = 1LL * dp[i][j] * power % mod;
            add(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
N, P = map(int, input().split())
S = input().strip()[::-1]

if P in [2, 5]:
    ans = 0
    for r in range(N):
        if int(S[r]) % P == 0:
            ans += N - r
    print(ans)
    exit()

d = [0] * (N + 1)
ten = 1
for i in range(N):
    a = int(S[i]) * ten % P
    d[i+1] = (d[i] + a) % P
    ten *= 10
    ten %= P

cnt = [0] * P
ans = 0
for i in range(N + 1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1

print(ans)


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

#define int long long

typedef pair<int, int> P;

int dist[100010];

vector<P> vec[100010];

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

    priority_queue<P, vector<P>, greater<P>> que;

    for(int i = 0;i < m;i++){
        int l, r, c;
        cin >> l >> r >> c;
        l--;
        r--;

        vec[l].push_back({r, c});
    }


    memset(dist, -1, sizeof(dist));

    dist[0] = 0;
    for(auto e : vec[0]){
        que.push({e.second, e.first});
    }


    int now = 0;
    while(!que.empty()){
        int cost = que.top().first;
        int r = que.top().second;
        que.pop();
        if(now < r){
            for(int i = now+1;i <= r;i++){
                dist[i] = cost;
                for(auto e : vec[i]){
                    que.push({e.second+cost, e.first});
                }
            }
            now = r;
        }
    }

    cout << dist[n-1] << endl;

    return 0;
}





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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


vector<string> cand = {"7", "5", "3"};
vector<string> strs;

void gen(int r, string u) {
    if (r == 0) {}
    else {
        strs.push_back(u);
        for (auto &&c:cand) {
            gen(r - 1, u + c);
        }
    }
}


auto solve() {
    ll N;
    cin >> N;

    gen(10, "");

    int res = 0;
    for (auto &&c:strs) {
        {
            bool s = false, f = false, t = false;
            for (auto &&dig:c) {
                if (dig == '7') s = true;
                if (dig == '5') f = true;
                if (dig == '3') t = true;
            }

            if (!s || !f || !t)
                continue;
        }

        ll d;
        stringstream ss;
        ss << c;
        ss >> d;

//        cerr << d << endl;

        if (d <= N) {
            res++;
        }
    }

    return res;
}

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

//    cout << solve() << endl;
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 2172
l= [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(l[k-1])

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};



typedef struct _state{
  int from,vis;
  double cost;
  _state(double ic,int ifr,int iv):cost(ic),from(ifr),vis(iv){
  };
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

vector<PI> V[30];


main(){
  int n,m,p,a,b;
  while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n){
    --a,--b;
    int ti[n];
    rep(i,n)scanf("%d",ti+i);

    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<state> Q;
    Q.push(state(0,a,0));

    bool cost[1<<n][m];
    memset(cost,0,sizeof(cost));
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().from,cti=Q.top().vis;
      double ccost=Q.top().cost;
      Q.pop();
      if(cost[cti][from])continue;
      cost[cti][from]=true;
      if(from==b){
        ans=ccost;
        break;
      }

      rep(i,n){
        if(cti>>i&1)continue;
        rep(j,V[from].size()){
          int to=V[from][j].first;
          int cc=V[from][j].second;
          if(cost[cti|1<<i][to])continue;
          double ncost=ccost+1.0*cc/ti[i];
          Q.push(state(ncost,to,cti|1<<i));
        }
      }
    }
    if(ans<0)puts("Impossible");
    else printf("%f\n",ans);
  }
}

Measured memory_bytes: 7772
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

class dice{
public:
  int label[7];
  void turn(char c) {
    int temp;
    if (c=='S') {
      temp=label[1];
      label[1]=label[5];
      label[5]=label[6];
      label[6]=label[2];
      label[2]=temp;
    } else if (c=='E') {
      temp=label[1];
      label[1]=label[4];
      label[4]=label[6];
      label[6]=label[3];
      label[3]=temp;
    } else if (c=='W') {
      temp=label[1];
      label[1]=label[3];
      label[3]=label[6];
      label[6]=label[4];
      label[4]=temp;
    }  else if (c=='N') {
      temp=label[1];
      label[1]=label[2];
      label[2]=label[6];
      label[6]=label[5];
      label[5]=temp;
    } else if (c=='T') {
      temp=label[2];
      label[2]=label[3];
      label[3]=label[5];
      label[5]=label[4];
      label[4]=temp;
    }
  }
  void out(int k){
    cout << label[k] << endl;
  }
};

int main(){
  int i,n,u,m;
  dice d1;
  for (i=1;i<7;i++){
    cin >> d1.label[i];
  }
  cin >> n;
  for (i=0;i<n;i++){
    cin >> u >> m;
    if (d1.label[2]==u) {
      d1.turn('N');
    } else if (d1.label[5]==u) {
      d1.turn('S');
    } else {
      while (d1.label[1]!=u) {
        d1.turn('W');
      }
    }
    while (d1.label[2]!=m) {
      d1.turn('T');
    }
    d1.out(3);
  }
  return 0;
}



Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int N =110;
const int inf =1e5+100;
int main()
{
    int B[N],n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<n;i++)
            scanf("%d",&B[i]);
        B[n] =inf,B[0] =inf;
        int ans =0;
        for(int i=1;i<=n;i++)
        {
            ans +=min(B[i-1],B[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

int n, m;
priority_queue<IP, vector<IP>, greater<IP> > que;

#define N 103
int parent[N];

int root(int x) {
  if(x == parent[x]) return x;
  return parent[x] = root(parent[x]);
}

void unite(int x, int y) {
  int px = root(x), py = root(y);
  if(px < py) {
    parent[py] = px;
  } else if(px > py) {
    parent[px] = py;
  }
}

int main() {
  while(cin >> n >> m && n && m) {
    rep(i, m) {
      int a, b, cost;
      cin >> a >> b >> cost;
      que.push(IP(cost, P(a, b)));
    }
    rep(i, n) parent[i] = i;
    int ans = 0;
    while(!que.empty()) {
      IP e = que.top(); que.pop();
      int cost = e.first, a = e.second.first, b = e.second.second;
      if(root(a) != root(b)) {
        unite(a, b);
        ans += cost;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3088
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

const ll modd=1e9+7;
const ll inf=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*    
         -> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         -> cout<<"Case #"<<casee<<": "<<ans<<endl; // for google kickstart

*/

/*-----------------------------------------------------------------------------------------------*/

int main(){
   fastt;
   
   ll n,k;
   cin>>n>>k;

   k--;

   string s;
   cin>>s;
 
   for(ll i=0;i<s.length();i++){
      char cc='a'+s[i]-'A';
      if(i!=k) cout<<s[i];
      else     cout<<cc;
   }

   cout<<endl;

   return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
tmp = 0
ans = 0
for i in range(0,n-1):
    if h[i] >= h[i+1]:
        tmp += 1
    else:
        if ans < tmp:
            ans = tmp
        tmp = 0
if ans < tmp:
    ans = tmp
print(ans)

Measured memory_bytes: 14224
import numpy as np
import itertools

N, M = map(int, input().split())
a = np.zeros((M,N), dtype='int8')
for n in range(M):
    for c in input().split()[1:]:
        a[n, int(c) - 1] = 1
p = np.array(list(map(int, input().split())))
count = 0
for case in itertools.product(range(2), repeat=N):
    np_case = np.array(case)
    b = np.sum(a * np_case, axis=1) % 2
    if all(p == b):
        count += 1
print(count)


Measured memory_bytes: 12416
A,B,C,X,Y = map(int,input().split())
sumAB = A+B
if sumAB >= 2*C:
    minXY = min(X,Y)
    ans = min(X,Y)*2*C
    X -= minXY
    Y -= minXY
    if X != 0:
        ans += X*min(A,2*C)
    elif Y !=0:
        ans += Y*min(B,2*C)
    print(ans)

else:
    print(A*X+Y*B)

Measured memory_bytes: 9116
N = int(input())
x = set()
last = ""

for i in range(N):
    W = input()
    if W in x:
        print("No")
        exit()
    elif i != 0:
        if last != W[0]:
            print("No")
            exit()

    last = W[-1]
    x.add(W)
print("Yes")


Measured memory_bytes: 2940
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b)
    {
        if(a==0)
        return 0;
        int res=1;
        //a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a);
            b>>=1;
            a=(a*a);
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ar[n+1];
    mii mp;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
        mp[ar[i]+i]++;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(mp.find(i-ar[i])!=mp.end())
        ans+=mp[i-ar[i]];
    }
    //ans/=2;
    cout<<ans;
}

Measured memory_bytes: 17636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();

        StringBuilder str = new StringBuilder();
        for(int i=0; i<s.length; i+=2) {
            str.append(s[i]);
        }
        System.out.println(str);
        sc.close();
    }
}


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

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	int arr[n];
	unsigned long long dp[n];
	for(int i = 0; i < n; i++)
		cin >> arr[i], dp[i] = 1e18L;
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = max(0, i - k); j < i; j++)
			dp[i] = min(abs(arr[i] - arr[j]) + dp[j], dp[i]);
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int N,K; cin >> N >> K;
    int R,S,P; cin >> R >> S >> P;
    string T; cin >> T;
    int ans = 0;
    vector<bool> ok(N,false);
    rep(i,N){
        if(T[i] == 'r'){
            if(i >= K && T[i-K] == 'r' && ok[i-K]) continue;
            ans += P;
            ok[i] = true;
        }
        else if(T[i] == 's'){
            if(i >= K && T[i-K] == 's' && ok[i-K]) continue;
            ans += R;
            ok[i] = true;
        }
        else{
            if(i >= K && T[i-K] == 'p' && ok[i-K]) continue;
            ans += S;
            ok[i] = true;
        }
    }
    cout << ans << endl;
}
    



Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<algorithm>

#define REP(i,a,n) for(int i=(a);i<(n);++i)

#define INV (-1)
#define N 102
#define INFTY (1<<30)
#define PLANE 2
#define MOAT 1

using namespace std;

int n,m;
int map[N][N];
int M[N][N];

bool inline inRange(int t, int min, int max){
	return min <= t && t < max;
}

void dfs(int i, int j, int now){
	const int ci[] = {-1,0,1,0};
	const int cj[] = {0,1,0,-1};

	if( M[i][j] != now )
		return ;

	for(int k = 0; k < sizeof(ci)/sizeof(*ci); ++k){
		int ti = i + ci[k];
		int tj = j + cj[k];
		if( inRange( ti, 0, m+2 ) && inRange( tj, 0, n+2 ) ){
			if( map[i][j] == MOAT && map[ti][tj] == PLANE ){
				M[ti][tj] = min( M[ti][tj], now + 1 );
				continue;
			}
			if( M[ti][tj] == now ){
				continue;
			}
			M[ti][tj] = now;
			dfs( ti, tj, now );
		}
	}
	return ;
}
void ResetMap(){
	REP(i,0,N)REP(j,0,N)
	{
		map[i][j] = PLANE;
		M[i][j] = INFTY;
	}
}
void PrintMap(){
	REP(i,1,m+1){
		REP(j,1,n+1){
			cout << setw(3) << M[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
bool Completed(int *ans){
	REP(i,0,m+2){
		if( M[i][0] < INFTY ){
			*ans = M[i][0];
			return true;
		}
		if( M[i][n+1] < INFTY ){
			*ans = M[i][n+1];
			return true;
		}
	}
	REP(j,0,n+2){
		if( M[0][j] < INFTY ){
			*ans = M[0][j];
			return true;
		}
		if( M[m+1][j] < INFTY ){
			*ans = M[m+1][j];
			return true;
		}
	}

	return false;
}

int main(){
	while(true){
		int now = 0;
		int ans = 1<<21;
		int si;
		int sj;
		
		cin>>n>>m;
		if( m==0&&n==0 )break;
		
		ResetMap();
		
		REP(i,1,m+1){
			string s;
			cin>>s;
			REP(j,1,n+1){
				if( s[j-1] == '&' ){
					si = i;
					sj = j;
					M[si][sj] = 0;
				}else if( s[j-1] == '#' ){
					map[i][j] = MOAT;
				}
			}
		}

		while( true ){
			REP(i,1,m+1){
				REP(j,1,n+1){
					dfs( i, j, now );		
				}
			}
			if( Completed(&ans) )
				break;
			else{
				++now;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int MAX_N = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return x;}

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
    int par[MAX_N];
    int rank[MAX_N];
public:
    void init(int n);
    int find(int x);
    void unite(int x,int y);
    bool same(int x,int y);
};

void UnionFind::init(int n) {
    for (int i = 0;i < n;i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int UnionFind::find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
    x = find(x);
    y = find(y);
    if (rank[x] < rank[y]) par[x] = y;
    else {
        par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool UnionFind::same(int x,int y) {
    x = find(x);
    y = find(y);
    return x == y;
}

int main() {
    string s;
    cin >> s;
    string a = "20190430";
    string b;
    for (int i = 0;i < s.size();i++) {
        if (s[i]!='/') {
            b+=s[i];
        }
    }
    if (a < b) cout << "TBD" << endl;
    else {cout << "Heisei" << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

int psum[4001][3];
char s[4002];

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

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++)
            psum[i][j] = psum[i - 1][j];
        if (s[i] == 'R') psum[i][0]++;
        if (s[i] == 'G') psum[i][1]++;
        if (s[i] == 'B') psum[i][2]++;
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int now = s[i];

        if (now == 'R') {
            ans += psum[i - 1][1] * (psum[n][2] - psum[i][2]);
            ans += psum[i - 1][2] * (psum[n][1] - psum[i][1]);
        }
        if (now == 'G') {
            ans += psum[i - 1][0] * (psum[n][2] - psum[i][2]);
            ans += psum[i - 1][2] * (psum[n][0] - psum[i][0]);
        }
        if (now == 'B') {
            ans += psum[i - 1][1] * (psum[n][0] - psum[i][0]);
            ans += psum[i - 1][0] * (psum[n][1] - psum[i][1]);
        }

        for (int j = 1; j <= n; j++) {
            if (i + j <= n && i - j >= 1) {
                if (now != s[i + j] && now != s[i - j] && s[i - j] != s[i + j])
                    ans--;
            }
        }

    }
    printf("%lld", ans);
}


Measured memory_bytes: 3832
#include <iostream>
#include <stdio.h>
using namespace std;

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

  if (N <= 999) {
    // printf("ABC%03d\n", N);
    cout << "ABC" << endl;
  } else {
    // printf("ABD%03d\n", (N - 999));
    cout << "ABD" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();

			for (int bit = 0; bit < (1<<n); bit++) {
				System.out.print(bit + ":");
				for (int j = 0; j < n; j++) {
					if (((bit>>j) & 1) == 1) {
						System.out.print(" " + j);
					}
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 64844
#include <cstdio>
#include <iostream>
#include <vector>
#include <limits>

using namespace std;
#define INF 1e18

int main() {
    int N, W;
    int w, v;
    scanf("%d%d", &N, &W);
    vector<int> wt(N), vl(N);
    int sum_val = 0;
    for (int i = 0; i < N; ++i) {
        scanf("%d%d", &w, &v);
        wt[i] = w;
        vl[i] = v;
        sum_val += v;
    }
    vector<vector<long long>> dp(N+1, vector<long long>(sum_val+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= sum_val; ++j) {
            if (j < vl[i])
                dp[i+1][j] = dp[i][j];
            else
                dp[i+1][j] = min(dp[i][j], dp[i][j - vl[i]] + wt[i]);
        }
    }
    int ans = 0;
    for (int j = sum_val; j >= 0; --j) {
        if (dp[N][j] <= W) {
            ans = j;
            break;
        }
    }
    cout << ans;
}

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

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1e9+7 
const int nax = 1e6+5;
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "

inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }

int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,d,a;
    cin>>n>>d>>a;
    vector<pair<ll,ll> > v(n);
    for(int i =0;i<n;++i){
        ll u,b;  cin>>u>>b;
        v[i] = {u,b};
    }
    sort(v.begin(),v.end());
    vl x(n);
    for(int i =0;i<v.size();++i){
        x[i] = v[i].ff;
    }
    ll ans = 0;
    vl pre(n+1,0);
    for(int i =0;i<n;++i){
        pre[i+1]+=pre[i];
        v[i].ss -= (pre[i]*a);
        if(v[i].ss <= 0)continue;
        ll right = v[i].ff + 2*d;
        ll num = (v[i].ss)/a;
        if(v[i].ss % a)num++;
        ans += num;
        pre[i+1] += num;
        ll u = upper_bound(x.begin(),x.end(),right) - x.begin();
        pre[u] -= num;
    }
    cout << ans;
    
    return 0;
 }

Measured memory_bytes: 6528
using System;


namespace AOJ0513
{
    class Program
    {
        public int card_num;
        public int[] card;

        public void Proc()
        {
            string input;
            input = Console.ReadLine();
            card_num = int.Parse(input);
            input = Console.ReadLine();
            int repeat = int.Parse(input);

            card = new int[card_num * 2];
            int k = 0;

            for (int i = 0; i < card_num * 2; i++)
            {
                card[i] = i + 1;
            }

            for (int i = 0; i < repeat; i++)
            {
               input = Console.ReadLine();
                k = int.Parse(input);
                if (k == 0)
                {
                    lShuffle();
                } else
                {
                    kShuffle(k);
                }
            }

            for (int i = 0; i < card.Length; i++)
            {
                Console.WriteLine(card[i]);
            }
          
        }

        static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }

        public void kShuffle(int k)
        {
            int rest = card_num * 2 - k;
            int[] tmp1 = new int[k];
            int[] tmp2 = new int[rest];
            Array.Copy(card, 0, tmp1, 0, k);
            Array.Copy(card, k, tmp2, 0, rest);
            Array.Copy(tmp2, card, rest);
            Array.Copy(tmp1, 0, card, rest, k);
            return;
        }

        public void lShuffle()
        {
            int[] tmp1 = new int[card_num];
            int[] tmp2 = new int[card_num];
            Array.Copy(card, tmp1, card_num);
            Array.Copy(card, card_num, tmp2, 0, card_num);

            for (int i = 0; i < card_num; i++)
            {
                card[2 * i] = tmp1[i];
                card[2 * i + 1] = tmp2[i];
            }
            return;
        }
    }
}

Measured memory_bytes: 9284
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc122/editorial.pdf
・数え上げDP
"""

import sys
from itertools import product
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()

# dp[i][j] := 全部でi文字の時、最後の3文字がjとなる文字列の数
dp=[Counter() for i in range(N+1)]
keys = [''.join(key) for key in product('ACGT', repeat=3)]
# 3文字での初期値
for key in keys:
    if key not in ['AGC', 'GAC', 'ACG']:
        dp[3][key]=1

keys = [''.join(key) for key in product('ACGT', repeat=4)]
for i in range(4, N+1):
    for key in keys:
        for j in range(4):
            tmp=list(key)
            if j>=1:
                # 隣同士をスワップさせる
                tmp[j],tmp[j-1]=tmp[j-1],tmp[j]
            if ''.join(tmp).count('AGC'):
                break
        else:
            # 4パターンいずれもAGCを含まないものだけ遷移させる
            cur,nxt=key[:3],key[1:]
            dp[i][nxt]=(dp[i][nxt]+dp[i-1][cur])%MOD
print((sum(dp[N].values()))%MOD)


Measured memory_bytes: 4208
#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 rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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; }

int main () {
  string s, t;
  cin >> s >> t;
  int S = sz(s);
  int T = sz(t);

  auto match = [&](int k) {
    // 0 <= k <= S-T
    rep(i,T) {
      if (t[i] != s[i+k] && s[i+k] != '?') return false;
    }
    return true;
  };

  auto construct = [&](int k) {
    string ans = s;
    rep(i,T) ans[k+i] = t[i];
    rep(i,S) {
      if (ans[i] == '?') ans[i] = 'a';
    }
    return ans;
  };

  int k = -1;
  rep(i,S-T+1) {
    if (match(i)) k = i;
  }

  if (k == -1) cout << "UNRESTORABLE" << endl;
  else cout << construct(k) << endl;
  return 0;
}

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

int main() {
  int n;
  cin>>n;
  long long a[n],b[n];
  for(int i=0;i<n;i++){
    long long p,q;
    cin>>p>>q;
    a[i]=p;
    b[i]=q;
  }
  sort(a,a+n);
  sort(b,b+n);
  if(n%2==1){
    cout<<b[n/2]-a[n/2]+1<<endl;
  }
  else{
    cout<<b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1<<endl;
  }
}

Measured memory_bytes: 6752
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$k = (int)$input[1];

$input = explode(' ', trim(fgets(STDIN)));

$cnt = 0;
foreach ($input as $v) {
	if ((int)$v >= $k) {
		$cnt += 1;
	}
}
echo $cnt;

Measured memory_bytes: 12792
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 50000

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

	int a, b, ans;
	cin >> a >> b;
	ans = (b - 1 + a - 2) / (a - 1);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
def count(i, s):
    left = right = 0
    for e in s:
        if e == "(":
            left += 1
        else:
            if left == 0:
                right += 1
            else:
                left -= 1

    return left-right, left, right, i


n = int(input())
S = [input() for i in range(n)]
s1 = []
s2 = []
for i, e in enumerate(S):
    c = count(i, e)
    # print(i, c)
    if c[0] >= 0:
        s1.append((c[2], c[3]))
    else:
        s2.append((-c[1], c[3]))

s1.sort()
s2.sort()
# print(s1, s2)
s = []
for e in s1:
    s.append(S[e[1]])
for e in s2:
    s.append(S[e[1]])
# print(s)

_, left, right, _ = count(0, "".join(s))
if left == right == 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 247300
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<functional>
#include<cmath>

#define Vi vector<int>
#define Vs vector<string>
#define PB push_back
#define ALL(a) a.begin(),a.end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define DEB cout<<"!"
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> piii;

int main(){
  int a,b,c,ans=0,INF=1000000000;
  cin>>a>>b>>c;
  int x[3],flag=0;
  for(int i=0;i<INF;i++){
    if(a%2!=0||b%2!=0||c%2!=0){
      flag=1;
      break;
    }
    x[0]=c/2+b/2;
    x[1]=a/2+c/2;
    x[2]=a/2+b/2;
    a=x[0]; b=x[1]; c=x[2];
    if(a==b&&b==c){
      ans=-1;
      flag=1;
      break;
    }
    ans++;
  }
  if(flag==0)ans=-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

const double PI=3.14159265358979323846;

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

int main(){
  int a=1,b=1;

  while(true){
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    rep(i,a){
      rep(j,b){
	cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3112
n = int(input())
w = list(map(int, input().split()))
a = []
x = 0
for i in range(n):
    x += w[i]
    a.append(x)

b = []
for j in range(n):
    b.append(abs(2 * a[j] - a[n - 1]))
print(min(b))

Measured memory_bytes: 9112
#include <stdio.h>
int main(){
  int n,i,x;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    x=i;
    if(x%3==0){
      printf(" %d",x);
    }
    else{
      while(x){
      if(x%10==3){ 
	printf(" %d",i);
        break;
      }
      x=x/10;
      }
    }
  }
    printf("\n");
  return 0;
}



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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    bool f=0;
    for(int i=0 ; i<4 ; i++){
        if(s[i]==s[i+1]) f=1;
    }
    if(f){
        cout << "Bad" << endl;
    }else cout <<"Good"<< endl;

    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}
int main(){
    int N;
    cin >> N;
    vector<vector<pair<int,int>>> XY(N);
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        for(int j = 0; j < A; j++){
            int X, Y;
            cin >> X >> Y;
            XY[i].push_back(make_pair(X,Y));
        }
    }
    int max_n = 0;
    for(int bit = 0; bit < (1 << N); bit++){
        bool ok = true;
        for(int i = 0; i < N; i++){
            if(!(bit & (1 << i))) continue;
            for(auto p : XY[i]){
                if((bit >> (p.fi - 1) & 1) != bool(p.se)) {
                    ok = false;
                    break;
                }
            }
        }
        if(ok) max_n = max(counter(bit), max_n);
    }
    cout << max_n << endl;
}


Measured memory_bytes: 3512
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if( a == b ) cout << a * 2;
    else if( a > b ) cout << a * 2 - 1;
    else cout << b * 2 - 1;
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
    elif len(x) == 3:
        x.sort()
        x1 = bisect_right(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if ((x[0] ^ x[1] ^ x[2]) == 0) and (x1 == x2 == x3):
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


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

typedef long long ll;
typedef pair<int, int> P;

#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100010;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

void solve(){
	ll n; cin >> n;
	ll a[n]; rep(i, n) cin >> a[i];
	sort(a, a + n);
	if(n % 2 == 0){
		ll k = n/2;
		ll hiku = 0;
		rep(i, k-1){ hiku += 2 * a[i]; }
		hiku += a[k-1];
		ll tasu = 0;
		frep(i, k+1, n){ tasu += 2 * a[i]; }
		tasu += a[k];
		cout << tasu - hiku << END;
	}else{
		ll k = n/2;
		ll hiku = 0;
		rep(i, k){ hiku += 2 * a[i]; }
		ll tasu = 0;
		frep(i, k+2, n){ tasu += 2 * a[i]; }
		tasu += a[k] + a[k+1];
		ll ans = tasu - hiku;
		k += 1;
		hiku = 0;
		rep(i, k-2){ hiku += 2 * a[i]; }
		hiku += a[k-2] + a[k-1];
		tasu = 0;
		frep(i, k, n){ tasu += 2 * a[i]; }
		cout << max(ans, tasu - hiku) << END;
	}
}

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


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

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

    int sum=0;
    for (int i=0; i<k; i++)
    {
        sum += p[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<algorithm>
using namespace std;
int solve(){
    int n;
    cin>>n;
    vector<bool> dp(n+1,true);
    vector<int> re;
    for(int i = 2;i<n;i++){
        if(!dp[i]) continue;
        re.push_back(i);
        int j = 2;
        while((i*j)<n){
            dp[i*j] = false;
            j++;
        }
    }
    while(true){
        bool flag = true;
        for(auto item:re){
            if(n%item == 0) {
                flag = false;
                break;
            }
        }
        if(flag) break;
        n++;
    }
    return n;
}

int main(){
    int T = 1;
    while(T--){
        int res = solve();
        cout<<res<<endl;
    }
    return 0;
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;
ll a[200010];
ll ans;

int main(){
	cin >> N;
	REP(i,0,N){
		cin >> a[i];
	}
	ll now=0;
	REP(i,0,N){
		if(a[i] == now+1){
			now++;
		}
	}
	if(now == 0){
		ans = -1;
	}else{
		ans = N - now;
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  return b ? gcd(b,a%b) : a;
}

ll lcm(ll a, ll b) {
  return a/gcd(a,b)*b;
}

ll f(ll x, int c, int d) {
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}

int main() {
  ll a, b;
  int c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256