akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=305;
inline void add(int&x,int y){(x+=y)%=MOD;}
int n,m,f[N][N],ans;
vector<pii>v[N];
inline bool jud(int i,int j,int k){for(pii x:v[i])if((j>=x.fi)+(k>=x.fi)+1!=x.se)return 0;return 1;}
int main(){
	n=rd(),m=rd();
	rep(i,1,m){int l=rd(),r=rd(),x=rd();v[r].pb(mp(l,x));}
	f[0][0]=1;
	rep(i,1,n)per(j,0,i)per(k,0,j)if(jud(i,j,k)){
		add(f[i][k],f[j][k]),add(f[i][j],f[j][k]);
	} else f[j][k]=0;
	int ans=0;rep(i,0,n)rep(j,0,i)add(ans,f[i][j]);
	cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<stdio.h>

int main(void)
{
  int n[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 
             5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int a;
  
  scanf("%d",&a);
  printf("%d",n[a-1]);
  return 0;
}

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

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

		cin >> a[i];

	}
	for (int k = 0; k <n; k++){
		j--;
		if (j == 0){
			cout << a[j]<<endl;
		}
		else{
			cout << a[j] << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
ll int MOD=998244353;
#define INF 2*1e9
#define N 310000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
int par[N],grade[N];
void init(int n){
    rep2(i,1,n){
        par[i]=i;
        grade[i]=0;
    }
}
int root(int x){
    return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
    return root(x)==root(y);
}
void unite(int x,int y){
    x=root(x); y=root(y);
    if(x==y)return;
    if(grade[x]<grade[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(grade[x]==grade[y]) grade[x]++;
    }
}
ll int n,m,color[N];
vector<int> v[N];
int dfs(int a,int b){
    if(color[a]==b) return 1;
    if(color[a]!=0&&color[a]!=b) return 0;
    color[a]=b;
    b*=-1;
    bool ans=true;
    rep(i,v[a].size()){
        ans=ans&dfs(v[a][i],b);
    }
    return ans;
}
main(){
    cin>>n>>m;
    init(n);
    rep(i,m){
        int u,w;
        cin>>u>>w;
        v[u].pb(w);v[w].pb(u);
        unite(u,w);
    }
    bool used[N]={};
    ll int a=0,b=0,c=0;
    rep2(i,1,n){
        int r=root(i);
        if(used[r])continue;
        used[r]=1;
        if(grade[r]==0){
            a++; continue;
        }
        if(dfs(r,1)) b++;
        else c++;
    }
    cout<<((2*n-1)*a-a*(a-1)+2*b*b+2*b*c+c*c);
    return 0;
}



Measured memory_bytes: 18176
s = input()
n = len(s)
import string
DD = [chr(i) for i in range(ord("a"), ord("z")+1)]
D = {}
for i in range(len(DD)):
    D[DD[i]] = i
A = [0] * 26
ans = 1
for i in range(n):
    ans += i - A[D[s[i]]]
    A[D[s[i]]] += 1
print(ans)

Measured memory_bytes: 43356
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30

int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);

    // 2 2
    // x 4 x 4 x 4 x

    int n; cin >> n;
    int f=0, t=0;
    REP(i,n){
        ll a; cin >> a;
        if(a%4==0) f++;
        else if(a%2==0) t++;
    }

    if(f*2+t>=n || f*2+1>=n){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


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

int main() {
	long A, B, C, D;
	cin >> A >> B >> C >> D;
	
	long long AB = A*B;
	long long CD = C*D;
	
	if(AB >= CD) cout << AB;
	else cout << CD;
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> cnt(n, 1);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
		cnt[p[i]]++;
	}
	vector<int> c = { 1,0 };
	if (p == c) {
		cout << "-1\n";
		return 0;
	}
	vector<set<int>> st(n + 1);
	rep(i, n) st[cnt[i]].insert(i);
	vector<int> ans;
	priority_queue<int, vector<int>, greater<int>> que;
	rep(i, n) que.push(i);
	int x = -1;
	int sz = n;
	while (sz > 3) {
		if (sz > 1 && st[sz].size() && x == -1) {
			int k = *st[sz].begin();
			ans.pb(k);
			st[cnt[k]].erase(k);
			cnt[k]--;
			st[cnt[p[k]]].erase(p[k]);
			cnt[p[k]]--;
			st[cnt[p[k]]].insert(p[k]);
			x = k;
		}
		else {
			int k = que.top(); que.pop();
			if (x == k) {
				k = que.top(); que.pop();
			}
			if (ans.size() == 0 || p[ans.back()] != k) {
				ans.pb(k);
				st[cnt[k]].erase(k);
				cnt[k]--;
				st[cnt[p[k]]].erase(p[k]);
				cnt[p[k]]--;
				st[cnt[p[k]]].insert(p[k]);
			}
			else {
				int nk = que.top(); que.pop();
				if (x == nk) {
					nk = que.top(); que.pop();
				}
				ans.pb(nk);
				st[cnt[nk]].erase(nk);
				cnt[nk]--;
				st[cnt[p[nk]]].erase(p[nk]);
				cnt[p[nk]]--;
				st[cnt[p[nk]]].insert(p[nk]);
				que.push(k);
			}
		}
		sz--;
	}
	vector<int> rem;
	while (!que.empty()) {
		int q = que.top(); que.pop();
		if (x != q) rem.pb(q);
	}
	sort(all(rem));
	do {
		bool flag = true;
		if (ans.size() > 0) {
			if (p[ans.back()] == rem[0]) flag = false;
		}
		rep(i, rem.size() - 1) if (p[rem[i]] == rem[i + 1]) flag = false;
		if (flag) {
			for (int i : rem) ans.pb(i);
			break;
		}
	} while (next_permutation(all(rem)));
	for (int i : ans) cout << i + 1 << ' ';
	cout << '\n';
}

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

int main(){
  int h,w; cin>>h>>w;
  vector<vector<int>> l(h,vector<int>(w,0)),r(h,vector<int>(w,0)),u(h,vector<int>(w,0)),d(h,vector<int>(w,0));
  char c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>c[i][j];
    }
  }
  for(int i=0;i<h;i++){
    if(c[i][0]=='.') l[i][0]++;
    for(int j=1;j<w;j++){
      if(c[i][j]=='.') l[i][j]=1+l[i][j-1];
    }if(c[i][w-1]=='.') r[i][w-1]++;
    for(int j=w-2;j>=0;j--){
      if(c[i][j]=='.') r[i][j]=r[i][j+1]+1;
    }
  }
  for(int j=0;j<w;j++){
    if(c[0][j]=='.') u[0][j]++;
    for(int i=1;i<h;i++){
      if(c[i][j]=='.') u[i][j]=u[i-1][j]+1;
    }if(c[h-1][j]=='.') d[h-1][j]++;
    for(int i=h-2;i>=0;i--){
      if(c[i][j]=='.') d[i][j]=d[i+1][j]+1;
    }
  }int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans=max(ans,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 67456
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string O, E, ans; cin >> O >> E;
    int n = min(O.size(), E.size());
    for (int i = 0; i < n; ++i) {
        cout << O[i] << E[i];
    }
    if (n < O.size()) cout << O[n];
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define all(arr) arr.begin(),arr.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
/*int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
int MOD = 100001;*/

void solve()
{
	int n;
	cin>>n;
	n--;
	string ans;
	while(n>=0)
	{
		ans+=((int)'a'+(n%26));
		n/=26;
		n--;
	}
	reverse(all(ans));
	cout<<ans<<endl;
}

int32_t main()
{
	FastIO; PRECISION;
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3132
import sys

input=sys.stdin.readline

H,W,N=map(int,input().split())
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)

def black(x,y):
    ans=0
    if (x-1,y-1) in point:
        ans+=1
    if (x-1,y) in point:
        ans+=1
    if (x-1,y+1) in point:
        ans+=1

    if (x,y-1) in point:
        ans+=1
    if (x,y) in point:
        ans+=1
    if (x,y+1) in point:
        ans+=1

    if (x+1,y-1) in point:
        ans+=1
    if (x+1,y) in point:
        ans+=1
    if (x+1,y+1) in point:
        ans+=1
        
    return ans

for _ in range(0,N):
    a,b=map(int,input().split())
    if a>2:
        if b>2:
            ss=black(a-1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a-1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a-1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1
    if H>a>1:
        if b>2:
            ss=black(a,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    if H-1>a:
        if b>2:
            ss=black(a+1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1
        if W>b>1:
            ss=black(a+1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a+1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    point.add((a,b))

for i in range(0,10):
    print(ans[i])


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

#define CHARA_NUM 26

using namespace std;

int main(void){
  int chara[CHARA_NUM];
  char in;

  for (int i = 0; i < CHARA_NUM; i++){
    chara[i] = 0;
  }

  while (cin >> in){
    if (!isalpha(in)){
      continue;
    }
    in = tolower(in);
    chara[in - 'a']++;
  }

  for (int i = 0; i < CHARA_NUM; i++){
    printf("%c : %d\n", i + 'a', chara[i]);
  }

  return 0;
}

Measured memory_bytes: 1124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
}node;
typedef node * NodePointer;
NodePointer root, nil;
NodePointer make(int key, NodePointer p){
  NodePointer n;
  n = malloc(sizeof(struct node));
  n->key = key;
  n->parent = p;
  n->left = p;
  n->right = p;
  return n;
}

void insert(int key){
  NodePointer n, x, z;
  z = make(key, nil);
  //n = malloc(sizeof(struct node));
  //x = malloc(sizeof(struct node));
  n = root;
  x = nil;
  while(n != nil){
    x = n;
    if(n->key < key) n = n->right;
    else n = n->left;
  }
  z->parent = x;
  if(x == nil) root = z;
  if(x->key < z->key) x->right = z;
  if(x->key > z->key) x->left = z;
}
void inorder(NodePointer T){
  if(T->left->key != 0) inorder(T->left);
  printf(" %d",T->key);
  if(T->right->key != 0) inorder(T->right);
}
void preorder(NodePointer T){
  printf(" %d",T->key);
  if(T->left != nil) preorder(T->left);
  if(T->right != nil) preorder(T->right);
}
void fre(NodePointer T){
  free(T);
  if(T->left != nil) fre(T->left);
  if(T->right != nil) fre(T->right);
}
int main(){
  int i ,n, key;
  char s[20];
  nil = make(0, nil);
  root = make(0, nil);
  root = nil;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(s[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(s[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");  
    }
  }
  fre(root);
  free(nil);
  return 0;
}

Measured memory_bytes: 24040
import sys
import fractions
input = sys.stdin.readline
import heapq

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A_sorted = sorted(A)
    div0 = make_divisors(A_sorted[0])
    ans = 1
    for d in div0[1:]:
        count = 0
        isAns = True
        for i in A_sorted[1:]:
            if i % d != 0:
                count += 1
                if count == 2:
                    isAns = False
                    break
        if isAns:
            ans = max(ans, d)
    div1 = make_divisors(A_sorted[1])
    for d in div1[1:]:
        count = 0
        isAns = True
        for i in A_sorted[2:]:
            if i % d != 0:
                isAns = False
                break
        if isAns:
            ans = max(ans, d)

    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 16132
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define MAX_H 20
#define MAX_W 20
#define INF 1000000

int h, w;

int bfs (vector<vector<char>> &s, vector<vector<int>> &dp, int sx, int sy) {
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  queue<P> que;
  vector<vector<int>> d(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d.at(i).at(j) = INF;
    }
  }
  que.push(P(sx, sy));
  d.at(sx).at(sy) = 0;
  int tmp = 0;
  while(que.size()) {
    P p = que.front(); que.pop();
    // やめる条件どうする？
    if (p.first >= h && p.second >= w) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && s.at(nx).at(ny) != '#' && d.at(nx).at(ny) == INF) {
        que.push(P(nx, ny));
        d.at(nx).at(ny) = d.at(p.first).at(p.second) + 1;
        dp.at(sx * w + sy).at(nx * w + ny) = d.at(nx).at(ny);
      }
    }
  }
  return 0;
}

int main(){
  
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s.at(i).at(j);
    }
  }
  
  vector<vector<int>> dp(h * w, vector<int>(h * w, -1));
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '.') {
        bfs(s, dp, i, j);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      ans = max(ans, dp.at(i).at(j));
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node {
  struct node *left, *right;
  int number;
};

static struct node *root = NULL;
#define BUF_SIZE 30
#define COMMAND_MAX 500001

void insert(int num) {
  struct node *nod = malloc(sizeof(struct node));
  nod->number = num;
  nod->left = nod->right = NULL;
  if(!root) {
    root = nod;
    return;
  }
  struct node **tmp = &root;
  while(*tmp) {
#ifdef DEBUG
    printf("%d: %d\n", num, (*tmp)->number);
#endif
    tmp = ((*tmp)->number > num) ? &(*tmp)->left : &(*tmp)->right;
  }
  // tmp = &nod is not the answer!
  *tmp = nod;
  return;
}

struct node** find(int num) {
  struct node **node = &root;
  while(*node) {
    struct node *cur = *node;
    if(cur->number > num) {
      node = &cur->left;
    } else if (cur->number == num) {
      return node;
    } else {
      node = &cur->right;
    }
  }
  return NULL;
}

struct node** findmin(struct node *node) {
  struct node** min = &node;
  while((*min)->left) {
    min = &(*min)->left;
  }
  return min;
}

void delete(int num) {
  struct node **node = find(num);
  if(node == NULL) return;
  struct node *cur = *node;
  if(!cur->left && !cur->right) {
    *node = NULL;
  } else if (cur->left && cur->right) {
    struct node** parent_min = findmin(cur->right);
    struct node* min = (*parent_min);
    min->left = cur->left;
    min->right = cur->right;
    (*parent_min) = NULL;
    (*node) = min;
  } else {
    (*node) = cur->left ? cur->left : cur->right;
  }
  free(cur);
}

void pre_order(struct node *node) {
  if(!node) return;
  printf(" %d", node->number);
  pre_order(node->left);
  pre_order(node->right);
}

void in_order(struct node *node) {
  if(!node) return;
  in_order(node->left);
  printf(" %d", node->number);
  in_order(node->right);
}

void print(void) {
  in_order(root);
  putchar('\n');
  pre_order(root);
  putchar('\n');
}

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;

  int num;
  sscanf(line, "%d", &num);

  int i, j;
  for(i = 0; i < num; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    char command[8];
    int n;
    sscanf(line, "%s %d", command, &n);
    if(!strncmp(command, "insert", 6)) {
      insert(n);
    } else if (!strncmp(command, "print", 5)) {
      print();
    } else if (!strncmp(command, "find", 4)) {
      struct node **res = find(n);
      printf("%s\n", res ? "yes" : "no");
    } else if (!strncmp(command, "delete", 6)) {
      delete(n);
    }
  }
  return 0;
}


Measured memory_bytes: 14188
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
using namespace std;
#define INF 2000000000 //2e9
#define max(a,b) (a>b?a:b)
typedef pair<int, int> pii;
const int N = 100 + 5;
const int M = 1e5 + 2;
int val[N], wt[N];
ll cache[N][M];
//vector<pii> res;
ll dp (int idx, int rem) {
    if (rem < 0)
        return -INF;
    if (idx == 0)
        return 0;
    ll &ans = cache[idx][rem];
    if (ans != -1)
        return ans;
    ans = max(val[idx] + dp(idx-1, rem-wt[idx]), dp(idx-1, rem));
    return ans;
}

void path (int idx, int rem) {
    if (idx == 0)
        return;
    if (rem < 0)
        return;
    ll &cur = cache[idx][rem];
    if (cur == val[idx] + cache[idx-1][rem-wt[idx]]) {
//        res.push_back({wt[idx], val[idx]});
        path(idx-1, rem-wt[idx]);
    }
    else
        path(idx-1, rem);
}

int32_t main() {
    IOS;
    int i, j, n, W;
    memset(cache, -1, sizeof(cache));
    cin >> n >> W;
    for(i = 1; i <= n; i++) 
        cin >> wt[i] >> val[i];
    cout << dp(n, W) << endl;
    /*path(n, W);
    for (auto& x: res) 
        cout << "{" << x.first << ", " << x.second << "} ";*/
    return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b){
    return {a.first + b.first, a.second + b.second};
}

// verified : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
// 負辺があると動作しない?
// O(E log V)
template<typename T>
vector<T> dijkstra(vector<vector<pair<int, T>>> &g, int s){
     
    int n = g.size();
    // numeric_limits がうまく使えない場合は自分で INF を定義する.
    const auto inf = numeric_limits<T>::max();
    vector<T> dist(n, inf);
 
    using P = pair<T, int>;
    // 小さい順に取り出せる
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()){
        T cost;
        int node;
        tie(cost, node) = que.top();
        que.pop();
        if(dist[node] < cost) continue;
        for(auto &e : g[node]){
            auto next_cost = cost + e.second;
            int next_node = e.first;
            if(dist[next_node] <= next_cost) continue;
            dist[next_node] = next_cost;
            que.emplace(next_cost, next_node);
        }
    }
 
    return dist;
}

signed main(){
    
    while(1){       
        int n, m; cin >> n >> m;
        if(n == 0) break;
        vector<vector<pair<int, int>>> g1(n);
        vector<vector<pair<int, pair<int, int>>>> g2(n);
        for(int i = 0; i < m; i++){
            int a, b, d, c; cin >> a >> b >> d >> c;
            a--;
            b--;
            g1[a].push_back({b, d});
            g1[b].push_back({a, d});
            g2[a].push_back({b, {d, c}});
            g2[b].push_back({a, {d, c}});
        }

        auto result = dijkstra(g1, 0);
        int ans = 0;
        for(int i = 1; i < n; i++){
            int tmp = INF;
            for(auto e : g2[i]){
                if(e.second.first + result[e.first] == result[i]){
                    tmp = min(tmp, e.second.second);
                }
            }
            ans += tmp;
        }
        
        cout << ans << endl;

    }

    return 0;
}



Measured memory_bytes: 6048
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

void solve() {
	int w, h; cin >> w >> h;
    vector<pair<ll, int>> es(w + h);
    rep(i, h + w) {
        cin >> es[i].fr;

        if(i < w) es[i].sc = 0;
        else es[i].sc = 1;
    }
    sort(all(es));
    ll ans = 0;
    int a = h + 1, b = w + 1;
    for(auto e: es) {
        if(e.sc == 0) {
            ans += e .fr * a;
            --b;
        } else {
            ans += e.fr * b;
            --a;
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
using namespace std;

int main() {
    int N;
    cin >> N;
    int colors[8] = {};
    int x = 0;
    int cmin = 0, cmax = 0;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        if (a <= 399)
            colors[0]++;
        else if (a <= 799)
            colors[1]++;
        else if (a <= 1199)
            colors[2]++;
        else if (a <= 1599)
            colors[3]++;
        else if (a <= 1999)
            colors[4]++;
        else if (a <= 2399)
            colors[5]++;
        else if (a <= 2799)
            colors[6]++;
        else if (a <= 3199)
            colors[7]++;
        else
            x++;
    }
    /*
        for (int i = 0; i < 8; i++) {
            cout << colors[i] << " ";
        }
        cout << endl;
    */
    for (int i = 0; i < 8; i++) {
        if (colors[i] > 0) cmin++;
    }
    cmax = x + cmin;
    cmin = max(cmin, 1);

    printf("%d %d\n", cmin, cmax);

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        //modをかける場所がわからない
        int N = int.Parse(Console.ReadLine());
        long[] A = new long[N];
        string[] str = Console.ReadLine().Split();
        for (var i = 0; i < N; i++)
        {
            A[i] = long.Parse(str[i]);
        }
        
        long ans = 0;
        int mod = (int)1e9 + 7;

        // bit列60桁分をすべて走査する
        for (int k = 0; k < 60; k++)
        {
            long x0 = 0;
            long x1 = 0;
            for (int i = 0; i < N; i++)
            {
                // k桁目をビット演算で取り出す
                var x = (A[i] >> k) & 1;
                // k桁目が 0, 1 のどちらかを数えておく
                if (x == 0) x0 += 1;
                else x1 += 1;
            }

            long p = 1;
            for (int i = 0; i < k; i++)
            {
                p *= 2;
                p %= mod;
            }
            // x0 * x1 が 0, 1 の組み合わせ数
            var count = (x0 * x1) % mod; //ここでmodしているのは2の0乗分を計算している
            ans += count * p; //modは2の1乗分から
            ans %= mod;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 53704
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] list;
		while(true) {
			int n = stdIn.nextInt();
			int w = stdIn.nextInt();
			if(n == 0 && w == 0) break;
			
			int max = 0;
			int[] log = new int[n];
			for(int i = 0; i < n; i++) {
				int a = stdIn.nextInt();
				log[i] = a;
				if(max < a) {
					max = a;
				}
			}
			
			list = new int[max/w+1];
			max = 0;
			int cx = 0;
			for(int i = 0; i < n; i++) {
				int a = log[i];
				list[a/w]++;
				if(list[a/w] > max) max = list[a/w];
			}
			
			double count = 0.0;
			
			for(int i = 0; i < list.length; i++) {
				int a = list[i];
				count += ((list.length - i-1.0)/(list.length-1.0)*a/max);
			}
			count += 0.01;
			System.out.printf("%.6f\n",count);
		}
	}
		
}

Measured memory_bytes: 23644
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val q = sc.nextInt()
  val lr = List.fill(q)((sc.nextInt()/2, sc.nextInt()/2))
  val m = 49999
  val isPrime = Array.fill(m+1)(true)
  isPrime(0) = false

  for (i <- 1 to m if isPrime(i)) {
    var k = 3
    while (((2*i + 1) * k) / 2 <= m) {
      isPrime(((2*i + 1) * k) / 2) = false
      k += 2
    }
  }

  val a = Array.tabulate(m+1){ i =>
    if (isPrime(i) && i % 2 == 0 && isPrime((i+1) / 2)) 1 else 0
  }
  a(1) = 1
  val b = a.scanLeft(0)(_+_)

  val pw = new java.io.PrintWriter(Console.out)
  for ((l, r) <- lr) {
    pw.println(b(r+1) - b(l))
  }
  pw.flush()
}


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

int main() {
  int N;
  cin >> N;
  if (N % 1111 == 0) {
    cout << "Yes" << endl;
  }
  else if (N % 1110 < 10 ) {
    cout << "Yes" << endl;
  }
  else {
    int x = N % 1000 ;
    if ( x % 111 == 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;


int main(){
	ll n;
	cin >> n;
	for (ll i = (ll)sqrt(n); i >= 1; i--){
		if (!(n%i)){
			cout << n/i + i - 2 << endl;
			return 0;
		}
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[n], b[n];
    vector<pair<int,int> >pairs(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
        pairs[i] = make_pair(b[i],a[i]);
    }
    sort(pairs.begin(),pairs.end());
    int worktime = 0;
    int t = 0;
    for(int j=0;j<n;j++){
        worktime += pairs[j].second;
        if(worktime > pairs[j].first){
            cout << "No" << endl;
            t = 1;
            break;
        }
    }
    if(t != 1){
        cout << "Yes" << endl;
    }
    return 0;

}

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

using namespace std;

const int N = 2e5 + 5;

int n, m, a[N], b[N], used[N];
int comp[N], sz;
vector <int> g[N], rg[N], vec;
vector < pair <int, int> > c;
map < pair <int, int>, int > mp;

void dfs(int v){
      used[v] = 1;
      for(int to : g[v]){
            if(!used[to]) dfs(to);
      }
      vec.push_back(v);
}

void Dfs(int v){
      comp[v] = sz;
      used[v] = 0;
      for(int to : rg[v]) {
            if(used[to]) Dfs(to);
      }
}

void vis(int v){
      used[v] = 1;
      for(int to : g[v])
            if(!used[to]) vis(to);
}

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

      for(int i = 1; i <= m; i ++){
            cin >> a[i] >> b[i];
            g[a[i]].push_back(b[i]);
            rg[b[i]].push_back(a[i]);
            c.push_back(make_pair(a[i], b[i]));
      }

      for(int i = 1; i <= n; i ++)
            if(!used[i]) dfs(i);

      reverse(vec.begin(), vec.end());

      for(int v : vec)
            if(used[v]) sz ++, Dfs(v);

      for(int v = 1; v <= n; v ++){
            memset(used, 0, sizeof(used));
            used[v] = 1;
            for(int to : g[v]){
                  if(used[to]){
                        mp[make_pair(v, to)] = 1;
                  }
                  vis(to);
            }
            memset(used, 0, sizeof(used));
            used[v] = 1;
            reverse(g[v].begin(), g[v].end());
            for(int to : g[v]){
                  if(used[to]){
                        mp[make_pair(v, to)] = 1;
                  }
                  vis(to);
            }
      }

      for(auto i : c){
            if(comp[i.first] != comp[i.second]) mp[i] = 1 - mp[i];
            if(mp[i]){
                  puts("same");
            } else {
                  puts("diff");
            }
      }
}


Measured memory_bytes: 30576
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define G 1

signed main(){
  string s;
  cin>>s;
  int n;
  cin>>n;
  int now=s[0]-'0';
  for(int i=1;i<s.size();i+=2){
    if(s[i]=='+'){
      now+=s[i+1]-'0';
    }
    if(s[i]=='*'){
      now*=s[i+1]-'0';
    }
  }
  int now2=0;
  int mode=-1;
  for(int i=0;i<s.size();i+=2){
    if(i==s.size()-1){
      if(mode==-1) now2+=s[i]-'0';
      else{
	now2+=mode*(s[i]-'0');
      }
    }
    else if(s[i+1]=='+'){
      if(mode==-1){
	now2+=s[i]-'0';
      }
      else{
	now2+=mode*(s[i]-'0');
	mode=-1;
      }
    }
    else{
      if(mode==-1) mode=s[i]-'0';
      else{
	mode*=s[i]-'0';
      }
    }
  }
  //cout<<now<<" "<<now2<<endl;
  if(n==now&&n==now2) cout<<"U"<<endl;
  else if(n==now) cout<<"L"<<endl;
  else if(n==now2) cout<<"M"<<endl;
  else cout<<"I"<<endl;
  return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> x(n);
  vector<int> sorted(n);
  rep(i,n){
    int a;cin>>a;
    x[i]=a;
    sorted[i]=a;
  }
  sort(all(sorted));
  rep(i,n){
    int ans;
    if(x[i]<sorted[n/2]){
      ans=sorted[n/2];
    }else{
      ans=sorted[n/2-1];
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            List<char> lstcS = sS.ToList();
            sS = System.Console.ReadLine().Trim();
            int iQ = int.Parse(sS);
            Boolean bNom = true;
            List<char> lstaS = new List<char>();                        // 先頭に追加文字
            List<char> lstaE = new List<char>();                        // 末尾に追加文字
            for (int i = 0; i < iQ; i++)
            {
                string[] sQ = System.Console.ReadLine().Trim().Split(' ');
                int iT = int.Parse(sQ[0]);
                switch (iT)
                {
                    case 1:
                        bNom = !bNom;                                       // 現状反転？
                        break;
                    case 2:
                        int iF = int.Parse(sQ[1]);
                        if (bNom && iF == 1) { lstaS.Add(sQ[2][0]); }               // どっちに加算するか
                        if (bNom && iF == 2) { lstaE.Add(sQ[2][0]); }
                        if (!bNom && iF == 1) { lstaE.Add(sQ[2][0]); }               // どっちに加算するか
                        if (!bNom && iF == 2) { lstaS.Add(sQ[2][0]); }
                        break;
                }
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            //if (!bNom) { lstcS.Reverse(); }
            lstaS.Reverse();
            List<char> lstAl = new List<char>();
            lstAl.AddRange(lstaS);
            lstAl.AddRange(lstcS);
            lstAl.AddRange(lstaE);
            if (!bNom) { lstAl.Reverse(); }
            string sOut = new string(lstAl.ToArray());                  // char配列string変換

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 24368
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv)
{
    int a, b;
    char l[256];

    if (!fgets(l, sizeof(l), stdin)) {
        fprintf(stderr, "error input string\n");
        return -1;
    }

    if (sscanf(l, "%d %d", &a, &b) != 2) {
        fprintf(stderr, "error input format\n");
        return -1;
    }

    printf("%d %d\n", a*b, a*2+b*2);

    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n, k;
  cin >> n >> k;
  vector<int> c(n), p(n);
  REP(i, n) cin >> p[i], p[i]--;
  REP(i, n) cin >> c[i];

  ll ans = -LINF;

  auto update = [&](int i) {
    int v = i;
    ll cycle_sum = 0;
    int cycle_cnt = 0;

    while(true) {
      cycle_cnt++;
      cycle_sum += c[i];
      i = p[i];
      if (i == v) break;
    }

    ll now = 0;
    int cnt = 0;

    while(true) {
      cnt++;
      now += c[v];

      if (cnt > k) break;

      int num = (k - cnt) / cycle_cnt;
      ll score = now + max(0ll, cycle_sum) * num;
      ans = max(ans, score);

      v = p[v];
      if (v == i) break;
    }
  };
  REP(i, n) update(i);
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3704
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        long y = aa[0];

        bool isPC = true;
        var hash = new HashSet<int>();

        for (int i = 0; i < n; i++) {
            if(i != 0) y = Gcd(y, aa[i]);

            if(!isPC) continue;
            var l = PrimeFact(aa[i]);
            foreach(var ll in l) {
                if (hash.Contains((int)ll)) {
                    isPC = false;
                } else {
                    hash.Add((int)ll);
                }
            }

            //if (isPC) { 
            //    for(int j = i + 1; j < n; j++) {
            //        var x = Gcd(aa[i], aa[j]);
            //        if(x > 1) isPC = false;
            //    }
            //}

        }
        //Debug.WriteLine(pn.Count);

        if (y > 1) return "not coprime";
        if(isPC) return "pairwise coprime";
        return "setwise coprime";
    }

    static List<long> PrimeFact(long n) {
        var list = new List<long>();

        for (long i = 2; i <= Math.Sqrt(n); i++) {
            if (n % i == 0) {
                list.Add(i);
                while (n % i == 0) {
                    n /= i;
                }
            }
        }
        if (n > 1) list.Add(n);
        return list;
    }

    static long Gcd(long m, long n) {
        //ユークリッド互除法
        if (m < n) { var t = m; m = n; n = t; }

        while (true) {
            var mod = m % n;
            if (mod == 0) return n;
            m = n;
            n = mod;
        }
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 111780
#include<bits/stdc++.h>
using namespace std;
int n,a,b,sum;
void dfs(int x,int y,int ban){
    if(__builtin_popcount(ban^sum)==1){
        printf("%d %d ",y,x^y);
        return;
    }
    for(int i=0;i<n;i++)
        if((~(ban>>i)&1)&&(x>>i&1))
            for(int j=0;j<n;j++)
                if((~(ban>>j)&1)&&i!=j){
                    dfs(1<<j,y,ban|1<<i);
                    dfs(x^(1<<i)^(1<<j),y^(1<<i)^(1<<j),ban|1<<i);
                    return;
                }
}
/*dfs(x,y,ban)表示需要从状态0走到状态x，ban是一个长度为n的二进制串，其中第i位为1表示这一维已经不存在了，即若这个二进制串总共有p个0，则表示当前需要处理的是在p维空间下从0走到x这件事情。
划分的时候先找到某个二进制位满足x在这一位上为1（也就是代码里的i），然后在随便选一个在第i位上是0且有奇数个1的数，代码里为了方便我就直接选了某个2^j，然后递归构造0 -> 2^j -> 2^j+2^i -> x的路径就行了。
那个y是指表明接下来处理的所有数在输出时都要异或上y，这样在划分问题的时候可以比较方便地把子问题归为“从0出发走到x”这种形式。*/
int main(){
    scanf("%d%d%d",&n,&a,&b);
    sum=(1<<n)-1;
    if(__builtin_popcount(a^b)&1){
        printf("YES\n");
        dfs(a^b,a,0);
    }
    else
        printf("NO");
    return 0;
}
/*要从0走到AxorB，可以选出一个二进制位p满足AxorB在第p位上值为1，遍历二进制第p位为0的所有点组成的n−1维超立方体后，再去遍历二进制位第p位为1的所有点组成的n−1维超立方体。两个n−1维超立方体之间的连接点的选取是任意的，只需要满足起点终点二进制位不同的位数是奇数。*/


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

int even[100001];
int odd[100001];

int main() {
		int N;
		cin >> N;
		for ( int i = 1; i <= N; i++ ) {
				int v;
				cin >> v;
				if ( i % 2 == 1 ) odd[v]++;
				else even[v]++;
		}
		
		int top1_even = 0, top2_even = 0;
		int top1_odd = 0, top2_odd = 0;
		for ( int i = 1; i <= 100000; i++ ) {
				if (even[top1_even] <= even[i]) {
						top2_even = top1_even;
						top1_even = i;
				} else if (even[top2_even] <= even[i]) {
						top2_even = i;
				}

				if (odd[top1_odd] <= odd[i]) {
						top2_odd = top1_odd;
						top1_odd = i;
				} else if (odd[top2_odd] <= odd[i]) {
						top2_odd = i;
				}
		}

		if (top1_even != top1_odd) cout << N - (even[top1_even] + odd[top1_odd]) << endl;
		else cout << N - max(even[top1_even] + odd[top2_odd], even[top2_even] + odd[top1_odd]) << endl;

		return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;

int a[100000];
int X[100000];

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

	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int maxlen = 1, len = 1;
	for(int i = 0; i < N - 1; i++) {
		if(a[i] < a[i + 1]) {
			len++;
		}
		else if(a[i] > a[i + 1]) {
			len = 1;
		}
		maxlen = max(maxlen, len);
	}
	len = 1;
	for(int i = 0; i < N - 1; i++) {
		if(a[i] > a[i + 1]) {
			len++;
		}
		else if(a[i] < a[i + 1]) {
			len = 1;
		}
		maxlen = max(maxlen, len);
	}

	cout << maxlen << endl;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll ans=0;
  string a;
  cin>>a;
  if(a=="SSS"){
    ans=0;
  }else if(a=="RSS"||a=="RSR"||a=="SRS"||a=="SSR"){
    ans=1;
  }else if(a=="RRS"||a=="SRR"){
    ans=2;
  }else{
    ans=3;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ss = []
for i in range(0, len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] not in ('?', t[j]):
            break
    else:
        c = s[:i] + t + s[i+len(t):]
        ss.append(c.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')


Measured memory_bytes: 5408
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N;

LL erase_bit(LL n, LL m)
{
	LL upper = (n >> (m + 1)) << m, lower = n % (1LL << m);
	return upper + lower;
}

LL push_bit(LL n, LL m, LL k)
{
	LL upper = (n - n % (1LL << m)) << 1, lower = n % (1LL << m);
	return upper + k * (1LL << m) + lower;
}

std::vector<LL>f(LL a, LL b, LL c)
{
	if (c == 1) return std::vector<LL>{a, b};

	LL diff_bit;
	std::vector<LL>res;
	rep(i, N)
	{
		if (((a ^ b) >> i) & 1)
		{
			diff_bit = i;
			break;
		}
	}
	auto res1 = f(erase_bit(a, diff_bit), erase_bit(a, diff_bit) ^ 1, c - 1), res2 = f(erase_bit(a, diff_bit) ^ 1, erase_bit(b, diff_bit), c - 1);
	for (auto i : res1) res.push_back(push_bit(i, diff_bit, (a >> diff_bit) & 1));
	for (auto i : res2) res.push_back(push_bit(i, diff_bit, (b >> diff_bit) & 1));
	return res;
}

int main()
{
	LL A, B;
	in >> N >> A >> B;

	LL cnt1 = 0, cnt2 = 0;
	rep(i, N)
	{
		if ((A >> i) & 1) ++cnt1;
		if ((B >> i) & 1) ++cnt2;
	}
	if (cnt1 % 2 == cnt2 % 2)
	{
		out << "No" << std::endl;
		return 0;
	}

	out << "YES" << std::endl;
	auto ans = f(A, B, N);
	rep(i, (1LL << N)) out << ans[i] << (i < (1LL << N) - 1 ? " " : "\n");
}


Measured memory_bytes: 2400
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;

    for (int i = 1; i < n; i++) {
        if (a[i - 1] == a[i]) continue;
        if (a[i - 1] > a[i]) {
            std::cout << "No" << std::endl;
            return 0;
        }
        --a[i];
    }
    std::cout << "Yes" << std::endl;

    return 0;
}


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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int a[N];
int used[N];
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 2; i <= n; i ++){
        cin >> a[i];
        used[a[i]] ++;
    }
    for(int i = 1; i <= n; i ++){
        cout << used[i] << "\n";
    }
}



Measured memory_bytes: 5172
A, B = list(map(int, input().split()))

def gcb(a,b):
  x = max(a,b)
  y = min(a,b)
  if x%y ==0:
    return y
  else:
    while x%y!=0:
      z = x%y
      x = y
      y = z
    else:
      return z
def lcm(a,b):
  return int(a * b / gcb(a,b))

print(lcm(A,B))

Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> ai = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            ai.add(sc.nextInt());
        }

        List<Integer> sorted = new ArrayList<>(ai);
        sorted.sort(Comparator.naturalOrder());

        int max = sorted.get(N - 1);

        int ans = 0;
        int x = 0;
        for (int a : ai) {
            int b = (a > max / 2) ? max - a : a;
            if (b > x) {
                ans = a;
                x = b;
            }
        }
        System.out.printf("%d %d\n", max, ans);

    }
}


Measured memory_bytes: 64800