akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    ll n;
    cin >> n;
    if(n % 2 == 1){
        cout << n * (n / 2) << endl;
    }else{
        cout << n * (n / 2 - 1) + n / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ; 
  intll total = 0 ;
  vector<intll> v(n+2) ;
  v.at(0) = 0 ;
  v.at(n+1) = 0 ;
  rep(i,n+1) {
    cin >> v.at(i+1) ; 
    total +=abs(v.at(i) - v.at(i+1))  ;
  }
  
  
  rep(i,n){
    intll ans = total - abs(v.at(i) - v.at(i+1)) - abs(v.at(i+1) -v.at(i+2)) + abs(v.at(i) -v.at(i+2)) ;
    cout << ans << endl ;
  }
    
  


}


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

int main()
{
    int d,s,t;
    int flag=0,ct=0;

    cin>>d>>s>>t;


    for(int i=0; i<=s; i++)
    {
        flag=t*i;
        if(flag<d)
        {
            ct++;
        }

    }
    if(ct<=s)
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}



Measured memory_bytes: 3592
//D
#include<bits/stdc++.h>
using namespace std;
int n;
char line[20];
int cnt[26];

void dfs(int u){
    int i,mx;
    if(u==n) {
            for(i=0;i<n;i++) cout<<line[i];
            puts("");
            return;
    }
    for(i=0;i<26;i++) {
        if(cnt[i]) mx=i;}
    for(i=0;i<=mx+1;i++){
            //cout<<mx+1<<endl;
            line[u]='a'+i;
            cnt[line[u]-'a']++;
            dfs(u+1);
            cnt[line[u]-'a']--;
    }
}
int main(){
    cin>>n;
    line[0]='a';
    cnt[0]=1;
    dfs(1);
}



Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

void visit(int x, int y, int w, int h, int **hor, int **ver, int **memo) {
  if (x == w-1 && y == h-1) return;
  if (x > 0 && ver[y][x] == 0 && memo[y][x] +1 < memo[y][x-1]) {
    memo[y][x-1] = memo[y][x] + 1;
    visit(x-1, y, w, h, hor, ver, memo);
  }
  if (y > 0 && hor[y][x] == 0 && memo[y][x] +1 < memo[y-1][x]) {
    memo[y-1][x] = memo[y][x] + 1;
    visit(x, y-1, w, h, hor, ver, memo);
  }
  if (x < w-1 && ver[y][x+1] == 0 && memo[y][x] +1 < memo[y][x+1]) {
    memo[y][x+1] = memo[y][x] + 1;
    visit(x+1, y, w, h, hor, ver, memo);
  }
  if (y < h-1 && hor[y+1][x] == 0 && memo[y][x] +1 < memo[y+1][x]) {
    memo[y+1][x] = memo[y][x] + 1;
    visit(x, y+1, w, h, hor, ver, memo);
  }
}

int main() {
  int w, h, tmp;
  while (cin >> w >> h, w | h) {
    int hor[h+1][w], ver[h][w+1], memo[h][w];
    //initialize
    for (int i = 0; i < h+1; i++) {
      for (int j = 0; j < w; j++) {
        hor[i][j] = 1;
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w+1; j++) {
        ver[i][j] = 1;
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        memo[i][j] = INF;
      }
    }
    memo[0][0] = 1;
    //input
    for (int i = 0; i < 2*h-1; i++) {
      if (i & 1) {
        for (int j = 0; j < w; j++) {
          cin >> tmp;
          hor[i/2+1][j] = tmp;
        }
      } else {
        for (int j = 0; j < w-1; j++) {
          cin >> tmp;
          ver[i/2][j+1] = tmp;
        }
      }
    }
    int *hor_tmp[h+1], *ver_tmp[h], *memo_tmp[h];
    for (int i = 0; i < h; i++) {
      hor_tmp[i] = hor[i];
      ver_tmp[i] = ver[i];
      memo_tmp[i] = memo[i];
    }
    hor_tmp[h] = hor[h];
    visit(0, 0, w, h, hor_tmp, ver_tmp, memo_tmp);
    if (memo[h-1][w-1] == INF) cout << "0" << el;
    else cout << memo[h-1][w-1] << el;
  }
}

Measured memory_bytes: 1260
#include<iostream>
using namespace std;
 
int main(){
  int a, b;

  cin >> a >> b;
  if(a<b){
      cout << "a < b" << endl;
  }else if(a>b){
      cout << "a > b" << endl;
  } else {
      cout << "a == b" << endl;
  }
  return 0;		 
}


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

using namespace std;

int n, m;
char g[55][55];
const int dx[] = {0, 0, +1, -1};
const int dy[] = {+1, -1, 0, 0};
bool fit(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> g[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == '#') {
        int cnt = 0;
        for (int k = 0; k < 4; ++k) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (fit(x, y) && g[x][y] == '#') {
            cnt++;
          }
        }
        if (cnt == 0) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  } 
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a; cin >> a;
	cout << a + a * a + a * a * a << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3612
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  items = input[1].split(' ').map(v => parseInt(v, 10))
  data = new Map()
  for (var i = 0; i < items.length; i++) {
    if (data.has(items[i])) {
      data.set(items[i], data.get(items[i]) + 1)
    } else {
      data.set(items[i], 1)
    }
  }

  sum = 0
  for (j of data.values()) {
    sum += Math.floor(j * (j - 1) / 2)
  }
  //文字列から10進数に変換するときはparseIntを使います
  // const a = parseInt(input[0], 10);
  //出力
  for (i = 0; i < items.length; i++) {
    console.log(sum - (data.get(items[i]) - 1))
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int d[101]={};
  int a,b,c,S=0;
  scanf("%d %d %d",&a,&b,&c);
  d[a]++;
  d[b]++;
  d[c]++;
  for(int i=1;i<=100;i++){
    if(d[i]>0) S++;
  }
  printf("%d\n",S);
  return 0;
}

Measured memory_bytes: 1676
//
//  main.cpp
//  ALDS1_10_A:FibonacciNumber
//
//  Created by Kang on 2020/8/12.
//  Copyright © 2020 Kang. All rights reserved.
//

#include <cstdio>
#include <cstring>
using namespace std;


int fiboFromTop(int n, int fibo[]) {
    if (fibo[n] != 0) {
        return fibo[n];
    }
    
    if (n == 0 || n == 1) {
        fibo[n] = 1;
        return 1;
    }
    else {
        fibo[n - 1] = fiboFromTop(n-1, fibo);
        fibo[n - 2] = fiboFromTop(n - 2, fibo);
        return fibo[n - 1] + fibo[n - 2];
    }
    
    
    return 0;
}

int fiboFromBottom(int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    int fibo[45];
    fibo[0] = 1;
    fibo[1] = 1;
    for (int i = 2; i <= n; i++) {
        fibo[i] = fibo[i-1] + fibo[i - 2];
    }
    return fibo[n];
}

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    int fibonacci[45];
    memset(fibonacci, 0, 45 * sizeof(int));
    scanf("%d", &n);
    
    printf("%d\n", fiboFromTop(n, fibonacci));
    // printf("%d\n", fiboFromBottom(n));
    
    return 0;
}



Measured memory_bytes: 2736
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;s[i];++i){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
}


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

    vector<vector<ll>> count(100, vector<ll>(5, 0));

    ll ans = 0;
    repd(i, 1, 100) {
        if (i > N) break;
        vector<ll> num;
        if (i % 10 == 0) continue;
        if (i < 10) {
            ll base = 10;
            num.push_back(1LL);
            ll tmp = i * base + i;
            //cout << i << ":" << tmp << endl;
            if (tmp <= N) num.push_back(1LL);
            base *= 10;
            tmp = i * base + i;
            //cout << i << ":" << tmp << endl;
            while (tmp <= N) {
                ll cnt = 0;
                rep(i, base / 10) {
                    if (tmp + i * 10 <= N) {
                        cnt++;
                        //cout << i << ":" << tmp + i * 10 << endl;
                    }
                }
                num.push_back(cnt);
                cnt = 0;
                base *= 10;
                tmp = i * base + i;
            }
            rep(i, num.size()) {
                rep(j, num.size()) {
                    ans += num[i] * num[j];
                }
            }
        }
        else {
            num.push_back(1LL);
            ll base = 10;
            ll up = (i % 10);
            ll down = i / 10;
            if (up == down) continue;
            ll tmp = up * 10 + down;
            count[up * 10 + down][0] = 1;
            //cout << i << ":" << tmp << endl;
            if (tmp <= N) num.push_back(1LL);
            base *= 10;
            tmp = up * base + down;
            //cout << i << ":" << tmp << endl;
            while (tmp <= N) {
                ll cnt = 0;
                rep(i, base / 10) {
                    if (tmp + i * 10 <= N) {
                        //cout << i << ":" << tmp + i * 10 << endl;
                        cnt++;
                    }
                }
                num.push_back(cnt);
                ll index;
                if (base == 100) index = 1;
                else if (base == 1000) index = 2;
                else if (base == 10000) index = 3;
                else if (base == 100000) index = 4;
                count[up * 10 + down][index] = cnt;
                cnt = 0;
                base *= 10;
                tmp = up * base + down;
            }
        }
    }

    repd(i, 12, 100) {
        ll up = (i % 10);
        ll down = i / 10;
        rep(j, 5) {
            rep(k, 5) {
                //cout << i << "::" << j << "::" << count[i][j] << endl;
                ans += count[i][j] * count[up * 10 + down][k];
            }
        }
    }

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

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

int main() {
  int N,Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> num(N,0);
  int now = 0;
  for (int i=0; i<N-1; i++) {
    if (S[i] == 'A' && S[i+1] == 'C') {
      now++;
    }
    num[i+1] = now;
  }
  int l,r;
  for (int i=0; i<Q; i++) {
    cin >> l >> r;
    cout << num[r-1] - num[max(l-1,0)] << endl;
  }
}

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

int main() {
	int a,b,c,d,e;
  	cin>>a>>b>>c>>d>>e;
  
  	int sum=a+b+c+d+e;
  
  cout<<15-sum<<endl;
  
}



Measured memory_bytes: 3616
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<climits>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> M(n, vector<int>(n, 0));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> M[i][j];
        }
    }

    vector<int> dp(1 << n, 0);
    dp[0] = 1;
    for(int mask = 0; mask < (1 << n) - 1; ++mask) {
        int a = __builtin_popcount(mask);
        for(int b = 0; b < n; ++b) {
            if(M[a][b] && (mask & (1 << b)) == 0) {
                dp[mask | (1 << b)] = (1LL * dp[mask | (1 << b)] + dp[mask]) % MOD;
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


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

#define REP(i,init, n) for(int i=init;i<n;i++)
#define REPE(i,init, n) for(int i=init;i<=n;i++)
typedef long long int lli;
typedef pair<int, int> P;

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

    if (a >= 13)
        cout << b << endl;
    else if (a >= 6)
        cout << b/2 << endl;
    else
        cout << 0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll solve(ll x, ll a, ll b){
    ll ans = inf;
    chmin(ans, abs(x-a)+abs(a-b));
    chmin(ans, abs(x-b)+abs(a-b));
    return ans;
}

int main() {
    ll a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    rep(i, a)cin >> s[i];
    rep(i, b)cin >> t[i];
    rep(i, q){
        ll x;
        cin >> x;
        auto it1 = lower_bound(all(s), x);
        auto it2 = lower_bound(all(t), x);
        ll a = inf, b = inf, c = inf, d = inf;
        if(it1 != s.begin())a = *(it1-1);
        if(it1 != s.end())b = *it1;
        if(it2 != t.begin())c = *(it2-1);
        if(it2 != t.end())d = *it2;
        ll ans = inf;
        chmin(ans, solve(x, a, c));
        chmin(ans, solve(x, a, d));
        chmin(ans, solve(x, b, c));
        chmin(ans, solve(x, b, d));
        cout << ans << endl;
    }
}


Measured memory_bytes: 2944
#include<stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i <= n; i++) {
        if ((int) (i * 1.08) == n) {
            printf("%d\n", i);
            return 0;
        }
    }

    puts(":(");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define bitcount(x)  __builtin_popcount(x)
#define bitcountll(x)  __builtin_popcountll(x)
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 200005
int main()
{
    int n,i,j,k,f;
    in(n);
    vi v(n);
    vi vis(n,0);
    read(v,i,n);
    f=1,j=0;
    rep(i,n-1)
    {
        if(v[i]<v[i+1])
        {
            j=i+1;
            continue;
        }
        else if(v[i]==v[i+1])
            continue;
        else if(v[i]-v[i+1]==1)
        {
            lp(k,j,i+1)
            {
                if(vis[k])
                    f=0;
                v[k]--;
                vis[k]=1;
            }
        }
        else
            f=0;
    }
    if(f)
        printf("Yes");
    else
        printf("No");
}





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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i], --b[i];
  }
  vector<int> v;
  int res = -1;
  auto dfs = [&](auto&& self) -> void {
    if ((int)size(v) == n) {
      int cur = 0;
      for (int i = 0; i < q; ++i) {
        if (v[b[i]] - v[a[i]] == c[i]) {
          cur += d[i];
        }
      }
      res = max(res, cur);
      return;
    }
    for (int x = empty(v) ? 0 : v.back(); x < m; ++x) {
      v.push_back(x);
      self(self);
      v.pop_back();
    }
  };
  dfs(dfs);
  cout << res << '\n';
}


Measured memory_bytes: 3660
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = input()


def main():
    x = int(N[-1])
    if x == 3:
        ans = "bon"
    elif x in [2, 4, 5, 7, 9]:
        ans = "hon"
    else:
        ans = "pon"
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
    int a;
    cin >> a;
    if(a==1) cout << "Hello World" << endl;
    else{
        int b,c;
        cin >> b >> c;
        cout << b+c << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
//ll mod = 1e9 + 7;
//ll MOD = 1e9 + 7;
//ll INF = 1e18;
//const int INF = 7 + (1e+9);

struct RollingHash
{
    typedef long long lint;
    const string str;
    const lint base, mod;
    vector<lint> hash, pw;

    RollingHash(const string &s, lint h = 1000000007, lint b = 1009) : str(s), mod(h), base(b)
    {
        int l = s.length();
        hash.assign(l + 1, 0);
        pw.assign(l + 1, 0);
        pw[0] = 1;
        for (int i = 0; i < l; ++i)
        {
            pw[i + 1] = pw[i] * base % mod;
            hash[i + 1] = (hash[i] * base + s[i]) % mod;
        }
    }

    lint const get_hash(int l, int r)
    {
        return ((hash[r] - hash[l] * pw[r - l]) % mod + mod) % mod;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll R = 0;
    ll L = 0;
    RollingHash tree(s);
    RollingHash tree2(s, 999999937LL, 1009);

    set<pair<ll, ll>> se;
    rep(i, k)
    {
        string t;
        cin >> t;
        if (t == "R++")
        {
            R++;
        }
        else if (t == "R--")
        {
            R--;
        }
        else if (t == "L++")
        {
            L++;
        }
        else if (t == "L--")
        {
            L--;
        }

        se.insert({tree.get_hash(L,R+1),tree2.get_hash(L,R+1)});
        // cout<<tree.get_hash(L, R + 1)<<endl;
    }
    cout << se.size() << endl;
}



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

using namespace std;

typedef long long int big;

int main(){
    string s;
    cin>>s;
    if((s[2]==s[3]) && s[4]==s[5]){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n, m, k, a, num[31]={0}, ans=0;
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> k;
		for(int j=0; j<k; j++){
			cin >> a;
			num[a]++;
		}
	}
	for(int i=1; i<=30; i++){
		if(num[i]==n){
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

char a[100][100];

int main ()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<m;++j)
        {
            cin>>a[i][j];
        }
    }

    for(int i=1;i<=m+2;++i)
        cout<<"#";
    cout<<endl;

    int i=0;

    while(i<n)
    {
        cout<<"#";
        for(int j=0;j<m;++j)
            cout<<a[i][j];
        cout<<"#"<<endl;
        ++i;
    }

    for(int i=1;i<=m+2;++i)
        cout<<"#";
    cout<<endl;  

    return 0;  
}

Measured memory_bytes: 256
/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- Sun Mar 22 18:49:43 2020

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


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
bool ispel(string s){
	string p=s;
	reverse(all(s));
	if(p==s) return 1;
	else return 0;
} 
 
int solve() {
 
	string s;
	cin>>s;
	if(sz(s)%2==0){
		puts("No");
	}
	else{
		int len1=(sz(s)-1)/2;
		int len2=(sz(s)+3)/2;
		len2--;
		string s1=s.substr(0,len1);
		string s2=s.substr(len2,sz(s)-len2);
		if(ispel(s) && ispel(s1) && ispel(s2)){
			puts("Yes");
		}
		else
		{
			puts("No");
		}
	}
	
 
	return 0;
}
 
 
 
 
int main()
{
	//speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int c1,c5,c10,c50,c100,c500;

    scanf("%d%d%d%d%d%d",&c1,&c5,&c10,&c50,&c100,&c500);
    if(c1+5*c5+10*c10+50*c50+100*c100+500*c500>=1000) printf("1\n");
    else printf("0\n");

    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
long long MOD;

typedef long long ll;
typedef pair<ll,ll> P;

long long totient(long long a) {
	ll ret = a;
	for(int i = 2;i * i <= a;i++){
		if(a % i == 0){
			ret = ret * (i - 1) / i;
			while(a % i == 0)a /= i;
		}
	}
	if(a > 1)ret = ret * (a - 1) / a;
	return ret;
}

// a / b (mod p) b と p は互いに素
// O(sqrt(p))かかるので注意
long long totient_div(long long a, long long b, long long p) {
	long long ret = a;
	long long tp = totient(p) - 1;
	long long c = b;
	for(int i = 0;i <= 60;i++){
		if(tp & (1LL << i))ret = (ret * c) % p;
		c = (c * c) % p;
	}
	return ret;
}

//a^b % MOD
long long mod_pow(ll a,ll b){
	long long ret = 1;
	long long c = a;
	for(int i = 0;i <= 60;i++){
		if(b & (1LL << i))ret = (ret * c) % MOD;
		c = (c * c) % MOD;
	}
	return ret;
}

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 333333
vector<long long> fact(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(fact[0] != 1){
		fact[0] = 1;
		for(long long i = 1;i < MAX_K;i++)fact[i] = (fact[i-1] * i) % MOD;
	}
    long long ret = fact[n];
	long long tmp = (fact[r] * fact[n-r]) % MOD;
    return mod_div(ret,tmp);
}


ll ten[1111111];
ll num[1111111];
ll cou[1111111];

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

  ll n;cin >> n >> MOD;
  string str;cin >> str;

	if(MOD == 2 || MOD == 5){
		ll ans = 0;
		REP(i, n)if((str[i] - '0') % MOD == 0)ans += (i + 1);
		cout << ans << endl;
		return 0;
	}

  ten[n-1] = 1;
  num[n-1] = (str[n-1] - '0') % MOD;
  REV(i, n - 1){
    ten[i] = ten[i+1] * 10 % MOD;
    num[i] = (num[i+1] + ten[i] * (ll)(str[i] - '0')) % MOD;
  }

  //SHOW1d(ten, n+1);
  //SHOW1d(num, n+1);

  ll ans = 0;
  REP(i, n){
    //cout << num[i] << endl;
    ans += cou[num[i]];
    cou[num[i]]++;
    //SHOW1d(cou, MOD);
  }

  cout << ans + cou[0] << endl;

	return 0;
}


Measured memory_bytes: 11412
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <algorithm>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明


// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }


// ll my_gcd(ll a, ll b){
// 	return (b==0) ? a : my_gcd(b, a%b);
// }


//  ll my_lcm(ll a, ll b){
//  	return a*b / my_gcd(a,b);
//  }


// ll factorial(ll a){
// 	ll ans = 1;
// 	for(ll i=a; i>0; i--){
// 		ans *= i;
// 	}
// 	return ans;
// }

int main(int argc, char *argv[]){
    int x, y;
    cin >> x >> y;
    cout << x + y/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    string s;
    cin >> s;
    ll n = SZ(s);
    ll cnt = 15-n;
    REP (i,n) cnt += (s[i] == 'o');
    if (cnt >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

using namespace std;

typedef long long ll;

void add(ll &x, int k) {
	if (x & (1LL << k)) {
		if (x & (1LL << k + 1)) {
			x ^= 1LL << k + 1;
		} else {
			add(x, k + 1);
			add(x, k + 2);
		}
	}
	x ^= (1LL << k);
}

int main() {
	ll n, sgn;
	cin >> n;
	sgn = n < 0;
	n = abs(n);
	ll ans = 0;
	for (int i = 0, k = 1; n >= k; i++, k <<= 1) {
		if (n & k) {
			add(ans, i);
			if (i & 1 ^ sgn) {
				add(ans, i + 1);
			}
		}
	}
	string s = bitset<40>(ans).to_string();
	s = string(find(s.begin(), s.end(), '1'), s.end());
	cout << (s.size() == 0 ? "0" : s) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll INF = (ll)1e18;
int a[MAXN];
ll dp[MAXN][2];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    dp[0][0] = a[0] / 2;
    if (a[0] > 0)
    {
        dp[0][1] = (a[0] - 1) / 2;
    }
    else
    {
        dp[0][1] = -INF;
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j <= 1; j++)
        {
            if (a[i] == 0 && j == 1)
            {
                dp[i][j] = -INF;
                continue;
            }
            dp[i][j] = -INF;
            for (int k = 0; k <= 1; k++)
            {
                int cur = a[i] + k - j;
                dp[i][j] = max(dp[i][j], cur / 2 + dp[i - 1][k]);
            }
        }
    }
    ll res = max(dp[n - 1][0], dp[n - 1][1]);
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 2176
class Combination
  def initialize(n, mod)
    @mod = mod
    create_fact_mod(n)
    create_seq_inv_mod(n)
    create_fact_inv_mod(n)
  end

  def create_fact_mod(num_max)
    @fmod = Array.new(num_max + 1)
    @fmod[0] = 1
    @fmod[1] = 1
    (2..num_max).each do |i|
      @fmod[i] = (@fmod[i - 1] * i) % @mod
    end
  end

  def create_seq_inv_mod(num_max)
    @simod = Array.new(num_max + 1)
    @simod[0] = 1
    @simod[1] = 1
    (2..num_max).each do |i|
      @simod[i] = (@mod - @mod / i) * @simod[@mod % i] % @mod
    end
  end

  def create_fact_inv_mod(num_max)
    @fimod = Array.new(num_max + 1)
    @fimod[0] = 1
    @fimod[1] = 1
    (2..num_max).each do |i|
      @fimod[i] = (@fimod[i - 1] * @simod[i]) % @mod
    end
  end

  def comb_mod(n, k)
    @fmod[n] * @fimod[n - k] * @fimod[k] % @mod
  end

  def perm_mod(n, k)
    @fmod[n] * @fimod[n - k] % @mod
  end
end

H, W, A, B = gets.split.map(&:to_i)

M = [H - A, W - B].min
mod = 10**9 + 7
ans = 0

comb = Combination.new(H + W, mod)

M.times  do |i|
  h1 = H - A - i - 1
  w1 = B + i
  ans += comb.comb_mod(h1 + w1, h1) * comb.comb_mod(H - h1 + W - w1 - 2, H - h1 - 1)
  ans %= mod
end
puts ans

Measured memory_bytes: 6524
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    uint64_t n, k, q;
    cin >> n >> k >> q;
    // cerr << n << "," << k << "," << q << endl;
    vector<int64_t> a(q);
    vector<int64_t> p(n);
    for (int64_t i = 0; i < n; ++i) {
        p[i] = k - q;
    }
    for (int64_t i = 0; i < q; ++i) {
        cin >> a[i];
        p[a[i]-1]++;
    }
    for (int64_t i = 0; i < n; ++i) {
        if (p[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    int n;
    std::cin >> n;
    VEC(ll,a,n);
    rep(i,n){
        a[i]-=(i+1);
    }
    sort(all(a));
    if(n%2==1){
        ll d=a[n/2];
        ll ans=0ll;
        rep(i,n)ans+=abs(a[i]-d);
        std::cout << ans << std::endl;
    }
    else{
        ll d=(a[n/2-1]+a[n/2])/2;
        ll an1=0ll,an2=0ll;
        rep(i,n)an1+=abs(a[i]-d);
        d++;
        rep(i,n)an2+=abs(a[i]-d);
        std::cout << min(an1,an2) << std::endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define vi vector <int>

using namespace std;			

const int N = 2e5 + 111;

int n, a, b;
vector <int> v[N];
vector <int> p[2];
vector <int> x[3];

void dfs(int u, int par, int o) {
	o %= 2;
	p[o].pb(u);
	for (auto it : v[u])
		if (it != par)
			dfs(it, u, o + 1);
}

int ans[N];

int main() {	
	scanf ("%d", &n);
	rep(i, 1, n - 1) {
		scanf ("%d%d", &a, &b);
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs(1, 0, 0);
	rep(i, 1, n) 
		x[i % 3].pb(i);
	if (ss(p[1]) > ss(p[0])) swap(p[0], p[1]);

	while (ss(x[1])) {
		ans[p[0].back()] = x[1].back();
		p[0].pop_back();
		x[1].pop_back();
	}
	
	if (ss(p[1]) > ss(p[0])) swap(p[0], p[1]);
	
	while (ss(x[2])) {
		ans[p[0].back()] = x[2].back();
		p[0].pop_back();
		x[2].pop_back();
	}
	
	while (ss(x[0])) {
		if (ss(p[0])) {
			ans[p[0].back()] = x[0].back();
			p[0].pop_back();
		}
		else {
			ans[p[1].back()] = x[0].back();
			p[1].pop_back();
		}
		x[0].pop_back();
	}
	rep(i, 1, n) printf ("%d ", ans[i]);
		
	
	
	
	
	return 0;
}


Measured memory_bytes: 22388
#include <bits/stdc++.h>
const int N = 10050;
using namespace std;
char s[N];
int a[N],b[N],n,pr[N],nx[N],sum[N],mx[N],ans,tot;
struct date{
  int l,r;
  bool operator < (const date &c) const {
    return l<c.l;
  }
}q[N];
void work1(int p){
  int num=n+1-p; tot=0;
  for (int i=1; i<=n; ++i)
    if (a[i+p-1]!=b[i]){
      ++num;
      if (sum[n+i]-sum[p+i-2])
	continue;
      else
	q[++tot]=(date){max((p+i-1-pr[p+i-1])*2,0),max((nx[p+i-1]-n-i)*2,0)};
    }
  sort(q+1,q+tot+1);
  mx[tot+1]=0;
  for (int i=tot; i; --i)
    mx[i]=max(mx[i+1],q[i].r);
  for (int i=0; i<=tot; ++i)
    ans=min(ans,q[i].l+mx[i+1]+num);
  return;
}
void work2(int p){
  int num=p-n-1; tot=0;
  for (int i=1; i<=n; ++i)
    if (a[i+p-1]!=b[i]){
      ++num;
      if (sum[p+i-1]-sum[n+i-1])
	continue;
      else
	q[++tot]=(date){max((n+i-pr[p+i-1])*2,0),max((nx[p+i-1]-p-i+1)*2,0)};
    }
  sort(q+1,q+tot+1);
  mx[tot+1]=0;
  for (int i=tot; i; --i)
    mx[i]=max(mx[i+1],q[i].r);
  for (int i=0; i<=tot; ++i)
    ans=min(ans,q[i].l+mx[i+1]+num);
  return;
}
int main(){
  scanf("%s",s+1);
  n=strlen(s+1);
  int sa=0,sb=0;
  n=strlen(s+1);
  for (int i=1; i<=n; ++i)
    b[i]=s[i]-'0',sb+=b[i];
  scanf("%s",s+1);
  for (int i=1; i<=n; ++i)
    a[i]=s[i]-'0',sa+=a[i];
  if (!sa&&sb){
    cout<<"-1"; return 0;
  }
  int now=1e9;
  for (int i=n+1; i<=n*3; ++i)
    a[i]=a[i-n];
  for (int i=1; i<=n*3; ++i)
    sum[i]=sum[i-1]+a[i];
  for (int i=n*3; i>=1; --i){
    nx[i]=now;
    if (a[i]) now=i;
  }
  now=-1e9;
  for (int i=1; i<=3*n; ++i){
    pr[i]=now;
    if (a[i]) now=i;
  }
  ans=1e9;
  for (int i=1; i<=n+1; ++i) work1(i);
  for (int i=n+1; i<=n*2; ++i) work2(i);
  cout<<ans;
  return 0;
}


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

int main() {
 int  n,m;
  cin >>n>>m;
  vector<int> vec(m);
  for(int i=0;i<m;i++){
  cin>>vec.at(i);}
  sort(vec.begin(), vec.end());
  int haba=vec.at(m-1)-vec.at(0);
  
  vector<int> tor(m-1);
  for(int i=0;i<m-1;i++){
    tor.at(i)=vec.at(i+1)-vec.at(i);}
  
  sort(tor.begin(), tor.end());
  reverse(tor.begin(), tor.end());

  int heru=0;
    if(m>n){
      for(int i=0;i<n-1;i++){
        heru+=tor.at(i);}
      cout << haba-heru <<endl;}
  
  else{
    cout << 0 << endl;}
      

}


Measured memory_bytes: 1024
#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;
	long double ans = 0;

	for (int i = 0; i < N; ++i)
	{
		long double a;
		string s;
		cin >> a >> s;

		if ( s[0] == 'J') ans += a;
		else ans += a * 380000;
	}

	cout << setprecision(20) << ans << endl;

	return 0;


}

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

using namespace std;

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

  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double pi = acos(-1);
  double anh = 2 * pi / 12 * h, anm = 2 * pi / 60 * m;
  anh += 2 * pi / 12 / 60 * m;
  double xh = a * cos(anh), yh = a * sin(anh);
  double xm = b * cos(anm), ym = b * sin(anm);
  cout << fixed << setprecision(20);
  cout << sqrt((xh - xm) * (xh - xm) + (yh - ym) * (yh - ym));

  return 0;
}


Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

using pss = pair<string,string>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    string pre;
    cin >> pre;
    string suf = pre.substr(N);
    reverse(suf.begin(),suf.end());
    pre = pre.substr(0,N);
    queue<pss> que;
    for(int i=0; i<N; i++){
        queue<pss> temp;
        if(i == 0){
            string now;
            now += pre[i];
            temp.emplace(now,"");
            temp.emplace("",now);
        }else{
            while(que.size()){
                string a,b;
                tie(a,b) = que.front();
                que.pop();
                temp.emplace(a+pre[i],b);
                temp.emplace(a,b+pre[i]);
            }
        }
        que = temp;
    }
    map<pss,int> fst;
    while(que.size()){
        fst[que.front()]++;
        que.pop();
    }
    for(int i=0; i<N; i++){
        queue<pss> temp;
        if(i == 0){
            string now;
            now += suf[i];
            temp.emplace(now,"");
            temp.emplace("",now);
        }else{
            while(que.size()){
                string a,b;
                tie(a,b) = que.front();
                que.pop();
                temp.emplace(a+suf[i],b);
                temp.emplace(a,b+suf[i]);
            }
        }
        que = temp;
    }
    map<pss,int> sec;
    while(que.size()){
        sec[que.front()]++;
        que.pop();
    }
    ll ans = 0;
    for(auto m: fst){
        ans += (ll)m.second * sec[m.first];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 104992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int debt = 100000;
		while(n-- != 0) {
			debt += debt*0.05;
			int a = debt%1000;
			if(a != 0) debt += 1000-a;
		}
		System.out.println(debt);
	}
}



Measured memory_bytes: 26024