akhauriyash/Code-Regression huggingface dataset:
def red(n):
    if n < 3:
        return 0
    elif n == 3:
        return 1
    memo = [0] * (n+1)
    memo[3] = 1
    rem = 10**9 + 7
    for i in range(4,n+1):
        memo[i] = (memo[i-1] + memo[i-3]) % rem
    return memo[n] % rem

n = int(input())
print(red(n))

Measured memory_bytes: 63164
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    map<int, int> m;
    for (int i = 0; i < n; ++i) {
        m[a[i]] += 1;
    }
    if (m.size() > 2) {
        cout << "No" << endl;
        return 0;
    }
    int A = (--m.end())->first, cntA = (--m.end())->second;
    if (m.size() == 1) {
        if (cntA >= 2 * A || A == cntA - 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        return 0;
    }
    int A_1 = m.begin()->first, cntA_1 = m.begin()->second;
    if (A_1 + 1 == A && cntA >= 2 * (A - cntA_1) && cntA_1 < A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	if (b < a || (n == 1 && a != b)) return 0 * puts("0");
	long long A = a * n - a + b,B = b * n - b + a;
	cout << B - A + 1 << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    I vec;
    map<int,int> mp;
    REP(a,N){
        CIN(b);
        vec.pb(b);
        if(mp.find(b)==mp.end()){
            mp[b]=1;
        }else {
            mp[b]++;
        }
    }
    int ans = 0;
    for(P a : mp){
        if(a.second%2==1){
            ans++;
        }
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000+5
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f){
    f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
string s;
int q;
bool flag=0;
char pre[DMAX],suf[DMAX];
int pcnt,scnt;
int main(){
    cin>>s;
    read(q);
    int ope,f;
    char c;
    while(q--){
        read(ope);
        if(ope==1){
            flag^=1;
        }
        if(ope==2){
            read(f);
            cin>>c;
            if(f==1){
                if(!flag){
                    pre[++pcnt]=c;
                }
                else{
                    suf[++scnt]=c;
                }
            }
            if(f==2){
                if(!flag){
                    suf[++scnt]=c;
                }
                else{
                    pre[++pcnt]=c;
                }
            }
        }
    }
    if(flag){
        for(int i=scnt;i>=1;i--){
            printf("%c", suf[i]);
        }
        for(int i=s.size()-1;i>=0;i--){
            cout<<s[i];
        }
        for(int i=1;i<=pcnt;i++){
            printf("%c", pre[i]);
        }
        printf("\n");
    }
    else{
        for(int i=pcnt;i>=1;i--){
            printf("%c", pre[i]);
        }
        cout<<s;
        for(int i=1;i<=scnt;i++){
            printf("%c", suf[i]);
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define llint long long int
#define ldouble long double

using namespace std;

int main() {
    vector<int> a(6);
    for(int i=0;i<6;i++){
        cin>>a.at(i);
    }

    bool jg=true;

    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(abs(a.at(i)-a.at(j))>a.at(5)){
                jg=false;
            }
        }
    }

    if(jg==false){
        cout<<":("<<endl;
    }
    else{
        cout<<"Yay!"<<endl;
    }
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const ll INF = 1LL << 60;

int main(){
 int n;
 cin >> n;
 priority_queue<int,vector<int>,greater<int>> rq;
 priority_queue<int> bq;
 vector<int> v(3*n);
 ll rans[100009];
 ll bans[100009];
 rep(i,n*3){
   cin >> v[i];
 }
 rep(i,n){
   rq.push(v[i]);
 }
 for (int w=2*n;w < 3*n;w++){
   bq.push(v[w]);
 }
 ll rsum=0,bsum=0;
 ll ans=-INF;
 rep(i,n){
   rsum+=v[i];
 }
 for (int r = 3*n-1; r  > 2*n-1; r--){
   bsum+=v[r];
 }
rans[0]=rsum;
bans[n]=bsum; 
  //printf("now : %d rsum : %lld bsum : %lld\n",now,rsum,bsum);
 int id=1;
 for (int j=n;j < n+n;j++){
     rq.push(v[j]);
     int tmp = rq.top();rq.pop();
     rsum+=v[j]-tmp;
     rans[id]=rsum;
     id++;
 }
 id=n-1;
 for (int j=2*n-1;j >= n-1;j--){
   bq.push(v[j]);
   int tmp = bq.top();bq.pop();
   //printf("now bsum : %lld\n",bsum);
   bsum+=v[j]-tmp;
   //printf("v[j] : %d\n",v[j]);
   //printf("bsum : %lld tmp : %d\n",bsum,tmp);
   bans[id]=bsum;
   id--;
 }
 for (int i = 0;i <= n;i++){
   ans=max(ans,rans[i]-bans[i]);
 }
 cout << ans << endl;
 return 0; 
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
 
int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    vector<int> q(n);
    rep(i,n) cin >> q[i];
    int ans = 0;
    if(p > q) swap(p,q);
    while(p < q){
        next_permutation(p.begin(),p.end());
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

constexpr int N = 5e5 + 10;
constexpr int MOD = 1e9 + 7;

int n, k, a[N], fen[N], p[N], d[N], lazy[4 * N];
pair <int, int> tree[4 * N];

void upd (int x, int val) {
    for (; x < N; x += x & (-x))
        fen[x] += val;
}

int get (int x) {
    int ret = 0;
    for (; x; x -= x & (-x))
        ret += fen[x];
    return ret;
}

void build (int b, int e, int idx) {
    if (b + 1 == e) {
        tree[idx] = {d[b], b};
        return;
    }
    int mid = (b + e) >> 1,
                lidx = idx << 1, ridx = lidx | 1;
    build (b, mid, lidx);
    build (mid, e, ridx);
    if (tree[ridx].first <= tree[lidx].first)
        tree[idx] = tree[ridx];
    else
        tree[idx] = tree[lidx];
}

void shift (int b, int e, int idx) {
    int lidx = idx << 1, ridx = lidx | 1;
    tree[lidx].first -= lazy[idx];
    tree[ridx].first -= lazy[idx];
    lazy[ridx] += lazy[idx];
    lazy[lidx] += lazy[idx];
    lazy[idx] = 0;
}

void dec (int b, int e, int l, int r, int idx) {
    if (b >= r || e <= l)
        return;
    if (b >= l && e <= r) {
        tree[idx].first--;
        lazy[idx]++;
        return;
    }
    int mid = (b + e) >> 1,
                lidx = idx << 1, ridx = lidx | 1;
    shift (b, e, idx);
    dec (b, mid, l, r, lidx);
    dec (mid, e, l, r, ridx);
    if (tree[ridx].first <= tree[lidx].first)
        tree[idx] = tree[ridx];
    else
        tree[idx] = tree[lidx];
}

void change (int b, int e, int pos, int idx) {
    if (b + 1 == e) {
        tree[idx] = {1e9, b};
        return;
    }
    int mid = (b + e) >> 1,
                lidx = idx << 1, ridx = lidx | 1;
    shift (b, e, idx);
    if (pos >= mid)
        change (mid, e, pos, ridx);
    else
        change (b, mid, pos, lidx);
    if (tree[ridx].first <= tree[lidx].first)
        tree[idx] = tree[ridx];
    else
        tree[idx] = tree[lidx];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++) {
        upd (a[i], 1);
        if (i > k)
            upd (a[i - k], -1);
        d[i] = get (N - 1) - get (a[i]);
    }
    memset (fen, 0, sizeof (fen));
    for (int i = n; i; i--) {
        upd (a[i], 1);
        if (i <= n - k)
            upd (a[i + k], -1);
        d[i] += get (N - 1) - get (a[i]);
    }
    build (1, n + 1, 1);
    int now = n;
    while (now) {
        int pos = tree[1].second;
        p[pos] = now;
        now--;
        dec (1, n + 1, max (1, pos - k + 1), min (n + 1, pos + k), 1);
        change (1, n + 1, pos, 1);
    }
    for (int i = 1; i <= n; i++)
        cout << p[i] << '\n';
    return 0;
}


Measured memory_bytes: 28672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, K; cin >> N >> K;
  vector<int> v;
  rep(i, K) {
    int x; cin >> x;
    v.push_back(x);
  }

  while(1) {
    string s = to_string(N);
    int n = s.size();
    bool ng = 0;
    rep(i, n) {
      if(find(all(v), s[i] - '0') != v.end()) {
        ng = 1;
        break;
      }
    }
    if(!ng) {
      cout << N << endl;
      return 0;
    }
    N++;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*
  || Shree Ganeshay Namah ||

     || Jai Shree Ram ||
  || Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define mod 1000000007
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
#define pb push_back
// to floor a/b you can do a/b and to ceiling a/b you can do (a+b-1)/b
int jai_shree_ram()
{
    return 1;
}
int shree_ganeshay_namah()
{
    return 1;
}
ll power(ll x,ll y)
{
    ll r=1;
    while(y>0)
    {
        if(y%2!=0)
            r=(r%mod * x%mod)%mod;
        x=(x%mod * x%mod)%mod;
        y=y/2;
    }
    return r;
}
ll ncr(ll n,ll k)
{

    ll c[k+1];
    memset(c,0,sizeof(c));
    c[0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=min(i,k);j>0;j--)
            c[j]=(c[j]%mod + c[j-1]%mod)%mod;
    }
    return c[k];
}

bool prime[1001];
void sieve()
{
    ll i,j;
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(i=2;i<=sqrt(100);i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=100;j=j+i)
                prime[j]=false;
        }
    }
}
//Start of Matrix Exponentiation Code
void mat_mul(ll F[2][2],ll M[2][2]) {
   ll a = ((F[0][0]%mod * M[0][0]%mod)%mod + (F[0][1]%mod * M[1][0]%mod)%mod)%mod;
   ll b = ((F[0][0]%mod * M[0][1]%mod)%mod + (F[0][1]%mod * M[1][1]%mod)%mod)%mod;
   ll c = ((F[1][0]%mod * M[0][0]%mod)%mod + (F[1][1]%mod * M[1][0]%mod)%mod)%mod;
   ll d = ((F[1][0]%mod * M[0][1]%mod)%mod + (F[1][1]%mod * M[1][1]%mod)%mod)%mod;
   F[0][0] = a;
   F[0][1] = b;
   F[1][0] = c;
   F[1][1] = d;
}
void mpower(ll F[2][2], ll n) {
   if (n == 0 || n == 1)
      return;
   ll M[2][2] = {{1,1},{1,0}};
   mpower(F, n / 2);
   mat_mul(F, F);
   if (n % 2 != 0)
      mat_mul(F, M);
}
ll fib_mat(ll n) {
   ll F[2][2] = {{1,1},{1,0}};
   if (n == 0)
      return 0;
   mpower(F, n - 1);
   return F[0][0]%mod;
}
//End of Matrix Exponentiation
/*
Segment Tree
ll ar[200005];
ll st[800005];
void build(ll si,ll ss,ll se)
{
    if(ss==se)
    {
        st[si]=ar[ss];
        return ;
    }
    ll mid=(ss+se)/2;
    build(2*si,ss,mid);
    build(2*si+1,mid+1,se);
    st[si]=(st[2*si]+st[2*si+1]);
}
ll query(ll si,ll ss,ll se,ll l,ll r)
{

   if(l<=ss && se<=r)
     return st[si];
   if(l>se || r<ss)
    return 0;
   ll mid=(ss+se)/2;
   ll x=query(2*si,ss,mid,l,r);
   ll y=query(2*si+1,mid+1,se,l,r);
   return x+y;
}
void update(ll si,ll ss,ll se,ll qi)
{
    if(ss==se)
    {
        st[si]=ar[ss];
        return;
    }
    ll mid=(ss+se)/2;
    if(qi<=mid)
        update(2*si,ss,mid,qi);
    else
        update(2*si+1,mid+1,se,qi);
    st[si]=st[2*si]+st[2*si+1];
}
*/


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    ll n,i,j;
    cin>>n;
    ll a[n],m=0;
    ll f=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(i!=0)
        {
            if(a[i]<m)
                f=f+m-a[i];
        }
        m=max(m,a[i]);
    }
    cout<<f;
	return 0;
}


Measured memory_bytes: 5216
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5&&b==7&&c==5||a==5&&b==5&&c==7||a==7&&b==5&&c==5){printf("YES\n");}else{printf("NO\n");}
    return 0;
}

Measured memory_bytes: 128
h, w, k = map(int, input().split())
mark = [input() for _ in range(h)]
ans = 0

for bit_h in range(1 << h):
  i_list = []
  for i in range(h):
    if bit_h & 1:
      i_list.append(i)
    bit_h >>= 1
  for bit_w in range(1 << w):
    count = 0
    j_list = []
    for j in range(w):
      if bit_w & 1:
        j_list.append(j)
      bit_w >>= 1
    for i in i_list:
      for j in j_list:
        if mark[i][j] == '#':
          count += 1
    if count == k:
      ans += 1
print(ans)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    REP(i, n){
        cin >> a[i];
    }
    REP(i, m){
        cin >> b[i];
    }
    vector<ll> a_ruiseki(n+1, 0);
    REP(i, n){
        a_ruiseki[i+1] = a_ruiseki[i] + a[i];
    }

    vector<ll> b_ruiseki(m+1, 0);
    REP(i, m){
        b_ruiseki[i+1] = b_ruiseki[i] + b[i];
    }

    ll ans = 0;
    ll now_time = 0;
    REP(i, n+1){
        if(a_ruiseki[i] > k) continue;
        auto ite = lower_bound(b_ruiseki.begin(), b_ruiseki.end(), k - a_ruiseki[i]);
        if(*ite != k - a_ruiseki[i]){
            ite --;
        }
        chmax(ans, i + ll(ite - b_ruiseki.begin()));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9580
#include <iostream>

using namespace std;

int main()
{
    char a;
    char b[1201];
    cin.get(b,1201);
    int c = 1200;
    int d = -1;
	while(c--)
	{
	    d++;
	    a = b[d];
		if(a >= 97 && a <= 122 )
			a-=32;
		else if(a >= 65 && a<=90)
			a+=32;
        else if(a == '\0')
        {
            cout<<endl;
            break;
        }
        cout<<a;
	}
	return 0;
}


Measured memory_bytes: 3060
n=int(input())
# a,b,c=map(int,input().split())
cnt=0
def gcd(a,b):
    if a==0: return b
    else: return gcd(b%a,a)
# print(gcd(a,b))

def gcd_3(a,b,c):
    if gcd(a,b)==0: return c
    else: return gcd(c % gcd(a,b),gcd(a,b))

for i in range(1,n+1):
    for j in range ( 1 , n + 1 ):
        for k in range ( 1 , n + 1 ):
            # print(i,j,k)
            cnt+=gcd_3(i,j,k)
print(cnt)


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

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//

int main() {
    IOS
    ll n, a, b;
    cin >> n;
    cin >> a >> b;

    if (a > b)
        swap(a, b);
    if ((b - a) % 2 == 0) {
        cout << (b - a) / 2;
        return 0;
    } else {
        ll la = 0;
        ll ra = 0;
        la += (a - 1) + 1 + (b - a) / 2;
        ra += (n - b) + 1 + (b - a) / 2;
        cout << min(la, ra);
    }

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int mod = 1e9+7;
int add(int a, int b) { return (a+b)%mod; }
int sub(int a, int b) { return (a-b+mod)%mod; }
int mult(int a, int b) { return (long long) a*b%mod; }
int n;
string s;
int dp[5005][5005];
int main() {
cin >> n >> s;
dp[0][s.length()] = 1;
for (int i=0;i<n;i++) {
for (int j=0;j<5004;j++) {
if (j==0) {
dp[i+1][0] = add(dp[i+1][0],dp[i][j]);
} else {
dp[i+1][j-1] = add(dp[i+1][j-1],dp[i][j]);
}
dp[i+1][j+1] = add(dp[i+1][j+1],mult(dp[i][j],2));
}
}
cout << dp[n][0];
}

Measured memory_bytes: 98048
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;
#define SORTVL(v) sort(v.begin(), v.end());
#define SORTVL_GR(v) sort(v.begin(), v.end(), greater<LL>());

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }
// 末尾数字で切り上げ
LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; }
//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

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

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N, D;
	cin >> N >> D;

	LL cover = D * 2 + 1;
	O(ceil((double)N / cover));

	return 0;
}

Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
    [n, x] <- map ( read :: String -> Int) . words <$> getLine
    mass <- map ( read :: String -> Int ) <$> replicateM n getLine
    let
        massMin = minimum mass
        massSum = sum mass
        result = n + ( x - massSum ) `div` massMin
    print result


Measured memory_bytes: 892
#include <stdio.h>
#include <math.h>
typedef long long ll;

ll sum(ll a) {
  ll ans = 0;
  while(a) ans += a % 10, a /= 10;
  return ans;
}

ll powi(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans *= a;
    a *= a, b >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, a, n, m, ans = 0;
  scanf("%lld%lld%lld", &a, &n, &m);
  for(i = 1; powi(i, n) <= m; ++i) if(powi(i, n) == powi(sum(powi(i, n)) + a, n)) ++ans;
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 2732
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    vector<pair<int, int>> ab(n);
    for (int i = 0; i < n; i++)
        cin >> ab[i].first >> ab[i].second;

    sort(ab.begin(), ab.end());
    const int ans = ab.back().first + ab.back().second;

    cout << ans << endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
long long X;
long long K;
long long D;
int main(){
  long long i;
  long long j;
  long long k;
  rd(X);
  rd(K);
  rd(D);
  X =max_L(-X, X);
  i =min_L(K, X / D);
  K -= i;
  X -= i * D;
  K %= 2;
  if(K){
    X -= D;
    X =max_L(-X, X);
  }
  wt_L(X);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200813-1 [beta]

// --- original code ---
// ll X, K, D;
// {
//   ll i, j, k;
//   rd(X, K, D);
//   X = max(-X, X);
//   i = min(K, X / D);
//   K -= i;
//   X -= i * D;
//   K %= 2;
//   if(K){
//     X -= D;
//     X = max(-X, X);
//   }
//   wt(X);
// }


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);
 
//firstに素因数、secondに素因数が何個あるか
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}
 
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    ll n;
    cin>>n;
    vector<pair<ll,ll>> v = prime_factorize(n);
    ll ans = 0;
    for(int i=0;i<v.size();i++){
        ll now = v[i].first;
        for(int j=1;j<=v[i].second;j++){
            if(v[i].second >= j){
                v[i].second -= j;
                n /= now;
                ans++;
            }
        }
    }
    cout << ans << endl;
    
 
}

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

long d;
long c[26];
long s[365][26];
long t[365];
long last[26];

long nowAns;

long calcMinus(int day,long* last);
long calcScore();

int main(){
    nowAns = 0;
    d = 365;
    cin >> d;
    for(int i=0;i<26;i++)cin >> c[i];
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    srand(1);

    for(int i=0;i<365;i++){
        t[i] = rand()%26 + 1;
    }
    nowAns = calcScore();

    for(int i=0;i<d;i++){
        cout << t[i]<<endl;
    }
    
}


long calcMinus(int day,long* tmplast){

    long ans = 0;
    for(int i=0;i<26;i++){
        ans -= c[i] * (day - tmplast[i]);
    }

    return ans;
}

long calcScore(){
    long ans = 0;

    long tmplast[26];
    for(int i=0;i<26;i++){
        tmplast[i] = -1;
    }

    for(int i=0;i<d;i++){
        tmplast[t[i]-1] = i;
        ans += s[i][t[i]-1];
        ans += calcMinus(i,tmplast);
    }
    return ans;
    
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

constexpr int64_t mod = 1000000000 + 7;
bool check[1001];

int main(){
    int64_t N;
    cin >> N;
    
    int64_t ans = 1;
    for(int i = 2; i <= N; ++i){
        bool check = true;
        for(int j = 2; j * j <= i; ++j){
            if(i % j == 0){
                check = false;
                break;
            }
        }
        if(!check) continue;
        int64_t cnt = 0;
        for(int j = i; j <= N; ++j){
            int64_t po = j;
            while(po % i == 0){
                po /= i;
                ++cnt;
            }
        }
        ans *= (1 + cnt);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy3


def in_place_solve(n, bs):
    # sentinel
    bs.insert(0, 0)
    rev_ops = []
    for i in range(1, n + 1)[::-1]:
        for j in range(1, i + 1)[::-1]:
            if bs[j] == j:
                rev_ops.append(j)
                del bs[j]
                break
        else:
            return False, None
    return True, rev_ops[::-1]


def main():
    n = int(input())
    bs = [int(z) for z in input().split()]
    is_possible, ops = in_place_solve(n, bs)
    if not is_possible:
        print(-1)
    else:
        print(*ops, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38768
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M;
  cin >> N >> M;
  ll ans;
  if (N == 1 && M == 1) {
    ans = 1;
  } else if (N == 1 || M == 1) {
    ans = max(N, M) - 2;
  } else {
    ans = (N * M) - (2 * N + 2 * M - 4);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]


colors = []

#後ろから見ていく
for i,n in enumerate(list(reversed(A))):
    # 一つ目はとりあえずなんか一色ぬる
    if i == 0:
        colors.append(n)
    else:
        #二つ目以降は、各色の最小値のなかで、今見ているのより小さいものがあればそれを置き換える
        #ここをbisect_leftにすると、colorsの中で同じ最小値があるときにinsertが必要なので遅い
        # 「各色の最小値集合の最小値と置き換える」を繰り返すので、最小値集合の最大より大きいなら最後に追加
        idx = bisect.bisect_right(colors, n)
        if idx == len(colors):
            colors.append(n)
        else:
            colors[idx] = n

print(len(colors))

Measured memory_bytes: 56536
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;


ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	ll r;
	while (a%b != 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return b;
}

ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> res;
	for (ll i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;//
	return res;
}

map<ll,ll> mp[10001];
map<ll,ll>M;
ll A[10001];

int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	ll N; cin >> N;
	FOR(i, 0, N) {
		cin >> A[i];
		mp[i] = prime_factor(A[i]);
		for (auto ite = mp[i].begin(); ite != mp[i].end(); ite++) {
			M[ite->first] = max(ite->second, M[ite->first]);
		}
	}
	ll ans = 0;
	ll cur = 1;
	for (auto ite = M.begin(); ite != M.end(); ite++) {
		cur = (cur *mod_pow(ite->first, ite->second)) % mod;
	}
	FOR(i, 0, N) {
		ll p = cur;
		p = (cur * mod_pow(A[i], mod - 2))%mod;
		ans = (ans+p)%mod;
	}
	cout << ans << endl;







	


}


Measured memory_bytes: 7256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
long int num[300000]={1,1};
int main(){

long int n,i,j;
 
for(i=3;i<300000;i+=2){
if(num[i]==1)
continue;
for(j=3*i;j<300000;j+=i*2)
num[j]=1;
}
for(i=4;i<300000;i+=2)
num[i]=1;
 

while(cin>>n,n){
long int co=0;
loop(i,n+1,2*n+1){
if(!num[i])co++;
}
cout<<co<<endl;
}
}

Measured memory_bytes: 3504
#include<cstdio>

int main(void) {
    int n;
    char s[1000];
    scanf("%d",&n);
    scanf("%s",s);

    int c=0;
    int a=0;
    for(int i=0; i<n; i++) {
        if(s[i] == ')') {
            c--;
            if(c < 0)
                a++, c++;
        } else {
            c++;
        }
    }

    for(int i=0; i<a; i++)
        printf("(");
    printf("%s", s);
    for(int i=0; i<c; i++)
        printf(")");
    printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    string c;
    cin >> c;
    int r = N-1; //左端のRの位置
    RREP(i,N){
        r = i;
        if(c[i]=='R')break;
    }
    if(r==0){
        pr(0);
        return 0;
    }
    int ans = 0;
    REP(i, N){
        if(c[i]=='W'){
            ans++;
            //R更新
            for(int j = r-1; j > i; j--){
                r = j;
                if(c[j]=='R')break;
            }
            if(r<=(i+1)){
                pr(ans);return 0;
            }
        }
        if(r<=(i+1)){
            pr(ans);return 0;
        }
    }
    pr(0);
    return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

const int N = 4000 + 7;

int n, m;
int x[N], y[N];
std::set<int> s[N];
int z[N];
int p;

std::vector<int> e[N];
int f[N], d[N];
int dfn[N], dfc;
void dfs(int s) {
	std::sort(e[s].begin(), e[s].end());
	if (f[s]) e[s].erase(std::lower_bound(e[s].begin(), e[s].end(), f[s]));
	dfn[++dfc] = s;
	for (auto t : e[s]) f[t] = s, d[t] = d[s] + 1, dfs(t);
}

int vf[N];
int getvf(int x) {
	return vf[x] == x ? x : vf[x] = getvf(vf[x]);
}
void merge(int x, int y) {
	vf[getvf(x)] = getvf(y);
}

int exist(int x, int y) {
	return s[x].find(y * 2) != s[x].end() || s[x].find(y * 2 + 1) != s[x].end();
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, u, v; i < n; ++i)
		scanf("%d%d", &u, &v), e[u].push_back(v), e[v].push_back(u);
	dfs(1);

//	for (int i = 1; i <= n; ++i)
//		printf("%d ", f[i]);
//	printf("\n");
//	for (int i = 1; i <= n; ++i)
//		printf("%d ", d[i]);
//	printf("\n");

	for (int i = 1; i <= m; ++i)
		scanf("%d%d", x + i, y + i);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", x + i, y + i);
		for (int u = x[i], v = y[i]; u != v; )
			d[u] > d[v] ? (s[u].insert(i * 2), u = f[u]) : (s[v].insert(i * 2 + 1), v = f[v]);
	}
	for (int i = 1; i <= m * 2; ++i) vf[i] = i;
	
//		printf("#\n");
//		for (int q = 2; q <= n; ++q) {
//			printf("%d | ", q);
//			for (auto p : s[q])
//				printf("%d(%d) ", p / 2, p & 1);
//			printf("\n");
//		}
//		for (int i = 1; i <= m; ++i)
//			printf("%d ", getvf(i));
//		printf("\n");
//		for (int i = 1; i <= m; ++i)
//			printf("%d ", getvf(i + m));
//		printf("\n");
//		printf("\n");
	
	for (int i = 1; i <= n; ++i)
		p += std::min(2, int(s[dfn[i]].size()));
	for (int i = n, j, k, l; i; --i) {
		if (s[dfn[i]].size() < 2 || z[dfn[i]]) continue;
		j = *s[dfn[i]].begin();
		k = *++s[dfn[i]].begin();
		l = (j ^ k) & 1 ^ 1;
		for (int q = 1; q <= n; ++q)
			if (exist(q, j / 2) && exist(q, k / 2))
				s[q].erase(j), s[q].erase(j ^ 1), s[q].erase(k), s[q].erase(k ^ 1), z[q] = 1;
		for (int q = 1; q <= n; ++q) {
			if (s[q].find(j) != s[q].end())
				s[q].erase(j), s[q].insert(k / 2 * 2 + (j & 1 ^ l));
			if (s[q].find(j ^ 1) != s[q].end())
				s[q].erase(j ^ 1), s[q].insert(k / 2 * 2 + (j & 1 ^ 1 ^ l));
		}
//		printf("dfn[i] = %d j = %d k = %d l = %d\n", dfn[i], j, k, l);
		merge(k / 2, j / 2 + m * l),
		merge(k / 2 + m, j / 2 + m * (l ^ 1));
		
//		printf("#\n");
//		for (int q = 2; q <= n; ++q) {
//			printf("%d | ", q);
//			for (auto p : s[q])
//				printf("%d(%d) ", p / 2, p & 1);
//			printf("\n");
//		}
//		for (int i = 1; i <= m; ++i)
//			printf("%d ", getvf(i));
//		printf("\n");
//		for (int i = 1; i <= m; ++i)
//			printf("%d ", getvf(i + m));
//		printf("\n");
//		printf("\n");
	}

	printf("%d\n", p);
	for (int i = 1; i <= m; ++i) {
		if (getvf(1) != getvf(i) && getvf(1) != getvf(i + m)) merge(1, i);
		getvf(1) == getvf(i) ? printf("%d %d\n", x[i], y[i]) : printf("%d %d\n", y[i], x[i]);
	}
	return 0;
}

Measured memory_bytes: 56704
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var Li = RL2IE().ToList();
            long ret = 0;
            var N = Li[0];
            var X = Li[1];
            var T = Li[2];

            var cnt = N / X;
            if (N % X != 0) cnt++;
            ret = cnt * T;


            Console.WriteLine(ret);
            Console.ReadLine();

        }

        static IEnumerable<long> RL2IE() { return spr(RL()).Select(x => (long)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 28232
// B - バイナリハックイージー

// A - キャンディーとN人の子供イージー
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n;

  repe(i, 1, n)
  {
    ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  vector<int> A(5);
  REP(i, 5) A[i] = i + 1;
  REP(i, 5) { int a;
    cin >> a;
    if(A[i]!=a){
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999

struct xyt{
	int x, y, ti;
};

bool map[123][123], check[123][123];
queue <xyt> q;
int ans;

void search(int x,int y, int n, int t){
	int d[6][2] = {{1,1},{1,0},{0,1},{-1,0},{0,-1},{-1,-1}};
	xyt s;
	//cout << x-61 << " " << y-61;
	ans++;
	if(n<t){
		for(int k=0;k<6;k++){
			if(map[x+d[k][0]][y+d[k][1]]==0 && check[x+d[k][0]][y+d[k][1]]==0){
				check[x+d[k][0]][y+d[k][1]]=1;
				s.x = x+d[k][0];
				s.y = y+d[k][1];
				s.ti = n+1;
				q.push(s);
			}
		}
	}
	q.pop();
	if(!q.empty())search(q.front().x, q.front().y, q.front().ti, t);
}

int main(){
	int i, j, t, n, x, y;
	while(1){
		cin >> t >> n;
		if(t==0&&n==0) break;
		for(i=-61;i<=61;i++){
			for(j=-61;j<=61;j++){
				check[i+61][j+61] = 0;
				if(i==-61||i==61) map[i+61][j+61] = 1;
				else if(j==-61||j==61) map[i+61][j+61] = 1;
				else map[i+61][j+61] = 0;
			}
		}
		for(i=0;i<n;i++){
			cin >> x >> y;
			map[x+61][y+61] = 1;
		}
		ans = 0;
		cin >> x >> y;
		check[x+61][y+61] = 1;
		xyt a;
		a.x = x + 61;
		a.y = y +61;
		a.ti = 0;
		q.push(a);
		search(q.front().x, q.front().y, q.front().ti, t);
		cout << ans << endl;
	}
	return 0;
}

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

int main(int argc, const char * argv[]) {
    int t[100001] = {0};
    int x[100001] = {0};
    int y[100001] = {0};
    int N;
    
    cin >> N;
    t[0] = x[0] = y[0] = 0; // start point is (0, 0)
    for (int i = 1; i <= N; i++) {
        cin >> t[i];
        cin >> x[i];
        cin >> y[i];
    }
    
    bool isPossible = true;
    for (int i = 0; i < N; i++) {
        int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        int tm = t[i + 1] - t[i];
        int t_mod = tm % 2;
        int d_mod = dist % 2;
        if (tm < dist || t_mod != d_mod) {
            isPossible = false;
        }
    }
    
    if (isPossible) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#define N 50000
struct jeep{
  int key;
  struct jeep *right;
  struct jeep *left;
  struct jeep *parent;
};
typedef struct jeep * com;
void insert(int);
void pre(com);
void in(com);
int search(com, int);
com root;
int main(){
  com z;
  int key,total,i,x,divala;
  char A[N];
  scanf("%d",&total);
  for(i = 0 ; i < total ; i++){
    scanf("%s",A);
      if ( A[0] == 'i' ){
        scanf("%d",&key);
        insert(key);
      }
      else if ( A[0] == 'p' ){
        in(root);
        printf("\n");
        pre(root);
        printf("\n");
      }
      else if ( A[0] == 'f' ){
        scanf("%d",&key);
        divala = search(root,key);

        if(divala == 1) printf("yes\n");
        else if(divala == 0) printf("no\n");
      }
  }
  return 0;
}
void insert(int k){
  com x= root;
  com y = NULL;
  com z;
  z = malloc(sizeof(struct jeep));
  z->key = k;
  z->left = NULL;
  z->right = NULL;
  while(x!=NULL){
    y = x;
    if(z->key < x->key){
      x = x->left;    }
    else{
      x = x->right;
    }
  }
  z->parent= y;
  if(y==NULL){
    root = z;
  }
  else if(z->key<y->key){
    y->left =z;
  }
  else{
    y->right =z;
  }
}
void in(com A){
  if(A != NULL){
    in(A->left);
    printf(" %d",A->key);
    in(A->right);
  }
}
   void pre(com A){
  if(A!=NULL){
    printf(" %d",A->key);
    pre(A->left);
    pre(A->right);
  }
}
int search(com A, int key){
   if(A == NULL) return 0;
  else if(A->key == key) return 1;

  if(key < A->key)  return search(A->left,key);
  else  return search(A->right,key);

}


Measured memory_bytes: 20548