akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

S = input()

print(S[:5], end = "")
print(" ", end = "")
print(S[6:13], end = "")
print(" ", end = "")
print(S[14:])

Measured memory_bytes: 13596
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  vl sum(N+1,0);
  rep(i,N) {
    sum[i+1] = sum[i] + A[i];
  }
  ll ans = 0;
  drep(k,50) {
    int cnt = 0;
    ll tar = ans + ((1ll)<<k);
    rep(i,N) {
      srep(j,i,N) {
        ll num = sum[j+1]-sum[i];
        if((num&tar)==tar) cnt++;
      }
    }
    if(cnt>=K) {
      ans = tar;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S = 0
p = 1
for i in range(N-1):
  if S == 0 and A[i] < A[i+1]:
    S = 1
  elif S == 0 and A[i] > A[i+1]:
    S = -1
  elif S == 1 and A[i] > A[i+1]:
    S = 0
    p += 1
  elif S == -1 and A[i] < A[i+1]:
    S = 0
    p += 1
print(p)

Measured memory_bytes: 14228
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int k;
  cin>>k;
  int m;
  m = max(a,max(b,c));
  int r;
  r = m;
  REP(i,k){
    r *=2;
  }
  int ans;
  ans = a+b+c+r-m;
  cout<<ans<<endl;
  return 0;
  
}

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

int main(void){
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
    vector<vector<long long>> dp(N+1, vector<long long>(100001, 100000000001));
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 100000; j++) {
            if (j - v[i-1] < 0) dp[i][j] = dp[i-1][j];
            else dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1]);
        }
    }
    for (int i = 100000; i >= 0; i--) {
        if (dp[N][i] <= W) {
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 83236
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[2000010],finv[2000010],inv[2000010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,2000010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=res*x%inf;
        b/=2;
        x=x*x%inf;
    }
    return res;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    combinit();
    ll n,k;cin>>n>>k;
    vector<ll>a(n+2);
    a[0]=1;
    REP(i,1,n+2){
        a[i]=a[i-1]+n-2*(i-1);
        //cout<<a[i]<<endl;
    }
    ll ans=0;
    REP(i,k,n+2){
        ans=(ans+a[i])%inf;
        //cout<<a[i]<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 51732
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    if(A + B <= N){
        cout << min(A, B) << " "<< 0 << endl;
    }else{
        cout << min(A, B) << " "<< A + B - N << endl;
    }
    return 0;
}

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

public class Main{
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String[] list = br.readLine().split(" ");
			int A = Integer.parseInt(list[0]);
			int B = Integer.parseInt(list[1]);
			for(int C=1;C<=3;C++){
				int mul = A * B *C ;
				if((mul&1)==1){
					System.out.println("Yes");
					return;
				}
			}
			System.out.println("No");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 23124
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] candles = new int[N];
        for(int i = 0; i < N; i++)  candles[i] = sc.nextInt();
        
        int temp = 0, time = Integer.MAX_VALUE;

        for(int i = 0; i <= N - K; i++){
                int j = i+K-1;
                temp = Math.min(Math.abs(candles[i]), Math.abs(candles[j])) + candles[j] - candles[i];
                time = time < temp ? time : temp;
        }
         System.out.println(time); 
	}
}

Measured memory_bytes: 50536
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--, b--, c--, d--;
  string s;
  cin >> s;
  bool ok = true;
  for (int i = a; i < c; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') ok = false;
  }
  for (int i = b; i < d; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') ok = false;
  }
  if (a < b && b < d && d < c) {
    bool ng = true;
    for (int i = b; i <= d; ++i) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') ng = false;
    }
    if (ng) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	string o, e;
	string ans;

	cin >> o >> e;
	for (int i = 1; i <= o.length() + e.length(); i++) {
		if ((i % 2) != 0) {
			ans += o.substr(i / 2, 1);
		}
		else {
			ans += e.substr((i / 2) - 1, 1);
		}
	}


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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int i, n, s[13], h[13], c[13], d[13];
    cin >> n;
    for(i = 0; i < 13; i++){
        s[i] = 1;
        h[i] = 1;
        c[i] = 1;
        d[i] = 1;
    }
    string m;
    int t;
    for(i = 0; i < n; i ++){
        cin >> m >> t;
        if(m == "S"){
            s[t-1] = 0;
        }else if(m == "H"){
            h[t-1] = 0;
        }else if(m == "C"){
            c[t-1] = 0;
        }else if(m == "D"){
            d[t-1] = 0;
        }
    }
    for(i = 0; i < 13; i++){
        if(s[i]){cout << "S " << i+1 << endl;}
    }
    for(i = 0; i < 13; i++){
        if(h[i]){cout << "H " << i+1 << endl;}
    }
    for(i = 0; i < 13; i++){
        if(c[i]){cout << "C " << i+1 << endl;}
    }
    for(i = 0; i < 13; i++){
        if(d[i]){cout << "D " << i+1 << endl;}
    }
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x;
  int l;
  int ans = 1;
  int cnt = 0;
  
  cin >> n >> x;
  for(int i = 0;i < n;i++){
    cin >> l;
    cnt += l;
    if(x >= cnt){
      ans ++;
    }
  }

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



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

int idx[MAXN];
int par[MAXN];

int rep(int x) {
	if(x == par[x]) return x;
	return par[x] = rep(par[x]);
}

void Union(int x , int y) {
	int T , X = rep(x);
	int Y = rep(y);
	if(X < Y) T = X , X = Y , Y = T;
	if(X != Y) par[X] = Y;
}

int main()
{
	int N , K , x , y;
	cin >> N >> K;
	int arr[N + 1] , U[K + 1];
	for(int i = 1 ; i <= N ; i++) par[i] = i;
	for(int i = 1 ; i <= N ; i++) cin >> arr[i] , idx[arr[i]] = i;
	for(int i = 0 ; i < K ; i++) cin >> x >> y , Union(arr[x] , arr[y]);
	for(int i = 1 ; i <= N ; i++) {
		int x = rep(i) , y = rep(arr[i]);
		if(x == y) {
			arr[ idx[ i ] ] = arr[i];
			idx[ arr[i] ] = idx[i];
			arr[i] = i;

		}
	}
	int cnt = 0;
	for(int i = 1 ; i <= N ; i++) if(i == arr[i]) cnt++;
	cout << cnt << endl;
}


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

using namespace std;
int main()
{
	string s;
	int cnt=0;
	cin>>s;
	if(s[0]=='1') cnt++;
	if(s[1]=='1') cnt++;
	if(s[2]=='1') cnt++;
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;
  vs S(N);
  cin >> S;

  vvll ans(N, vll(N, -1));

  rep(i, N) rep(j, N) {
    if (ans[i][j] != -1) continue;

    ll ok = 1;
    rep(ii, N) rep(jj, N) {
      if (ii == jj) continue;

      ll ti = ii - i;
      if (ti < 0) ti = N + ti;
      ll tj = jj - j;
      if (tj < 0) tj = N + tj;

      ll oi = jj - i;
      if (oi < 0) oi = N + oi;
      ll oj = ii - j;
      if (oj < 0) oj = N + oj;

      if (S[ti][tj] != S[oi][oj]) ok = 0;
    }

    ll ni = i;
    ll nj = j;
    while (ni < N and nj < N) {
      ans[ni][nj] = ok;
      ni++;
      nj++;
    }
  }

  ll sum = 0;
  rep(i, N) rep(j, N) sum += ans[i][j];
  COUT(sum);

  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <tuple>
#include <stdlib.h>

using namespace std;

int main()
{
	bool flag = true;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++)
	{
		if (i % 2) {
			if (S[i] == 'R')flag = false;
		}
		else
		{

			if (S[i] == 'L')flag = false;
		}
	}
	cout << (flag ? "Yes" : "No");
	return 0;
}

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

typedef long long ll;

int N;
ll a[401], pref[401], dp[401][401];

ll interval(int i, int j)
{
    return pref[j] - pref[i-1];
}

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", a + i);
        pref[i] = pref[i-1] + a[i];
    }
    for (int l = 1; l < N; l++)
    {
        for (int i = 1; i <= N; i++)
        {
            if (i + l > N) break;
            dp[i][i+l] = dp[i][i] + dp[i+1][i+l] + interval(i, i+l);
            for (int j = 1; j < l; j++)
            {
                dp[i][i+l] = min(dp[i][i+l], dp[i][i+j] + dp[i+j+1][i+l] + interval(i, i+l));
            }
        }
    }
    printf("%lld\n", dp[1][N]);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long X)

{
    if(X==1){
        cout << 1 << endl;
    }
    for (int i = X; i >= 1; i--)
    {
        for (int j = 2; j*j <= i; j++)
        {
            ll tmp = i;
            while (tmp % j == 0)
            {
                tmp /= j;
            }
            if (tmp == 1)
            {
                cout << i << endl;
                return;
            }
        }
    }
}

int main()
{
    long long X;
    scanf("%lld", &X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n, k;
  cin >> n >> k;
  int tmp;
  vector<int> b(n + 1, 0);
  for (int i = 0; i < n; i++){
    cin >> tmp;
    b[tmp]++;
  }
  sort(b.begin(), b.end());
  int count = 0, ans;
  for (int i = 0; i <= n-k; i++){
    count+=b[i];
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R) >> 1)
using namespace std;
typedef long long LL;
const int N = 200500;
const int mod = 998244353;
bool is[N];
int x[N], y[N], h[N], n;
bool cmp(const int &o, const int &p) { return x[o] < x[p]; }
bool cmp1(const int &o, const int &p) { return y[o] < y[p]; }
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &x[i], &y[i]);
		if (x[i] > y[i]) swap(x[i], y[i]);
		h[i] = i;
	}
	sort(h, h + n, cmp1);
	int mx = h[n - 1];
	LL ans = y[h[n - 1]] - y[h[0]];
	sort(h, h + n, cmp);
	int mn = h[0];
	ans *= x[h[n - 1]] - x[h[0]];
	if (mn == mx) {
		cout << ans << endl;
		return 0;
	}
	multiset<int> s;
	for (int i = 0; i < n; ++i) {
		if (i == mn) {
			s.insert(y[i]);
		} else {
			s.insert(x[i]);
		}
	}
	LL con = y[mx] - x[mn];
	int ans2 = *s.rbegin() - *s.begin();
	for (int i = 1; i < n; ++i) {
		if (h[i] == mx) continue;
		s.erase(s.find(x[h[i]]));
		s.insert(y[h[i]]);
		ans2 = min(ans2, *s.rbegin() - *s.begin());
	}
	cout << min(ans, con * ans2) << endl;
	return 0;
}


Measured memory_bytes: 13952
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 kk, tt, aa, sum = 0;
	cin >> kk >> tt;
	multiset<int64> memo;
	for(int64 ii = 0;ii < tt;ii++)
	{
		cin >> aa;
		memo.insert(aa);
		sum += aa;
	}
	auto ite = memo.end();
	ite--;
	sum -= *ite;
	cout << (max((int64)0, *ite - sum - 1)) << endl;
	return 0;
}

Measured memory_bytes: 3580
// 2020-08-16 09:43:03
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  vector<ll> c(n);
  rep(i, n) cin >> c[i];
  ll ans = -1e18;
  rep(si, n) {
    ll sum = 0;
    vector<ll> d;
    {
      int x = si;
      while(1) {
        x = p[x];
        sum += c[x];
        d.push_back(c[x]);
        if(si == x) break;
      }
    }
    chmax(sum, 0ll);
    int sz = d.size();
    {
      ll cur = 0;
      rep(i, sz) {
        if(i+1 > k) break;
        cur += d[i];
        ll q = (k-(i+1))/sz;
        chmax(ans, cur + sum * q);
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3828
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int T = sc.nextInt();
      int A = sc.nextInt();
      double[] Temp = new double[N];
      
      double min = (double)Integer.MAX_VALUE;
      int minNum = -1;
      
      for(int i=0; i<N; i++){
        double temp = sc.nextDouble();
        if(Math.abs(A - (T - temp*0.006)) < min) {
			min = Math.abs(A - (T - temp*0.006));
            minNum = i+1;               
        }  
      }  
      System.out.println(minNum);
    }  
} 

Measured memory_bytes: 28244
q = int(input())
import math
def is_prime(n):
	if n == 1:
		return False
	
	for k in range(2, int(math.sqrt(n)) + 1):
		if n%k == 0:
			return False
	return True

a = [0 for i in range(10**5+1)]
for i in range(1,10**5+1,2):
	if is_prime(i) and is_prime((i+1)//2):
		a[i] = a[i-1] + 1
		a[i+1] = a[i-1] + 1
	else:
		a[i] = a[i-1]
		a[i+1] = a[i-1]
for i in range(q):
	l, r = map(int, input().split())
	print (a[r]-a[l-1])

Measured memory_bytes: 4400
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

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

    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string sx; cin >> sx;
    a -= (sx == s);
    b -= (sx == t);

    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import sys
n, m = map(int, sys.stdin.readline().split())
a=[sys.stdin.readline().split() for i in range(m)]
wa = [0 for i in range(n)]
ac = [0 for i in range(n)]

for i in range(m):
    p = int(a[i][0])-1
    s = a[i][1]
    if s=="WA" and ac[p]==0:
        wa[p] +=1
        #print(wa, 'wa')
    elif s=="AC":
        ac[p] = 1
        #print(ac, 'ac')

cnt=0
for i in range(n):
    if ac[i]==1:
        cnt += wa[i]
print(sum(ac), cnt)

Measured memory_bytes: 33864
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint l(N);
    REP(i,N) cin>>l[i];

    sort(ALL(l),greater<int>());
    cout<<accumulate(l.begin(),l.begin()+K,0LL)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << (A * (double)B / 2);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			String ans = "No";
			for(int i = 1; i <= 9; i++) {
				for(int j = 1; j <= 9; j++) {
					if(i * j == N) {
						ans = "Yes";
						break;
					}
				}
			}
			System.out.println(ans);
		}
	}

	static boolean permutation_2(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}

		int[] letters = new int[256];

		char[] s_array = s.toCharArray();
		for (char c : s_array) {
			letters[c]++;
		}

		for (int i = 0; i < t.length(); i++) {
			int c = (int) t.charAt(i);
			if (--letters[c] < 0) {
				return false;
			}
		}
		return true;
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 23380
M, D = map(int, input().split())

ret = 0
for i in range(1, M+1):
    for j in range(1, D+1):
        d10 = j // 10
        d1 = j % 10
        if i == d10 * d1 and d1 >= 2 and d10 >= 2:
            ret += 1

print(ret)


Measured memory_bytes: 2940
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a;
    string str;
    int cou[4]={0};
    while(scanf("%d",&a)!=EOF){
        cin>>str;
        if(str.size()==3)cou[2]++;
        else if(str[1]=='A')cou[0]++;
        else if(str[1]=='O')cou[3]++;
        else if(str[1]=='B')cou[1]++;
    }
    for(int i=0;i<4;i++)cout<<cou[i]<<endl;
    return 0;
}

Measured memory_bytes: 1232
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

template<class T> void ReadInteger(T & x) {
    x = 0;
    int f = 1, ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 - '0' + ch;
        ch = getchar();
    }
    x *= f;
}

typedef long long LL;

const LL inf = 1LL << 60;
int N;
int head[205], ecnt;
queue< pair<int, int> > q;

struct edge {
    int to, nex;
};
edge G[205];
inline void addedge(int u, int v) {
    G[ecnt] = (edge) {v, head[u]};
    head[u] = ecnt++;
    G[ecnt] = (edge) {u, head[v]};
    head[v] = ecnt++;
}

int dep[205], anc[205], d;
void DFS(int u, int step) {
    dep[u] = step;
    if(step > dep[d]) d = u;
    for(int i = head[u]; ~ i; i = G[i].nex) {
        int v = G[i].to;
        if(v != anc[u]) {
            anc[v] = u;
            DFS(v, step + 1);
        }
    }
}

int cnt[205], vis[205];
LL BFS(int st, int f) {
    if(!st) return inf;
    if(f && !anc[st]) return inf;
    memset(cnt, 0, sizeof(cnt));
    memset(vis, 0, sizeof(vis));
    q.push(make_pair(st, 1)), cnt[1]++, vis[st] = 1;
    if(f) q.push(make_pair(anc[st], 1)), cnt[1]++, vis[ anc[st] ] = 1;
    while(!q.empty()) {
        int u = q.front().first;
        int d = q.front().second;
        vis[u] = 1;
        q.pop();
        int deg = 0;
        for(int i = head[u]; ~ i; i = G[i].nex) {
            int v = G[i].to;
            if(!vis[v]) {
                q.push(make_pair(v, d + 1));
                deg++;
            }
        }
        cnt[d + 1] = max(cnt[d + 1], deg);
    }
    /*cout << "DEBUG " << st << ' ' << anc[st] << endl;*/
    long long res = 1;
    for(int i = 1; i <= N; i++) if(cnt[i]) {
        /*cout << i << ' ' << cnt[i] << endl;*/
        res *= cnt[i];
        if(i > (dep[d] + 1) / 2) return inf;
    }
    return res;
}

void Solve() {
    DFS(1, 1);
    memset(anc, 0, sizeof(anc));
    DFS(d, 1);
    long long ans = inf;
    for(int i = 1; i <= N; i++) ans = min(ans, BFS(i, 0));
    for(int i = 1; i <= N; i++) ans = min(ans, BFS(i, 1));
    printf("%d %lld\n", (dep[d] + 1) >> 1, ans);
}
int main() {
    ReadInteger(N);
    memset(head, -1, sizeof(head));
    for(int i = 1; i < N; i++) {
        int u, v;
        ReadInteger(u);
        ReadInteger(v);
        addedge(u, v);
    }
    Solve();
    return 0;
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


long long n, m, ma = -INF, mi = INF, sum;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		ma = max(ma, m);
		mi = min(mi, m);
		sum += m;
	}
	cout << mi << " " << ma << " " << sum << endl;
}


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

int main() {
    long mod = 1e9+7;
    string S;
    cin>>S;
    long Anum = 0, ABnum = 0, ABCnum = 0;
    long patturn = 1;
    for(int i=0;i<S.size();++i){
        if(S[i]=='A'){
            Anum += patturn;
        }
        if(S[i]=='B'){
            ABnum += Anum;
        }
        if(S[i]=='C'){
            ABCnum += ABnum;
        }
        if(S[i]=='?'){
            ABCnum = ABCnum * 3 + ABnum;
            ABnum = ABnum * 3 + Anum;
            Anum = Anum * 3 + patturn;
            patturn *= 3;
        }
        Anum %= mod;
        ABnum %= mod;
        ABCnum %= mod;
        patturn %= mod;
    }
    cout<<ABCnum<<endl;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main{
  static int n;
  static int[] t;
  static boolean[] used, passed;

  /*
  //stack over flow function

  static int dfs(int id){
    if(used[id]){
      if(!passed[id]){
        return t[id];
      }
      return -1;
    }
    if(t[id] == 0){
      return id;
    }

    used[id] = passed[id] = true;
    t[id] = dfs(id + t[id]);

    return t[id];
  }
  */

  static void loop(int start){
    passed = new boolean[n + 2];

    int id = start;
    int to = -1;
    ArrayList<Integer> al = new ArrayList<Integer>();

    while(true){
      if(used[id]){
        to = passed[id] ? -1 : t[id];
        break;
      }
      if(t[id] == 0){
        to = id;
        break;
      }

      al.add(id);
      used[id] = passed[id] = true;
      id += t[id];
    }

    for(int x : al){
      t[x] = to;
    }
  }

  static int dijk(){
    boolean[] closed = new boolean[n + 2];
    PriorityQueue<State> open = new PriorityQueue<State>();

    open.add(new State(0, 0));

    while(!open.isEmpty()){
      State st = open.poll();

      if(st.id == n - 1) return st.cost;
      if(closed[st.id]) continue;
      closed[st.id] = true;

      if(used[st.id]){
        if(t[st.id] == -1) continue;
        open.add(new State(t[st.id], st.cost));
      }
      else{
        for(int i = 1; i <= 6; i++){
          if(st.id + i >= n) break;
          open.add(new State(st.id + i, st.cost + 1));
        }
      }
    }

    return -1;
  }

  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while(br.ready()){
      n = Integer.parseInt(br.readLine());
      t = new int[n + 2];
      used = new boolean[n + 2];

      for(int i = 0; i < n; i++){
        t[i] = Integer.parseInt(br.readLine());
      }

      for(int i = 0; i < n; i++){
        if(t[i] != 0 && !used[i]){
          loop(i);
        }
      }

      System.out.println(dijk());
    }
  }
}

class State implements Comparable<State>{
  int id, cost;

  State(int id, int cost){
    this.id = id;
    this.cost = cost;
  }

  public int compareTo(State st){
    return this.cost - st.cost;
  }
}

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

bool isok(string s){
  string t(s);
  reverse(t.begin(), t.end());
  return s == t;
}

int main(){
  string s; cin >> s;
  int n = (int)s.size();
  
  bool ans = true;
  
  if(!isok(s)) ans = false;
  if(!isok(s.substr(0,n/2))) ans = false;
  if(!isok(s.substr(n/2+1))) ans = false;
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

using namespace std;

using ll = long long int;

int main() {
    // Input
    int K;
    string S;
    cin >> K;
    cin >> S;

    // Process
    string ans;
    if (S.size() <= K) {
        ans = S;
    } else {
        ans = S.substr(0, K) + "...";
    }

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

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

using namespace std;

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

	cout << t / a * b << endl;

	return 0;
}

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

string s,t,u;
int a,b;

int main()
{
	cin>>s>>t>>a>>b>>u;

   	if(u==s)
   		cout<<(a-1)<<" "<<b;
   	else
   		cout<<a<<" "<<(b-1);

}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;

class Main {

    //public static PrintWriter pw;
    public static PrintWriter pw = new PrintWriter(System.out);

    public static  void solve() throws IOException {
        //	pw=new PrintWriter(new FileWriter("C:\\Users\\shree\\Downloads\\small_output_in"));
        FastReader sc = new FastReader();
        String s1=sc.next();
        String s2=new String(s1);
        s2=s2.replaceAll("x","");
        if(!isPalindrome(s2)){
            pw.println(-1);
            pw.close();
            return;
        }
        int ans=0;
        int i=0,j=s1.length()-1;
        while(i<j){
            if(s1.charAt(i)!=s1.charAt(j)){
                if(s1.charAt(i)=='x'){
                    i++;

                }else j--;
                ans++;
            } else {
                i++; j--;
            }
        }
        pw.println(ans);
        pw.close();

    }
    static boolean isPalindrome(String s2){
        int i=0,j=s2.length()-1;
        while(i<j){
            if(s2.charAt(i)!=s2.charAt(j)) return false;
            i++; j--;
        }
        return true;
    }


    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                try {

                    solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();

    }

    static BufferedReader br;
    static long M = (long) 1e9 + 7;

    static class FastReader {

        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            //br=new BufferedReader(new FileReader("C:\\Users\\shree\\Downloads\\B-small-practice.in"));
            br = new BufferedReader(new InputStreamReader(System.in));

        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int I() {
            return Integer.parseInt(next());
        }

        long L() {
            return Long.parseLong(next());
        }

        double D() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public boolean hasNext() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return false;
                }
                st = new StringTokenizer(s);
            }
            return true;
        }

    }
}

Measured memory_bytes: 33620
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long w,h,x,y;
  cin >> w >> h >> x >> y;
  printf("%.10lf ",(double)w*h/2);
  if(w==x*2 and h==y*2){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
LL A[210012], CUM[210012];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    LL total = 0, ans = 505050505050505;
    rep(i, N){
        scanf("%lld", A + i);
        CUM[i + 1] = CUM[i] + A[i];
        total += A[i];
    }
    // rep(i, N + 1) printf("%d ", CUM[i]);
    // printf("\n");
    
    // 2. 棒の長さを二等分するには？
    rep(i, N + 1) ans = min(ans, abs(total - 2 * CUM[i]));
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll n;
    cin>>n;
    
    cout<<n/2+bool(n%2 != 0)<<endl;
    return 0;
}
    
    



Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
use std::collections::HashMap;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let _n: usize = read_line()[0];
    let a: Vec<usize> = read_line();

    let mut temp_dict: HashMap<usize, usize> = HashMap::new();

    let mut res: usize = 0;
    for (i, &a_i) in a.iter().enumerate() {
        let left: usize = i + 1 + a_i;

        if i + 1 >= a_i {
            let right: usize = i + 1 - a_i;

            match temp_dict.get(&right) {
                Some(cum_num) => {res += cum_num},
                _ => {},
            }
        }

        *(temp_dict.entry(left).or_insert(0)) += 1
    }

    println!("{}", res);
}


Measured memory_bytes: 12240
#include "stdio.h"

int main(){
  int ret ;	
  int maxNum;
  ret = scanf("%d", &maxNum);
  int dataAaray[200];
  int ii;  
  int retCount;

  //情報を取得
  for(ii=0;ii<maxNum;ii++){
    ret = scanf("%d",&dataAaray[ii]);
  }
  
  while(1){
      int count = 0;
      //偶数奇数を判定
      for(ii=0;ii<maxNum;ii++){
        if(0==(dataAaray[ii]%2))
          count++;
      } 
      //Count==maxNumなら/2
      if(count==(maxNum)){
         retCount++;
          for(ii=0;ii<maxNum;ii++)
            dataAaray[ii]/=2;
      }else{
        break;
      }
  }
  printf("%d",retCount);
  
	return 0; 
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	string str;
	getline(cin, str);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string command;
		cin >> command;
		if (command == "replace")
		{
			int beginIdx, endIdx;
			cin >> beginIdx >> endIdx;
			int len = endIdx - beginIdx + 1;
			string tmp;
			cin >> tmp;
			str.replace(beginIdx, len, tmp);
		}
		else if (command == "reverse")
		{
			int idx1, idx2;
			cin >> idx1 >> idx2;
			reverse(str.begin() + idx1, str.begin() + idx2+1);
		}
		else if (command == "print")
		{
			int idx1, idx2;
			cin >> idx1 >> idx2;
			int len = idx2 - idx1 + 1;
			string tmp = str.substr(idx1, len);
			cout << tmp << endl;
		}
	}
}


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

int main(){
  char C;
  cin >> C;
  
  switch(C){
    case 'A':
      cout << 'T';
      break;
    case 'G':
      cout << 'C';
      break;
    case 'T':
      cout << 'A';
      break;
    case 'C':
      cout << 'G';
      break;
    default :
      break;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2001;
vector<ll> g[N];
int dis[2001][2001];
vector<pair<ll,ll>> edges;
vector<bool> vis(2001);
void dfs(int start){
    queue<ll> q;
    fill(vis.begin(),vis.end(),false);
    q.push(start);
    vis[start]=true;
    dis[start][start]=0;
    while(!q.empty()){
        int cur=q.front();
        q.pop();
        for(int i:g[cur]){
            if(vis[i]) continue;
            q.push(i);
            vis[i]=true;
            dis[start][i]=1+dis[start][cur];
        }
    }
}
int main(){
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
        edges.push_back({x,y});
    }
   for(int i=1;i<=n;i++) dfs(i);
    if(k%2==0){
        ll ans=1e16;
        for(int i=1;i<=n;i++){
            ll cnt=0;
            for(int j=1;j<=n;j++){
                if(dis[i][j]>k/2) cnt++;
            }
            ans=min(ans,cnt);
        }
        cout<<ans<<endl;
    }
    else{
        ll ans=1e16;
        k--;
        for(int i=0;i<edges.size();i++){
            ll cnt=0;
            for(int j=1;j<=n;j++){
                if(dis[edges[i].first][j]>k/2 && dis[edges[i].second][j]>k/2) cnt++;
            }
            ans=min(ans,cnt);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 19392
#include <stdio.h>

int t[105], r[105];
int s[4];

int main(void)
{
	int n, i, j, a;
	
	scanf("%d", &n);
	
	for (i = 0; i < n * (n - 1) / 2; i++){
		for (j = 0; j < 4; j++){
			scanf("%d", &s[j]);
		}
		if (s[2] == s[3]){
			t[s[0] - 1]++;
			t[s[1] - 1]++;
		}
		else if (s[2] > s[3]){
			t[s[0] - 1] += 3;
		}
		else{
			t[s[1] - 1] += 3;
		}
	}
	
	for (i = 0; i < n; i++){
		for (j = 0; j < n; j++){
			if (t[i] < t[j]){
				r[i]++;
			}
		}
		printf("%d\n", r[i] + 1);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 

typedef unsigned long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

const int DIM = 120;

int v1[DIM];
int v2[DIM];

main()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> v1[i];
		v1[i] += v1[i - 1];
	}
	
	for(int i = 1; i <= n; i++)
	{
		cin >> v2[i];
		v2[i] += v2[i - 1];
	}
	
	int mx = 0;
	
	for(int i = 1; i <= n; i++)
		amax(mx, v1[i] + v2[n] - v2[i - 1]);
	
	cout << mx;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

bool in_field(int x, int y, int W, int H)
{
    return (0 <= x && x < W && 0 <= y && y < H);
}

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> M(H, vector<int>(W));
    vector<pair<int, int>> a(H * W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> M[i][j];
            a[M[i][j] - 1] = make_pair(j, i);
        }
    }
    
    vector<vector<int>> ridge(H, vector<int>(W, -1));
    constexpr int dx[] = {-1, 0, 1, 0};
    constexpr int dy[] = {0, -1, 0, 1};
    
    int res = 0;
    for (int i = 0; i < H * W; i++) {
        int x, y, large_cnt = 0;
        vector<int> r;
        tie(x, y) = a[i];
        for (int j = 0; j < 4; j++) {
            int nx = x + dx[j];
            int ny = y + dy[j];
            
            if (!in_field(nx, ny, W, H)) {
                ++large_cnt;
                continue;
            }
            if (ridge[ny][nx] >= 0) {
                r.emplace_back(ridge[ny][nx]);
            }
                
            large_cnt += (M[y][x] < M[ny][nx]);
        }

        constexpr int MUL = 252521;
        
        if (large_cnt == 4) {
            ridge[y][x] = i;
        } else {
            sort(r.begin(), r.end());
            r.erase(unique(r.begin(), r.end()), r.end());
            
            int rs = r.size();
            if (rs == 1) {
                ridge[y][x] = r[0];
            } else {
                ridge[y][x] = MUL;
            }
        }

        if (ridge[y][x] == MUL) {
            ++res;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 18648
namelist="MARCH"
N=int(input())
bucket=[0,0,0,0,0]

for i in range(N):
	msg=input()
	for k in range(5):
		if(msg[0]==namelist[k]):
			bucket[k]+=1;

s=0
for i in range(0,3):
	for j in range(i+1,4):
		for k in range(j+1,5):
			s+=bucket[i]*bucket[j]*bucket[k]
print (s)

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

using namespace std;

struct abc072_d{
  int N;
  vector<int> v;
  void init(){
    cin >> N;
    v.resize(N);
    for(auto&& x:v)cin >> x;
  }
  
  void solve(){
    init();
    int ans = 0;
    for(int i=0;i<N-1;i++){
      if(v[i] == i+1){
        swap(v[i], v[i+1]);
        ans++;
      }
    }
    if(v[N-1] == N){
      swap(v[N-2], v[N-1]);
      ans++;
    }
    cout << ans << endl;
  }
};

int main(){
  abc072_d ins;
  ins.solve();
}

Measured memory_bytes: 640