akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
S = input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= [int(input()) for _ in range(N)]
#= {i:[] for i in range(N)}

abc = "abcdefghijklmnopqrstuvwxyz"
dic = {d: 0 for d in abc}

for s in S:
    dic[s] += 1

for k in dic:
    if dic[k] == 0:
        print(S + k)
        exit()

li = []
for i in range(1, len(S) + 1):
    s = S[-i]
    for l in li:
        if s < l:
            print(S[: len(S) - i] + l)
            exit()
    li.append(s)
    li.sort()

print(-1)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, n;
    cin >> x >> n;
    V<int> a(n);
    read(a);
    set<int> st;
    for (int i = 0; i < n; i++) st.insert(a[i]);
    int mi = INF;
    int s = -1000;
    for (int i = -100; i <= 200; i++) {
        if (st.count(i)) continue;
        if (mi > abs(x - i)) {
            mi = abs(x - i);
            s = i;
        }
    }
    cout << s << newl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int>
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0);
const int32_t mod = 1e9+7;
const int32_t maxn=2e5+5;
int inf=1e18;

void solve(){
    int s,d,t;
    cin>>d>>t>>s;
    if(s*t>=d) cout<<"Yes";
    else cout<<"No";
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
from collections import Counter
n, p = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f*f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = Counter(prime_factorize(p))
ans = 1
for key, value in a.items():
    if n <= value:
        pow = value // n
        # print(pow, value, n)
        # pow = 1
        ans *= int(key)**pow

print(ans)

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

using namespace std;
typedef long long ll;
typedef long double ld;

const ll MOD = 1e9+7;
const int N = 200200;

ll fac[N];
ll ifac[N];

ll modpow(ll b, ll p) {
    ll ans = 1;
    for (; p; p/=2, b=b*b%MOD) {
        if (p&1) ans = ans*b%MOD;
    }
    return ans;
}

void setup() {
    fac[0] = ifac[0] = 1;
    for (int i=1; i<N; ++i) {
        fac[i] = fac[i-1]*i%MOD;
        ifac[i] = ifac[i-1]*modpow(i, MOD-2)%MOD;
    }
}

ll choose(int n, int k) {
    ll ans = 1;
    for (int i=n; i>n-k; --i) {
        ans = ans*i%MOD;
    }
    ans = ans*ifac[k]%MOD;
    return ans;
}



ll n, a, b;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    setup();
    cin >> n >> a >> b;
    ll x = modpow(2, n) + MOD -1;
    x -= choose(n, a);
    x -= choose(n, b);
    x = (x+MOD*MOD)%MOD;
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){
  stack<int> S;
  S.push(r);
  color[r] = c;
  while (!S.empty()) {
    int u = S.top();
    S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
      color[v] = c;
      S.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  for (int i = 0; i < n; i++) {
    color[i] = NIL;
  }
  for (int u = 0; u < n; u++) {
    if(color[u] == NIL) {
      dfs(u, id++);
    }
  }
}

int main(void){
  int s, t, m, q;
 
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 8912
#include <bits/stdc++.h>
#define MOD 1000000007
#define md %998244353
#define INF 2e9
#define INFI 1e9 + 5
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
  ll n,i,j,k;
  cin>>n>>k;
  ll a[n];

  for(i=0;i<n;i++)cin>>a[i];
  
   vector<ll> dp(n,INFI);
  
  dp[0]=0;
  
  
  for(i=0;i<n;i++)
  {
  	for(j=i+1;j<=k+i;j++)
  	{
  		
  		
	  if(j<n)
  	dp[j]=min( dp[j] ,dp[i] + abs(a[i] - a[j]) );
  	 
  	
  }
  	
  }
  
  
  cout<<dp[n-1];
   
}




Measured memory_bytes: 1792
<?PHP
  $ans = fgets(STDIN);
$aaa = fgets(STDIN);
$heights = explode(" ", $aaa);
$array = explode(" ", $ans);
$amount=$array[0];
$kick_power=$array[1];
$dps=[];

foreach (range(0, $ans-1) as $index) {
	$dps[$index] = INF;
	if($index===0){ 
		$dps[0]=0; 
		continue;
	}
//	$dps[$index]=$dps[$index-1]+abs($heights[$index]-$heights[$index-1]);
	foreach (range(1, $kick_power) as $i) {
		if($index>=$i){
			$distanse=abs($dps[$index - $i] + abs($heights[$index] - $heights[$index - $i]));
			if ($dps[$index]> $distanse){$dps[$index]=$distanse;}
		}

	}
}

echo end($dps);

Measured memory_bytes: 23028
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (c).size()
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int n;
int main(){
fcin;
    cin >> n;
    if(n>=30) cout << "Yes\n";
    else cout << "No\n";


}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    string N; cin >> N;
    if(N[N.size()-1]=='s') {cout<<N+"es";}
    else {cout<<N+"s";};
    return 0;
}

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

int main()
{
    int n, tmp, res = 0;
    cin >> n;
    unordered_map<int, int> m;

    for(int i = 0; i < n; ++i)
    {
        cin >> tmp;
        m[tmp]++;
    }

    for(auto i : m)
    {
        if(i.first > i.second)
        {
            res += i.second;
        } else if(i.first < i.second)
        {
            res += i.second - i.first;
        }
    }

    cout << res << "\n";
}


Measured memory_bytes: 7332
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
 int k,s;
 cin>>k>>s;
 int ans =0;
 rep(i,k+1){
   rep(j,k+1){
     if(s-i-j<=k&&i+j<=s){
       //cout<<s-i-j<<endl;
       ans++;
       }
   }
 }
 cout<<ans<<endl;

}


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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int res = 0;
    
    for (int a =  0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                int total = (500 * a) + (100 * b) + (50 * c);
                if (total == X) res++;
            }
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/* ex 5_4
   KitamoriFumiya */

#include <stdio.h>
#include <string.h>

int main(void){
	int length, number, max_number, part[11], i, j; // length,number,max_number,i,jをint型の変数, partをACGT文字列の長さを調べて格納するための配列として宣言
	char letter[11]; // 文字列は10文字以下なので要素数を11とする
	scanf("%s", letter);
	// 文字列の長さを求める
	length = strlen(letter);
	number = 0; // ACGT文字列の長さの初期値は0
	// ACGT文字列を調べる
	for(i = 0; i < length; i++){
		number = 0; // ACGT文字列の長さの初期値は0
		// i番目の文字からA,T,C,Gのいづれかが続けば、その文字列の長さを数え、part[i]に記録
		for(j = i; j < length; j++){
			if(letter[j] == 'A' || letter[j] == 'C' || letter[j] == 'G' || letter[j] == 'T'){
				number++;
			}else break;
		}
		part[i] = number;
	}
	// 最長のACGT文字列の長さを求める
	max_number = part[0];
	for(i = 1; i < length; i++){
		if(max_number < part[i]){
			max_number = part[i];
		}
	}
	// 最長のACGT文字列の長さを出力
	printf("%d\n", max_number);
	
	return 0;
}

Measured memory_bytes: 1728
N, X = map(int, input().split())
x_list = list(map(int, input().split()))

x_list.sort()
def gcd(a, b):
    if a >= b:
        return a if b == 0 else gcd(b, a % b)
    else:
        return gcd(b, a)


D = abs(X-x_list[0])
for i in range(0, N):
    D = gcd(D,  abs(x_list[i]-X))

print(D)


Measured memory_bytes: 15020
/*
        ####   ####
     ###    ###    ###
   ###    Bravery    ###
  ###  Determination  ###
   ##  Perseverance   ##
    ##   Integrity   ##
     ##  Patience   ##
      ## Kindness  ##
        ##Justice##
         ##     ##
           ## ##
             #
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
using namespace std;
string str;
int main(){
	ios::sync_with_stdio(false);
	cin>>str;
	for (int i=0;i<str.size();i++) if (str[i]=='?') cout<<'D'; else cout<<str[i];
	return 0;
}

Measured memory_bytes: 3740
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
for n, v in enumerate(itertools.permutations(range(1,N+1),  N)):
  if v == P:
    a = n
  if v == Q:
    b = n
print(abs(a-b))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int a[105];
int f(int x){
	int res = 0;
	for(int i=0;i<N;i++)res += sq(a[i]-x);
	return res;
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> a[i];
	int ans = INF;
	for(int i=-100;i<=100;i++)ans = min(ans,f(i));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;

    vector<long long> a(n), suff(n + 1);

    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }

    for(long long i = n - 1; i >= 0; i--){
        suff[i] = suff[i + 1] + a[i];
        suff[i] %= MOD;
    }

    long long ans = 0;
    for(long long i = 0; i < n; i++){
        long long k = a[i] * suff[i + 1];
        k %= MOD;
        (ans += k) %= MOD;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 6332
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string S;

    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef struct{
  int surface[6];
}Dice;

void move_dice(Dice *d,char c){
  int temp = d->surface[0];
  if(c == 'N'){
    d->surface[0] = d->surface[1];
    d->surface[1] = d->surface[5];
    d->surface[5] = d->surface[4];
    d->surface[4] = temp;
  }
  else if(c == 'E'){
    d->surface[0] = d->surface[3];
    d->surface[3] = d->surface[5];
    d->surface[5] = d->surface[2];
    d->surface[2] = temp;
  }
  else if(c == 'S'){
    d->surface[0] = d->surface[4];
    d->surface[4] = d->surface[5];
    d->surface[5] = d->surface[1];
    d->surface[1] = temp;
  }
  else if(c == 'W'){
    d->surface[0] = d->surface[2];
    d->surface[2] = d->surface[5];
    d->surface[5] = d->surface[3];
    d->surface[3] = temp;
  }
}

int main(void){
  Dice dice;
  char command[102];
  for(int i = 0; i < 6; i++){
    int temp;
    scanf("%d",&temp);
    dice.surface[i] = temp;
  }
  char dump = getchar();
  fgets(command,sizeof(command),stdin);
  for(int i = 0; i < strlen(command); i++){
    move_dice(&dice,command[i]);
  }
  printf("%d\n",dice.surface[0]);
  return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const ll mod = 1e9 + 7;
const int N = 2e5 + 10;
ll c[N], p[2*N];


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> c[i];
    }
    sort(c + 1, c + n + 1);
    p[0] = 1;
    for (int i=1; i<=2*n+5; i++) {
        p[i] = (p[i-1] * 2) % mod;
    }
    ll ans = 0;
    for (int i=1; i<n; i++) {
        ll cur = (p[n+i-1] * c[i]) % mod;
        cur = (cur * (p[n-i] + (n - i) * p[n-i-1] % mod)) % mod;
        ans = (ans + cur) % mod;
    }
    ll cur = (p[n+n-1] * c[n]) % mod;
    ans = (ans + cur) % mod;
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S;
    REP(i, S.size())
    S[i] = 'x';
    cout << S << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using namespace std;

using lli = long long int;
using ulli = unsigned long long int;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int N;
int aA[114514];
bool fa[114514];
int R = 1, cnt = 0;
bool f = true;

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

	cin >> N;

	for(int i = 0; i < N; i++){
		cin >> aA[i];
		fa[i] = true;
	}
	fa[0] = false;

	do{
		R = aA[R-1];
		if(fa[R-1] == false) {
			break;
		}else{
			fa[R-1] = false;
		}
		cnt++;
	}while(fa[1]);
	if(fa[1]){
		cout << -1 << endl;
	}else{
		cout << cnt << endl;
	}
  return 0;
}


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

int main(){

 long long int n;
  cin >> n;
 long long int sum = 0;
  
  for(int i=0;i<=n;i++){
    if(i%3 == 0||i%5 == 0){
      continue;
    }
    else{
      sum += i;
    }
  }
   cout << sum << endl;
   return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N), sum(N + 1), B, can;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum[i + 1] = A[i];
    }

    rep(i, N) { sum[i + 1] += sum[i]; }

    for (int i = 0; i < N + 1; i++) {
        for (int j = i + 1; j < N + 1; j++) {
            B.push_back(sum[j] - sum[i]);
        }
    }

    sort(all(B));
    vector<ll> now = B;
    for (int i = 60; i > -1; i--) {
        vector<ll> next;
        for (auto n : now) {
            if (n & (1LL << i))
                next.push_back(n);
        }
        // 桁が大きいところにbitフラグが立っている順に、振るい落として候補を絞っていく。
        if (next.size() >= K)
            now = next;
    }

    ll ans = now[now.size() - 1];
    rep(i, K) { ans &= now[now.size() - 1 - i]; }

    cout << ans << endl;
}

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

#define endl '\n'

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  int n;
  cin >> n;
  
  int ans = pow(n, 3);
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 3312
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <functional>
using namespace std;
typedef pair<int,int> P;
typedef unsigned long long int ull;
#define pb push_back
#define INF 1000000000
#define fi first
#define sec second
int dist1[100100],dist2[100100];
int c[40100],d[40100];
bitset<1024> dp[100100];
struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};
vector<edge> g[100100];
int comp(int x,int y){
    return dist1[x]<dist1[y];
}
void dijkstra(int s,int t){
    for(int i=0;i<100100;i++)dist1[i]=INF,dist2[i]=INF;
    dist1[s]=0,dist2[t]=0;
    priority_queue<P,vector<P>,greater<P> >q;
    q.push(P(0,s));
    while(!q.empty()){
        P a = q.top();
        q.pop();
        int v = a.sec;
        for(int i=0;i<g[v].size();i++){
            edge e = g[v][i];
            if(dist1[e.to]>dist1[v]+e.cost){
                dist1[e.to] = dist1[v]+e.cost;
                q.push(P(dist1[e.to],e.to));
            }
        }
    }
    q.push(P(0,t));
    while(!q.empty()){
        P a = q.top();
        q.pop();
        int v = a.sec;
        for(int i=0;i<g[v].size();i++){
            edge e = g[v][i];
            if(dist2[e.to]>dist2[v]+e.cost){
                dist2[e.to] = dist2[v]+e.cost;
                q.push(P(dist2[e.to],e.to));
            }
        }
    }
    return;
}
int S,R,Q;
int a,b;
int main(){
    scanf("%d %d",&S,&R);
    for(int i=0;i<R;i++){
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        u--;v--;
        g[u].pb(edge(v,w));
        g[v].pb(edge(u,w));
    }
    scanf("%d %d %d",&a,&b,&Q);
    a--;b--;
    dijkstra(a,b);
    /*for(int i=0;i<S;i++)
    {
        cout << dist1[i] << ' ' << dist2[i] << endl;
    }*/
    vector<int> tp;
    for(int i=0;i<S;i++)tp.pb(i);
    sort(tp.begin(),tp.end(),comp);
    //for(int i=0;i<S;i++)cout << tp[i] << ' ';
    for(int i=0;i<Q;i+=1024){
    	for(int j=0;j<100100;j++)dp[j]=bitset<1024>(0);
        for(int j=0;j<min(1024,Q-i);j++){
            scanf("%d %d",&c[j],&d[j]);
            c[j]--;d[j]--;
            dp[c[j]].set(j);
        } 
        for(int j=0;j<S;j++){
            int f = tp[j];
            if(dist1[f]+dist2[f]!=dist1[b])continue;
            for(int k=0;k<g[f].size();k++){
                edge e = g[f][k];
                if(dist1[e.to]+dist2[e.to]!=dist1[b])continue;
                if(dist1[e.to]!=dist1[f]+e.cost)continue;
                dp[e.to]|=dp[f];
            }
        }
        for(int j=0;j<min(1024,Q-i);j++){
            if(dp[d[j]][j])printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 24004
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": # "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vector<pii> scores; // score,id
	for(int n,score;scanf("%d,%d",&n,&score),n|score;)
		scores.push_back(mp(score,n));
	
	sort(allof(scores),greater<pii>());
	
	vector<pii> places(1,mp(scores[0].second,1)); // id,place
	repi(i,1,scores.size()){
		if(scores[i].first<scores[i-1].first)
			places.push_back(mp(scores[i].second,places.back().second+1));
		else
			places.push_back(mp(scores[i].second,places.back().second));
	}
	
	sort(allof(places));
	
	for(int n;cin>>n;)
		cout<<places[n-1].second<<endl;
	
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] p = sc.nextIntArray(n);
    double[] v = new double[n + 1];
    v[0] = 0.0;
    for (int i = 0; i < n; i++) {
      v[i + 1] = (p[i] + 1) / 2.0 + v[i];
    }
    double max = 0.0;
    for (int i = 0; i + k <= n; i++) {
      max = Math.max(max, v[i + k] - v[i]);
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 42620
#include <iostream>
#include <vector>
#include <limits>

using namespace std;
typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] % b[i] == 0) c[i] = 0;
        else c[i] = b[i] * (a[i] / b[i] + 1) - a[i];
    }

    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        c[i] -= ans;
        if (c[i] < 0) c[i] += (-c[i] + b[i] - 1) / b[i] * b[i];
        ans += c[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    string a = "", b = "";
    cin >> a >> b;
    a += b;
    int num = stoi(a);
    int i = 1;
    while (i*i <= num) {
        if (i*i == num) {
            cout << "Yes" << endl;
            return 0;
        }
        i++;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}


int main(){
 ll d ; cin>> d ;
 ll c[26] ; rep(i,26) cin>>c[i] ;
 ll s[d][26] ;
 vector<ll> bns(d)  ;
  rep(i,d){
     rep(j,26){
        cin>> s[i][j] ;
        if(s[i][bns[i]] <s[i][j]) bns[i]= j ;
     }
 }
 
 ll t[d] ; 
 
 rep(i,d){
   t[i]=(bns[0]+i)%26 ;
 }
 
 ll m= 365*100 ;
 ll p[m] ;ll q[m] ;
 rep(i,m){
   p[i]=m%365 ;
   ll a= m/365 ;
   q[i]= (i+a)%26 ;
 }
 ll ans=0 ;
ll last[26] ; rep(i,26) last[i]=0 ;
rep(i,d){
  ans+= s[i][t[i]] ;
  rep(i,26) last[i] ++ ;
  last[t[i]]=0 ;
  ll sum=0 ;
  rep(i,26) sum+= c[i]*last[i] ;
  ans-= sum ;
  }
  
  
  
  rep(i,m){
   ll rans= ans ;
   ll memo = t[p[i]] ;
   t[p[i]]= q[i] ;
   ll maex=p[i]+1, atox= d-p[i] ;
   ll maey=p[i]+1 ,atoy= d-p[i] ;
    rep(j,d){
     if(t[j]==memo&&j<p[i]) maex=p[i]-j ;
     if(t[j]==memo&&j>p[i]){
       atox= j-p[i] ;
       break ;
     }
    }
    rep(j,d){
     if(t[j]==q[i]&&j<p[i]) maey=p[i]-j ;
     if(t[j]==q[i]&&j>p[i]){
       atoy= j-p[i] ;
       break ;
     }
    }
    ans -= c[memo]*atox*maex ;
    ans += c[q[i]]*atoy*maey ;
    ans = ans- s[p[i]][memo] + s[p[i]][q[i]] ;
    if(ans<rans){
      t[p[i]]= memo ;
    }
  }

   rep(i,d) cout<< t[i]+1<<endl ;
 return 0 ;
}


Measured memory_bytes: 4280
//   _/                  _/                  _/_/_/    _/
//_/_/_/_/    _/_/    _/_/_/_/    _/_/    _/        _/_/
// _/      _/    _/    _/      _/    _/  _/_/_/      _/
//_/      _/    _/    _/      _/    _/  _/    _/    _/
// _/_/    _/_/        _/_/    _/_/      _/_/      _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[200005]={},ans=0,cnt=0,r=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int l=0; l<n; l++) {
    while(r<n&&(cnt^a[r])==cnt+a[r]) {
      cnt+=a[r];
      r++;
    }
    ans+=r-l;
    if(r==l) {
      r++;
    }
    else {
      cnt-=a[l];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>

using namespace std;

int main() {

	int N, M, a, b;
	bool s[200010] = { false };
	bool t[200010] = { false };
	bool flag = false;

	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		if (a == 1) s[b] = true;
		if (b == N) t[a] = true;
	}

	for (int i = 0; i < N; i++) {
		if (s[i] == true &&  t[i] == true)
			flag = true;
	}

	if(flag) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;

	return 0;

}

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

using ll=long long;
using ld=long double;

void solve(){
	int n;
	cin>>n;
	int x=1;
	while((x*1000)<n){
		x+=1;
	}
	cout<<(x*1000)-n<<'\n';
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

using namespace std;

using int64 = long long;

int main() {
  int64 M, Rd, Rr, Cd, Cr;
  cin >> M >> Rd >> Rr >> Cd >> Cr;
  
  int64 D = (Cd * 100 + Rd - 1) / Rd;
  int64 R = (Cr * 100 + Rr - 1) / Rr;

  if(M - D - R < 0) {
    cout << -1 << endl;
  } else {
    cout << M - D - R << endl;
  }
}




Measured memory_bytes: 3136
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
    char c=getchar();ll f=1,x=0;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return x*f;
}
#define mod 1000000007
void MOD(int &x){if(x>=mod)x-=mod;}
#define maxn 100010
#define inf (1<<30)
int l,nxt[maxn*2],head[maxn],to[maxn*2],cl[maxn*2],v[maxn*2];
void add(int x,int y,int c,int z){
	l++;nxt[l]=head[x];head[x]=l;to[l]=y;cl[l]=c;v[l]=z;
}
int bin[maxn];
int fa[maxn][30],d[maxn],s[maxn];
void dfs(int x){
	FOR(i,1,20)fa[x][i]=fa[fa[x][i-1]][i-1];
	FORL(i,x){
		int c=to[i];
		if(c==fa[x][0])continue;
		fa[c][0]=x;d[c]=d[x]+1;s[c]=s[x]+v[i];
		dfs(c);
	}
}
int lca(int x,int y){
	if(d[x]<d[y])swap(x,y);
	int k=d[x]-d[y];
	FOR(i,0,20)
		if(k&(1<<i))
			x=fa[x][i];
	if(x==y)return x;
	FORD(i,20,0)
		if(fa[x][i]!=fa[y][i])
			x=fa[x][i],y=fa[y][i];
	return x==y?x:fa[x][0];
}
struct A{
	int cl,v,c,id;
};
#include<vector>
vector<A>ve[maxn];
int ans[maxn];
int sz[maxn],sum[maxn];
void dfs2(int x){
	int l=ve[x].size();
	FOR(i,0,l-1){
		A q=ve[x][i];
		ans[q.id]-=q.c*sum[q.cl];
		ans[q.id]+=q.c*sz[q.cl]*q.v;
	}
	FORL(i,x){
		int c=to[i];
		if(c==fa[x][0])continue;
		sum[cl[i]]+=v[i];
		sz[cl[i]]++;
		dfs2(c); 
		sum[cl[i]]-=v[i];
		sz[cl[i]]--;
	}
}
int main(){
	int n,m;
	in(n);in(m);
	FOR(i,2,n)bin[i]=bin[i/2]+1;
	FOR(i,1,n-1){
		int x,y,C,D;
		in(x);in(y);in(C);in(D);
		add(x,y,C,D);add(y,x,C,D); 
	}
	dfs(1);
	FOR(i,1,m){
		int x,y,u,v;
		in(x);in(y);in(u);in(v);
		int z=lca(u,v);
		ans[i]=s[u]+s[v]-2*s[z]; 
		ve[u].push_back((A){x,y,1,i});
		ve[v].push_back((A){x,y,1,i});
		ve[z].push_back((A){x,y,-2,i});
	}
	dfs2(1);
	FOR(i,1,m)out(ans[i]);
}

Measured memory_bytes: 31476
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        char[] array = sc.next().toCharArray();
        for (char tmp : array) {
            if (tmp == '0') {
                sb.append('0');
            } else if (tmp == '1') {
                sb.append('1');
            } else if (sb.length() > 0 && tmp == 'B'){
                sb.deleteCharAt(sb.length() - 1);
            }
        }
        System.out.println(sb.toString());
    }
}

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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

typedef vector<int> vi;
typedef pair<int,int> pi;


int main()
{
    int n;
    cin >>n;
    string s;
    cin>>s;

    if(n%2==1) 
    {
        cout<<"No"<<endl; 
        return 0; 
    }

    int j=s.length()/2;
    rep(i,0,s.length()/2)
    {
        if(s[i]!=s[j])
        {
            cout<<"No"<<endl;
            return 0; 
        }
        j++; 
    }
    cout<<"Yes"<<endl; 

    return 0; 
}



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

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  cout << max(A+B, max(A-B, A*B)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef vector<ll> vll;
const int inf = 1e9;
int main(){
    int a,b, c;
    cin >> a >> b >> c;
    cout << ((c >= a && c <= b)?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

int main() {
 int a;
  cin>>a;
  cout<<48-a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;
using ll = long long;

int main(void)
{
    int n,x,t;
    cin >> n >> x >> t;
    
    int i;
    for (i = 1; 1; i++)
    {
        if (x*i>=n)
        {
            break;
        }
    }
    cout << i*t << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
 
  int main(){      
        lint n,q;
        string s;
        cin>>n>>q;
        if(n<=q)cout<<"unsafe";
       else cout<<"safe";
 
          }
  

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i,n)cin>>a[i]>>b[i]>>c[i];

    ll dp[100001][3];

    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for(int i=0;i<n;i++){
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i];
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b[i];
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c[i];
    }

    cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;

    
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>
using namespace std;
int main(void){
    int n,a;
    double bun, hyo, ave,sum;
    while (true) {
        cin >> n;
        if (n == 0) {
            break;
        } else {
            int l[n];
            sum = 0;
            bun = 0;
            for (int i = 0; i < n; i++) {
                cin >> a;
                l[i] = a;
                sum += a;
            }
            ave = sum / n;
            for (int i = 0; i < n; i++) {
                bun += (l[i] - ave)*(l[i] - ave);
            }
            bun /= n;
            hyo = sqrt(bun);
            printf("%f\n",hyo);
        }
    }
    return 0;
}


Measured memory_bytes: 3204
import java.util.Scanner;
import java.util.Arrays;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			
			int results[] = new int[100];
			int last = 0;;
			
			for (int i = 0; i * 200 <= n; i++)
			{
				for (int j = 0; i * 200 + j * 300 <= n; j++)
				{
					for (int k = 0; i * 200 + j * 300 + k * 500 <= n; k++)
					{
						if (i * 200 + j * 300 + k * 500 == n)
						{
							int a  = (int) (380 * (i - (i % 5)) * 0.8 + 380 * (i % 5));
							int b  = (int) (550 * (j - (j % 4)) * 0.85 + 550 * (j % 4));
							int c  = (int) (850 * (k - (k % 3)) * 0.88 + 850 * (k % 3));
							results[last] = a + b + c;
							last++;
						}
					}
				}
			}
			Arrays.sort(results, 0, last);
			System.out.println(results[0]);
		}
	}
}

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

int n,k,ans=0,visited[100005];
char a[100005];

struct node
{
	char x;
	int s;
}b[5];

bool cmp(node a,node b)
{
	return a.s>b.s;
}

inline void get_s()
{
	int last=-1e9-7,score;
	for (int i=1;i<=3;i++)
	{
		if (b[i].x=='s')
		{
			score=b[i].s;
			break;
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i]!='p')  continue;
		if (visited[i])  continue;
		if (i-k>=1)
		{
			if (visited[i-k]==1)  continue;	
		}
		ans+=score;
		last=i;
		visited[i]=1;
	}
}

inline void get_p()
{
	int last=-1e9-7,score;
	for (int i=1;i<=3;i++)
	{
		if (b[i].x=='p')
		{
			score=b[i].s;
			break;
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i]!='r')  continue;
		if (visited[i])  continue;
		if (i-k>=1)
		{
			if (visited[i-k]==2)  continue;	
		}
		ans+=score;
		last=i;
		visited[i]=2;
	}
}

inline void get_r()
{
	int last=-1e9-7,score;
	for (int i=1;i<=3;i++)
	{
		if (b[i].x=='r')
		{
			score=b[i].s;
			break;
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i]!='s')  continue;
		if (visited[i])  continue;
		if (i-k>=1)
		{
			if (visited[i-k]==3)  continue;
		}
		ans+=score;
		last=i;
		visited[i]=3;
	}
}

signed main()
{
	cin>>n>>k;
	b[1].x='r',b[2].x='s',b[3].x='p';
	
	for (int i=1;i<=3;i++)  cin>>b[i].s;
	for (int i=1;i<=n;i++)  cin>>a[i];
	
	sort(b+1,b+4,cmp);
	
	for (int i=1;i<=3;i++)
	{
		if (b[i].x=='s')  get_s();
		else if (b[i].x=='p')  get_p();
		else if (b[i].x=='r')  get_r();
	}
	cout<<ans<<endl;
	
	return 0; 
}

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

int main(void){
    string s, t;
    cin >> s >> t;
    
     
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    bool flag = true;
    for (int i=0; i<min(s.size(), t.size()); i++) {
        if (s.at(i) != t.at(i)) flag = false;
    }
    if (s < t || (flag && s.size() < t.size())) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    
    
}



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

int N,C;


int a[10000];
long long ans;

void check(){
    a[N]=C;
    for(int i=0;i<N;i++)a[2*N-i]=a[i];

    long long val=0;
    for(int i=0;i<2*N+1;i++){
        val=val*10+a[i];
    }

    for(long long i=2;i*i<=val;i++){
        if(val%i==0)return;
    }

    ans=max(ans,val);
}

void dfs(int pos){
    if(pos==N){
        check();
        return;
    }

    for(int i=0;i<10;i++){
        if(pos==0&&i==0)continue;
        a[pos]=i;
        dfs(pos+1);
    }

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

    if(C<0&&N>1){
        for(int i=0;i<2*N;i++)cout<<9;
        cout<<endl;
    }
    else if(C<0){
        cout<<11<<endl;
    }
    else{
        dfs(0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>
#include<string.h>
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
 char S[4];
 scanf("%s", S);
 char *s1 ="ARC";
 if(strcmp(s1,S)==0){
 printf("ABC\n");
 }else {
  printf("ARC\n");
 }
  return 0;
}

Measured memory_bytes: 1608
import collections

n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  if cmc1[0][0] == cmc2[0][0]:    
    ans1 = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[1][1])
    ans2 = (len(v1) - cmc1[1][1]) + (len(v2) - cmc2[0][1])
    print(min(ans1, ans2))
  else:
    ans = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[0][1])
    print(ans)

Measured memory_bytes: 21084
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
	inp_out();
	int n;
	cin>>n;
	vi l(n),r(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>l[i]>>r[i];
	}

	sort(l.begin(),l.end());
	sort(r.begin(),r.end());

	if(n&1)
	{
		int low=l[n/2],high=r[n/2];
		cout<<(high-low+1);
	}

	else
	{
		int low=(l[n/2] + l[n/2-1]),high=(r[n/2] + r[n/2-1]);
		int ans=( high - low + 1) ;
		cout<<ans;
	}

	return 0;
}

Measured memory_bytes: 6344
import java.util.*;

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

        if (s.charAt(0) != 'A') {
            System.out.println("WA");
            return;
        }

        int c = 0;
        for (int i = 2; i <= s.length() - 2; i++) {
            if (s.charAt(i) == 'C') {
                c++;
            }
        }

        if (c != 1) {
            System.out.println("WA");
            return;
        }

        for (int i = 0; i < s.length(); i++) {
            char c1 = s.charAt(i);
            if (c1 == 'A' || c1 == 'C') {
                continue;
            }

            if ((c1 >= 'a') && (c1 <= 'z')) {

            } else {
                System.out.println("WA");
                return;
            }
        }
        System.out.println("AC");

    }
}


Measured memory_bytes: 23252
H, W, A, B = map(int, input().split())
INF = 10**9 + 7

def powmod(a, n, mod):
    p = 1
    while n > 0:
        if n % 2 == 0:
            a = a**2 % mod
            n /= 2
        else:
            p *= a
            p %= mod
            n -= 1
    return p


def invmod(a, mod):
    return powmod(a, mod-2, mod)


def combmod(n, k, mod):
    if n < k : return 0
    else:
        if n < 2*k: k = n-k
        bunsi = fac[n]
        bunbo = inv[k] * inv[n-k]
        return bunsi * bunbo % mod

fac = [1] * (H+W+1)
inv = [1] * (H+W+1)
for i in range(H+W+1):
    if i == 0:
        fac[i] = 1
        inv[i] = 1
    else:
        fac[i] = fac[i-1] * i % INF
        inv[i] = inv[i-1] * invmod(i, INF) % INF

ans = 0
for i in range(min(W, H - A + B) - B):
    h = H - A - i
    w = B + 1 + i
    ans += combmod(h+w-2, h-1, INF) * combmod(H+W-h-w, H - h, INF) % INF

print(ans%INF)

Measured memory_bytes: 46556