akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[200200]={};
	LL c=0;
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
	}
	a[n]=1<<30-1;
	int l=0,sum=0,xorsum=0,mem=0;
	FOR(r,0,n+1){
		int tmp=xorsum;
		sum+=a[r];
		xorsum^=a[r];
		if(sum!=xorsum||r==n){
			//c+=(r-l)*(r-l+1)/2;
			int bl=l;
			for(l=l;l<=r;l++){
				sum-=a[l];
				xorsum^=a[l];
				if(sum==xorsum||l==r){
					l++;
					if(r==n)l=n;
					c+=1LL*(l-bl)*(l-bl+1)/2+1LL*(l-bl)*(r-l);
					//cout<<"      l:"<<l<<" bl:"<<bl<<" r:"<<r<<" c:"<<c<<endl;
					break;
				}
			}
		}
		//cout<<r<<" "<<c<<endl;
	}
	//c+=1LL*(n-l)*(n-l+1)/2;
	cout<<c<<endl;
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

  int N=in(),Q=in();
  string S=in<string>();
  vector<int> total(N+1,0);
  int index=0;
  while(index<S.size()){
    if(S[index]=='A' && index!=S.size()-1 && S[index+1]=='C'){
      total[index+1] = total[index]+1;
      total[index+2] = total[index+1];
      index += 2;
    }
    else{
      total[index+1] = total[index];
      index++;
    }
  }
  REP(i,Q){
    int L=in(),R=in();
    cout << total[R-1]-total[L-1]<< endl;
  }
  return 0;
}

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

struct Point{double x,y,mine,high;};
bool comp(Point a,Point b) {return (a.x==b.x ? a.y<b.y : a.x<b.x);}

bool Intersection(Point p1,Point p2,Point p3,Point p4,Point *res){
    double d = (p2.x-p1.x)*(p4.y-p3.y)-(p2.y-p1.y)*(p4.x-p3.x);
    double u = ((p3.x-p1.x)*(p4.y-p3.y)-(p3.y-p1.y)*(p4.x-p3.x))/d;
    double v = ((p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x))/d;
    if (d == 0 || u<0.0 || u>1.0 || v<0.0 || v>1.0)return false;
    res->x = p1.x + u * (p2.x - p1.x);
    res->y = p1.y + u * (p2.y - p1.y);
    res->high = (p3.mine == p3.high);

    return true;
}

int main(void){
    int N,xa,ya,xb,yb,n,xs,ys,xt,yt,o,l;
    cin>>N;
    while(N--){
        vector<Point> cross;
        cin>>xa>>ya>>xb>>yb>>n;
        Point a = {xa,ya,true,true};
        Point b = {xb,yb,true,true};
        rep(i,n){
            cin>>xs>>ys>>xt>>yt>>o>>l;
            Point s = {xs,ys,o,l};
            Point t = {xt,yt,o,l};
            Point res;
            if(Intersection(a,b,s,t,&res)){
                cross.push_back(res);
            }
        }

        sort(cross.begin(),cross.end(),comp);
        int cnt=0;
        for(int i=0;i+1<cross.size();i++){
            cnt+=(cross[i].high!=cross[i+1].high);
        }
        cout<<cnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>
int main(void){
    int n;
    int a[1000],b[1000],c[1000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);  
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);  
    }
     for(int i=0;i<n-1;i++){
        scanf("%d",&c[i]);
    }
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=b[a[i]-1];
       // printf("%d\n",sum);
        //printf("%d %d\n",a[i],a[i-1]);
        if((a[i]-1)==a[i-1]){
            sum+=c[a[i]-2];
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
a,b,c=map(int,input('').split())
k=int(input())
for i in range(k):
    if a<b and b<c:
        print("Yes")
        exit()
    if b<=a:
        b*=2
        continue
    if c<=b:
        c*=2
        continue
if a<b and b<c:
    print("Yes")
else:
    print('No')
    

Measured memory_bytes: 9160
#include <stdio.h>
#include <stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while (x->right != NIL) {
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if (u == NIL || k == u->key) return u;

  else if (k < u->key) return treeSearch(u->left, k);

  else return treeSearch(u->right, k);

}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}


void insert(int k){
  Node y = NIL; //xの親
  Node x = root; //root
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if (y == NIL) root = z; // T empty
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if (u != NIL) {
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if (u != NIL) {
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20524
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;
  ll a[n];
  for (ll i = 0; i < n; ++i)
  {
  cin>>a[i];
  }
  sort(a,a+n);
  c(a[n/2] - a[n/2 - 1]);
}

signed main(){
 
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main () {
  long long ca[5];
  long long N;
  cin >> N;
  for (int i = 0; i < 5; i ++) cin >> ca[i];
  long long min = ca[0];
  long long ans;
  for (int i = 0; i < 5; i ++) {
    if (min > ca[i]) min = ca[i];
  }
  ans = N / min;
  if (N % min) ans ++;
  ans += 4;
  cout << ans << endl;
}
  



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1000 * 1000 + 3;
int mod(int n) {
    return (n % M + M) % M;
}   
int fp(int a, int p) {
    int ans = 1, cur = a;
    for (int i = 0; (1 << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * cur);
        cur = mod(cur * cur);
    }   
    return ans;
}   
int dv(int a, int b) {
    return mod(a * fp(b, M - 2));
}   
int p[M];
int get(int l, int len) {
    int r = l + len - 1;
    if (r >= M) return 0;
    else return dv(p[r], p[l - 1]);
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    p[0] = 1;
    for (int i = 1; i < M; ++i) {
        p[i] = mod(p[i - 1] * i);
    }   
    int q;
    cin >> q;
    while (q--) {
        int x, d, n;
        cin >> x >> d >> n;
        if (d == 0) {
            cout << fp(x, n) << '\n';
        }
        else {
            cout << mod(fp(d, n) * get(dv(x, d), n)) << '\n';
        }   
    }   
}   

Measured memory_bytes: 8704
#include <stdio.h>

int main() {
	double a, sum;
	int i=0;
	
	while( scanf("%lf", &a)!=EOF ) {
		sum=0.0;
		for(i=2; i<=10; i++) {
			sum+=a;
			if ( i%2==1 ) a/=3.0;
			else a*=2.0;
		}
		sum+=a;
		printf("%lf\n", sum);
	}
	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  VAR(int, D);
  if (D == 25) OUTL("Christmas");
  else if (D == 24) OUTL("Christmas Eve");
  else if (D == 23) OUTL("Christmas Eve Eve");
  else OUTL("Christmas Eve Eve Eve");
  return 0;
}


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

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n, k;
	cin >> n >> k;

	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	sort(begin(a), end(a));

	ll ans = n, score = 0;
	for (ll i = n - 1; i >= 0; i--) {
		if (score + a[i] < k) {
			score += a[i];
			continue;
		}

		ans = min(ans, i);
	}

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


Measured memory_bytes: 384
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

string col[3] = {"WHITE", "GRAY", "BLACK"};
struct Node{
	int color, d, f;
	queue<int> Q;
};

int main(){
	int n;
	cin >> n;
	Node node[n + 1];
	stack<int> move;
	for(int i = 1; i <= n; i++){
		int u, k, v;
		cin >> u >> k;
		node[u].color = WHITE;
		while(k--){
			cin >> v;
			node[u].Q.push(v);
 		}
	}

	int start = 1;
	int tt = 1, p, next;

	do{
		move.push(start);
		node[start].color = GRAY;
		node[start].d = tt;
		tt++;

		while(!move.empty()){
			p = move.top();
			//cout << "Is at " << p << endl;
			if(node[p].Q.empty()){
				//cout << "Cant move from here!" << endl;
				node[p].color = BLACK;
				node[p].f = tt;
				move.pop();
				tt++;
			} else {
				next = node[p].Q.front();
				if(node[next].color == WHITE){
					//cout << "Moving to " << next << endl;
					move.push(next);
					node[next].color = GRAY;
					node[next].d = tt;
					tt++;
				} else {
					//cout << "Cant move to " << next << endl;
					node[p].Q.pop();
				}
			}
			/*
			for(int i = 1; i <= n; i++)
				cout << i << "'s color is " << col[node[i].color] << endl;
			*/
		}

		start = -1;
		for(int i = 1; i <= n; i++){
			if(node[i].color == WHITE){
				start = i;
				break;
			}
		}
		//cout << "start = " << start << endl;
	} while (start > 0);
	

	for(int i = 1; i <= n; i++){
		cout << i << " " << node[i].d << " " << node[i].f << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
N = int(input())
S = input()

s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

res = []

for i in S:
    index = s.index(i)
    s_index = index+N if index + N < 25 else index + N - 26
    res.append(s[s_index])

print(''.join(res))

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

using namespace std;

int main() {
  string x;
  cin >> x;
  while (x[0] != '0') {
    int sum = 0;
    for (int i = 0; i < x.size(); i++) {
      sum += (x[i] - '0');
    }
    cout << sum << endl;
    cin >> x;
  }
}


Measured memory_bytes: 3152
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include<bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#define inf  (int)1e18
#define EPS   1e-9
#define MOD 1000000007
#define all(k) k.begin(),k.end()
#define Pi 3.14159
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define ll  long long unsigned int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vi vector<int>
#define vc vector<char>
#define vvc vector<vc>
#define mi map<int,int>
#define ml map<ll,ll>
#define umap unordered_map<int,int>
using namespace std;

void sol() {
	int n;
	int cnt = 0;
	cin >> n;
	vi a(n), b(n);

	rep(i, 0, n)
	cin >> a[i] >> b[i];

	rep(i, 0, n) {


		if (a[i] == b[i])
			cnt++;
		else
			cnt = 0;

		if (cnt == 3) {
			cout << "Yes"; return;
		}

	}

	cout << "No";
}



int main() {


	int t = 1;


	// for (cin >> t; t; t--)
	sol();


	return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
T gcd(T a, T b) {
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

int main() {
    int k;
    cin >> k;
    ll res = 0;
    for (int a = 1; a <= k; ++a) {
        for (int b = 1; b <= k; ++b) {
            for (int c = 1; c <= k; ++c) {
                res += gcd(a, gcd(b, c));
            }
        } 
    } 
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define int long long

using namespace std;

typedef pair<string, int> Rec;

vector<Rec> f(int N){
    vector<Rec> ret;
    if(N == 1) {
        ret.push_back(make_pair("a", 1));
        return ret;
    }
    auto t = f(N - 1);
    for(auto i = t.begin(); i!= t.end(); i++){
        string S = i->first;
        auto c = i->second;
        for(auto j = 0; j < c; j++){
            auto tS = "" + S;
            tS.push_back('a' + j);
            ret.push_back(make_pair(tS, c));
        }
        S.push_back('a' + c);
        ret.push_back(make_pair(S, c+1));
    }
    return ret;
}

signed main() {
    int N;
    cin >> N;
    auto ans = f(N);
    for(auto i = ans.begin(); i != ans.end(); i++){
        cout << i->first << endl;
    }
    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);
    vi a(N);
    vi cnt(N);
    Repe(i,N,1){
        Scd(a[i]), a[i]--;
        cnt[a[i]]++;
    }

    Rep(i,N) printf ("%d\n", cnt[i] );

    return 0;
}



Measured memory_bytes: 4844
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	var s, t []byte
	fmt.Scan(&s)
	fmt.Scan(&t)
	cnt := 0
	for i := range s {
		if s[i] != t[i] {
			cnt++
		}
	}

	fmt.Println(cnt)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 5004
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <numeric>

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

using namespace std;


int main(){
    int n;
    cin >> n;
    
    vector<int> b(n-1);
    vector<int> a(n);
    // int before_num = 0;
    rep(i,n-1) {
        int num;
        cin >> num;
        a[i+1] = num;
        if (i == 0) {
            a[i] = num;
            continue;
        }
        a[i] = min(num, a[i]);
    }
    long long ans = accumulate(a.begin(), a.end(), 0);

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

Measured memory_bytes: 888
def prime_factor(n):
    factors = {}
    if n % 2 == 0:
        cnt = 0
        while n % 2 == 0:
            cnt += 1
            n //= 2
        factors[2] = cnt
    i = 3
    while i * i <= n:
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            factors[i] = cnt
        i += 2
    if n != 1:
        factors[n] = 1
    return factors

def extgcd(a, b):
    s, sx, sy, t, tx, ty = a, 1, 0, b, 0, 1
    while t:
        q = s // t
        s -= t * q
        s, t = t, s
        sx -= tx * q
        sx, tx = tx, sx
        sy -= ty * q
        sy, ty = ty, sy
    return sx, sy

def calc(a, b):
    x, y = extgcd(-a, b)
    if x < 0:
        k = (-x + b - 1) // b
        x += b * k
        y += a * k
    if x == 0:
        x += b
        y += a
    if y < 0:
        k = (-y + a - 1) // a
        x += b * k
        y += a * k
    if y == 0:
        x += b
        y += a
    return x, y

N = int(input())
primes = prime_factor(2 * N)
ans = float('inf')
for S in range(1 << len(primes)):
    a = b = 1
    for i, (p, c) in enumerate(primes.items()):
        if S >> i & 1:
            a *= pow(p, c)
        else:
            b *= pow(p, c)
    x, y = calc(a, b)
    ans = min(ans, a * x)
    x, y = calc(b, a)
    ans = min(ans, b * x)
print(ans)



Measured memory_bytes: 68896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}



int main(){
	int n; cin >> n; 
	std::vector<int> A(n);
	rep(i,n) cin >> A[i];

	std::vector<int> ANS(n);

	for (int i = 0; i < n; ++i)
	{
		if(i%2==0) ANS[0] += A[i];
		else ANS[0] -= A[i];
	}

	for (int i = 1; i < n; ++i)
	{
		ANS[i] = A[i - 1] * 2 - ANS[i - 1];
	}

	for (int i = 0; i < n - 1; ++i)
	{
		cout << ANS[i] << " ";
	}
	cout << ANS[n - 1] << endl;

}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;

    int ans = 0;

    if (a == b && a == c && a != 1)
    {
        cout << -1 << endl;
    }
    else
    {
        while(1)
        {
            if (a % 2 || b % 2 || c % 2) break;
            int _a = a, _b = b, _c = c;
            a = (_b + _c) / 2;
            b = (_a + _c) / 2;
            c = (_a + _b) / 2;
            ans++;
        }
    cout << ans << endl;
    }

    
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it!= v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
#define MOD 1000000007
//////////////////////////////////////////

int main(){
  ins(S);
  rep(i,sz(S) - 1){
    if(S[i] == 'A' && S[i + 1] == 'C') die("Yes");
  }
  die("No");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		long a,b,count=0;
		for(int i=0;i<n;i++)
		{
			a=sc.nextLong();
			b=sc.nextLong();
			if(Math.sqrt((a*a)+(b*b))<=m) 
				{
				 	count++;
				}
			
		}
		System.out.println(count);
	}
	
}


Measured memory_bytes: 60924
import math


def answer(a: int, b: int) -> str:
    joined_value = int(str(a) + str(b))
    return 'Yes' if math.sqrt(joined_value) % 1 == 0 else 'No'


def main():
    a, b = map(int, input().split())
    print(answer(a, b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string A,B,C;cin>>A>>B>>C;
  if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0]){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  int h,w;
  cin>>h>>w;

  rep(j,h){
    for(char i='A';i<'A'+w;++i){
      str s;cin>>s;
      if(s=="snuke"){
        cout<<i<<(j+1)<<endl;
        return 0;
      }
    }
  }
  
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N,W;
    cin>>N>>W;
    //basic knap question
    vector<int> lw(N);
    vector<int> lv(N);
    for(int i=0;i<N;i++)
	cin>>lw[i]>>lv[i];
    
    vector<vector<long long> > f(W+1,vector<long long>(N+1));
    for(int i=1;i<=W;i++){
	for(int j=1;j<=N;j++){
	    //f[i][j]=max(f[i][j-1],f[i-wj][j-1]+v[j])
	    long long temp;
	    if(i-lw[j-1]<0)
		temp=0;
	    else
		temp=f[i-lw[j-1]][j-1]+lv[j-1];
	    f[i][j]=f[i][j-1]>temp? f[i][j-1]:temp;
      //cout<<f[i][j]<<" ";
	}
      //cout<<endl;
    }
    cout<< f[W][N]<<endl;
    return 0;
}

Measured memory_bytes: 82304
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int ncr[55][55];

void calc(){
    rep(i,55){
        ncr[i][0] = 1;
        ncr[i][i] = 1;
    }
    loop(i,1,55)loop(j,1,i){
        ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
    }
}

signed main(void) {
    int i,j;
    int n, a, b;
    cin >> n >> a >> b;
    vi v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));
    int c = 0;
    for(i = n-1; i >= 0; i--)if(v[i]==v[n-1])c++;

    calc();

    if(c <= a){//a
        int sum = 0;
        rep(i,a) sum += v[n-1-i];
        cout << shosu(8) << sum * 1.0 / a << endl;
        int c1 = 0, c2 = 0;
        rep(i,n)if(v[n-a] == v[i]){
            if(i<n-a)c1++;
            else c2++;
        }

        cout << ncr[c1+c2][c1] << endl;


    }else if(c < b){//c
        cout << v[n-1] << endl;
        int ans = 0;
        loop(i,a,c+1){
            ans += ncr[c][i];
        }
        cout << ans << endl;
    }else{//b
        cout << v[n-1] << endl;
        int ans = 0;
        loop(i,a,b+1){
            ans += ncr[c][i];
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class EGolf {
public:

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int k; cin >> k;
      int x, y; cin >> x >> y;
      if (k%2==0 && (abs(x)+abs(y))%2==1) {
        cout << -1 << endl;
        return;
      }

      int signx = 1;
      int signy = 1;
      if (x < 0) {
        signx = -1;
        x = -x;
      }
      if (y < 0) {
        signy = -1;
        y = -y;
      }

      bool swapped = false;
      if (x < y) {
        swap(x, y);
        swapped = true;
      }

      vector<P> ans;
      ans.emplace_back(0, 0);
      if (x+y < k && (x+y)%2 == 1) {
        int s = (k+x-y)/2;
        int d = abs(x)+abs(x-k);
        assert(d==k);
        ans.emplace_back(x, x-k);
        d = abs(s) + abs(y-k+s-(x-k));
        assert(d==k);
        ans.emplace_back(x+s, y-k+s);
        d = abs(s) + abs(k-s);
        assert(d==k);
        ans.emplace_back(x, y);
      } else if (x+y < k) {
        int r = k-((x+y)/2);
        int d = abs(k-r) + abs(-r);
        //assert(d==k);
        ans.emplace_back(k-r, -r);
        d = abs(x-k+r) + abs(y+r);
        //assert(d==k);
        ans.emplace_back(x, y);
      } else {
        int n = (x+y+k-1)/k;
        if ((n*k-x-y)%2 != 0) {
          n++;
        }
        int r = (n*k-x-y)/2;
        int len = 0;
        rep(i, n) {
          len += k;
          if (len <= r) {
            ans.emplace_back(0, -len);
          } else if (len <= r+x) {
            ans.emplace_back(len-r, -r);
          } else {
            ans.emplace_back(x, len-r-r-x);
          }
        }
      }

      cout << ans.size()-1 << endl;
      for(int i=1; i<ans.size(); i++) {
        auto& e = ans[i];
        auto& f = ans[i-1];
        if (swapped) swap(e.first, e.second);
        cout << e.first*signx << ' ' << e.second*signy << '\n';
        auto d = abs(e.first-f.first)+abs(e.second-f.second);
        //assert(d==k);
      }

    }
};

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

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

using namespace std;

int main(void)
{
    long long x, ans = 1, lim = 1e8;
    int n;
    cin >> n;
    while (n--)
    {
        cin >> x;
        if (x == 0)
        {
            cout << 0;
            return 0;
        }
        if (1e18 / x < ans)
        {
            ans = -1;
            break;
        }
        ans *= x;
    }
    if ((ans == -1) && (n > 0))
        while (n--)
        {
            cin >> x;
            if (x == 0)
            {
                cout << 0;
                return 0;
            }
        }
    if (ans > (long long)(1e18))
        ans = -1;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main() {
  int val; cin >> val;
  int i = 1;
  while ((val != 4) && (val != 2) && (val != 1)) {
    if (val % 2 == 0) val = val / 2;
    else val = val * 3 + 1;
    ++i;
  }
  cout << i + 3 << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

#define MAXN 105
#define INF 999999999
#define lyh 1000000007


signed main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = n * 3 + m;
	printf("%d", ans / 2);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll a,b,n;
int main(){FAST;
cin>>a>>b>>n;
ll mx = min(b-1,n);
cout<<a*mx/b;
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3648
<?php
  
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $num = array_fill(1, 100001, 0);
  for ($i=0; $i<$n; $i++) {
    $num[$a[$i]]++;
  }

  $ans = 0;
  $p = count($num);
  for ($i=1; $i<$p; $i++) {
    if($num[$i] != 0){
//      echo $i." ".$num[$i].PHP_EOL;
      $ans += $num[$i] - 1;
    }
  }

  if($ans % 2 == 1){
    $ans++;
  }

  echo $n - $ans;

Measured memory_bytes: 25872
#define p(c,n)for(y=0;y++<n;)putchar(c);
y,z,w;main(x){scanf("%d%d%d%d",&x,&y,&z,&w);z-=x;w-=y;p(82,z)p(85,w+1)p(76,z+1)p(68,w+1)p(82,1)p(68,1)p(82,z+1)p(85,w+1)p(76,z+1)p(68,w);}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1<<20;
int n, A[500000];
V<int> v[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int X = 0;
  FOR(i, 0, n){
    cin >> A[i];
    X ^= A[i];
  }
  if(X){
    ll ans = 0;
    int x = 0;
    FOR(i, 0, n-1){
      x ^= A[i];
      if(x==X || x==0) v[0].pb(x);
    }
    ll p = 0, sx = 0, s0 = 1;
    for(int a:v[0]){
      if(a==X){
        sx = (sx + s0) % MOD;
      }else{
        s0 = (s0 + sx) % MOD;
      }
    }
    cout << s0 << endl;
    return 0;
  }
  X = 0;
  FOR(i, 0, n-1){
    X ^= A[i];
    v[X].pb(i);
  }
  ll ans = 0;
  FOR(i, 1, N){
    if(v[i].empty()) continue;
    int p = -1;
    ll sx = 0, s0 = 1;
    for(int a:v[i]){
      int d = lower_bound(all(v[0]), a) - lower_bound(all(v[0]), p);
      p = a;
      s0 = (s0+sx*d) % MOD;
      sx = (sx + s0) % MOD;
    }
    ans += sx;
  }
  ans = (ans % MOD + modPow(2, sz(v[0]), MOD)) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 36468
/**
*    author:  yuya1234
*    created: 24.06.2020 16:13:01
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n,t,a;
    cin>>n>>t>>a;

    double h[1000];
    int ans = 0;
    REP(i,n)
    {
        cin>>h[i];
        h[i]=abs(a - (t-h[i]*0.006));
        if(h[i] < h[ans])ans=i;
    }

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

Measured memory_bytes: 3796
"use strict";
(function(input){
  input=input.trim();
  input=input.split(/\n+/);
  const N=input[0]-0,
        A=input[1].split(/\s+/).map(x=>x-0);
  let last=A[N-1];
  for(let i=0;i<(N-1)/2;i++){
    last-=A[2*i];
    last+=A[2*i+1];
  }
  const ansReversed=[last];
  for(let i=N-2;i>=0;i--){
    ansReversed.push(2*A[i]-ansReversed[ansReversed.length-1]);
  }
  const ans=ansReversed.reverse();
  console.log(ans.join(" "));
})(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 35788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	LL N;
	cin >> N;
	string ans;
	while(N){
		N--;
		LL n=N%26;
		char c='a'+n;
		ans.push_back(c);
		N/=26;
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>

using namespace std;

char last(string s) {
  return(s[s.size() - 1]);
}

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

  vector<string> words(N);
  for (int i = 0; i<N; ++i) {
    cin >> words[i];
  }

  //同一単語を含まないかチェック(N*(N+1)/2回比較)，同一単語があればその時点で出力し終了．(比較の時間が不安…)
  for (int i = 0; i<N-1; ++i) {
    for (int j = i+1; j<N; ++j) {
      if (words[i] == words[j]) {
        cout << "No" << endl;
        return(0);
      }
    }
  }

  string ans = "Yes";
  char c = last(words[0]);

  //しりとりになっているかチェック，しりとりになっていなければans="No"として抜ける．
  for (int i = 1; i<N; ++i) {
    if (words[i][0] != c) {
      ans = "No";
      break;
    } else {
      c = last(words[i]);
    }
  }
  cout << ans << endl;

  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000;

using ll = long long;
using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    vector<string> s(n, "");
    rep(i, n) cin >> s.at(i);
    sort(s.begin(), s.end());
    rep(i, n) cout << s.at(i);
    cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef vector<int> vint;
#define rep(i,n) for(lint i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define clr(a) memset(a,0,sizeof(a))
int main(void){
    string s;
    cin >> s;
    rep(i,4){
        if(s[i] == '1')
            s[i] = '9';
        else
            s[i] = '1';
    }
    cout << s;
    return 0;
}
/*
ループ for(lint i = 0;i < N;i++)
ソート sort(a,a+N);
*/

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

int MAX = 1e18;
int n, A[100005];

signed main(){
  
  cin >> n;
  
  int mul = 1;
  
  for(int i=0;i<n;i++) cin >> A[i];
  
  sort( A, A + n );
  
  if( A[0] == 0 ){
    cout << 0 << endl;
    return 0;
  }
  
  for(int i=0;i<n;i++){
    
    if( mul > MAX / A[i] ){
      cout << -1 << endl;
      return 0;
    }
    
    mul *= A[i];
    
  }
  
  cout << mul << endl;
  
  return 0;
}


Measured memory_bytes: 4352
//#pragma GCC optimize(2)
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cstdio>    
#include<queue>    
#include<cmath>    
#include<vector>    
#include<cstring>   
#include<climits>    
#include<iostream>   
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
#define MAXN 200000
#define INF 0x3f3f3f3f
struct Edge{
	int v,nxt;
}edge[2*MAXN+5];
int ecnt,head[MAXN+5];
void Addedge(int u,int v){
	edge[++ecnt]=(Edge){v,head[u]},head[u]=ecnt;
	edge[++ecnt]=(Edge){u,head[v]},head[v]=ecnt;
	return ;
}
int fa[MAXN+5],mx[MAXN+5];
void DFS(int u){
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].v;
		if(v==fa[u]) continue;
		fa[v]=u,mx[v]=max(mx[u],v),DFS(v);
	}
	return ;
}
map<pair<int,int>,int> Map;
int Q(int u,int val){
	if(Map.count(make_pair(u,val)))
		return Map[make_pair(u,val)];
	int ret=1;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].v;
		if(v==fa[u]||v>val) continue;
		ret+=Q(v,val);
	}
	return Map[make_pair(u,val)]=ret;
}
int c[MAXN+5];
void Solve(int u){
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].v;
		if(v==fa[u]) continue;
		if(v==mx[v])
			c[v]=c[u]+Q(v,mx[u]);
		else if(u==mx[u]){
			if(v>mx[fa[u]])
				c[v]=c[u]+Q(v,mx[u]);
			else 	
				c[v]=c[u]+Q(v,mx[u])-Q(v,mx[fa[u]]);
		}
		else
			c[v]=c[u];
		Solve(v);
	}
	return ;
}
int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Addedge(u,v);
	}
	mx[1]=1,DFS(1);
	c[1]=1,Solve(1);
	for(int i=2;i<=n;i++)
		printf("%d ",c[i]-1);
	return 0;
}

Measured memory_bytes: 44208
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int n2 = 0;
    int n4 = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 4 == 0) ++n4;
        else if (a % 2 == 0) ++n2;
    }

    int odd = n - n4 - n2;
    if (n2 == 0) {
        if (odd <= n4 + 1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        if (odd <= n4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a, b, c, num;
	int i, temp;

	scanf("%d", &num);
	for (i = 0; i < num; i++) {

		scanf("%d %d %d", &a, &b, &c);

		if (a < b) {
			temp = a;
			a = b;
			b = temp;
		}

		if (a < c) {
			temp = a;
			a = c;
			c = temp;
		}


		if (a*a == b*b + c*c)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int count=0;
  vector<int>wcount(n);
  for(int i=0;i<n;i++){
    if(s[i]=='W')count++;
    wcount[i]=count;
  }
  int MIN=INF;
  for(int i=0;i<n;i++){
    if(s[i]=='W'){
      MIN=min(MIN,n-1-i-(count-wcount[i])+wcount[i]-1);
    }
    else {
      MIN=min(MIN,n-1-i-(count-wcount[i])+wcount[i]);
    }
  }
  cout<<MIN<<endl;
}

Measured memory_bytes: 1796