akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n),l(n),r(n+1),s(n+1);
    rep(i,n)cin >> a[i];
    s[0] = a[0];
    rep(i,n){
        if(i==0)continue;
        s[i] = s[i-1]+a[i];
    }
    rep(i,n){
        if(a[i]>0)l[i] += a[i];
        if(i!=0)l[i]+=l[i-1];
    }
    for(int i=n-1;i>=0;i--){
        if(a[i]>0)r[i] += a[i];
        if(i<n-1)r[i] += r[i+1];
    }
    ll ans = max(s[k-1]+r[k],r[k]);
    for(int i=0;i<n-k;i++){
        ll tmp = 0;
        tmp += s[i+k]-s[i];
        tmp += l[i];
        tmp += r[i+k+1];
        ans =max(ans,tmp);
        tmp = 0;
        tmp += l[i];
        tmp += r[i+k+1];
        ans =max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int a[20];
int x[20][20];
int y[20][20];

int counter(int x){
  if(x==0) return 0;
  return counter(x>>1)+(x&1);
}

signed main()
{
  int n;
  cin>>n;
  
  for(int i=1; i<=n; i++){
    cin>>a[i];
    for(int j=1; j<=a[i]; j++){
      cin>>x[i][j]>>y[i][j];
    }
  }
  int ans=0;
  // bits ビットが立っているところが人iが正しい証言をしていることを意味する
  for(int bits=1; bits<(1<<n); bits++){
    bool ok=true;
    // 最大15人の人iについてのループ
    for(int i=1; i<=n; i++){
      // ビットiが立っている時だけ処理する
      // 正しい証言をしていると仮定しているもの(=ビットが立っている)だけ確認すればよい
      // iが立っていないものは「不確か」であって、「不正確であること」では無い事に注意
      if(!(bits & (1<<(i-1)))) continue;
      // 各人iの証言についてのループ
      for(int j=1; j<=a[i]; j++){
        // 矛盾しないかを判定する
        // 0^1 (bits上は不親切と仮定したのに正直者であると証言してしまっている)
        // 1^0 (正直者と仮定したのに不親切と証言してしまっている)
        if(((bits>>x[i][j]-1)&1) ^ y[i][j]) {
          // bits上正しいと仮定した人iの証言が全て矛盾しなければここを通らず、
          // bitsの立っているビットの数が、正直者の数と同地になる
          ok = false;
          break;
        }
      }
    }
    if(ok) chmax(ans, counter(bits));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

const int MAXN = 100000;

int value[MAXN];

int ask(int pos) {
  if (value[pos] != -1) {
    return value[pos];
  }

  printf("%d\n", pos);
  fflush(stdout);
  char buf[100];
  scanf("%s", buf);
  if (buf[0] == 'M') {
    return value[pos] = 0;
  } else if (buf[0] == 'F') {
    return value[pos] = 1;
  } else {
    exit(0);
  }
}

int check(int lf, int rg) {
  int v1 = ask(lf);
  int v2 = ask(rg);
  return v1 ^ v2 ^ ((rg - lf) & 1);
}

int main() {
#ifdef LOCAL
//  freopen("c.in", "r", stdin);
//  freopen("c.out", "w", stdout);
#endif

  memset(value, -1, sizeof(value));


  int n;
  scanf("%d", &n);
  int lf = 0;
  int rg = n - 1;
  assert(check(lf, rg));

  while (true) {
    int m = (lf + rg) / 2;
    if (check(lf, m)) {
      rg = m;
    } else {
      assert(check(m, rg));
      lf = m;
    }
  }

  return 0;
}


Measured memory_bytes: 1236
/*
 * Author: apikdech
 * Time: 19:37:33 15-06-2019
 * Last Modified: 20:01:11 15-06-2019
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007, N = 55;
int x[N], y[N];
map<pair<int, int>, int> m;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			m[{x[i]-x[j], y[i]-y[j]}]++;
			m[{x[j]-x[i], y[j]-y[i]}]++;
		}
	}
	for (auto it : m) ans = max(ans, it.second);
	cout << n - ans << "\n";
	// cerr << "time = " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

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

map<string,int>my;

int main()
{
    int n;
    cin>>n;
    string str;
    char pre;
    int flag = 0;
    for(int i = 0;i < n;i++)
    {
        cin>>str;
        if(i == 0)
            pre = str[str.length() - 1];
        else{
            if(pre != str[0] || my[str])
                flag = 1;
            pre = str[str.length() - 1];
        }
        my[str] = 1;

    }
    if(!flag)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
// 1_2_D

#include <iostream>
using namespace std;

int main(){
  int W, H, x, y, r;
  cin >> W; cin >> H; cin >> x; cin >> y; cin >> r;
  if(x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
  int n,m;
  cin>>n>>m;
  int sum=0;
  while(m--)
  {
    int x ;
    cin>>x;
    sum+=x;
  }
  if(n-sum < 0)
  {
    cout<<"-1\n";
  }
  else
  {
    cout<<n-sum<<"\n";
  }
}


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

#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) int t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
const ll mod=1e9 +7;const ll M1=998244353;
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;x=x*x;y=y>>1;}return res;}

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

    int n,k;cin>>n>>k;
    vector<int> h(n),dp(n+1,mod);
    f(i,0,n)cin>>h[i];
    dp[1]=0;
   // dp[2]=abs(h[1]-h[0]);//ce(dp[2]);
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i>j)dp[i]=min(dp[i-j]+abs(h[i-1]-h[i-j-1]),dp[i]);
        }
    }cs(dp[n]);


}

Measured memory_bytes: 3988
from collections import deque

N, M = map(int, input().split())
graph = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
# print(graph)

res = [-1] * (N)
que = deque()
que.append(0)

while que:
    i = que.popleft()
    for j in graph[i]:
        if res[j] == -1:
            res[j] = i
            que.append(j)

print("Yes")
for i in res[1:]:
    print(i+1)


Measured memory_bytes: 94988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template <typename T>
void print(vector<T> v) {
    for(int i = 0; i < v.size(); ++i) cout << i << v[i] << " ";
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0); 
    
    int n; cin >> n;
    string s; cin >> s;
    ll ans = 0;
    vector<int> pg(n + 1, 0), pr(n + 1, 0), pb(n + 1, 0);
    for(int i = 0; i < n; ++i) {
        pg[i + 1] += pg[i] + (s[i] == 'G');
        pb[i + 1] += pb[i] + (s[i] == 'B');
        pr[i + 1] += pr[i] + (s[i] == 'R');
    }
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            if (s[i] == s[j]) continue;
            int d = (j - i);
            char cur = 'R';
            if (s[i] != 'G' and s[j] != 'G') {
                cur = 'G';
                ans += pg[n] - pg[j];
            } else if (s[i] != 'B' and s[j] != 'B') {
                cur = 'B';
                ans += pb[n] - pb[j];
            } else {
                ans += pr[n] - pr[j];
            }
            if (d + j < n and s[d + j] == cur) ans--;
        }
    }
    cout << ans << endl;   
}

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

const ll MOD = (ll)1e9 + 7;

ll n, k;
vector<ll> v;
void solve() {
    cin >> n >> k;
    v.push_back(0);
    for (ll i = 1; i <= n; i++) {
        v.push_back(v[i-1] + i);
    }

    ll ans = 1;
    for (int i = k; i <= n; i++) {
        ll mi = v[i-1];
        ll mx = v[n] - v[n-i];
        ans += mx - mi + 1;
        ans %= MOD;
        // cout << mi << " " << mx << " " << ans << endl;
    }

    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 5348
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
signed main(){
	int n;
	cin>>n;
	if(n==1)puts("Hello World");
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt();
    Arrays.sort(A);
    long[] cum = new long[N];
    cum[0] = A[0];
    for (int i = 1; i < N; i++) {
      cum[i] = cum[i - 1];
      cum[i] += A[i];
    }

    int p = N - 2;
    while (p >= 0 && cum[p] * 2 >= A[p + 1]) p--;
    System.out.println(N - p - 1);
  }
}


Measured memory_bytes: 50592
#include <bits/stdc++.h>
using namespace std;
int LOG = 20;
int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x[i];
  }
  int L;
  cin >> L;
  vector<vector<int>> next(LOG, vector<int>(N));
  for (int i = 0; i < N; i++){
    next[0][i] = upper_bound(x.begin(), x.end(), x[i] + L) - x.begin() - 1;
  }
  for (int i = 1; i < LOG; i++){
    for (int j = 0; j < N; j++){
      next[i][j] = next[i - 1][next[i - 1][j]];
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int a, b;
    cin >> a >> b;
    if (a > b){
      swap(a, b);
    }
    a--;
    b--;
    int ans = 0;
    for (int j = LOG - 1; j >= 0; j--){
      if (next[j][a] < b){
        ans += (1 << j);
        a = next[j][a];
      }
    }
    cout << ans + 1 << endl;
  }
}

Measured memory_bytes: 11904
import sys


def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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


def input():
    return sys.stdin.readline().rstrip()


#############
# Main Code #
#############
a = getN()
b = getN()
h = getN()
print(h * (a + b) // 2)


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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second

using namespace std;

const int N = (int) (1 << 18) + 10;

int n;
int a[N];

bool is_submask(int mask, int val) {
	return (val | mask) == mask;
}

#define li vector<pii> 

li v[N];

void merge(li &v, li x) {
	for (auto it : x) v.pb(it);
	sort(all(v), greater<pii>());
	v.resize(unique(all(v)) - v.begin());
	while (sz(v) > 2) v.pop_back();
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	for (int i = 0; i < (1 << n); i++) 
		cin >> a[i];
	for (int i = 0; i < (1 << n); i++) 
		merge(v[i], {{a[i], i}});
	for (int mask = 0; mask < (1 << n); mask++) {
		for (int  i = 0; i < n; i++) {
			if ((mask >> i) % 2) {
				merge(v[mask], v[mask - (1 << i)]);
			}
		}
	}
	for (int K = 1; K < (1 << n); K++) {
		int ans = 0;
		for (int id = 0; id < n; id++) { 
			if ((K >> id) % 2 == 0)
				continue;
			// position where bit of (i | j) < bit of K
			int mask = 0;
			for (int pos = id + 1; pos < n; pos++) {
				if ((K >> pos) % 2) 
					mask |= (1 << pos);
			}
			// mask(id) => 0
			for (int pos = 0; pos < id; pos++) { 
				mask |= (1 << pos);
			}
			if (sz(v[mask]) > 1)
				ans = max(ans, v[mask][0].f + v[mask][1].f);
		}
		if (sz(v[K]) > 1)
			ans = max(ans, v[K][0].f + v[K][1].f);
		cout << ans << "\n";
	}		
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

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

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

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

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

  int n;
  cin >> n;

  int ans = 0;
  rep(i, n) {
    int l, r;
    cin >> l >> r;
    int tmp = r - l + 1;
    ans += tmp;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
const int MOD = 1e9 + 7; // 10^9 + 7
using namespace std;

// ------------------ コンビネーション関数 ------------------ //
// ---------------- 使用前「COMinit();」必須 ---------------- //
const int MAX = 510000;
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 GCD(int x, int y) {
	if (x == 0) return y;
	else GCD(y % x, x);
}

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}


// ------------------------------------------------ //
// ------------------ ここから下 ------------------ //
// ------------------------------------------------ //

int main(void) {

	int S, W;
	cin >> S >> W;
	cout << (S <= W ? "unsafe" : "safe") << endl;

	return 0;
}

Measured memory_bytes: 3676
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    rep(i, tx - sx) cout << "R";
    rep(i, ty - sy) cout << "U";
    rep(i, tx - sx) cout << "L";
    rep(i, ty - sy) cout << "D";
    cout << "L";
    rep(i, ty - sy + 1) cout << "U";
    rep(i, tx - sx + 1) cout << "R";
    cout << "D";
    cout << "R";
    rep(i, ty - sy + 1) cout << "D";
    rep(i, tx - sx + 1) cout << "L";
    cout << "U" << endl;
    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n;
string s,t;
int main()
{
	cin>>n>>s>>t;
	int ans=mod;
	for(int i=0;i<=min(s.size(),t.size());i++)
	{
		string s1=s+t.substr(i);
		string s2=s.substr(0,s.size()-i)+t;
		if(s1==s2)ans=min(ans,int(s.size()+t.size()-i));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;cin>>H>>W;
    vector<vector<int>>c(10,vector<int>(10));
    rep(i,0,10)rep(j,0,10)cin>>c[i][j];
    rep(i,0,10)c[i][i]=0;
    rep(k,0,10)rep(i,0,10)rep(j,0,10)
        chmin(c[i][j],c[i][k]+c[k][j]);
    long long ans(0);
    rep(i,0,H)rep(j,0,W){
        int a;cin>>a;
        if(a!=-1)ans+=c[a][1];
    }
    cout<<ans<<endl;

    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int h, w;
  cin >> h >> w;
  char a[h+2][w+2];
  for(int i=0; i<h+2; ++i) for(int j=0; j<w+2; ++j) a[i][j] = '#';
  for(int i=1; i<h+1; ++i) for(int j=1; j<w+1; ++j) cin >> a[i][j];

  for(int i=0; i<h+2; ++i){
    for(int j=0; j<w+2; ++j){
      if(j==w+1){
        cout <<a[i][j] << endl;
      }
      else cout << a[i][j];
    }
  }
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  double L;
  cin>>L;
  cout<<fixed<<setprecision(20)<<L/3*L/3*L/3<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

map <long long, int> mymap;
int n, ans, pri[N], npri[N], nprime;
long long a[N], b[N];

long long po(long long x, int c){
    if (c == 0) return 1;
    if (c == 1) return x;
    return x * x;
}

int main(){
    for (int i = 2; i < 2300; i++) if (!npri[i]) {pri[++nprime] = i; for (int j = i; j < N; j += i) npri[j] = true;}
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        long long x; scanf("%lld", &x);
        a[i] = b[i] = 1;
        for (int j = 1; j <= nprime && pri[j] <= x; j++){
            int cnt = 0;
            while (x % pri[j] == 0) x /= pri[j], cnt++;
            cnt %= 3;
            if (cnt == 1) a[i] *= po(pri[j], 1), b[i] *= po(pri[j], 2);
            if (cnt == 2) a[i] *= po(pri[j], 2), b[i] *= po(pri[j], 1);
        }
        a[i] *= x;
        long long sqr = sqrt(x);
        if (sqr * sqr == x) b[i] *= sqr;
        else b[i] *= x * x;
        mymap[a[i]]++;
    }
    for (int i = 1; i <= n; i++){
        if (mymap[a[i]] == 0) continue;
        if (a[i] == 1) {ans++; mymap[1] = 0; continue;}
        ans += max(mymap[a[i]], mymap[b[i]]), mymap[a[i]] = mymap[b[i]] = 0;
    }
    printf("%d", ans);
}

Measured memory_bytes: 14720
# 2019/10/15

import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
avg=np.mean(a)

ans=abs(a-avg)
min_a=10**9
idx=-1
for i,e in enumerate(ans):
    if min_a>e:
        min_a=e
        idx=i
print(idx)

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

typedef long long ll;

int N;
string S;
vector<int> V;
vector<int> R, G, B;

void input_init(void) {
	cin >> N >> S;
	V.resize(N);
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'R')
			V[i] = 1;
		else if (S[i] == 'G')
			V[i] = 2;
		else
			V[i] = 4;
	}
}

void init_calcu(void) {
	R.resize(N, 0);
	G.resize(N, 0);
	B.resize(N, 0);

	if (S[0] == 'R')
		R[0] = 1;
	else if (S[0] == 'G')
		G[0] = 1;
	else
		B[0] = 1;

	for (int i = 1; i < N; ++i) {
		R[i] += R[i - 1];
		G[i] += G[i - 1];
		B[i] += B[i - 1];

		if (S[i] == 'R')
			++(R[i]);
		else if (S[i] == 'G')
			++(G[i]);
		else
			++(B[i]);
	}
}

ll calcu_all(void) {
	ll cnt = (ll)0;
	for (int i = 1; i < N - 1; ++i) {
		if (S[i] == 'R') {
			cnt += (ll)G[i - 1] * (B[N - 1] - B[i]);
			cnt += (ll)B[i - 1] * (G[N - 1] - G[i]);
		}
		else if (S[i] == 'G') {
			cnt += (ll)R[i - 1] * (B[N - 1] - B[i]);
			cnt += (ll)B[i - 1] * (R[N - 1] - R[i]);
		}
		else {
			cnt += (ll)R[i - 1] * (G[N - 1] - G[i]);
			cnt += (ll)G[i - 1] * (R[N - 1] - R[i]);
		}
	}
	return cnt;
}

ll calcu_same_d(void) {
	ll cnt = (ll)0;
	for (int i = 0; i < N - 2; ++i) {
		for (int d = 1; d < N; ++d) {
			if (i + 2 * d >= N)
				break;
			if (V[i] + V[i + d] + V[i + d + d] == 7)
				++cnt;
		}
	}
	return cnt;
}

int main(void) {
	input_init();
	init_calcu();
	ll all_d = calcu_all();
	ll same_d = calcu_same_d();
	ll ans = all_d - same_d;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long

using namespace std;

bool compare(int i,int j)
{
    return i>j;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin>>s;
    int ones=0;
    for (int i=0;i<s.size();i++)
    {
        if (s[i]=='1')
        {
            ones++;
        }
    }
    int zeros=s.size()-ones;
    cout<<min(ones, zeros)*2;



    return 0;

}


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

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  rep(i, N) cin >> p[i];

  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  for (int i = 0; i <= N; i++) {
    auto it2 = find(p.begin(), p.end(), X - i);
    if (it2 == p.end()) {
      cout << X - i << endl;
      return 0;
    }
    auto it3 = find(p.begin(), p.end(), X + i);
    if (it3 == p.end()) {
      cout << X + i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;


void input(){

}

void solve(){

}

void output(){
  
}

int main(){
  int a, b;
  cin>>a>>b;
  if((a+b)%2==1)cout<<"IMPOSSIBLE"<<endl;
  else cout<<(a+b)/2<<endl;
  input();
  solve();
  output();
}


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

int main() {
   string s, t;
   cin >> s >> t;

   rep(i, s.length()) {
       if (s[i] != t[i]) {
           cout << "No" << endl;
           return 0;
       }
   }

   cout << "Yes" << endl;
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

struct state {
	lnt idx, money, time;
	bool operator> (const state &n) const{
		if(time != n.time) return time > n.time;
		return idx > n.idx;
	}
};

struct edge {lnt to, money, time;};

int main(){
	summon_tourist;

	lnt N, M, S; cin >> N >> M >> S;
	chmin(S, 5000ll);
	vector<vector<edge>> G(N);

	REP(i, M){
		lnt u, v, a, b; cin >> u >> v >> a >> b;
		u--; v--;
		G[u].pb({v, -a, b});
		G[v].pb({u, -a, b});
	}
	REP(i, N){
		lnt c, d; cin >> c >> d;
		G[i].pb({i, c, d});
	}

	lnt dp[55][5010];
	REP(i, 55) REP(j, 5010) dp[i][j] = BBIG;
	dp[0][S] = 0;

	pque<state, vector<state>, greater<state>> que;
	que.push({0, S, 0});
	
	while(!que.empty()){
		state st = que.top(); que.pop();
		lnt pos = st.idx, money = st.money, time = st.time;
		if(dp[pos][money] < time) continue;
		for(auto e: G[pos]){
			lnt nxmoney = money + e.money;
			if(nxmoney < 0) continue;
			if(nxmoney > 5000) nxmoney = 5000;
			if(chmin(dp[e.to][nxmoney], time + e.time)){
				que.push({e.to, nxmoney, time+e.time});
			}
		}
	}

	RANGE(i, 1, N){
		lnt ans = BBIG;
		REP(j, 5010){
			chmin(ans, dp[i][j]);
		}
		cout << ans << ln;
	}
}

Measured memory_bytes: 11572
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
satis = 0
for i in range(N):
    satis += B[A[i]-1]
    if i == 0:
        continue
    
    if A[i] - A[i-1] == 1:
        satis += C[A[i-1]-1]
        
print(satis)

Measured memory_bytes: 38532
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans=sum(p[:K])
cnt=sum(p[:K])
for i in range(N-K):
    cnt+=p[K+i]
    cnt-=p[i]
    if cnt>ans:
        ans=cnt
print(K+(ans-K)/2)

Measured memory_bytes: 71792
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class AtCoderD
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());
        int x = int.Parse(Console.ReadLine());

        int answer = 0;
        for (int i = 0; i <= a; i++)
        {
            for (int j = 0; j <= b; j++)
            {
                for (int k = 0; k <= c; k++)
                {
                    if (500 * i + 100 * j + 50 * k == x)
                    {
                        answer++;
                    }
                }
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S=sc.next();
		String[] S2=S.split("");
		if(S2.length%2==1) {
			System.out.println("No");
			System.exit(0);
		}

		for(int i=0;i<S2.length;i+=2) {
			if(S2[i].equals("h")) {
				if(!S2[i+1].equals("i")) {
					System.out.println("No");
					System.exit(0);
				}
			}else {
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}

int a,b,c,x,y;
vector<int> red,green,coless;
int main() {
    IO;
    cin >> x >> y >> a >> b >> c;
    red.resize(a), green.resize(b), coless.resize(c);
    for (int i = 0; i < a; i++) {
        cin >> red[i];
    }
    for (int i = 0; i < b; i++)
        cin >> green[i];
    for (int i = 0; i < c; i++)
        cin >> coless[i];
    sort(red.begin(), red.end(),greater<int>());
    sort(green.begin(), green.end(),greater<int>());
    for (int i = 0; i < x; i++)
        coless.push_back(red[i]);
    for (int i = 0; i < y; i++)
        coless.push_back(green[i]);
    sort(coless.begin(), coless.end(), greater<int>());
    ll ans = 0;
    for (int i = 0; i < x + y; i++)
        ans += coless[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 2680
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

double add_double(double a,double b){
	if(abs(a+b)<eps*(abs(a)+abs(b))) return 0;
	return a+b;
}

struct point{
	double x,y;
	point operator+(point p){
		return point{add_double(x,p.x),add_double(y,p.y)};
	}
	point operator-(point p){
		return point{add_double(x,-p.x),add_double(y,-p.y)};
	}
	point operator*(double p){
		return point{x*p,y*p};
	}
	point operator/(double p){
		if(!p) return point{0,0}; 
		return point{x/p,y/p};
	}
	bool operator==(point p){
		return fabs(add_double(x,-p.x))<eps&&fabs(add_double(y,-p.y))<eps;
	}
	bool operator<(point p){
		if(fabs(y-p.y)>eps) return y<p.y;
		return x<p.x;
	}
};
 
typedef pair<point,point> pp;
typedef vector<point> VP;
const point O{0,0};
 
class Geom{
	public:
	double IP(point p,point q){
		return p.x*q.x+p.y*q.y;
	}
	double CP(point p,point q){
		return p.x*q.y-q.x*p.y;
	}
	VP Convex_Hull(VP p){
		sort(p.begin(),p.end());
		int v=0,n=p.size();
		VP q(n*2);
		for(int i=0;i<n;i++){
			while(v>1&&CP(q[v-1]-q[v-2],p[i]-q[v-2])<-eps) v--;
			q[v++]=p[i];
		}
		for(int i=n-2,t=v;i>=0;i--){
			while(v>t&&CP(q[v-1]-q[v-2],p[i]-q[v-2])<-eps) v--;
			q[v++]=p[i];
		}
		q.resize(v-1);
		return q;
	}
	void Point_in(point& p){
		cin>>p.x>>p.y;
	}
	void Point_out(point p){
		cout<<p.x<<' '<<p.y<<endl;
	}
};

int N;
VP p,ans;

int main(){
	Geom geo;
	cin>>N;
	p=VP(N);
	for(int i=0;i<N;i++) geo.Point_in(p[i]);
	ans=geo.Convex_Hull(p);
	cout<<ans.size()<<endl;
	for(VP::iterator i=ans.begin();i!=ans.end();i++) geo.Point_out(*i);
}

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

vector<int> getNext(int c, vector<int> a, vector<int> b, int skip){
  vector<int> r;
  for (int i=0;i<a.size();i++){
    if (i==skip)continue;
    if (a[i]==c)
      r.push_back(b[i]);
    else if (b[i]==c)
      r.push_back(a[i]);
  }
  return r;
}

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

  int ans=0;
  for (int i=0;i<m;i++){
    set<int> pass;
    queue<int> que;
    que.push(1);
    while(!que.empty()){
      int f =que.front();
      vector<int> next = getNext(f,a,b,i);
      que.pop();
      for (int j : next){
        if(pass.emplace(j).second){
          que.push(j);
        }
      }
    }
    if (pass.size()!=n)
      ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
a = int(input())
e = 10 ** 9
for i in range(10 ** 6):
    if i > a:
        break
    else:
        b = str(i)
        c = str(a - int(b))
        d = 0
        if int(b) > 0 and int(c) > 0:
            for j in range(len(b)):
                d += int(b[j])
            for j in range(len(c)):
                d += int(c[j])
            e = min(e, d)
print(e)


Measured memory_bytes: 3060
import java.util.*;

public class Main{

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

    static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static void main(String[] srgs){
        Scanner sc=new Scanner(System.in);

        long a=sc.nextInt();
        long b=sc.nextInt();
        System.out.println(lcm(a,b));
    }
}


Measured memory_bytes: 21844
# coding: utf-8
N, M = map(int, input().split())
graph = [[False for i in range(N)] for j in range(N)]
visited = [False for i in range(N)]
def dfs(v):
    visited[v] = True
    for k in range(N):
        # 橋がなければわたらない
        if not graph[v][k]:
            continue
        # すでに訪れていたら渡らない
        if visited[k]:
            continue
        dfs(k)
A, B = [], []
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)
    # 橋をTrueとして表す
    graph[a][b] = True
    graph[b][a] = True 

ans = 0
# a, bの橋が通れないとして都度DFSを実行
for a, b in zip(A, B):
    graph[a][b] = False
    graph[b][a] = False
    visited = [False for i in range(N)]
    dfs(0)
    bridge = False
    for j in range(N):
        if not visited[j]:
            bridge = True
    # 渡れない島があったら+1
    if bridge:
        ans += 1
    graph[a][b] = True
    graph[b][a] = True
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

struct node{
	int data;
	node *l, *r;
};

node *new_node(int in){
	node *ret = (node *)malloc(sizeof(node));
	ret->data = in;
	ret->l = NULL;
	ret->r = NULL;
	return ret;
}

void insert_node(node **root, int in){
	node *add = new_node(in);
	if(*root == NULL){
		*root = add;
		return ;
	}
	node *p = *root, *pp = NULL;
	while(p != NULL){
		pp = p;
		if(add->data < p->data) p = p->l;
		else p = p->r;
	}
	if(add->data < pp->data) pp->l = add;
	else pp->r = add;
	return ;
}

void print_n(node *root, bool mode){
	if(mode == true) cout << " " << root->data;
	if(root->l != NULL) print_n(root->l, mode);
	if(mode == false) cout << " " << root->data;
	if(root->r != NULL) print_n(root->r, mode);
}

void print_node(node *root){
	print_n(root, false);
	cout << endl;
	print_n(root, true);
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	node *root = NULL;
	rep(i, n){
		string s;
		cin >> s;
		if(s == "print"){
			print_node(root);
		}else{
			int in;
			cin >> in;
			insert_node(&root, in);
		}
	}
	return 0;
}


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

struct tree{
	int x,y;
};

int main(){
	int N,W,H,S,T;
	while(1){
		cin>>N;
		if(N==0)break;
		tree t[N];
		cin>>W>>H;
		for(int i=0;i<N;i++){
			cin>>t[i].x>>t[i].y;
		}
		cin>>S>>T;
		int field[H][W];
		for(int i=0;i<W;i++){
			for(int j=0;j<H;j++){
				field[j][i]=0;
			}
		}
		for(int j=0;j<N;j++){
			field[t[j].y-1][t[j].x-1]=1;
		}
		int num=0;
		int iterator=0;
		int ans[(H-T+1)*(W-S+1)];
		for(int i=0;i<=(H-T);i++){
			for(int j=0;j<=(W-S);j++){
				for(int k=i;k<(i+T);k++){
					for(int m=j;m<(j+S);m++){
						if(field[k][m]==1)num++;
					}
				}
				ans[iterator]=num;
				num=0;
				iterator++;
			}
		}
		sort(ans,ans+(H-T+1)*(W-S+1));
		cout<<ans[(H-T+1)*(W-S+1)-1]<<endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

const long long inf = 1e9;
#define fr(i,a,n) for (int i=a;i<n;i++)
#define rfr(i,n,a) for (int i=n;i>=a;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define endl "\n"
typedef vector<int> VI;
typedef vector<ll> VL;
typedef priority_queue<int> Pqi;
typedef priority_queue<ll> Pql;

ll n, m, k;

int main () {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	cout << s.substr(0,3) << endl;
	return 0; 
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
	long long int a, b, x;
	scanf("%lld%lld%lld", &a, &b, &x);
	if (a%x == 0)
		printf("%lld\n", b / x - a / x + 1);
	else
		printf("%lld\n", b / x - a / x);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>

int main(){
	int n, x;
	std::cin>>n>>x;

	std::vector<long long> aList(n);
	std::vector<long long> sumList(n+1);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	int times=0;
	sumList[0]= 0;

	for(int i=0; i<n; i++)
		sumList[i+1]= sumList[i]+ aList[i];
	
	for(int i=0; i<n+1; i++){
		if(sumList[i]<= x)
			times++;
		else
			break;
	}



	std::cout<<times<<std::endl;

	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
bool judge(string a)
{
    string b = a;
    reverse(b.begin(),b.end());
    return b==a;
}
int main()
{
    string a;
    while(cin>>a){
    int n = a.size();
    if(judge(a)&&judge(a.substr(0,(n-1)/2))&&judge(a.substr((n+3)/2-1,n-(n+3)/2+1)))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define ipr pair<ll,ll>
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 998244353
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l,n;
    cin>>n;
    set<string> vc;
    string s;
    for(i=1;i<=n;i++){
        cin>>s;
        vc.insert(s);
    }
    cout<<vc.size()<<endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
const int Max_Num=1000010;

int main(){
  LL N;
  cin >> N;
  LL ans=0;
  for(LL K=2; K*K<=N; K++){
    if(N%K!=0) continue;
    LL Nc=N;
    while(Nc%K==0) Nc/=K;
    if(Nc%K==1) ans++;
  }
  LL div[Max_Num]={0};
  N--;
  for(LL K=2; K*K<=N; K++) while(N%K==0) N/=K, div[K]++;
  LL num=1;
  for(LL K=2; K<Max_Num; K++) num*=div[K]+1;
  if(N!=1) num*=2;
  ans+=num;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8192
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
 
def comb(N, x):
    numerator = 1
    for i in range(N-x+1, N+1):
        numerator = numerator * i % mod
    denominator = 1
    for j in range(1, x+1):
        denominator = denominator * j % mod
    d = pow(denominator, mod-2, mod)
    return numerator * d
 
a = comb(n, a)
b = comb(n, b)
 
print((pow(2, n, mod) -1 -a -b) % mod)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
using namespace std;
char s[110];
long long n,pos,maxn;
int main()
{
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;++i)
    {
        if(s[i]=='I') ++pos;
        else --pos;
        maxn=max(maxn,pos);
    }
    printf("%d\n",maxn);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
  ll N;
  cin>>N;
  
if(N==0){
  cout<<1<<endl;}

  if(N==1){
  cout<<0<<endl;}

  
}


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

int main()
{
    ll n,W,i,j;
    cin>>n>>W;

    ll A[n+1][2];
    for(i=1;i<=n;i++)
        cin>>A[i][0]>>A[i][1];

    ll dp[W+1][n+1];

    for(i=1;i<=W;i++)
        dp[i][0]=0;

    for(i=0;i<=n;i++)
        dp[0][i]=0;

    for(i=1;i<=W;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(i>=A[j][0])
                dp[i][j]=max(dp[i][j-1],dp[i-A[j][0]][j-1]+A[j][1]);
            else
                dp[i][j]=dp[i][j-1];
        }
    }
    cout<<dp[W][n]<<"\n";
}


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

#define int long long

int32_t main(){
	int n , m ;
	cin >> n >> m ;
	int dp[n+1][m+1] = {} ;
	char ch[n][m] ;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++) cin >> ch[i][j] ;
	}
	int mod = 1e9 + 7 ;
	dp[n-1][m-1] = ch[n-1][m-1] != '#';
	for(int i = n - 1 ; i >= 0 ; i--){
		for(int j = m - 1 ; j >= 0 ; j--){
			if(i == n - 1 && j == m - 1 || ch[i][j] == '#') continue ;
			dp[i][j] = (dp[i+1][j] + dp[i][j+1]) ;
			dp[i][j] %= mod ;
		}
	}
	cout << dp[0][0] ;
	return 0 ;
}



Measured memory_bytes: 12360
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


 
template< unsigned mod >
struct RollingHash {
  vector< unsigned > hashed, power;
 
  inline unsigned mul(unsigned a, unsigned b) const {
    unsigned long long x = (unsigned long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
    return m;
  }
 
  RollingHash(const string &s, unsigned base = 10007) {
    int sz = (int) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }
 
  unsigned get(int l, int r) const {
    unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }
 
  unsigned connect(unsigned h1, int h2, int h2len) const {
    unsigned ret = mul(h1, power[h2len]) + h2;
    if(ret >= mod) ret -= mod;
    return ret;
  }
 
  int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = -1, high = len + 1;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return (low);
  }
};
 
using RH1 = RollingHash< 1000000007 >;
using RH2 = RollingHash< 1000000021 >;
 
int main(){
    string S,t;cin >> S >> t;
    string s=S;
    while(s.size()<5*1e6) s=s+s;
    RH1 rhs1(s+s+s+s);
    RH1 rht1(t);
    RH2 rhs2(s+s+s+s);
    RH2 rht2(t);
    int ans = 0;
    bool f=true;
    vector<bool> used(s.size(),false);
    for (int i = 0; i < s.size(); i++) {
        int cnt=0;
        for (int j = i; j < s.size(); j+=t.size()) {
            if(used[j]) break;
            used[j]=true;
            cnt++;
            if(rht1.get(0,t.size())==rhs1.get(j,j+t.size())||rht2.get(0,t.size())==rhs2.get(j,j+t.size())) ans=max(cnt,ans);
            else break;
            if(j>1e6&&i<S.length()){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 573804