akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string a, b, c; cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [0] + [int(s) for s in input().split()] + [0]
    for x in solve(n, a):
        print(x)

def solve(n, a):
    s = [0]
    p = 0

    for x in a[1:]:
        s.append(s[-1] + abs(x - p))
        p = x
    
    r = []
    for i in range(1, n + 1):
        x = s[i-1] + (s[-1] - s[i+1]) + abs(a[i+1] - a[i-1])
        r.append(x)

    return r

main()


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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int fractional(int n) {
    if(n<=1) return 1;
    else return n*fractional(n-1);
}

double square(double p) {
    return p*p;
}

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

    vector<double> x(n);
    vector<double> y(n);
    for(int in=0;in<n;in++) {
        cin >> x.at(in) >> y.at(in);
    }

    double ans = 0, anstmp;
    for(int in=0;in<n;in++) {
        for(int jn=in+1;jn<n;jn++) {
            anstmp = square(x.at(in)-x.at(jn))+square(y.at(in)-y.at(jn));
            ans += sqrt(anstmp);
        }
    }

    ans /= fractional(n);
    ans *= 2*(n-1)*fractional(n-2);

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6 + 5;
char cake[400][400];
int res[400][400];
void dfs(int row, int col, int color, int bound) {
    if (res[row][col] || col < 0 || col >= bound)
        return;
    res[row][col] = color;
    dfs(row, col + 1, color, bound);
    dfs(row, col - 1, color, bound);
}
void dfs2(int row, int r, int col, int bound) {
    if (res[row][0] || row < 0 || row >= bound)
        return;
    for (int i = 0; i < col; ++i)
        res[row][i] = res[r][i];
    dfs2(row + 1, row, col, bound);
    dfs2(row - 1, row, col, bound);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j) {
            cin >> cake[i][j];
            if (cake[i][j] == '#') {
                res[i][j] = k;
                --k;
            }
        }
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j) {
            if (cake[i][j] == '#') {
                dfs(i, j + 1, res[i][j], w);
                dfs(i, j - 1, res[i][j], w);
            }
        }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (cake[i][j] == '#') {
                dfs2(i - 1, i, w, h);
                dfs2(i + 1, i, w, h);
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j)
            cout << res[i][j] << ' ';
        cout<< '\n';
    }
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    if (N >= K) {
        cout << K * X + (N - K) * Y << endl;
    }
    else {
        cout << N * X << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    ll n;cin>>n;
    ll x = (ll)ceil((double)n/1000);
    cout<< x*1000-n <<"\n";
    
}





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


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


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

int N,A[100],swapcount;

inline void Initial() {
  std::ios::sync_with_stdio(false);
  cout.tie(0); cin.tie(0);
}
inline void Input() {
  cin>>N;
  for (int i=0; i<N; i++) {
    cin>>A[i];
  }
}
inline void BubbleSort() {
  bool flag=true;
  while (flag) {
    flag=false;
    for (int j=N-1; j>=1; j--) {
      if (A[j]<A[j-1]) {
        swap(A[j],A[j-1]);
        flag=true;
        swapcount++;
      }
    }
  }
}
inline void Output() {
  for (int i=0; i<N; i++) {
    if (i) {
      cout<<" "<<flush;
    }
    cout<<A[i]<<flush;
  }
  cout<<endl;
  cout<<swapcount<<endl;
}
int main() {
  Initial(),Input(),BubbleSort(),Output();
  return 0;
}




Measured memory_bytes: 3140
public class Main {

  private static void solve() {
    char[] s = ns();

    for (int i = 0; i < s.length; i++) {
      if (s[i] == '?') {
        s[i] = 'D';
      }
    }
    System.out.println(s);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 40400
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<tuple<string,int,int>> a;
    for(int i=0;i<n;i++){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.emplace_back(s,p,i+1);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++) cout << get<2>(a[i]) << endl;
}  

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int k,dp[105][2][105]={},ans=0;
  cin >> s >> k;
  dp[0][0][0]=1;
  for(int i=0; i<s.size(); i++) {
    for(int j=0; j<2; j++) {
      for(int l=0; l<105; l++) {
        int lim=j?9:s[i]-'0';
        for(int m=0; m<=lim; m++) {
          (dp[i+1][j||m<lim][l+(m!=0)]+=dp[i][j][l])%=MOD;
        }
      }
    }
  }
  for(int i=0; i<2; i++) {
    (ans+=dp[s.size()][i][k])%=MOD;
  }
  //0は0でない数字が0個なのでans-1をする必要がない
  cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    bool s[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            char c; cin >> c;
            s[i][j] = c=='1';
        }
    }
    int ans = -1;
    for(int i = 0; i < n; i++){
        vector<int> dep(n, 1<<30);
        dep[i] = 1;
        int tmpdep = 1, cnt = 1;
        vector<int> bef({i});
        bool valid = true;
        while(valid && cnt <= n){
            tmpdep++;
            vector<int> next;
            for(int j : bef){
                for(int k = 0; k < n; k++){
                    if(!s[j][k])    continue;
                    if(dep[k] != 1<<30){
                        valid &= abs(dep[k]-dep[j])==1;
                    }else{
                        next.push_back(k);
                        dep[k] = tmpdep;
                    }
                }
            }
            bef = next;
            if(bef.size() == 0) break;
            cnt += bef.size();
        }
        if(valid && cnt == n)   ans = max(ans, tmpdep-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    float n,d;
    cin >> n >> d;
    cout << ceil(n/(d*2+1)) << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

ll fact[4005], invfact[4005];
const ll mod = 1'000'000'007;

ll bm(ll b, ll p, ll m) {
	ll r = 1;
	for (; p; p >>= 1, b = b * b % m) if (p & 1) r = r * b % m;
	return r;
}

ll modinv(ll b) { return bm(b, mod - 2, mod); }
ll ncr(ll n, ll r) { 
	//printf("%lldC%lld\n", n, r);
	if (r < 0 || r > n) return 0;
	return fact[n] * invfact[r] % mod * invfact[n - r] % mod; 
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	fact[0] = 1;
	rep(i, 1, 4005) fact[i] = fact[i - 1] * i % mod;
	rep(i, 0, 4005) invfact[i] = modinv(fact[i]);

	int n, k; read(n, k);
	int blue = k, red = n - k;

	vector<int> ans(k + 1);
	rep(i, 1, k + 1) {
		ll bb = ncr(blue - 1, i - 1);
		ll rr = ncr(red - (i - 1) + (i + 1) - 1, i);
		ans[i] = bb * rr % mod;
		//printf("%d: BB=%lld RR=%lld\n", i, bb, rr);
		//printf("Solve %d\n", i);
	}

	rep(i, 1, k + 1) write(ans[i]);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) (((a%MOD+MOD)%MOD-(b%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x/gcd(x,y)*y)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i = 0){ return accumulate(f, l, i); }


string s;
string t;
VI p[30];


signed main(){
    cin >> s;
    cin >> t;

    rep(i, 0, SZ(s)) p[s[i]-'a'].pb(i);

    int cnt = 0;
    int x = -1;
    for(char ti : t){
        int c = ti-'a';
        if(SZ(p[c]) == 0){ cnt = -1; break; }
        int d = distance(begin(p[c]), ub(ALL(p[c]), x));
        if(d == SZ(p[c])) cnt++ , x = p[c][0];
        else x = p[c][d];
    }

    if(cnt == -1) cout << -1 << endl;
    else cout << SZ(s)*cnt+x+1 << endl;

    return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int num[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int n, m;
    cin >> n >> m;
    vector<int> ok(m);
    for (int i = 0; i < m; i++) {
        cin >> ok[i];
    }
    auto comp = [](const string& a, const string& b) {
        if (a.size() < b.size()) return true;
        if (a.size() > b.size()) return false;
        int n = a.size();
        for (int i = 0; i < n; i++) {
            if (a[i] < b[i]) return true;
            if (a[i] > b[i]) return false;
        }
        return false;
    };
    vector<string> dp(n + 1, string("0"));
    dp[0] = "";
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            int u = num[ok[j]];
            if (i - u >= 0 && dp[i - u] != "0") {
                dp[i] = max(dp[i], dp[i - u] + char('0' + ok[j]), comp);
            }
        }
    }
    cout << dp[n] << endl;    
}

Measured memory_bytes: 41600
#include<iostream>

using namespace std;

int N,C;
int s[100005], t[100005], c[100005];
int check[200002], num[200002];
int sm[200002]; int tt[200002];
int tmp;

int main(void) {

	cin >> N>>C;
	for (int i = 0; i < N; i++) {
		cin >> tmp; s[i] = tmp;
		cin >> tmp; t[i] = tmp;
		cin >> tmp; c[i] = tmp;
	}

	//======================================
/*	for (int i = 1; i <= C; i++) {
		for (int j = 0; j<200002; j++)tt[j] = 0;
		for (int j = 0; j<N; j++)if (c[j] == i)tt[s[j] * 2 - 1]++, tt[t[j] * 2]--;
		for (int j = 1; j<200002; j++)tt[j] += tt[j - 1];
		for (int j = 0; j<200002; j++)if (tt[j]>0)sm[j]++;
	}
	int mx = 0; for (int j = 0; j<200002; j++)if (mx<sm[j])mx = sm[j]; printf("%d\n", mx);
	//=====================================
*/

	for (int j = 1; j <= C; j++) {
		for (int i = 0; i < 200002; i++) { check[i] = 0;}
		for (int i = 0; i < N; i++) { if (c[i] == j) {
				check[2 * s[i] - 1]++; check[2 * t[i]]--;
			}
		}
			for (int i = 1; i < 200002; i++) { check[i] += check[i - 1]; }
			for (int i = 0; i < 200002; i++) { if (check[i] > 0) { num[i]++; } }
	}

	int max_num = 0;
	for (int i = 0; i < 200002; i++) {
		if (num[i] > max_num) { max_num = num[i]; }
	}

	cout << max_num << endl;
	

	//system("pause");
	return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
using namespace std;
using ll = long long;

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    // BWBBW -> WWBBB
    int numW = 0;
    int numB = 0;
    for(auto c: S) {
        if(c == '.') {
            numW++;
        } else {
            numB++;
        }
    }
    int seenW = 0;
    int seenB = 0;
    int ret = seenB + numW;
    for(auto c: S) {
        if(c == '.') {
            seenW++;
            numW--;
        } else {
            seenB++;
            numB--;
        }
        ret = min(ret, seenB + numW);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
int main(){
  ll a, b;
  cin >> a >> b;
  string ans;
  if (a <= 0 && b >= 0) ans = "Zero";
  else if (a > 0) ans = "Positive";
  else if ((b - a) % 2 == 0) ans = "Negative";
  else ans = "Positive";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <typeinfo>

struct Square {
	int left, top, right, bottom;
};
class UnionFind {
	std::vector<int> parent;
public:
	UnionFind(int size) : parent(size, -1) {};
	int find(int a) {
		return (parent[a] < 0) ? a : parent[a] = find(parent[a]);
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a); b = find(b);
		if (a != b) {
			if (parent[a] < parent[b]) {
				parent[a] += parent[b];
				parent[b] = a;
			}
			else {
				parent[b] += parent[a];
				parent[a] = b;
			}
		}
	}
	int size() const {
		return parent.size();
	}
};
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<Square> squares(n); for (auto& s : squares) std::cin >> s.left >> s.top >> s.right >> s.bottom;
		std::vector<int> horizontal{ -1, 1000001 }, vertical{ -1, 1000001 };
		for (const auto s : squares) {
			horizontal.push_back(s.left); horizontal.push_back(s.right);
			vertical.push_back(s.top); vertical.push_back(s.bottom);
		}
		std::sort(horizontal.begin(), horizontal.end()); std::sort(vertical.begin(), vertical.end());
		horizontal.erase(std::unique(horizontal.begin(), horizontal.end()), horizontal.end()); vertical.erase(std::unique(vertical.begin(), vertical.end()), vertical.end());
		std::unordered_map<int, int> h_map, v_map;
		for (auto i = 0; i < horizontal.size(); ++i) {
			h_map[horizontal[i]] = i;
		}
		for (auto i = 0; i < vertical.size(); ++i) {
			v_map[vertical[i]] = i;
		}
		for (auto& s : squares) {
			s.top = v_map[s.top];
			s.bottom = v_map[s.bottom];
			s.left = h_map[s.left];
			s.right = h_map[s.right];
		}
		std::vector<std::vector<long long int>> state(vertical.size(), std::vector<long long int>(horizontal.size(), 0));
		for (auto i = 0; i < n; ++i) {
			const auto s = squares[i];
			for (auto h = s.bottom; h < s.top; ++h) for (auto v = s.left; v < s.right; ++v) {
				state[h][v] |= 1LL << i;
			}
		}
		UnionFind uft(vertical.size() * horizontal.size());
		for (auto i = 0; i < state.size(); ++i) for (auto j = 0; j < state[i].size(); ++j) {
			if (i > 0 && state[i][j] == state[i - 1][j]) {
				uft.unite(j * state.size() + i, j * state.size() + i - 1);
			}
			if (j > 0 && state[i][j] == state[i][j - 1]) {
				uft.unite(j * state.size() + i, (j - 1) * state.size() + i);
			}
		}
		int result{ 0 };
		for (auto i = 0; i < uft.size(); ++i) {
			if (uft.find(i) == i) ++result;
		}
		std::cout << result << std::endl;
	}
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

//#define int ll

int main(){

    ll n,k;cin>>n>>k;
    ll a[n+1];rep(i,1,n)cin>>a[i];
    a[0]=0;rep(i,1,n)a[i]=a[i-1]+a[i];
    vector<ll>v;
    rep(i,1,n){
        rep(j,0,i-1){
            v.pb(a[i]-a[j]);
        }
    }
    //sort(v.begin(),v.end());
    /*for(auto x:v){
        cout<<x<<" ";
    }*/
    ll ans=0;
    int N=40;
    for(int i=N;i>=0;i--){
        ll p=(ll)1<<i;
        vector<ll>ok;
        for(auto x:v){
            if((x&p)==p){
                ok.pb(x);
            }
        }
        if(ok.size()>=k){
            ans+=p;
            v.clear();
            v=ok;
        }
       // cout<<i<<" "<<v.size()<<" "<<ok.size()<<endl;
        ok.clear();
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 8904
#include <iostream>
int main(){
  int a,b,c;
  std::cin >> a >> b >> c;
  if(a<b){
    if(b<c){
      std::cout << "Yes"<< std::endl;
    } else {
      std::cout << "No"<< std::endl;
    }
  } else {
    std::cout << "No"<< std::endl;
  }
}


Measured memory_bytes: 3108
#include<stdio.h>
#define N 10005
#define M 500

int main(){
  int S[N],n,T[M],q,key,count=0,co=0;
  int i,j,k;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }

  for(i = 0; i < q; i++){
    key =T[i];
    for(j = 0; j < n; j++){
      if(key == S[j]) {
	count++;
	break;
      }
    }
  }

  printf("%d\n",count);

  return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}
P;


P Q[LEN];
int head,tail,n;

void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}

P dequeue(){
	P x=Q[head];
	head=(head+1)%LEN;
	return x;
}

int min(int a,int b){return a<b?a:b;}

int main(){
	int elaps=0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1; tail=n+1;
	
	while(head!=tail){
		u=dequeue();
		c=min(q,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0)enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
		
	}
	return 0;
}



Measured memory_bytes: 11852
#include<iostream>
#include<string>
using namespace std;
int main(){
string a;
cin>>a;
if(a=="a")cout<<"vowel"<<endl;
else if(a=="e")cout<<"vowel"<<endl;
else if(a=="i")cout<<"vowel"<<endl;
else if(a=="o")cout<<"vowel"<<endl;
else if(a=="u")cout<<"vowel"<<endl;
else cout<<"consonant"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second         
    int main() 
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        string s;
        cin>>s;
        int ans = (s[5]-'0')*10+s[6]-'0';
        if(ans > 4)
            cout<<"TBD"<<endl;
        else
            cout<<"Heisei"<<endl;
        return 0;
    }
       

Measured memory_bytes: 256
#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 < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;

vector<int> g[100005];
vector<int> dist;

void dfs(int s, int p, int d) {
    dist[s] = d;
    for (auto u : g[s]) {
        if (u == p) continue;
        dfs(u, s, d + 1);
    }
}

vector<int> calc(int s) {
    dist = vector<int>(n);
    dfs(s, -1, 0);
    return dist;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int u, v;
    cin >> n >> u >> v;
    --u, --v;
    rep (i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> distT, distA;
    distT = calc(u);
    distA = calc(v);
    int res = 0;
    rep (i, n) {
        if (distT[i] < distA[i]) res = max(res, distA[i] - 1);
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 10744
#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 , k ; 
  cin >> n >> k ;
  int ans = 0 ;
  
  if(k != 1 ) ans = n- k ; 
  
  cout << ans ;

}


Measured memory_bytes: 3624
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

const int N = 1e5 + 7;
const long long oo = 1e18L + 5;

int n;

int main() {
    cin >> n;
    vector<int> h(n + 1);
    vector<ll> dp(n + 2, oo);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1408
n = int(input(), 10)
a = list(map(int, input().split()))
greatCDlist = []


def gcd(m, n):
    if m < n:
        m ^= n
        n ^= m
        m ^= n
    if n == 0:
        return m
    else:
        return gcd(n, m % n)


left = [0 for i in range(n+1)]
right = [0 for i in range(n+1)]

for i in range(n):
    left[i+1] = gcd(left[i], a[i])


for i in range(n-1, -1, -1):
    right[i] = gcd(right[i+1], a[i])


result = 0
for i in range(n):
    l = left[i]
    r = right[i+1]
    result = max(result, gcd(l, r))

print(result)

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

int main() {

	int n, m; cin >> n >> m;
	vector<pair<int, int>> pa;
	vector<vector<pair<int, int>>> c(n);
	for (int i = 0; i < m; i++) {
		int p, y; cin >> p >> y;
		p--;
		y--;
		pa.emplace_back(p, y);		
		c[p].emplace_back(y, i);
	}
	for (int i = 0; i < n; i++) {
		sort(c[i].begin(), c[i].end());
		for (int j = 0; j < c[i].size(); j++) {
			pa[c[i][j].second].second = j;
		}		
	}
	for (int i = 0; i < m; i++) {
		cout << setw(6) << setfill('0') <<  pa[i].first + 1  << setw(6) << setfill('0') << pa[i].second + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 9516
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

ans = 0

for i in range(K):
    if T[i]=='r':ans += P
    elif T[i]=='s':ans += R
    else: ans+= S

for i in range(K, N):
    if T[i]=='r':
        if T[i-K]!='r':ans += P
        else:T[i] = '0'
    elif T[i]=='s':
        if T[i-K]!='s':ans += R
        else:T[i] = '0'
    else:
        if T[i-K]!='p': ans+= S
        else:T[i] = '0'
print(ans)

Measured memory_bytes: 4084
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool f(int a, int b, string &S) {
  int N = S.size();
  vector<int> kind(N, -1);
  kind[0] = a, kind[1] = b;
  for (int i = 1; i <= N; i++) {
    int r = (i + 1) % N;
    int l = (i + N - 1) % N;
    int newk;
    if (((kind[i % N] == 0) ^ (S[i % N] == 'o')) == 0) {
      newk = kind[l];
    } else {
      newk = 1 - kind[l];
    }
    if (kind[r] == -1) {
      kind[r] = newk;
    } else {
      if (kind[r] != newk) return false;
    }
  }
  for (int i = 0; i < N; i++) {
    if (kind[i] == 0) {
      cout << "S";
    } else {
      cout << "W";
    }
  }
  cout << endl;
  return true;
}

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

  bool flag = false;
  for(int i = 0; i < 4; i++) {
    flag |= f(i & 1, i >> 1 & 1, S);
    if (flag) break;
  }
  if (!flag) {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 8256
#include<stdio.h>
int A[100][100];
int visit[100];
void MinimumSpanningTree(int);
  
main(){
  int n, i, j;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &A[i][j]);
    }
  }
  MinimumSpanningTree(n);
  return 0;
}
  
void MinimumSpanningTree(int n){
  int i, j, k=1, X[100], minCost, min, sum=0;
    
  X[0] = 0;
  visit[0] = 1;
  for(i = 1; i < n; i++){
    visit[i] = 0;
  }
  while(1){
    minCost = 2001;
    for(i = 0; i < k; i++){
      for(j = 0; j < n; j++){
    if(A[X[i]][j] < minCost && A[X[i]][j] != -1 && visit[j] != 1){
      minCost = A[X[i]][j];
      min = j;
    }
      }
    }
    if(k != n){
      X[k] = min;
      visit[min] = 1;
      sum += minCost;
      k++;
    }
    else break;
  }
  printf("%d\n", sum);
}

Measured memory_bytes: 640
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)
before = -1
res = 0
A.each do |a|
    res += B[a-1]
    if before == a-1 then
        res += C[before-1]
    end
    before = a
end
puts res

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

int main(){
    float n;
    cin>>n;
    float sum = 0;
    for (int i=0;i<n;++i){
        float x;
        cin>>x;
        sum+=1/x;
    }
    float ans = 1/sum;
    cout<<ans;
}

Measured memory_bytes: 256
#!/bin/bash

read num

for ((i = 1; i <= $num; i++))
do
	read str
	echo $str >> tmp.txt
done


echo "AC x `grep AC tmp.txt | wc -l`"
echo "WA x `grep WA tmp.txt | wc -l`"
echo "TLE x `grep TLE tmp.txt | wc -l`"
echo "RE x `grep RE tmp.txt | wc -l`"


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 3e15
    
const int N=1e5+5;
const int M=1e9+7;
void solve()
{
	int k;
	int a,b;
	cin>>k>>a>>b;
	int ans=b/k;
	ans-=(a-1)/k;
	if(ans>0)
	cout<<"OK";
	else
	cout<<"NG";
	
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}



Measured memory_bytes: 3640
f [] _ = (False, [])
f s@(c:u) t
  | not b && and (zipWith (\x y -> x == '?' || x == y) (s ++ repeat '_') t) = (True, t ++ drop (length t - 1) v)
  | otherwise = (b, (if c == '?' then 'a' else c) : v)
  where (b,v) = f u t
main = do
  (b,s) <- f <$> getLine <*> getLine
  putStrLn $ if b then s else "UNRESTORABLE"

Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin >> s;

    ll n = s.size();

    ll cnt = 0;
    rep(i, n/2){
        if(s[i] != s[n-1-i]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

int main() {
	// your code goes here
	int n;int w;
	cin>>n>>w;
	int arr[n][2];
	for(int i=0;i<n;i++){
	    for(int j=0;j<2;j++){
	        cin>>arr[i][j];
	    }
	}
	long long int dp[n+1][w+1];
    // dp1[0]=max(dp[0][0],max(dp[0][1],dp[0][2]));
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
               if(i==0 || j==0){
                   dp[i][j]=0;
               }
               else if(arr[i-1][0]<=j){
                   dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i-1][0]]+arr[i-1][1]);
               }
               else{
                   dp[i][j]=dp[i-1][j];
               }
        }
        // cout<<dp[j]<<" ";
    }
    cout<<dp[n][w];
}


Measured memory_bytes: 82412
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> as(n);
    for(int i=0; i<n; ++i){
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    int t=as[n-1];
    int s, diff=t*2;
    for(int i=0; i<n-1; ++i){
        int d=abs(t-as[i]*2);
        if(d<diff){
            diff=d;
            s=as[i];
        }
    }
    cout << t << " " << s << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
int a[100000], b[100000], c[100000];
struct SegTree {
	vector<vector<int>> data;
	int size;
	SegTree(int n, int *d) {
		size = 1;
		while (size < n) size *= 2;
		data.resize(2 * size - 1);
		for (int i = 0; i < n; i++) {
			data[i + (size - 1)].push_back(d[i]);
		}
		for (int i = size - 2; i >= 0; i--) {
			data[i].resize(data[i * 2 + 1].size() + data[i * 2 + 2].size());
			merge(data[i * 2 + 1].begin(), data[i * 2 + 1].end(), data[i * 2 + 2].begin(), data[i * 2 + 2].end(), data[i].begin());
		}
	}
	int query(int a, int b, int x, int k, int l, int r) { //x以下
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) {
			return upper_bound(data[k].begin(), data[k].end(), x) - data[k].begin();
		}
		return query(a, b, x, k * 2 + 1, l, (l + r) / 2) + query(a, b, x, k * 2 + 2, (l + r) / 2, r);
	}
};
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i], b[i] = a[i];
	sort(b, b + N);
	int l = 0, r = N;
	ll all = (ll)N*(N + 1) / 2;
	while (r - l > 1) {
		int m = (l + r) / 2;
		for (int i = 0; i < N; i++) {
			if (a[i] >= b[m]) c[i] = 1; else c[i] = -1;
			if (i > 0) c[i] += c[i - 1];
		}
		SegTree S(N, c);
		ll cnt = 0;
		for (int i = 0; i < N; i++) {
			cnt += S.query(0, i, c[i], 0, 0, S.size);
			if (c[i] >= 0) cnt++;
		}
		if (cnt >= all / 2) l = m;
		else r = m;
	}
	cout << b[l] << endl;
}


Measured memory_bytes: 21316
n,k=map(int,input().split())
ans=0
mod=10**9+7
sum_=[0]
for i in range(n):
    sum_.append(sum_[-1]+(i+1))
for i in range(k-1,n+1):
    ans+=(i+1)*n-sum_[i]-(sum_[i]-1)
    ans=ans%mod
print(ans)

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

using namespace std;

int main(){
  int n, m, count;
  count = 0;
  m = 0;
  cin >> n;
  int h[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
    if(m < h[i]+1){
      count += 1;
      m = h[i];
    
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
typedef long long ll;

int main(){
    string s; cin >> s;
    int q; cin >> q;
    int revflag = 1;
    string s1,s2;
    rep(i,q){
        int query; cin >> query;
        if(query == 1){
            revflag *= -1;
        }
        else if(query == 2){
            int f; cin >> f;
            char c; cin >> c;
            if(revflag == 1){
                if(f == 1){
                    s1 += c;
                }
                else if(f == 2){
                    s2 += c;
                }
            }
            else{
                if(f == 1){
                    s2 += c;
                }
                else if(f == 2){
                    s1 += c;
                }
            }
        }
    }

    if(revflag == 1){
        reverse(s1.begin(),s1.end());
        cout << s1 << s << s2 << endl;
    }

    if(revflag == -1){
        reverse(s2.begin(),s2.end());
        reverse(s.begin(),s.end());
        cout << s2 << s << s1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll r, g, b;
  cin >> r >> g >> b;
  ll a = 100 * r + 10 * g + b;
  cout << (a % 4 == 0 ? "YES" : "NO") << endl;
}

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

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

	//string s;
	int n,k;//,b;

	cin >> n >> k;
	//cin >> s;
	
	//string ans="Yes";
	
	int ans=0;
	vector<int> h(n);
	
	rep(i,n){
		
		cin >> h[i];
		if((h[i]-k)>=0) ans++;
	}
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, K, a, b;

    cin >> N >> K;

    a = N%K;

    b = K-a;

    cout << min(a,b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=924844033,maxn=200010;
int hea[maxn],nxt[maxn<<1],to[maxn<<1],a[maxn<<2],b[maxn<<2],n,tot;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';x=(x<<1)+(x<<3)+ch-'0',ch=getchar());
	return x*f;
}
void add(int x,int y)
{
	nxt[++tot]=hea[x];
	hea[x]=tot;
	to[tot]=y;
}
int powmod(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
int dfs(int x,int fa)
{
	int s=1;
	for(int i=hea[x];i;i=nxt[i])if(to[i]!=fa)
	{
		int t=dfs(to[i],x);
		a[t]++;
		if(a[t]>=mod)a[t]-=mod;
		s+=t;
	}
	if(s<n)a[n-s]++;
	if(a[n-s]>=mod)a[n-s]-=mod;
	return s;
}
void NTT(int n,int *x,int f)
{
	for(int i=0,j=0;i<n;i++)
	{
		if(j<i)swap(x[i],x[j]);
		for(int l=n>>1;(j^=l)<l;l>>=1);
	}
	for(int i=2;i<=n;i<<=1)
	{
		int m=i>>1,wn=powmod(5,(mod-1)/i);
		if(f==-1)wn=powmod(wn,mod-2);
		for(int j=0;j<n;j+=i)
			for(int k=0,w=1;k<m;k++)
			{
				int t=1ll*w*x[j+k+m]%mod;
				x[j+k+m]=(x[j+k]-t+mod)%mod;
				x[j+k]=(x[j+k]+t)%mod;
				w=1ll*w*wn%mod;
			}
	}
	int t=powmod(n,mod-2);
	if(f==-1)
		for(int i=0;i<n;i++)
			x[i]=1ll*x[i]*t%mod;
}
int main()
{
	n=read();
	int x,y,s=1;
	for(int i=1;i<n;i++)
	{
		x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
	b[0]=1;
	for(int i=1;i<=n;i++)
	{
		s=1ll*s*i%mod;
		a[i]=1ll*a[i]*s%mod;
		b[i]=powmod(s,mod-2);
	}
	for(int i=0;i<=n>>1;i++)
		swap(a[i],a[n-i]);
	int n1=1,t=n<<1;
	while(n1<=t)n1<<=1;
	NTT(n1,a,1),NTT(n1,b,1);
	for(int i=0;i<n1;i++)
		a[i]=1ll*a[i]*b[i]%mod;
	NTT(n1,a,-1);
	int s1=1,s2=1;
	for(int i=1;i<=n;i++)
	{
		s1=1ll*s1*i%mod;
		s2=1ll*s2*(n-i+1)%mod;
		int t=powmod(s1,mod-2);
		printf("%lld\n",(1ll*n*s2%mod*t%mod-1ll*t*a[n-i]%mod+mod)%mod);
	}
	return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main () {
  long N, M;
  cin >> N >> M;
  vector<long> data(sqrt(M) + 1);
  for(int i = 2; i <= sqrt(M); i++){
    while(M % i == 0){
      data.at(i)++;
      M /= i;
    }
  }
  if(M != 1)data.at(0)++;
  COMinit();
  long ans = 1;
  for(int i = data.size() - 1; i >= 0; i--){
    ans *= COM(N - 1 + data.at(i), data.at(i));
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int k,a,b,c;
int ansppp;
void solve(){
	ansppp=a;
	k-=a;k++;
	if(k%2==1)ansppp++;
	ansppp+=(k/2)*(b-a);
	cout<<ansppp<<endl;
}
signed main(){
	cin>>k>>a>>b;
	if(a>=b-2){
        cout<<(k+1)<<endl;
        return 0;
    }
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        for(int i = 0; i<a.length()-1; i++){
            if(a.charAt(i) != a.charAt(i+1)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

vector<pair<llint, llint> > prime_factorize(llint n) {
    vector<pair<llint, llint> > res;
    llint num;

    for(llint p=2;p*p<=n;p++) {
        if (n%p!=0) continue;
        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;
}

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n;
    cin >> n;

    auto c = prime_factorize(n);

    llint ans = 0;
    for(auto ic:c) {
        llint q = ic.second;
        llint sum = 0;
        llint cnt = 1;

        while(sum<=q) {
            sum += cnt;
            if(sum>q) { 
                cnt--;
                break;
            }
            else if(sum==q) break;
            else ;
            cnt++;
        }
        ans += cnt;
    }

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


Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(){
	char c;
	int i;
	
	for(i=1;i<=19;i++){
		scanf("%c",&c);
		if(i==6 || i==14){
			printf(" ");
		}else{
			printf("%c",c);
		}
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 128