akhauriyash/Code-Regression huggingface dataset:
/*
 * @author Dhruvit
 */
#include <bits/stdc++.h>
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include <fstream>
#include <bits/stdc++.h>
long int max1(long int a,long int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}
class DKnapsack1 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n,w;
        in>>n>>w;
        long int dp[n+1][w+1],we[n],val[n];
        for(int i=0;i<n;i++){
            in>>we[i]>>val[i];
        }
        for(int i=0;i<=w;i++){
            dp[0][i] = 0;
        }
        for(int i = 1;i <= n; i++){
            for(int j = 0;j <= w; j++){
                dp[i][j] = dp[i-1][j];
                if(j - we[i-1] >= 0){
                    dp[i][j] = max1(dp[i][j], dp[i-1][j - we[i-1]] + val[i-1]);
                }
            }
        }
        out<<dp[n][w];
	}
};


int main() {
	DKnapsack1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if(0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n;
vector<pair<int, int> > vec;
vector< vector<int> > permutations;

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

  cin >> n;
  for(int i=0;i<n;i++){
    int a, b;
    cin >> a >> b;
    vec.push_back({a, b});
  }

  sort(vec.begin(), vec.end());
  long double sum = 0;
  long double it = 0;
  do {

    for(int i=0;i<sz(vec) - 1;i++){
      sum += (
        sqrt((vec[i].S - vec[i+1].S)*(vec[i].S-vec[i+1].S) +
        (vec[i].F - vec[i+1].F)*(vec[i].F-vec[i+1].F))
      );
    }
    it++;
  } while(next_permutation(vec.begin(), vec.end()));

  cout << setprecision(11) << sum/it << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> sum(N + 1);
    vector<ll> cood;
    rep(i, N) sum[i + 1] = sum[i] + A[i];
    rep(i, N) {
        for(int j = i + 1; j < N + 1; j++) {
            cood.pb(sum[j] - sum[i]);
        }
    }

    ll res = 0;
    for(int i = 50; i >= 0; i--) {
        vector<ll> next_cood;
        rep(j, cood.size()) {
            if(cood[j] & (1LL << i))
                next_cood.pb(cood[j]);
        }
        if(next_cood.size() < K) {

        } else {
            res += (1LL << i);
            cood = next_cood;
        }
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> b(n);
    for (int i = 0; i < n; i++)cin >> b[i];
    vector<int> c(n - 1);
    for (int i = 0; i < n - 1; i++)cin >> c[i];

    int ret = 0;
    for (int i = 0; i < n; i++) {
        ret += b[a[i]];
        if (i > 0 && a[i] == a[i - 1] + 1)ret += c[a[i - 1]];
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
  int n;
  cin >> n;
  int d[n];

  rep(i,n)cin >> d[i];

  int ans=0;
  for(int i=0;i<n;i++){
	for(int j=i+1;j<n;j++){
	  ans += d[i]*d[j];
	}
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back
 
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()
 
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN= 3*1e3;
int main(){
    int n ; cin >> n ; 
    int ar[n];   
    vector<vll> dp ( MAXN , vll (MAXN));
    
 //   puts("e");
    REP(i, n ){
        cin >> ar[i];
    }
    DFOR(l, n, 0){
     //   puts("e");
        FOR(r ,l,n){
        //    puts("dd");
            if(r-l == 0)dp[l][r] = ar[l];
            else
            dp[l][r] = max(ar[l] - dp[l+1][r] , ar[r] - dp[l][r-1] );
        }
    }
    cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 73636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> V(N);
    rep(i,0,N)cin >> V[i];
    int dsum = 0;
    rep(i,0,N){
        if(i % 2 == 0)dsum += V[i];
        else dsum -= V[i];
    }
    //cout << dsum << endl;
    vector<ll> ans(N);
    ans[0] = dsum;
    
    rep(i,1,N){
        ans[i] = (V[i-1] - ans[i-1]/2) * 2;
    }
    rep(i,0,N){
        cout << ans[i] << " ";
    }
}

Measured memory_bytes: 2816
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
    int key;
    Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur-> next;
    }
    return cur;
}

void init(){
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil)break;
        if(isf++ >0)printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil)return;
    t -> prev -> next = t -> next;
    t -> next -> prev = t -> prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->next = nil-> next;
    nil -> next -> prev = x;
    nil -> next = x;
    x -> prev = nil;
}

int main(){
    int key,n,i;
    int size = 0;
    char com[20];
    int np = 0,nd = 0;
    scanf("%d",&n);
    init();
    for (i=0;i<n;i++){
        scanf("%s%d",com,&key);
        if( com[0] == 'i'){
            insert(key); np++; size++;
        }else if(com[0] == 'd'){
            if(strlen(com) >6){
                if(com[6] == 'F')deleteFirst();
                if(com[6] == 'L')deleteLast();
            }else{
                deleteKey(key); nd++;
            }
            size--;
        }

    
    }
    printList();
    return 0;
}


Measured memory_bytes: 33932
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(setq *n* (read))
(setq *k* (read))

(defun ans (cnt)
  (cond
  ((<= *n* cnt) 0)
  ((>= (read) *k*) (1+ (ans (1+ cnt))))
  (t (ans (1+ cnt)))
  ))


(format t "~a~%" (ans 0))


Measured memory_bytes: 64564
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= print . solve

solve :: Int -> Int 
solve n = 180 * (n - 2)

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 508
#include<stdio.h>
int main(){
int m[11],i,j,work;
for(i=0;i<10;i++){
 scanf("%d",&m[i]);
}
for(i=0;i<10;i++){
 for(j=0;j<10;j++){
  if(m[i]>m[j]){
   work=m[i]; m[i]=m[j]; m[j]=work;
   }
  }
 }
for(i=0;i<3;i++){
 printf("%d\n",m[i]);
}
return 0; }

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

using namespace std;

typedef long long ll;

struct ev {
    int p, t, x;
};

bool operator < (const ev &a, const ev &b) {
    if (a.p == b.p) {
        return a.t > b.t;
    }
    return a.p < b.p;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector <ev> e;
    for (int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        t--;
        int l = 0, r = 0;
        if (x < s) {
            l = s - x;
        } else {
            l = 0;
        }
        if (x > t) {
            r = -1;
        } else {
            r = t - x;
        }
        if (l > r) {
            continue;
        }
        e.push_back({l, 1, x});
        e.push_back({r + 1, -1, x});
    }
    sort(e.begin(), e.end());
    int ptr = -1;
    multiset <int> ms;
    for (int i = 0; i < q; i++) {
        int d;
        cin >> d;
        while (ptr + 1 < (int) e.size() && e[ptr + 1].p <= d) {
            ptr++;
            if (e[ptr].t == 1) {
                ms.insert(e[ptr].x);
            } else {
                ms.erase(ms.find(e[ptr].x));
            }
        }
        cout << (ms.empty() ? -1 : *ms.begin()) << '\n';
    }
    return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && a < c){
        if(b < c){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  string cur;
  map<string, ll> mp;
  cin >> n;
  cin >> cur;
  mp[cur]++;
  ok = true;
  rep(i, n - 1) {
	cin >> s;
	if (mp[s] != 0 || cur[cur.length() - 1] != s[0]) ok = false;
	mp[s]++;
	cur = s;
  }

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
using namespace std;

struct Point
{
    double x,y;
}
    ;


void koch(int n, Point a, Point b)
{

    if(n==0) return;


    Point s,t,u;

    double th = M_PI * 60.0/180.0;


    s.x = (2.0*a.x + 1.0*b.x)/3.0;

    s.y = (2.0*a.y + 1.0*b.y)/3.0;

    t.x = (1.0*a.x + 2.0*b.x)/3.0;

    t.y = (1.0*a.y + 2.0*b.y)/3.0;

    u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;

    u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;


    koch(n-1,a,s);

    printf("%.8f %.8f\n", s.x,s.y);

    koch(n-1,s,u);

    printf("%.8f %.8f\n", u.x,u.y);

    koch(n-1,u,t);

    printf("%.8f %.8f\n", t.x,t.y);

    koch(n-1,t,b);

}


int main() 
{

    Point a,b;

    int n;


    scanf("%d",&n);


    a.x = 0;

    a.y = 0;

    b.x = 100;

    b.y = 0;


    printf("%.8f %.8f\n",a.x,a.y);

    koch(n,a,b);

    printf("%.8f %.8f\n",b.x,b.y);


    return 0;

}

Measured memory_bytes: 1068
#include <iostream>
#include <map>
using namespace std;
 
int main() {
  int N;
  map<string, int> gacha;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
  	cin >> S;
    
	auto itr = gacha.find(S);
    if( itr != gacha.end() ) {
		gacha[S] += 1;
    } else {
    	gacha[S] = 1;
    }
  }
  
  int sum = 0;
 
  for(auto itr = gacha.begin(); itr != gacha.end(); itr++) {
  	sum += 1;
  }
  cout << sum;
}

Measured memory_bytes: 19184
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
using namespace std;
#define MAX_N 500005
#define MAX_Q 20010
#define MAX_L 40010
 
struct data{
  int y,id;
  bool operator < (const data &p)const{
    return (y==p.y?id<p.id:y<p.y);
  }
};
 
int n;
int px[MAX_N],py[MAX_N];
int ax[MAX_Q],ay[MAX_Q];
int bx[MAX_Q],by[MAX_Q];
 
 
set<data> t[500];
set<data> u[MAX_L];
  
void Set(int x,int y,int id){
  u[x].insert((data){y,id});
  t[x/500].insert((data){y,id});
}
vector<int> ans;
void Find(int ax,int ay,int bx,int by){
  set<data> :: iterator it;
  for(int i=ax;i<bx;i++){
    if(i%500==0&&i+500<=bx){
      it=t[i/500].lower_bound((data){ay,-1});
      while(1){
        if(it==t[i/500].end() || by < it->y)break;
        ans.push_back(it->id);
        it++;
      }
      i+=499;
    }else{
      it=u[i].lower_bound((data){ay,-1});
      while(1){
        if(it==u[i].end() || by < it->y)break;
        ans.push_back(it->id);
        it++;
      }
    }
  }
}

int tx[MAX_L];
int ux[MAX_L];
int size=0;
 
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d %d",&px[i],&py[i]);
   
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%d %d %d %d",&ax[i],&bx[i],&ay[i],&by[i]);
    bx[i]++;
    tx[size++]=ax[i];
    tx[size++]=bx[i];
  }
  tx[size++]=1e9+2;
  tx[size++]=-1e9-2;
  sort(tx,tx+size);
  ux[0]=1;
  for(int i=1;i<size;i++)ux[i]=ux[i-1]+(tx[i]!=tx[i-1]); 
  for(int i=0;i<n;i++){
    px[i]=ux[ upper_bound(tx,tx+size,px[i])-tx-1 ];
    Set(px[i],py[i],i);
  }
 
  for(int i=0;i<q;i++){
    ans.clear();
    ax[i]=ux[ lower_bound(tx,tx+size,ax[i])-tx ];
    bx[i]=ux[ lower_bound(tx,tx+size,bx[i])-tx ];

    Find(ax[i],ay[i],bx[i],by[i]); 
    sort(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++){
      if(i&&ans[i]==ans[i-1])continue;
      printf("%d\n",ans[i]);
    }    
    printf("\n");  
  }
  return 0;
}

Measured memory_bytes: 53264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }



using psii = pair<pair<string, int>, int>;

void solve() {
    int n;
    cin >> n;
    vector<int> ans(n);
    
    vector<psii> v(n);
    rep(i, n) {
        cin >> v[i].F.F >> v[i].F.S;
        v[i].S = i;
        v[i].F.S *= -1;
    }
    sort(all(v));
    // rep(i, n) cout << v[i].F.F << " " << v[i].F.S << " " << v[i].S << endl;
    
    rep(i, n) ans[i] = v[i].S + 1;
    rep(i, n) cout << ans[i] << endl;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

vll divisor(ll n) {
    vll ans;
    for (ll i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ans.push_back(i);
            if (i*i != n) ans.push_back(n/i);
        }
    }
    sort(all(ans));
    return ans;
}

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

    vll g = divisor(n);
    ll ans = 0; 
    srep(i, g.size(), 1) {
        ll tmp = g[i] - 1;
        if (n % tmp == n / tmp) ans += tmp; 
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

vector< int > g[1001];
int sz[1001], num[1001];

void Latte(int &idx, int cnt)
{
  int now = idx, dd;
  num[cnt] = now;
  for(int i = 0; i < sz[now] - 1; i++) {
    cin >> dd;
    if(dd < 0) {
      --sz[num[dd + cnt]];
      g[num[dd + cnt]].push_back(now);
      g[now].push_back(num[dd + cnt]);
    } else if(dd > 0) {
      sz[++idx] = dd;
      g[now].push_back(idx);
      g[idx].push_back(now);
      Latte(idx, cnt + 1);
    }
  }
}

int main()
{
  int T;
  cin >> T;
  while(T--) {
    memset(sz, 0, sizeof(sz));
    memset(num, 0, sizeof(num));
    for(int i = 0; i < 1001; i++) g[i].clear();

    cin >> sz[0];
    int idx = 0;
    Latte(idx, 0);
    cin >> sz[0];
    for(int i = 0; i <= idx; i++) {
      sort(begin(g[i]), end(g[i]));
      cout << i + 1;
      for(int j : g[i]) cout << " " << j + 1;
      cout << endl;
    }
  }
}

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

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  int sum = 0;
  for(int i = 0; i < n-1; i++){
    for(int j = i + 1; j < n; j++){
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
ll modpow(ll a, ll p){
  ll x = 1;
  while(p != 0){
    if(p%2 == 1){
      x = (x * a) % MOD;
      p--;
    }
    a = (a * a) % MOD;
    p /= 2;
  }
  return x;
}

int main(){
  int n;
  cin >> n;
  ll ans = (modpow(10, n) - 2 * modpow(9, n) + modpow(8, n)) % MOD;
  while(ans < 0) ans += MOD;
  cout << ans << endl;

}

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

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

    long long a[n], b[n], c[m], d[m];

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

    for(long long i = 0; i < m; i++){
        cin >> c[i] >> d[i];
    }

    long long check[n];

    long long min;
    for(long long i = 0; i < n; i++){
        min = 1e9;
        for(long long j = 0; j < m; j++){
            if(min > abs(a[i] - c[j]) + abs(b[i] - d[j])){
                min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                check[i] = j;
            }
        }
    }

    for(long long i = 0; i < n; i++){
        printf("%lld\n", check[i]+1);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = 1LL << 61;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i, j;
string S, T;
vl A, B;
void solve() {
    rep(i,3){
        ans+=(S[i]==T[i]);
    }
    cout<<ans<<endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>S>>T;
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll n, sum[n] = {0}, sum1[n] = {0}, sum2[n] = {0};
    cin >> n;
    ll a[n], b[n], c[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i] >> b[i] >> c[i];
    for(int i = 0; i < n; ++i){
        sum[i] += a[i];
        if(i != 0)
            sum[i] += max(sum1[i-1], sum2[i-1]);
        sum1[i] += b[i];
        if(i != 0)
            sum1[i] += max(sum[i-1], sum2[i-1]);
        sum2[i] += c[i];
        if(i != 0)
            sum2[i] += max(sum[i-1], sum1[i-1]); 
    }
    cout << max(sum[n-1], max(sum1[n-1], sum2[n-1]));
    return 0;
}

Measured memory_bytes: 150272
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll>>a(n);
	REP(i, n) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	ll b = 0;
	REP(i,n) {
		b += a[i].second;
		if (b >= k) {
			cout << a[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cassert>
#include <set>
#include <map>
#include <bitset>
#include <unordered_set>
#include <string>
#include <cstring>
#include <cmath>
#include <numeric>
#define forn(x, n)             for (int x = 0; x < n; x++)
#define fore(x, a, b, c)       for (int x = a; x <= b; x += c)
#define forr(x, a)             for (int x = a; x >= 0; x--)
#define all(container)         (container).begin(), (container).end()
#define rall(container)        (container).rbegin(), (container).rend()
#define sz(container)          (int) container.size()
#define mp                     make_pair
#define fi                     first
#define se                     second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector< vector< int > > vvi;
typedef vector<bool> vb;
typedef vector<long long> vll;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define debug(...) 0
#endif

void read(int &a) {scanf("%d", &a);}
void read(ll &a) {scanf("%lld", &a);}
void read(char* a, string& s) {scanf("%s", a); s = string(a);}
void read(float &a) {scanf("%f", &a);}
void read(double &a) {scanf("%lf", &a);}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int n, m;
ll x;
vll cost;
vll curr;
vector<vector<ll>> inc;
const ll nax = 1e18;
ll ans = nax;

void rec(int pos, ll tot) {
    if (pos == n) {
        bool ok = true;
        forn(i, m) if (curr[i] < x) {
            ok = false;
            break;
        }
        if (ok) uin(ans, tot);
    } else {
        forn(i, m) curr[i] += inc[pos][i];
        rec(pos + 1, tot + cost[pos]);
        forn(i, m) curr[i] -= inc[pos][i];
        rec(pos + 1, tot);
    }
}

void solve() {
    read(n), read(m), read(x);
    cost.resize(n);
    inc.resize(n, vll(m));
    curr.resize(m, 0LL);
    forn(i, n) {
        read(cost[i]);
        forn(j, m) read(inc[i][j]);
    }
    rec(0, 0);
    if (ans == nax) puts("-1");
    else printf("%lld\n", ans);
}

int main(void) {
    int T = 1;
    while (T--)
        solve();
    return 0;
}

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

int main()
{
    int N,W,V[101][10001],i,j;
    int v[1000],w[1000];
    cin >> N >> W;
    for(i=1;i<=N;i++)
        cin >> v[i] >> w[i];
    for(i=0;i<=N;i++)
        for(j=0;j<=W;j++)
            V[i][j]=0;
    for(i=1;i<=N;i++)
        for(j=1;j<=W;j++)
        {
            if(j-w[i]<0)
                V[i][j]=V[i-1][j];
            else    V[i][j]=max((v[i]+V[i-1][j-w[i]]),V[i-1][j]);
        }
    cout << V[N][W] << endl;
    return 0;
}


Measured memory_bytes: 7060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = 0;
		try {
			n = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int a[] = new int [n];
		String str[] = new String [n];
		String line;
		try {
			line = br.readLine();
			str = line.split(" ");
			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(str[i]);
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += 1.0 / a[i];
		}
		
		System.out.println(1.0 / sum);
		
	}
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n;
    cin>>n;
    map<string, int> mp;
    rep(i,0,n){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans=0;
    for(auto i:mp){
        if(i.second>=2){
            ll val=0;
            for(int num=i.second-1;num>=1;num--){
                val+=num;
            }
            ans+=val;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

////////////////////////////////////////
ll max(ll a,ll b){return a>b?a:b;}

int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    if(k==0){
        cout<<(ll)n*n;
        return 0;
    }
    rep(b,1,n){
        ans+=max(0,n/b*(b-k));
        ans+=max(0,n%b+1-k);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "1024" ].parse.expand.solve == 2020 );
	assert( [ "0" ].parse.expand.solve == 0 );
	assert( [ "1000000000" ].parse.expand.solve == 2000000000 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto x = input.front.to!( long );
	return tuple( x );
}

auto solve( long x )
{
	return ( x / 500 ) * 1000 + ( x % 500 / 5 ) * 5;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int field[4][4], limit, MD = 0;
bool ans = false;

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

struct Point {
    int x;
    int y;
};

void dfs(Point nowpos, Point prevpos, int depth) {
    if (MD == 0) {
        ans = true;
        return;
    }
    if (depth + MD > limit) {
        return;
    }

    int MD_bk = MD;
    for (int i = 0; i < 4; i++) {
        Point nextpos = nowpos;
        nextpos.x += dx[i];
        nextpos.y += dy[i];
        if (nextpos.x < 0 || nextpos.x > 3 || nextpos.y < 0 || nextpos.y > 3 || (nextpos.y == prevpos.y && nextpos.x == prevpos.x)) {
            continue;
        }
        MD = MD - MDT[nextpos.y][nextpos.x][field[nextpos.y][nextpos.x]] + MDT[nowpos.y][nowpos.x][field[nextpos.y][nextpos.x]];
        swap(field[nextpos.y][nextpos.x], field[nowpos.y][nowpos.x]);
        dfs(nextpos, nowpos, depth + 1);
        swap(field[nextpos.y][nextpos.x], field[nowpos.y][nowpos.x]);
        MD = MD_bk;
    }
}

void calc_MD() {
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 1; k <= 15; k++) {
                MDT[i][j][k] = abs(i - (k - 1) / 4) + abs(j - (k - 1) % 4);
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (field[i][j] != 0) {
                MD += MDT[i][j][field[i][j]];
            }
        }
    }
}

int main() {
    Point space, temp;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            cin >> field[i][j];
            if (field[i][j] == 0) {
                space.x = j;
                space.y = i;
            }
        }
    }
    calc_MD();

    temp.x = temp.y = -1;
    for (int i = 0; i <= 45; i++) {
        limit = i;
        dfs(space, temp, 0);
        if (ans == true) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
//
//  main.c
//  ITP1_5_D
//
//  Created by k16031kk on 2018/05/22.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

void call(int n, int i) {
    while(n>=3) {
        if(n%10==3) {
            printf(" %d", i);
            break;
        } else {
            n/=10;
        }
    }
}
    
int main(int argc, const char * argv[]) {
    // insert code here...
    int n,x;
    scanf("%d", &n);
    
    for(int i=1; i<=n; i++) {
        x=i;
        //count++;
        if(x%3==0) {
            printf(" %d", x);
        } else {
               call(x, i);
        }
    }
    printf("\n");
    
    return 0;
}



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

struct unionFind {
  vector<int> d;  // 根： 木のサイズ x -1, それ以外： 親のID
  unionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    // root化しておく
    x = find(x);
    y = find(y);
    if (x == y) return false;

    // x を y に unite
    // d[x] のほうが多きい（=サイズが小さい）場合はswap
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
} uf;

int main() {
  int n, q;
  cin >> n >> q;
  uf = unionFind(n);
  rep(i, q) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0)
      uf.unite(x, y);
    else
      cout << uf.same(x, y) << endl;
  }
  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int n,r,p,c;
    while (true) {
        /* code */
        cin >> n >> r;
        if(n==0 && r==0) break;
        int hanafuda[n];
        rep(i,n) hanafuda[i]=n-i;
        rep(i,r){
            cin >> p >> c;
            int cs[c];
            rep(j,c){
                cs[j]=hanafuda[p+j-1];
            }
            for(int j=p-2;j>=0;j--){
                hanafuda[j+c]=hanafuda[j];
            }
            rep(j,c){
                hanafuda[j]=cs[j];
            }
        }
        cout << hanafuda[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <queue>
#define rep(a,b) for(int a=0;a<(int)b;a++)
const int INF = 1000000000;
using namespace std;

int main(){
        int N,X,Y;
        cin >> N >> X >> Y;
        --X; --Y;
        vector<int> ans(N);
        queue<int> q;
        rep(idx, N){
                vector<int> dist(N, INF);
                auto push = [&](int ix, int dt){
                        if (dist[ix]!=INF) return;
                        dist[ix] = dt;
                        q.push(ix);
                };
                push(idx, 0);
                while(!q.empty()){
                        int v = q.front();
                        q.pop();
                        int d = dist[v];
                        if(v-1>=0) push(v-1, d+1);
                        if(v+1<N) push(v+1, d+1);
                        if(v==X) push(Y, d+1);
                        if(v==Y) push(X, d+1);
                }
                rep(i, N) ans[dist[i]]++;
        }
        rep(i,N) ans[i]/=2;
        for(int i=1;i<N;i++) cout << ans[i] << endl;
        return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
result = 0
result += max((n - k + 1) , 0) / n
for i in range(1, min(k, n+1)):
    num = i
    count = 0
    while num < k:
        num *= 2
        count += 1
    result += (1/n) * ((1/2) ** count)

print(result)

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

int main() {
    while (true) {
        int H, W;
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }

        for (int hc = 0; hc < H; hc++) {
            for (int wc = 0; wc < W; wc++) {
                if ((hc + wc) % 2 == 0) {
                    cout << '#';
                } else {
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
n, m = map(int, input().split())
H = list(map(int, input().split()))
road = [0 for i in range(m)]
ans = [0] * n

for i in range(m):
    road[i] = list(map(int, input().split()))

for j in range(m):
    if H[road[j][0]-1] < H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
    elif H[road[j][0]-1] > H[road[j][1]-1]:
        ans[road[j][1]-1] = 1
    elif H[road[j][0]-1] == H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
        ans[road[j][1]-1] = 1

total = sum(ans)
print(n-total)

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

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

	int ret = 0;
	if (s == "SUN") {
		ret = 7;
	}
	else if (s == "MON") {
		ret = 6;
	}
	else if (s == "TUE") {
		ret = 5;
	}
	else if (s == "WED") {
		ret = 4;
	}
	else if (s == "THU") {
		ret = 3;
	}
	else if (s == "FRI") {
		ret = 2;
	}
	else if (s == "SAT") {
		ret = 1;
	}

	cout << ret << endl;

	return 0;
}

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

#define int long long

#define REP(i,n) for(int i=0;i<n;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 pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 9999999999
 
using namespace std;

int32_t main(){
    string str;
    int n;
    cin >> str;
    n=str.length();

    int ans=INF;
    for(char i='a'; i<='z'; i++){
        vector<int> v(1, -1);
        REP(j, n){
            if(str[j]==i){
                v.pb(j);
            }
        }
        v.pb(n);

        int maxi=-1;
        FOR(j, 1, v.size()){
            maxi=max(maxi, v[j]-v[j-1]);
        }
        ans=min(ans, maxi);
    }

    cout << ans-1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include <cstdlib>
struct gay{
	std::string taskname;
	int tasktime;
};
int main(){
	gay gay_meme;
	std::queue<gay> G;
	int n,q,b,ctime=0;
	std::string fag;
	std::cin>>n>>q;
	for(int i=0;i<n;i++){
		std::cin>>fag>>b;
		gay_meme.taskname=fag;gay_meme.tasktime=b;
		G.push(gay_meme);
	}
	while(!(G.empty())){
		if(G.front().tasktime>q){
			gay_meme.taskname=G.front().taskname;
			gay_meme.tasktime=G.front().tasktime-q;
			G.push(gay_meme);
			G.pop();
			ctime+=q;
		}
		else{
			ctime+=G.front().tasktime;
			std::cout<<G.front().taskname<<" "<<ctime<<"\n";
			G.pop();
		}
	}
	return 0;
}

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

void swap(int &i, int &j) {
    if (j < i) {
        int tmp = i;
        i = j;
        j = tmp;
    }
}

int main() {
    for (;;) {
        int i, j;
        cin >> i >> j;

        if (i == 0 && j == 0) {
            break;
        } else {
            swap(i, j);
            cout << i << " " << j << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if((a-b)%2==0) {
        cout << "Alice" <<endl;
    }else{
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int n;
    int a[100000+100];
    int b[100000+100];
    while(cin>>n){
        memset(b,-1,sizeof(b));
        for(int i=1;i<=n;i++){
            cin>>a[i]; b[i]=0;
        }
        int flag=0; int k=0;
        int i=1;
        while(1){
            if(b[i]==0){
                b[i]=1; k++;
                i=a[i];
                if(i==2){
                  flag=1; break;
                }
            }
            else if(b[i]==1){
                flag=0; break;
            }
        }
        if(flag==0)
            cout<<-1<<endl;
        else
            cout<<k<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int N, M;
int main() {
	char str[100];
	scanf("%s", str);
	int len = strlen(str);
	int a = (len - 1) / 2, b = (len + 3) / 2;
	rep(i, 0, len) {
		if (str[i] != str[len - 1 - i]) {
			printf("No");
			return 0;
		}
	}
	rep(i, 0, a) {
		if (str[i] != str[a - 1 - i]) {
			printf("No");
			return 0;
		}
	}
	rep(i, 0, a) {
		if (str[i + b - 1] != str[len - i - 1]) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

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

using namespace std;

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

    int N; cin >> N; int A[ N ];

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

    sort( A, A + N ), cout << ( A[ N - 1 ] - A[ 0 ] );
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    scanf("%d %d",&H,&W);
    for (int i=1;i<=300;i++){
        if(H==0 && W==0){
            break;
        }
        else{
            for(int j=1;j<=H;j++){
                for(int k=1;k<=W;k++){
                    if(j==1 || j==H || k==1 || k==W){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
                printf("\n");
            }
            printf("\n");
            scanf("%d %d",&H,&W);
        }
    }
    return 0;
}



Measured memory_bytes: 3092
#include "bits/stdc++.h"
 
using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454545;
ll N, M, S, T;
 
vector<ll > dijkstra(vector<vector<pi > > G, ll start){
    //準備
    vector<bool > used(N, false);
    vector<ll > dist(N, INF);
    priority_queue<pi , vector<pi >, greater<pi > > que;
    //初期化
    que.push(make_pair(0, start));
 
    //cout << que.top().first << endl;
 
    while(!que.empty()){
        //距離
        ll d = 0;
        //次の頂点
        ll t_v = 0;
        d = que.top().first;
        t_v = que.top().second;
        //topから削除
        que.pop();
        //探査済みなら処理しない
        if(used[t_v] == true) continue;
        //探査済みにする
        used[t_v] = true;
        //キューの上には既に最小距離が来ているので
        dist[t_v] = d;
        
        //次探査する頂点はt_vなのでt_vから更に次にの頂点の繋がりをキューにいれる
        for(ll i = 0; i < G[t_v].size(); i++){
            //もし探査済みの頂点で，そこまでの累積距離より今更新しようとしている距離が
            //大きいときは更新しない
            ll to = G[t_v][i].first;
            ll cost = d+G[t_v][i].second;
            if(dist[to] <= cost) continue;
            //累積距離と次の頂点
            que.push(make_pair(cost, to));
            //仮dist
            dist[to] = cost;
        }
        //cout << endl;
    }   
    
    return dist;
 
}
 
int main() {
    //頂点数
    cin >> N >> M >> S >> T;

    vector<vector<pi > > yen(N);
    vector<vector<pi > > snuuke(N);
 
    for(ll i = 0; i < M; i++){   
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        //双方向に貼りましょうね
        yen[u].push_back(make_pair(v, a));
        yen[v].push_back(make_pair(u, a));    

        snuuke[u].push_back(make_pair(v, b));
        snuuke[v].push_back(make_pair(u, b));   
    }

    //i年後には強制的にi番目を通らざるを得ない
    //そこまでの円とそこからのSnuukeでコストが決まる
    //更にi-1年後にはi-1番目を通れる可能性があり，そちらのほうがコストが安いかも
    //そのときに答えを更新していく
    //s-(経由地)-tで円-Snuukeがどれだけ消費されるかを求めれば良い

    //円でsからスタート
    vector<ll > distYen = dijkstra(yen, S-1);
    //snuukeでtからスタート
    vector<ll > distSnuuke = dijkstra(snuuke, T-1);
    //答え
    vector<ll > ans(N, 0);

    ll mn = INF;
    for(ll i = N-1; i >= 0; i--){
        ll tmp = distYen[i] + distSnuuke[i];
        if(tmp < mn){
            mn = tmp;
        }
        ans[i] = mn;
    }

    for(ll i = 0; i < N; i++){
        cout << (ll)(1e15 - ans[i]) << endl;
    }

}

Measured memory_bytes: 26680
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans;
  cin>>N;
  ll A[N+1];
  vector<ll> S;
  S.PB(0);
  RREP(i,N){
    cin>>A[i];
    S.PB(S.at(i-1)+A[i]);
  }
  SORT(S);
  
  ll t=S.at(0),cnt=1;
  for(int i=1; i<S.size(); ++i){
    if(t!=S.at(i) || i==S.size()-1){
      t=S.at(i);
      if(i==S.size()-1 && S.at(i)==S.at(i-1)) cnt++;
      ans+=cnt*(cnt-1)/2;
      cnt=1;
    }
    else{
      cnt++;
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 3444