akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n;
const int maxn=2005;
vector<pair<ll,ll>> a;
ll dp[maxn][maxn];
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n;
    repA(i,1,n)
    {
        ll val;
        cin>>val;
        a.pb(mp(val,(ll)i));
    }
    sortA(a);
    reverse(a.begin(),a.end());
    repA(i,1,n)
    {
        repA(j,0,i)
        {
            if(j!=i)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j]+abs(n-(i-1-j)-a[i-1].se)*a[i-1].fi);
            }
            if(j)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+abs(j-a[i-1].se)*a[i-1].fi);
            }
        }
    }
    ll ans=0;
    repA(i,0,n) ans=max(ans,dp[n][i]);
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 26360
import java.util.*;
import java.io.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 998244353;
    int n = 1;
    int[] dat;
    int default_value = 0;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        // int t = sc.nextInt();
        int t= 1;
        while(t-->0){
            out.println(main.solve());
        }
        out.flush();
    }
    long solve() throws Exception {
        int n = sc.nextInt();
        int[][] rec = new int[n][2];
        for(int i=0; i<n; i++){
            rec[i] = new int[]{sc.nextInt(), sc.nextInt()};
        }
        Arrays.sort(rec, (o1, o2)->(o1[0]-o2[0])); // sort according to increasing order of x[i]
        long plus = rec[0][0]+rec[0][1], minus = rec[0][0]-rec[0][1];
        long ans = 0;
        for(int i=1; i<n;i++){
            long temp_plus = rec[i][0]+rec[i][1], temp_minus = rec[i][0]-rec[i][1];
            ans = Math.max(ans, temp_plus-plus);
            ans = Math.max(ans, temp_minus-minus);
            plus = Math.min(plus, temp_plus);
            minus = Math.min(minus, temp_minus);
        }
        return ans;
    }

    int paIn(String s){return Integer.parseInt(s);}
}

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

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

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

vector<int> a(200005);

struct segtree {
	int seg[800005];
	int segmin(int u, int v) { return a[u] <= a[v] ? u : v; }
	void build(int id, int l, int r) {
		if (l == r) { seg[id] = l; return; }
		int m = l + r >> 1;
		build(id * 2, l, m);
		build(id * 2 + 1, m + 1, r);
		seg[id] = segmin(seg[id * 2], seg[id * 2 + 1]);
	}
	int query(int id, int l, int r, int ql, int qr) {
		if (l == ql && r == qr) return seg[id];
		int m = l + r >> 1;
		if (qr <= m) return query(id * 2, l, m, ql, qr);
		else if (ql > m) return query(id * 2 + 1, m + 1, r, ql, qr);
		else return segmin(
				query(id * 2, l, m, ql, m),
				query(id * 2 + 1, m + 1, r, m + 1, qr));
	}
} seg;

int n;

ll solve(int l, int r) {
	if (l > r) return 0;
	int u = seg.query(1, 1, n, l, r);
	return solve(l, u - 1) + solve(u + 1, r) + 1ll * (u - l + 1) * (r - u + 1) * a[u];
}

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

	read(n);
	rep(i, 1, n + 1) {
		read(a[i]);
	}
	seg.build(1, 1, n);
	die(solve(1, n));
}


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

const int MAXN = 705;

int g[MAXN][MAXN];
int n, m, u, v;
int vis[MAXN];
int A[MAXN], B[MAXN], top = 0, c[MAXN];
int flag = 1;

void dfs(int nd, int col, int &x, int &y)
{
	if (col == 0) x++;
	else y++;
	vis[nd] = 1, c[nd] = col;
	for (int i = 1; i <= n; i++) {
		if (!g[nd][i]) continue;
		if (!vis[i])
			dfs(i, col^1, x, y);
		else if (vis[i] && c[i] == col)
			flag = 0;
	}
}

bool dp[MAXN][MAXN];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			g[i][j] = (i!=j);
	for (int i = 1; i <= m; i++) {
		cin >> u >> v;
		g[u][v] = g[v][u] = 0;
	}
	for (int i = 1; i <= n; i++) {
		if (vis[i]) continue;
		++top;
		dfs(i, 0, A[top], B[top]);
	}
	if (flag == 0) puts("-1");
	else {
		dp[0][0] = 1;
		for (int i = 0; i < top; i++)
			for (int j = 0; j <= n; j++) {
				if (dp[i][j]) {
					dp[i+1][j+A[i+1]] = 1;
					dp[i+1][j+B[i+1]] = 1;
				}
			}
		long long ans = 1e15;
		for (int i = 0; i <= n; i++)
			if (dp[top][i]) 
				ans = min(ans, (long long)i*(i-1)/2+(long long)(n-i)*(n-i-1)/2);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;

    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        sc.close();
        int ans = 3*r*r;
        System.out.println(ans);

	}

}

Measured memory_bytes: 23764
using System;
using System.Linq;

class Program {
    static void Main() {
        int n = int.Parse(Console.ReadLine());
        for(int i = 1; i <= n; i++) {
            if(i % 3 == 0) {
                Console.Write(" {0}", i);
                continue;
            }
            int x = i;
            while(x > 0) {
                if(x % 10 == 3) {
                    Console.Write(" {0}", i);
                    break;
                }
                x /= 10;
            }
        }
        Console.WriteLine();
    }
}


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

int main() {
    int n;
    cin >> n;
    set<string> s;
    for (int i = 0; i < n; i++)
    {
        string st;
        cin >> st;
        s.insert(st);
    }

    cout << s.size() << endl;
}

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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define sz(x)          (int)x.size()
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof(a))
#define endl           '\n'

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> T sqr(T a) {return a * a;}
template <TN T> T cube(T a) {return a * a * a;}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

template <TN T> inline void Int(T &n) {
	n = 0; int f = 1; register int ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
	n = n * f;
}

#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
	vector <string> v;
	stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
	cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
	err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

inline int add(int a, int b, int mod) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b, int mod) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b, int mod) {return (ll)a * b % mod;}

const int N          = 2e5 + 5;
const ll  Mod        = (ll)1e9 + 7;
const int inf        = (int)2e9;
const ll  Inf        = (ll)1e18;
const int mod        = (int)1e9 + 7;


int solve() {
	int n = in();
	vi dp(3, 0);
	for (int day = 1; day <= n; day++) {
		vi c(3);
		for (int i = 0; i < 3; i++) {
			c[i] = in();
		}
		vi tem_dp(3, 0);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i != j) smax(tem_dp[j], dp[i] + c[j]);
			}
		}
		dp = tem_dp;
	}
	printf("%d\n", max({dp[0], dp[1], dp[2]}));

	return 0;
}

int main() {
	int test = 1, tc = 0;
	//scanf("%d", &test);
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int N;
    int D;
    vector<vector<int>> point;

    cin>>N;
    cin>>D;

    for(int i=0;i<N;i++){
        vector<int> p_x;
        for(int j=0;j<D;j++){
            int buff;
            cin>>buff;
            p_x.push_back(buff);
        }
        point.push_back(p_x);
    }
    int integer_num=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double dis=0;
            
            for(int k=0;k<D;k++){
                dis+=(point.at(i).at(k)-point.at(j).at(k))*(point.at(i).at(k)-point.at(j).at(k));
            }
            dis = sqrt(dis);
            if(dis == int(dis)){
                integer_num++;
            }
        }
    }
    cout<<integer_num<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];
    ll ans=0;
    for(int i=n-1;i>=0;i--){
        if((a[i]+ans)%b[i]!=0) ans+=b[i]-(a[i]+ans)%b[i];
    }
    cout<<ans;
}

Measured memory_bytes: 4808
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use std::collections::*;

fn pf_map(mut n: i64) -> HashMap<i64, i64> {
    let mut res = HashMap::new();
    for i in 2.. {
        if i * i > n {
            break;
        }
        while n % i == 0 {
            n /= i;
            *res.entry(i).or_insert(0) += 1;
        }
    }
    if n != 1 {
        res.insert(n, 1);
    }
    res
}

fn main() {
    input! {
        n:i64
    }
    let ans: i64 = pf_map(n)
        .iter()
        .map(|(_, &index)| {
            (1..)
                .take_while(|&i| index >= i * (i + 1) / 2)
                .last()
                .unwrap()
        })
        .sum();
    println!("{}", ans);
}

Measured memory_bytes: 2176
/*
[abc137] A - +-x
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int A, B;

ll solve() { return max(max(A + B, A - B), A * B); }

int main() {
    cin >> A >> B;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>

#define MOD 1000000007

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int x;
	cin >> x;
    int y = x%1000;
    if(y==0){
      cout << 0; return 0;
            }else{
      cout << 1000 - y;
      return 0;
    }
  
}

Measured memory_bytes: 3648
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC168D
//ABC168C
int main(void) {
  double a, b, c, h, m, n, theta=0;
  int k, i, cou=0, tmp;
  scanf("%lf %lf %lf %lf", &a, &b, &h, &m);

  theta=fabs(m*6-h*30-m/2);
 // printf("%lf\n",theta);
  while(theta>360)theta-=360;
  theta=theta*M_PI/180;
  //printf("%lf\n",theta);
  //printf("%lf\n",cos(theta));
  c=pow(-2*a*b*cos(theta)+a*a+b*b, 0.5);
  printf("%.10lf", c);
  return 0;
}

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

int main(){
  // input the data
  string str;
  cin >> str;
  
  string rec="";				// record the characters which appear on str
  vector<int> lap(str.size());	// record the number of times of character appearance
  
  sort(str.begin(),str.end());	// sort str lexicographically
  
  int m=0;
  for(int i=0; i<str.size(); i++){
    bool x=false;
    if (i==0){
      rec+=str.at(0);
      lap.at(0)++;
    }
    else{
      if (str.at(i)==str.at(i-1)){
        x=true;
        lap.at(m)++;
      }
      if (x==false){
        rec+=str.at(i);
        m++;
        lap.at(m)++;
      }
    }
  }
  /* For debug
  for(int i=0; i<=m; i++){
    cout<<rec.at(i)<<" ";
  }
  cout<<endl;
  for(int i=0; i<=m; i++){
    cout<<lap.at(i)<<" ";
  }
  cout<<endl;
  */
  
  for(int i=0; i<=m; i++){
    if (lap.at(i)%2==1){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;
const int X[]={0,1,0,-1},Y[]={1,0,-1,0};

int H,W,K,eh,ew,apple,d[30][30],bfs[1001][1001],dp[1<<20][30];
char A[1000][1000];
vector<int>x(1),y(1);

int bitdp(int app,int last){
    if(dp[app][last])return dp[app][last];
    int num=0;
    rep(i,apple)if((app>>i)&1)num++;
    if(num==K)return dp[app][last]=d[last][x.size()-1];
    dp[app][last]=1e7;
    rep(i,apple)if(!((app>>i)&1)){
        dp[app][last]=min(dp[app][last],bitdp(app+(1<<i),i+1)+d[last][i+1]);
    }
    return dp[app][last];
}

int main(){
    cin>>H>>W>>K;
    rep(i,H)rep(j,W){
        cin>>A[i][j];
        if(A[i][j]=='e')eh=i,ew=j;
        if(A[i][j]=='s')x[0]=i,y[0]=j;
        if(A[i][j]=='a'){
            x.push_back(i);
            y.push_back(j);
            apple++;
        }
    }
    x.push_back(eh);
    y.push_back(ew);

    queue<pair<int,int> > que;
    rep(i,x.size()){
        fill(bfs[0],bfs[1001],1e7);
        que.push({x[i],y[i]});
        bfs[x[i]][y[i]]=0;
        while(!que.empty()){
            int nx=que.front().first,ny=que.front().second;
            que.pop();
            rep(j,4){
                int NX=nx+X[j],NY=ny+Y[j];
                if(NX<0||H<=NX||NY<0||W<=NY||A[NX][NY]=='#'||bfs[NX][NY]!=1e7)continue;
                bfs[NX][NY]=bfs[nx][ny]+1;
                que.push({NX,NY});
            }
        }
        rep(j,x.size())d[i][j]=bfs[x[j]][y[j]];
    }

    cout<<(bitdp(0,0)>=1e7?-1:dp[0][0])<<endl;
}


Measured memory_bytes: 130928
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A=0,B=0,C=0;
    cin >> A >> B >> C;
    if(A+B >= C){
        cout << B+C << endl;
    }else{
        cout << A+2*B+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace A
{
    class Program
    {
        public IEnumerable<string> Solve()
        {
            //var ut = new Util();
            var sc = new Scanner();

            var n = sc.Num;
            var a = sc.Num;
            var b = sc.Num;

            var res = Math.Min(n * a, b);

            yield return res.ToString();
        }
    }

    class StartingPoint
    {
        static void Main(string[] args)
        {
            if (args?.Any() == true)
            {
                var assembly = Assembly.GetEntryAssembly();
                var resourceName = "AtCoderCSharp.In.txt";
                var stream = assembly.GetManifestResourceStream(resourceName);
                var streamReader = new StreamReader(stream, Encoding.UTF8);
                var str = streamReader.ReadToEnd();
                var textReader = new StringReader(str);
                Console.SetIn(textReader);
            }

            try
            {
                foreach (var s in new Program().Solve())
                {
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (args?.Any() != true)
                    throw e;
            }

            if (args?.Any() == true)
                Console.ReadKey();
        }
    }

    class Scanner
    {
        public int[] Nums(int count) => Enumerable.Range(0, count).Select(_ => Num).ToArray();
        public int Num => int.Parse(Str);
        public long NumLong => long.Parse(Str);
        public double NumDouble => (double)NumLong;

        StringBuilder sb = new StringBuilder();

        public string Str => GetStr();
        public string GetStr()
        {
            sb.Clear();

            int r = 0;
            bool? b = null;
            do
            {
                r = Console.Read();
                b = IsBreak(r);
            } while (b == true);

            if (b == null)
                throw new Exception("input error: unexpected end of stream");

            do
            {
                sb.Append((char)r);
                r = Console.Read();
                b = IsBreak(r);
            } while (b == false);

            return sb.ToString();
        }

        bool? IsBreak(int c)
        {
            switch (c)
            {
                case -1:
                    return null;
                case (int)' ':
                case (int)'\n':
                case (int)'\r':
                    return true;
                default:
                    return false;
            }
        }
    }
}

Measured memory_bytes: 13268
let (p1, p2, p3) = (257, 251, 1000000007)

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let pow x n =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x mod p3) (n / 2) acc
    else doit (x * x mod p3) (n / 2) (acc * x mod p3) in
  doit x n 1

let make_hash v (x, y) (r, c) =
  let h1 = Array.make_matrix x y 0 in
  let c1 = pow p1 c in
  for i = 0 to x - 1 do
    let rec aux j acc =
      if j = c then acc
      else aux (j + 1) ((acc*p1 + Char.code v.(i).(j)) mod p3) in
    let rec doit j z =
      if j = y - c then h1.(i).(j) <- z
      else begin
        h1.(i).(j) <- z;
        let z = (z*p1 - (Char.code v.(i).(j))*c1 + Char.code v.(i).(j+c)) mod p3 in
        doit (j + 1) (if z < 0 then z + p3 else z)
      end in
    aux 0 0 |> doit 0;
  done;
  let h2 = Array.make_matrix x y 0 in
  let c2 = pow p2 r in
  for j = 0 to y - 1 do
    let rec aux i acc =
      if i = r then acc
      else aux (i + 1) ((acc*p2 + h1.(i).(j)) mod p3) in
    let rec doit i z =
      if i = x - r then h2.(i).(j) <- z
      else begin
        h2.(i).(j) <- z;
        let z = (z*p2 - h1.(i).(j)*c2 + h1.(i+r).(j)) mod p3 in
        doit (i + 1) (if z < 0 then z + p3 else z)
      end in
    aux 0 0 |> doit 0;
  done;
  h2

let solve (h, w) (r, c) a b =
  let s = make_hash a (h, w) (r, c) in
  let t = make_hash b (r, c) (r, c) in
  for i = 0 to h - r do
    for j = 0 to w -c do
      if s.(i).(j) = t.(0).(0) then Printf.printf "%d %d\n" i j;
    done
  done

let read_array x y =
  let a = Array.make_matrix x y '\000' in
  for i = 0 to x - 1 do
    let l = read_line () in
    for j = 0 to y - 1 do
      a.(i).(j) <- l.[j];
    done
  done;
  a

let () =
  match read_line () |> split_on_char ' ' |> List.map int_of_string with
  | [h; w] ->
    begin
      let a = read_array h w in
      match read_line () |> split_on_char ' ' |> List.map int_of_string with
      | [r; c] ->
        if h < r || w < c then ()
        else read_array r c |> solve (h, w) (r, c) a
      | _ -> assert false
    end
  | _ -> assert false

Measured memory_bytes: 43012
#include <cstdio>
int main(){
  int N,p,cnt=0;
  scanf("%d",&N);
  for(int i=0,tmp=N+1;i<N;i++){
    scanf("%d",&p);
    if(p<tmp){
      tmp=p;cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int a1[10][10];

void solve(int x) {
  int p = x%10;
  while(x>9) {
    x /= 10;
  }
  a1[p][x]++;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n; cin>>n;
  memset(a1, 0, sizeof a1);
  rep(i,1,n+1) {
    solve(i);
  }
  lli ans = 0;
  rep(i,1,10) {
    rep(j,1,10) {
      ans += a1[i][j] * 1LL * a1[j][i];
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include "iostream"

using namespace std;

int main() {
	int x, a, b, c;
	int ans = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i < a+1; i++) {
		for (int k = 0; k < b+1; k++){
			for (int p = 0; p < c+1; p++) {
				if (500 * i + 100 * k + 50 * p == x) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main
 
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)

func  next() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}

func main() {
  sc.Split(bufio.ScanWords)
  approved := true
  n := next()
  a := make([]int, n, n)
  for i := 0; i < n; i++ {
    a[i] = next()
    if a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0 {
      approved = false
      break
    }
  }

  if approved {
    fmt.Println("APPROVED")
  } else {
    fmt.Println("DENIED")
  }
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define LL long long

int main()
{
    LL a, b, c, d;
    while(cin >> a >> b >> c >> d){
        LL x = a * b;
        LL y = c * d;
        cout << max(x, y) << '\n';
    }
    return 0;
}


Measured memory_bytes: 504
#
# abc085 a
#
import unittest
from io import StringIO
import sys


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


def resolve():
    S = input()
    print(S[0:3]+"8"+S[4:])


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2017/01/07"""
        output = """2018/01/07"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2017/01/31"""
        output = """2018/01/31"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()
    resolve()


Measured memory_bytes: 5568
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {

	string s;
	cin >> s;
	string p[4] = { "dreamer","eraser","erase","dream" };
	string tm = "";
	for (int i = s.size() - 1; i >= 0; i--)
	{
		tm = s[i] + tm;
		for (int j = 0; j < 4; j++)
		{
			if (tm == p[j]) {
				tm = "";
				break;
			}
		}
	}

	if (tm == "") {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC103C()
{
	int N;
	cin >> N;
	ll sum = 0;
	for (int i = 0; i < N; ++i)
	{
		int x;
		cin >> x;
		sum += x - 1;
	}
	cout << sum << endl;
}

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

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int H,N;
vector<int> A;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> H >> N;
    A = fetch_vec<int>(N);
}

void solve(){
    input();
    if(H<=accumulate(ALL(A),0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

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


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int i,j,k,n,T,q;
	string s1,s2;
	char s[100000];
	cin>>s1;
	reverse(s1.begin(),s1.end());
	//cout<<s1<<endl<<endl;
	while(s1.length()>0){
        if(s1.substr(0,5)=="maerd"){
            s1=s1.substr(5,s1.length());
            //cout<<s1<<endl;
        }
        else if(s1.substr(0,7)=="remaerd"){
            s1=s1.substr(7,s1.length());
            //cout<<s1<<endl;
        }
        else if(s1.substr(0,5)=="esare"){
            s1=s1.substr(5,s1.length());
            //cout<<s1<<endl;
        }
        else if(s1.substr(0,6)=="resare"){
            s1=s1.substr(6,s1.length());
            //cout<<s1<<endl;
        }
        else{
            cout<<"NO"<<endl;
            return 0;
        }
	}
	cout<<"YES"<<endl;
}



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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int point[w + 1][h + 1];
  for (int i = 0; i < w + 1; i++) {
    for (int j = 0; j < h + 1; j++) {
      point[i][j] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      for (int i = 0; i < x; i++) {
        for (int j = 0; j < h + 1; j++) {
          point[i][j] = 0;
        }
      }
    } else if (a == 2) {
      for (int i = x; i < w + 1; i++) {
        for (int j = 0; j < h + 1; j++) {
          point[i][j] = 0;
        }
      }
    } else if (a == 3) {
      for (int i = 0; i < w + 1; i++) {
        for (int j = 0; j < y; j++) {
          point[i][j] = 0;
        }
      }
    } else {
      for (int i = 0; i < w + 1; i++) {
        for (int j = y; j < h + 1; j++) {
          point[i][j] = 0;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      ans += point[i][j];
    }
  }

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


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
int prodmod(vector<int> w);
int summod(vector<int> w);
///CUIDADO COM MAXN
#define N 300050

int n, m, q, k, v[N], ans;
pii w[N];
string s;

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int q;
	cin>>n;
	map<int,int>qtd;
	int sum = 0;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		sum+=x;
		qtd[x]++;
	}
	cin>>q;
	while(q--){
		int ai,bi;
		cin>>ai>>bi;
		int aux=qtd[bi];
		sum += bi*qtd[ai];
		sum -= ai*qtd[ai];
		qtd[bi] += qtd[ai];
		qtd[ai]=0;
		cout<<sum<<"\n";
	}
}
/*
    CUIDADO COM MAXN, MOD, OVERFLOW 
    >Colocar (>DEFINE INT LONG LONG<) no inicio do template
    >mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR)
    >NAO ESQUECER DEFINE INT LONG LONG
    > N = 1 ? 
*/
int summod(vector<int> w){int curr=0;for(int i=0;i<sz(w); i++){curr = (curr+w[i])%mod;if(curr<0)curr+=mod;}return curr;}
int prodmod(vector<int> w){int curr = 1;
for(int i = 0; i < sz(w); i++){if(w[i] >= mod) w[i] %= mod;curr = (curr * w[i]) % mod;if(curr < 0) curr += mod;}return curr;}

Measured memory_bytes: 9528
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int X = sc.nextInt();
		int h500 = Math.floorDiv(X, 500);
		int h5 = Math.floorDiv(X - 500 * h500, 5);
		System.out.println(h500 * 1000 + h5 * 5);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        double r = scan.nextDouble();
        double π = 3.141592653589;
        System.out.println(
                String.format("%.6f",r * r * π) + " " + String.format("%.6f", (r + r) * π));
    }
}

Measured memory_bytes: 18908
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char G[15][15];
int main() {
	int H, W;
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) scanf("%s", G[i]);
	int r = 0, c = 0;
	for (;;) {
		assert(G[r][c] == '#');
		G[r][c] = '.';
		if (c != W - 1 && G[r][c + 1] == '#') {
			++c;
		} else if (r != H - 1 && G[r + 1][c] == '#') {
			++r;
		} else break;
	}
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
			if (G[i][j] == '#') {
				printf("Impossible\n");
				return 0;
			}
	printf("Possible\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for (int i=0;i<n;i++)

ll mod = 1e9+7;

int ans = 0;
vector<bool> path;
vector<vector<int> > ab;

void dfs(int pos){
    bool visited = true;
    rep(i,path.size()){
        if (!path[i]){
            visited = false;
            break;
        }
    }
    if (visited){
        ans++;
        return;
    }
    for (auto i:ab[pos]){
        if (path[i]) continue;
        path[i] = true;
        dfs(i);
        path[i] = false;
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    ab = vector<vector<int> >(n);
    path = vector<bool>(n,false);
    path[0] = true;
    for (int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        ab[a-1].push_back(b-1);
        ab[b-1].push_back(a-1);
    }
    dfs(0);
    cout << ans << endl;
}

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

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

	bool ans = false;
	if (a % 3 == 0) ans = true;
	else if (b % 3 == 0) ans = true;
	else if ((a + b) % 3 == 0) ans = true;

	if (ans)
	{
		cout << "Possible" << endl;
	}
	else
	{
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

#define MAXN 1000000
#define MOD 1000000007
char str[MAXN+5];
long long Pow[MAXN+5];
long long A[MAXN+5],C[MAXN+5],M[MAXN+5],N[MAXN+5];

int main(){
    Pow[0]=1;
    for(int i=1;i<=MAXN;i++)
        Pow[i]=Pow[i-1]*3%MOD;
    scanf("%s",str+1);
    int len=strlen(str+1);
    for(int i=1;i<=len;i++){
        A[i]=A[i-1]+(str[i]=='A');
        M[i]=M[i-1]+(str[i]=='?');
    }
    for(int i=len;i>=1;i--){
        C[i]=C[i+1]+(str[i]=='C');
        N[i]=N[i+1]+(str[i]=='?');
    }
    long long Ans=0;
    for(int i=1;i<=len;i++){
        if(str[i]=='B'||str[i]=='?'){
            Ans=(Ans+
                 A[i]*C[i]*Pow[M[i-1]%MOD+N[i+1]]%MOD+
                 A[i]*N[i+1]%MOD*Pow[M[i-1]+N[i+1]-1]%MOD+
                 C[i]*M[i-1]%MOD*Pow[M[i-1]+N[i+1]-1]%MOD+
                 Pow[M[i-1]+N[i+1]-2]*M[i-1]%MOD*N[i+1])%MOD;
        }
    }
    printf("%lld",Ans);
}


Measured memory_bytes: 19584
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, X, dm, min int
	fmt.Scan(&N)
	fmt.Scan(&X)
	m := make([]int, N)
	min = math.MaxInt32
	for i := 0; i < N; i++ {
		fmt.Scan(&m[i])
		dm += m[i]
		if min > m[i] {
			min = m[i]
		}
	}
	fmt.Println(N + (X-dm)/min)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  std::map<int, int> mp_d,mp_t;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    mp_d[tmp]++;
  }
  int m;
  cin>>m;
  for (int i = 0; i < m; ++i)
  {
    int tmp;
    cin>>tmp;
    mp_t[tmp]++;
  }
  for(auto&& e: mp_t) {
    if(e.second>mp_d[e.first]){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
}

Measured memory_bytes: 18944
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL) x=x->right;
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;

  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
  
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
    return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right == NIL) y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent = y->parent;

  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key=y->key;

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL) root =z;
  else if(z->key<y->key) y->left=z;
  else (y->right = z);
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
n=int(input())
s=input()
dic={}
for i in set(list(s)):
    if s.count(i)>1:
        dic[i]=s.count(i)
#print(dic)

d=0
for i in range(n-1):
    c=0
    x=s[:i+1]
    y=s[i+1:]
    if len(y)>len(x):
        for j in dic:
            if x.count(j)!=dic[j] and x.count(j)>0:
                c+=1
    else:
        for j in dic:
            if y.count(j)!=dic[j] and y.count(j)>0:
                c+=1
    if c>d:
        d=c
        #print(i)

print(d)


Measured memory_bytes: 3064
#include<iostream>
#include<assert.h>

template<typename T>
void swap(T &a,T &b){
  T x=a;
  a=b;
  b=x;
}

int dif(int x,int y){return x-y>=0?x-y:y-x;}

const int N = 3;
int st[N*N];

int calc(int i,int j){ 
  if(st[i*N+j]<0) return 0;
  int res=0; 
  res+=dif(i,st[i*N+j]/N);
  res+=dif(j,st[i*N+j]%N);
  return res;
}

int dist=0,ans=31;

int check(int cur){
  if(dist==0&&ans>cur) ans=cur;
  int val=cur+dist;
  return val<ans;  
}

int dy[]={0,0,1,-1};
int dx[]={1,-1,0,0};
int in(int y,int x){return 0<=y&&y<N&&0<=x&&x<N;};

void dfs(int di,int y,int x,int p){
  for(int k=0;k<4;k++){
    if((p>=0)&&((p^1)==k)) continue;
    int ny=y+dy[k],nx=x+dx[k];
    if(!in(ny,nx)) continue;
    dist-=calc(ny,nx);
    swap(st[y*N+x],st[ny*N+nx]);
    dist+=calc(y,x);
    if(check(di+1)) dfs(di+1,ny,nx,k);    
    dist-=calc(y,x);
    swap(st[y*N+x],st[ny*N+nx]);
    dist+=calc(ny,nx);
  }
}

int main(){
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      std::cin>>st[i*N+j],st[i*N+j]--;
  
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      dist+=calc(i,j);
  
  int y=-1,x=-1;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      if(st[i*N+j]<0) y=i,x=j;

  check(0);
  dfs(0,y,x,-1);
  
  std::cout<<ans<<std::endl;
  return 0;
}



Measured memory_bytes: 3072
f=[True]*(10**5+1)
like=[False]*(10**5+1)
f[0]=False
f[1]=False
import math
for i in range(2,len(f)):
  if not f[i]:
    continue
  fact=True
  for j in range(2,int(math.sqrt(i))+1):
    if i%j==0:
      fact=False
      break
  
  if fact:
    f[i]=True
    if i*2-1<len(like):
      like[i*2-1]=True
    for p in range(i*2,len(f),i):
      f[p]=False

sums=[0]*(10**5+1)
cur=0
for i in range(len(sums)):
  if f[i] and like[i]:
    sums[i]=cur+1
    cur+=1
  else:
    sums[i]=cur

Q=int(input())
for i in range(Q):
  l,r=map(int,input().split())
  print(sums[r]-sums[l-1])


Measured memory_bytes: 5876
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
int a[100001],b[100001];
int main()
{
     int n,k,x=0,y=0;

     std::cin>>n>>k;

     for(int i=1;i<=n;i++)
     {
         int w;std::cin>>w;
         if(w<0)a[++x]=-w;
         else b[++y]=w;
     }
     std::sort(a+1,a+1+x);
     int gg=1e9;

     for(int i=0;i<=std::min(x,k);i++)if(k-i<=y)gg=std::min(a[i]*2+b[k-i],gg);
     for(int i=0;i<=std::min(y,k);i++)if(k-i<=x)gg=std::min(b[i]*2+a[k-i],gg);

     std::cout<<gg<<std::endl;
}


Measured memory_bytes: 640
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, tmp, h, w, x, y, sum, k, q;
ll d, dm, m;

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

  cin >> n >> s >> q;

  while (q--) {
    cin >> k;
    ans = 0;
    m = 0;
    d = 0;
    dm = 0;
    rep(i, n) {
      if (i - k >= 0) {
        if (s[i - k] == 'D') {
          d--;
          dm -= m;
        } else if (s[i - k] == 'M')
          m--;
      }
      if (s[i] == 'D')
        d++;
      else if (s[i] == 'M')
        dm += d, m++;
      else if (s[i] == 'C')
        ans += dm;
    }
    Cout(ans);
  }
  return 0;
}

Measured memory_bytes: 1948
#include<cstdio>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;static char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,k,a[100001],g,mx;
int gcd(int a,int b){
	return a%b==0?b:gcd(b,a%b);
}
int main(void){
	register int i;
	n=read(),k=read();
	for(i=1;i<=n;++i)
		a[i]=read(),mx=max(mx,a[i]);
	if(n==1)
		if(a[1]==k){
			puts("POSSIBLE");
			return 0;
		}else {
			puts("IMPOSSIBLE");
			return 0;
		}
	g=a[1];
	for(i=2;i<=n;++i)
		g=gcd(g,a[i]);
	if(mx>=k&&k%g==0){
		puts("POSSIBLE");
		return 0;
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 512