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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define MAXI 100010

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

int main(){

	int n, x;
	cin >> n >> x;

	vector<pair<ll, ll>> v(n);
	rep(i, n) cin >> v[i].second >> v[i].first;
	sort(v.begin(), v.end());

	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> qu;
	rep(i, n) qu.push(make_pair(0, 0));

	vector<bool> used(MAXI*3+1, false);

	while(!qu.empty()){
		auto tmp = qu.top(); qu.pop();

		if(used[tmp.second]) continue;
		used[tmp.second] = true;

		if(tmp.second == x){
			cout << tmp.first << endl;
			return 0;
		}

		rep(i, n){
			ll cost = tmp.first + v[i].first;
			ll nx1 = tmp.second + v[i].second;
			if(0 <= nx1 && nx1 <= 3*MAXI && !used[nx1]) qu.push(make_pair(cost, nx1));
			ll nx2 = tmp.second - v[i].second;
			if(0 <= nx2 && nx2 <= 3*MAXI && !used[nx2]) qu.push(make_pair(cost, nx2));
		}

	}

	cout << -1 << endl;

	return 0;
}



Measured memory_bytes: 35740
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef double db;
const int mod = 1e9+7;
const int N = 1e6 + 5;
int n, m, k;
int vis[N], cnt[N];

int main(){
    scanf("%d%d", &n, &m);
    int ac=0, wa=0;
    rep(i,1,m){
        int p;
        char s[5];
        scanf("%d%s", &p, s);
        if(vis[p]) continue;
        if(s[0]=='A'){
            wa += cnt[p];
            ++ac;
            vis[p] = 1;
        }
        else{
            ++cnt[p];
        }
    }
    printf("%d %d\n", ac, wa);
    return 0;
}
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    long long n, k;
    cin >> n >> k;
    vector<long long> as(n);
    REP(i, n) { cin >> as[i]; }
    map<long long, long long> cnt;
    long long cur = 0;
    long long cycle = 181;
    REP(i, n + 2) {
        cnt[cur]++;
        cur = as[cur] - 1;
        if (cnt[cur] > 1) {
            break;
        }
    }
    // cout << cur;
    long long cur2 = 0;
    REP(i, n) {
        if (cur2 == cur) {
            cycle = i;
            break;
        }
        cur2 = as[cur2] - 1;
    }
    long long cur3 = 0;
    if (k <= cycle) {
        REP(i, k) { cur3 = as[cur3] - 1; }
        cout << cur3 + 1 << endl;
        return 0;
    }
    // cout << cycle;
    k = k - cycle;
    map<long long, long long> cnt2;
    long long cyclelength = 0;
    cnt2[cur]++;
    REP(i, n) {
        cyclelength++;
        cur = as[cur] - 1;
        cnt2[cur]++;
        if (cnt2[cur] > 1) {
            break;
        }
    }
    k = k % cyclelength;
    REP(i, k) { cur2 = as[cur2] - 1; }
    cout << cur2 + 1 << endl;
}

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

long long dp[1<<17][3];

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	
	for (int i = 1; i <= n; i++) {
		int fun[3];
		for (int j = 0; j < 3; j++) {
			cin >> fun[j];
			for (int k = 0; k < 3; k++) if ( k != j) {
				dp[i][j] = max(dp[i - 1][k] + fun[j], dp[i][j]);
			}
		}
	}
	cout << *max_element(dp[n], dp[n] + 3) << '\n';
} 

Measured memory_bytes: 2560
// <------------- Template -----------------------> //

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#pragma optimization_level 3   									//Comment optimisations for an interatcive problem - use endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

// <------------- Declare Variables Here ------------> //

ll n,a[200019] ,Min=INF,cou=0;;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

int main() {
	fastio;
	cin>>n;
	for(ll i=0;i<n;i++) cin>>a[i];
	for(ll i=0;i<n;i++) {
		if(a[i]<Min) Min=a[i],cou++;
	}
	cout<<cou;newl;
	return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;

    rep(i, N + 1) {
        rep(j, M + 1) {
            int b = i * M;
            b -= j * i;
            b += j * (N - i);
            if (b == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const maxBuf = 200100

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

/* #### main #### */
func main() {
	a := readInt()
	b := readInt()

	var plug, tap int = 1, 0

	for plug < b {

		plug += a - 1
		tap++
	}

	fmt.Println(tap)
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//input
ll n,m,l;

//Warshall-floyd
ll dp1[310][310];//dpテーブルには辺がないところにはINF、i==jには０を入れておく
void warshallfloyd1(){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dp1[i][j]=min(dp1[i][j],dp1[i][k]+dp1[k][j]);
            }
        }
    }
}

ll dp2[310][310];//dpテーブルには辺がないところにはINF、i==jには０を入れておく
void warshallfloyd2(){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dp2[i][j]=min(dp2[i][j],dp2[i][k]+dp2[k][j]);
            }
        }
    }
}

int main(){
    cin >> n >> m >> l;
    rep(i,310)rep(j,310)dp1[i][j]=INF;
    rep(i,310)dp1[i][i]=0LL;
    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        dp1[a][b]=c;
        dp1[b][a]=c;
    }
    warshallfloyd1();
    rep(i,310)rep(j,310)dp2[i][j]=INF;
    rep(i,310)dp2[i][i]=0LL;
    rep(i,n){
        rep(j,n){
            if(dp1[i][j]<=l){
                dp2[i][j]=1;
            }
        }
    }
    warshallfloyd2();
    ll q;
    cin >> q;
    rep(i,q){
        ll s,t;
        cin >> s >> t;
        s--;t--;
        if(dp2[s][t]==INF){
            cout << -1 << endl;
        }
        else{
            cout << dp2[s][t]-1 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 5128
def main():
  S = input()
  j = 0
  m = S[0]
  ls = []
  for i in range(len(S)):
    if m!=S[i]:
      ls.append(i-j)
      j = i
      m = S[i]
  ls.append(len(S)-j)
  N = len(ls)
  if N<3:
    print(max(ls))
  else:
    ans = float('inf')
    sls = [ls[0]]
    for i in range(1,N):
      sls += [sls[-1]+ls[i]]
    ans = min(max(sls[i], sls[-1]-sls[i]) for i in range(N-1))
    print(ans)

if __name__=='__main__':
  main()

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

typedef long long ll;

int main(void) {
	ll N, A, B;
	cin >> N >> A >> B;

	ll k = N / (A + B);
	ll m = N % (A + B);
	ll ans = (ll)0;
	if (m < A)
		ans = m;
	else
		ans = A;
	ans += k * A;

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


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int n,a;
    cin>>n;
    vector<int>v;
    double sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
        sum+=a;
    }
    int x=ceil(sum/n);
    int y=floor(sum/n);
    int ans1=0,ans2=0;

    for(int i=0;i<n;i++)
    {
        ans1+=(v[i]-x)*(v[i]-x);
    }
    for(int i=0;i<n;i++)
    {
        ans2+=(v[i]-y)*(v[i]-y);
    }
    cout<<min(ans1,ans2)<<"\n";
}


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

int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    rep(i,n)cin>>d[i];
    sort(d.begin(),d.end());
    cout<<d[n/2]-d[n/2-1]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
const int inf=0x3f3f3f3f;

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>K;
    cout<<min(N%K,K-N%K);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
inline int Abs(int a){return a<0?-a:a;}
inline int min(int a,int b){return a<b?a:b;}
const int N=1e5+3;
int a[N],n,dp[N],m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	dp[1]=0;
	for(int i=2;i<=n;i++){
	  dp[i]=2e9;
	  for(int j=1;j<=m&&i-j>=1;j++)
		dp[i]=min(dp[i],dp[i-j]+Abs(a[i]-a[i-j]));
	}
	printf("%d",dp[n]);
	return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int main(void){
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	printf("%d\n",(x-a)%b);
	return 0;
}






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

sl = []
for i in s:
    sl.append(i)
tl = []
for j in t:
    tl.append(j)

count = 0
if sl[0] == tl[0]:
    count += 1
if sl[1] == tl[1]:
    count += 1
if sl[2] == tl[2]:
    count += 1
print(count)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,n;
	cin>>a>>b;
	if(b==1){
		cout<<0;
		return 0;
	}
	if((b-1)%(a-1)==0) cout<<(b-1)/(a-1);
	else cout<<(b-1)/(a-1)+1;
	return 0;
}

Measured memory_bytes: 256
using System;

class Watch {
    static void Main() {
        var s = int.Parse(Console.ReadLine()); // ?§?
        int h = 0; // ???
        int m = 0; // ???
        
        if(s > 59)
        {
           m = s / 60;
           s = s % 60;
        }
        if(m > 59)
        {
           h = m / 60; 
           m = m % 60;
        }
        Console.WriteLine("{0}:{1}:{2}", h, m, s);
    }
}

Measured memory_bytes: 9184
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

# N = int(readline())
# D = [int(d) for d in readline().split()]

import numpy as np

N, K = map(int, readline().split())
h = [int(x) - K for x in readline().split()]

# ha = np.array(h)

print(len([x for x in h if x >= 0]))


Measured memory_bytes: 19524
import sys
input = sys.stdin.readline
from bisect import bisect_left

def main():
    n=int(input())
    a=list(map(int,input().split()))
    l=[0]*(n+1)
    for i in range(n):
        l[a[i]]=i+1
    print(' '.join(map(str, l[1:])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 18596
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    res = 0
    ans = 0
    for i in range(1, n + 1):
        n = int(str(i)[::])
        cnt = 0
        while n % 2 == 0:
            n //= 2
            cnt += 1

        if res <= cnt:
            res = cnt
            ans = i
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[10000];
int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    int cnt = -1;
    int v = 0;
    scanf("%s", str);
    int len = strlen(str);
    REP(i, len) {
      v += str[i] - '0';
      cnt++;
      if (v >= 10) {
        cnt++;
        v = v / 10 + v % 10;
      }
    }
    if (cnt % 2 == 0) {
      puts("Audrey wins.");
    } else {
      puts("Fabre wins.");
    }
  }
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int integer(const string &e, int &pos);

int expr(const string &e, int &pos) {
  if (isdigit(e[pos])) return integer(e, pos);

  vector<int> votes;
  while (e[pos] == '[') {
    int v = expr(e, ++pos);
    votes.push_back(v);
    assert(e[pos] == ']');
    pos++;
  }

  int ret = 0;
  sort(votes.begin(), votes.end());
  int ub = ceil(votes.size()/2.0);
  for (int i = 0; i < ub; i++) {
    ret += votes[i];
  }

  return ret;
}

int integer(const string &e, int &pos) {
  int ret = 0;
  while (e[pos] != ']') {
    ret *= 10;
    ret += (e[pos] - '0');
    pos++;
  }
  return (int)ceil(ret/2.0);
}

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    string e; cin >> e;
    int pos = 0;
    cout << expr(e, pos) << endl;
  }
  return 0; 
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define mp make_pair 
#define pb push_back 
#define fi first
#define se second
#define MOD 1000000007
#define DOMOD(d) if ((d) >= MOD) d %= MOD;
#define DONEGMOD(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
 
#define inp(a) scanf("%d", &a)
#define inp2(a,b) scanf("%d %d", &a, &b)
#define inp3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define inp4(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
 
#define inpl(a) scanf("%lld", &a)
#define inpl2(a,b) scanf("%lld %lld", &a, &b)
#define inpl3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define inpl4(a,b,c,d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i=a;i<b;i++)
#define mset(a,val) memset(a,val,sizeof(a))
#define printv(v) for (int i=0;i<(int) v.size(); i++) cout<<v[i]<<" " 
#define MAX 100005
using namespace std ;
typedef long long int ll ;
typedef pair<int,int> pii ;
typedef pair<long long , long long > pll ;
typedef pair<int,pii> pipi ;
typedef pair<int,pair<int,string>> piis ;
typedef pair<ll,string> pls ;
typedef pair<ll,pll> plpl ;



int main()
{
	#ifdef DIRI
		//freopen("inp.txt","r",stdin) ;
	#endif
	
	time_t start = clock() ;
	
	string s ; cin>>s ;
	int z = (int) s.size() ;
	vector<char> v ;
	for (auto it : s) v.pb(it) ;
	
	if (z < 26)
	{
		int a[26] ; mset(a,0) ;
		for (auto it : v) a[it-'a'] = 1 ;
		cout<<s ;
		for (int i=0;i<26;i++)
		{
			if (a[i] == 0)
			{
				cout<<char('a' + i) ; break ;
			}
		}
		cout<<endl ; return 0 ;
	}
	
	while (next_permutation(all(v)))
	{
		set<char> s1 ;
		string ans ;
		for (auto it : v) s1.insert(it) ;
		if ((int) s1.size() == z)
		{
			for (auto it : v) ans.pb(it) ; 
			
			for (int i=0;i<z;i++)
			{
				if (s[i] == ans[i]) cout<<s[i] ;
				else 
				{
					cout<<ans[i]<<endl ; return 0 ;
				}
			}
			
		}
	}
	
	cout<<"-1"<<endl ;
		
	time_t end = clock() ;
	
	double tt = (end - start) / CLOCKS_PER_SEC ;
	cerr<<fixed<<setprecision(5)<<tt<<endl ;
	
    return 0 ;
}


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

using namespace std;

typedef long long ll;

#define eps 1e-9
#define all(a)   a.begin(),a.end()
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define sz size()
#define rd(inp) scanf("%lld",&inp)
#define rd2(inp1, inp2) scanf("%lld %lld",&inp1, &inp2)
#define rl(inp) scanf("%d",&inp)
#define pf(out) printf("%lld\n", out);

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int inf = 1e9;

ll read(){
	bool minus = false;
	ll result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus){
		return -result;
	}
	else{
		return result;
	}
}

ll fpow(ll base,ll power){
	ll result = 1;
	while (power > 0){
		if (power%2 == 1) result=(result*base);
  		base = (base*base);
  		power /= 2;
  	}
	return result;
}

int main(){
  	ll A, B, C;
  	cin >> A >> B >> C;
  	ll ans = 0 ;
  	if ( A >= B && A >= C ){
  		// A
  		if ( A % 2 == 1 ){
  			ans = B * C;
  		}
  		else{
  			ans = 0;
  		}
  	}
  	else if ( B >= A && B >= C ){
  		if ( B % 2 == 1 ){
  			ans = A * C;
  		}
  		else{
  			ans = 0;
  		}
  	}
  	else{
  		if ( C % 2 == 1 ){
  			ans = A * B;
  		}
  		else{
  			ans = 0;
  		}
  	}
  	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
  	int t;
    cin>>t;
    if(t%2==0 && !( t%3==0 || t%5==0 ) ){
      cout<<"DENIED"; return 0;
    }
  }
  cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	int ans=0;
	for(int i=a;i<=b;++i){
		string s="";
		int x=i;
		while(x>0){
			char c='0'+x%10;
			s=c+s;
			x/=10;
		}
		if(s.at(0)==s.at(4) && s.at(1)==s.at(3)) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
bool prime[55556];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  fill(prime, prime + 55556, true);
  prime[0] = false;
  prime[1] = false;
  for(int i = 2; i < 55556; i++){
    for(int j = 2; i * j < 55556; j++){
      prime[i * j] = false;
    }
  }
  vector<int> vec;
  for(int i = 2; i < 55556; i+=5){
    if(prime[i])vec.pb(i);
    if(vec.size() == n)break;
  }
  for(int i = 0; i < n; i++){
    cout << vec[i];
    if(i != n - 1)cout << " ";
    else cout << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;
string s3="Fizz";
string s5="Buzz";
string s15="FizzBuzz";
typedef unsigned long long int ll;
string num(ll a){
string temp;
        ll keta=1;
        while(a>0){
                char b='0'+a%10;
                temp+=b;
                a/=10;
        }
        ll n=temp.size();
        string s;
        for(ll i=0;i<n;i++){
        s+=temp[n-1-i];
        }
        return s;
}
ll prenum(ll n){
	ll keta=1;
	ll sum=0;
	ll m=1;
	while(keta*10<=n){
	ll n3 =	keta*3;
	ll n5 = keta*9/5;
	ll n15 = keta*9/15;
	sum+=(keta*9+n15-n3-n5)*m;
	sum+=(n3+n5)*4;	
	keta*=10;
	m++;
	}
	ll n3 = (n-keta)/3;
	ll n5 = (n-1)/5-(keta-1)/5;
	ll n15 = (n-1)/15-(keta-1)/15;
	sum+=(n-keta+n15-n3-n5)*m;
	sum+=(n3+n5)*4;

return sum;
}
void solve(ll s){
	ll st=0,e= 100000000000000000;
	while(e-st>1){
	ll m=(e+st)/2;
	if(prenum(m)<s){
	 st=m;
	}else{
	e=m;
	}
	}

	string ans;
	ll se = prenum(st);
	for(ll i=st;ans.size()<=30+s-se;i++){
	if(i%15==0){ans+=s15;}
	else if(i%3==0){ans+=s3;}
	else if(i%5==0){ans+=s5;}
	else{ans+=num(i);}
	}
	
	for(int i=0;i<20;i++){
	cout<<ans[i+s-se-1];
	}
	cout<<endl;
//	cout<<ans<<endl;
//	cout<<st<<' '<<e<<endl;
//	cout<<prenum(st)<<endl;
//	cout<<prenum(e)<<endl;
//	cout<<se<<' '<<s<<' '<<prenum(se)<<endl;
	return;
}

int main(){
//	cout<<num(89814814814814814)<<endl;
	ll s;
	cin>>s;
	solve(s);


	return 0;

}



Measured memory_bytes: 3204
N=int(input(), 10)
K=int(input(), 10)
X=int(input(), 10)
Y=int(input(), 10)

total = 0
if N-K < 0:
    for _ in range(N):
        total += X
else:
    for _ in range(K):
        total += X

    for _ in range(N-K):
        total += Y

print(total)


Measured memory_bytes: 3060
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	ll N;
	cin >> N;
	
	string ans;
	if (N == 0) {
		cout << 0 << endl;
		return 0;
	}
	while (N != 0) {
		ll rem = (N + 2 * (ll)1e9) % -2;
		ans += to_string(rem);
		if (rem)N -= 1;
		N /= -2;
	}
	reverse(ALL(ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

a,b,c = map(int,input().split())
print(len(set([a,b,c])))


Measured memory_bytes: 7492
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
    n:usize
    }
    let mut table = vec![0; n + 1];
    for i in 1..=n {
        let mut j = i;
        while j <= n {
            table[j] += 1;
            j += i;
        }
    }
    let mut ans = 0_usize;
    for i in 1..=n {
        ans += i * table[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 80084
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,c,k,ans=0,cnt=1,tmp;
  cin >> n >> c >> k;
  long long a[n];
  for(int i=0;i<n;i++){
  	cin >> a[i];
  }
  sort(a,a+n);
  tmp=a[0];
  for(int i=1;i<n;i++){
	if(a[i]>tmp+k or cnt==c){
	  ans++;
	  cnt=1;
	  tmp=a[i];
	}else{
	  cnt++;
  	}
  }
  cout << ans+(cnt>0) << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        long[] sum = new long[N+1];
        sum[0] = 0;
        for (int i = 1; i <= N; i++) {
            sum[i] = -sum[i-1] + 2* ni();
        }
        long x = sum[N]/2;
        for (int i = 0; i < N; i++) {
            if(i%2==0) out.print(sum[i]+x);
            else out.print(sum[i]-x);
            out.print(" ");
        }
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 46148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    string ans = "Yes";
    if(K * 500 < X) ans = "No";
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> key;
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    ll s = 0;
    REP(j, b) {
      ll c;
      cin >> c;
      c--;
      s |= 1 << c;
    }
    key.emplace_back(s, a);
  }

  vector<ll> dp(1 << n, INF);
  dp[0] = 0;
  REP(s, 1 << n) {
    REP(i, m) {
      ll t = s | key[i].first;
      ll cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }
  ll ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m=gets.split.map &:to_i
a,b=$<.map{|e|e.split.map(&:to_i).sort.reverse<<0}
x=y=0
c=1
(n*m).downto(1){|i|
	if a[x]==i&&b[y]==i
		x+=1;y+=1
	elsif a[x]==i
		x+=1;c*=y
	elsif b[y]==i
		y+=1;c*=x
	else
		c*=x*y-n*m+i
	end
	c%=10**9+7
}
p c

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

const int N = 4000010;

int n;
std::bitset <N> set;

int main(){
	scanf("%d", &n);
	set.set(0);
	int sum = 0;
	for (int i = 0, x; i < n; ++ i){
		scanf("%d", &x);
		set |= set << x;
		sum += x;
	}
	for (int i = sum + 1 >> 1; ; ++ i){
		if (set.test(i)){
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
n=int(input())
dp=[[0]*3 for _ in range(n+1)]
for i in range(1,n+1):
    a,b,c=map(int,input().split())
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[-1]))


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

using Graph = vector<vector<int>>;

//グラフとして解く

int main(){
  int N, M;
  //頂点の数と辺の数
  cin >> N >> M;
  Graph G(N);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(int i = 0; i < N; i++){
    cout << G[i].size() << endl;
  }
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N,M;

signed main()
{
	cin>>N>>M;
	vector<int>a(N);
	int sum=0;
	rep(i,N)cin>>a[i],sum+=a[i];

	sort(all(a),greater<int>());
	bool f = true;
	rep(i, M) {
		if (a[i] * 4*M < sum) f = false;
	}
	cout << (f ? "Yes" : "No") << endl;
}




Measured memory_bytes: 256
import numpy as np

n, m, x = map(int, input().split())
data = []
for i in range(n):
    temp = list(map(int, input().split()))
    data.append(temp)
# ------------------------
# 今回の場合は、MとNが異様に小さいので、全探索して、Xを超える条件をMinで取るのがBetter
cost = 10 ** 17


# 0の場合は全部がOFFなので、はじく。
for bit in range(1, 2 ** n):
    # print(bit)
    ttt = np.zeros(m + 1)

    for j in range(n):
        # onの場合
        if (bit >> j & 1):
            #print('OK!', j)
            tar = np.array(data[j])
            ttt += tar

    check = np.where(ttt[1:] >= x)[0]
    if (len(check) == m):
        cost = min(cost, ttt[0])
    else:
        pass

if (cost == 10 ** 17):
    print(-1)
else:
    print(int(cost))


Measured memory_bytes: 27048
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int N;
ll dfs(string s){
    //sではじまる753数の個数
    if (s!="" and stol(s) > N){
        return 0;
    }
    int ret = 0;
    //sじたいが753数かどうか
    
    if((count(s.begin(),s.end(),'7')>0) and 
        (count(s.begin(),s.end(),'5')>0) and 
        (count(s.begin(),s.end(),'3')>0)){
        //cout<<s<<":753"<<endl;
        ret++;
    }
    string tmp = "753";
    for(int i = 0; i<tmp.size();i++){
        char c = tmp[i];
        ret += dfs(s+c);
    }
    return ret;
}
int main(){
    cin>>N;
    cout<<dfs("")<<endl;
}

Measured memory_bytes: 256
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    ans = price

    while True:
        if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
                   [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
            return ans

        ans += 1


if __name__ == '__main__':
    print(abc042_c())


Measured memory_bytes: 3060
#include<stdio.h>
 int s(int d)
{
   int x=0,sum=0;
   while(x<600){
     sum+=x*x*d;
     x+=d;}
   return sum;
}

int main()
  {
    int d;
    while(scanf("%d",&d)!=EOF)
     printf("%d\n",s(d));

    return 0;
  }

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define INF (1<<28)
typedef long long Int;

int N, B[64], C[64];
string A[64], D[64][64];
int g[64][64], vis[64];
int r[64], p[64];
Int f[64];

void collect(vector<int>& q, int at) {
    if (vis[at]) return ;
    vis[at] = 1;
    q.push_back(at);
    rep (i, N) if (g[at][i]) collect(q, i);
}

void prepare(vector<int>& q) {
    const int n = q.size();
    vector<pair<int, int> > ps;
    rep (i, n) ps.push_back(mp(-B[q[i]], q[i]));
    sort(ps.begin(), ps.end());
    rep (i, n) r[i] = ps[n-1-i].second;
    //rep (i, n) r[i] = q[i];
    rep (i, n) p[i] = B[r[i]];
    rep (i, n) {
        f[i] = 0;
        rep (j, n) if (g[r[i]][r[j]]) f[i] |= 1LL<<j;
    }
}

int n, a;

void rec(int k, Int u) {
    int s = 0;
    rep (i, n) if (u&(1LL<<i)) s += p[i];
    if (s < a) return ;
    if (k == n) a = s;
    else {
        rep (i, k) if (!(u&(1LL<<i)) && !(f[i]&u)) return ;
        const int mask = (1LL<<n) - 1;
        if (u&(1LL<<k)) rec(k+1, u&(mask-f[k]));
        if (r[k]) rec(k+1, u&(mask-(1LL<<k)));
    }
}

int solve() {
    memset(vis, 0, sizeof(vis));
    int ans = 0;
    rep (i, N) if (!vis[i]) {
        vector<int> q;
        collect(q, i);
        prepare(q);
        n = q.size();
        a = 0;
        rec(0, (1LL<<q.size())-1);
        ans += a;
    }
    return ans;
}

int main() {
    for (;;) {
        cin >> N;
        if (N == 0) return 0;
        map<string, int> of;
        rep (i, N) {
            cin >> A[i] >> B[i] >> C[i];
            of[A[i]] = i;
            rep (j, C[i]) cin >> D[i][j];
        }
        memset(g, 0, sizeof(g));
        rep (i, N) rep (j, C[i]) g[i][of[D[i][j]]] = 1;
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 1396
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

bool ok1(vector<int> &a) {
  return a.back() == 0;
}

bool ok2(vector<int> &a) {
  int n = a.size();
  if (n % 3 != 0) {
    return false;
  } else {
    int sn = n / 3;
    if (a[sn - 1] == 0 && a[sn] == a.back()) {
      return true;
    } else {
      return false;
    }
  }
}

bool ok3(vector<int> &a) {
  int n = a.size();
  if (n % 3 != 0) {
    return false;
  } else {
    int sn = n / 3;
    if (a[0] == a[sn - 1] && a[sn] == a[2 * sn - 1] && a[2 * sn] == a.back()) {
      if ((a[0]^a[sn]) == a[2 * sn]) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));

  if (ok1(a) || ok2(a) || ok3(a)) {
    print("Yes");
  } else {
    print("No");
  }


  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

using VecP = Vec1<P>;

Vec pn;

bool isPrime(ll n){
	if(n == 1) return false;
	for(ll i : pn){
		if(i * i > n) return true;
		if(n % i == 0) return false;
	}
	return true;
}

void init(ll n = 2e5){
	pn.pb(2);
	REP(num, 3, n) if(isPrime(num)) pn.pb(num);
}

VecP primeFactorization(ll n){
	VecP res;

	for(ll i : pn){
		ll cnt = 0;
		while(n % i == 0){
			n /= i;
			cnt++;
		}
		if(cnt) res.pb({i, cnt});
		if(n < i * i) break;
	}
	if(n != 1) res.pb({n, 1});

	return res;
}

Vec divisorEnumeration(ll n){
	auto v = primeFactorization(n);

	Vec res, a, b, cp;
	res.pb(1);
	for(auto p : v){
		cp.resize(res.size());
		copy(all(res), cp.begin());
		a.resize(res.size());
		repn(k, p.sc){
			ll t = pow(p.fs, k);
			rep(i, a.size()) a[i] = cp[i] * t;
			merge(all(res), all(a), back_inserter(b));
			swap(res, b);
			b.clear();
		}
	}

	return res;
}

int main(void){
	init();
	ll n;
	cin >> n;

	ll ans = 0;
	repn(i, n){
		if(i * 2 > n){
			ans += (i + n) * (n - i + 1) / 2;
			break;
		}
		ll e = n / i * i;
		ans += (i + e) * e / i / 2;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3752
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<long long,int>vis;
int main()
{
	int n,i,x;
	long long y=0,ans=0;
	scanf("%d",&n);
	vis[0]++;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		y+=x;
		//printf("%d\n",y);
		ans+=vis[y];
		vis[y]++;
	}
	printf("%lld\n",ans);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int sum=0,d=0;
    vector<int> res;
    for(int i=1;i<=n;i++){
        sum+=i;
        res.push_back(i);
        if(sum>n) d=sum-n;
        if(sum>=n)break;
    }
    //cout<<d<<endl;
    for(auto it:res){
        if(it!=d)cout<<it<<endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef unsigned long ul;
typedef unsigned long long ull;

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

  int n , l;
  cin >> n >> l;
  string str[n];
  for (int i = 0; i < n; i++) {
    std::cin >> str[i];
  }

  sort(str, str+n);
  for (int i = 0; i < n; i++) {
    std::cout << str[i];
  }
  std::cout << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int N;
    cin >> N;
    if (N % 10 == 7 ||
    (N/10) % 10 == 7 ||
    (N/100) % 10 == 7){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int r0 = 0;
  int r1 = 0;
  for (int i=0; i<S.size(); i++) {
    int d = S[i] - '0';
    int c0 = i % 2;
    int c1 = 1 - c0;
    if (d == c0) r1++;
    else r0++;
  }
  cout << min(r0, r1) << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int b, r, g, c, s, t;
	while (1) {
		cin >> b >> r >> g >> c >> s >> t;
		if (b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0)break;

		ll ans = 100;
		ans += b * 15 + r * 15 + (b * 5 + r * 3) * 15 + g*7 + c*2;
		ans -= 2 * (b * 5 + r * 3);
		ans -= 3 * (t-(b*5+r*3)-s);

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

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

#define pb push_back

typedef long long ll;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	int n; cin >> n;
	int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
	
	unordered_map<int,int,custom_hash> cnt;
	for (int x : a) cnt[x]++;
	
	int ret = 0;
	for (int i = 1; i <= n; i++) {
		cnt[a[i-1]] = cnt[a[i-1]] - 1;
		
		int rt = (int) sqrt(a[i-1]);
		bool ok = true;

		for (int j = 1; j <= rt; j++) {
			if (a[i-1] % j == 0) {
				if (cnt[a[i-1]/j]) ok = false;
				if (cnt[j]) ok = false;
			}
		}
		
		cnt[a[i-1]]++;
		ret += ok;
	}
	
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 32512
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			
			if(n == 0) {
				break;
			}
			
			long ans = dfs(n);
			if(ans % 10 == 0) {
				ans /= 10;
			}
			else {
				ans /= 10;
				ans += 1;
			}
			if(ans % 365 == 0) {
				System.out.println(ans / 365);
			}
			else {
				System.out.println(ans / 365 + 1);
			}
		}
	}
	
	public static long dfs(int n) {
		if(n == 0) {
			return 1;
		}
		if(n < 0) {
			return 0;
		}
		long ans = 0;
		ans += dfs(n - 1);
		ans += dfs(n - 2);
		ans += dfs(n - 3);
		return ans;
	}
}

Measured memory_bytes: 19148