akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

#define M 1000001
#define L 14

char H[M][L];

int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum = 0,p = 1,i;

    for(i=0;i<strlen(str);i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    return key % M;
}

int h2(int key){
    return 1 + (key%(M-1));
}

int find(char str[]){
    int i = 0,element;
    long long key;

    key = getKey(str);

    while(1){
        element = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[element],str) == 0){
            return 1;
        }
        else if(strlen(H[element]) == 0){
            return 0;
        }
        i++;
    }

    return 0;
}

int insert(char str[]){
    int i = 0,element;
    long long key;

    key = getKey(str);

    while(1){
        element = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[element],str) == 0){
            return 1;
        }
        else if(strlen(H[element]) == 0){
            strcpy(H[element],str);
            return 0;
        }
        i++;
    }
    return 0;
}

int main(){
    int i,n,h;
    char str[L],com[9];
    for(i=0;i<M;i++) H[i][0] = '\0';

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s%s",com,str);

        if(com[0] == 'i'){
            insert(str);
        }
        else{
            if(find(str)){
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 15388
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
#include<cctype>
#include<fstream>
#include<unordered_map>
#include<complex>
#pragma warning(disable:4996)
using namespace std;

#define debug(i) cout<<"<debug> "<<#i<<" "<<i<<" <\\debug>"<<endl
#define mfor(i,a,b) for(int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(int i=(a);i>=(b);i--)
#define lll __int128
#define Re register
#define mem(a,b) memset(a,(b),sizeof(a))
#define Design ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
typedef pair<ll, ll> llpair;
typedef long double ld;
const double pi = acos(-1);
const double eps = 1e-5;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

int a[300010];
int b[300010];

struct STtree
{
    //默认min add功能
    //query功能修改push_up cmp
    //update功能修改push_down update
    //greater功能修改greater
#define lc(x) x<<1
#define rc(x) x<<1|1
    struct tree
    {
        int a;
        int l, r;
        tree():l(0),r(0),a(0) {}
    }node[(int)300010 << 2];

    STtree() {}

    STtree(int l, int r, int* a)
    {
        build(1, l, r, a);
    }

    inline void push_up(int x)
    {
        //query功能
        node[x].a = max(node[lc(x)].a, node[rc(x)].a);
    }

    inline int cmp(int a, int b)
    {
        //query功能
        return (a > b ? a : b);
    }

    void build(int x, int l, int r, int* a)
    {
        node[x].l = l;
        node[x].r = r;
        if (l == r)
        {
            node[x].a = 0;
            return;
        }
        int mid = (l + r) >> 1;
        build(lc(x), l, mid, a);
        build(rc(x), mid + 1, r, a);
        push_up(x);
    }
    void update(int left, int right, int x, int k)
    {
        if (left <= node[x].l && node[x].r <= right)
        {
            node[x].a = k;
            return;
        }
        int mid = (node[x].l + node[x].r) >> 1;
        if (left <= mid) update(left, right, lc(x), k);
        if (right > mid) update(left, right, rc(x), k);
        push_up(x);
    }
    int query(int left, int right, int x)
    {
        int res = 0;
        if (left <= node[x].l && node[x].r <= right) return node[x].a;
        int mid = (node[x].l + node[x].r) >> 1;
        if (left <= mid) res = max(res, query(left, right, lc(x)));
        if (right > mid) res = max(res, query(left, right, rc(x)));
        return res;
    }
}st;

int main()
{
    Design;
    int n, k;
    cin >> n >> k;
    mfor(i, 1, n)
    {
        cin >> a[i];
        a[i]++;
    }
    st.build(1, 1, 300001, 0);
    int ans = 0;
    mfor(i, 1, n)
    {
        int t = st.query(max(a[i] - k, 1), min(a[i] + k, 300001), 1);
        ans = max(ans, t + 1);
        st.update(a[i], a[i], 1, t + 1);
    }
    cout << ans;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N;
	cin >> N;
	vector<int> inputs(N);
	int maxi =0;
	rep(i,0,N){
		cin >> inputs[i];
		maxi = max(maxi, inputs[i]);
	}
	vector<bool> dp(maxi+5, false), is_appeared(maxi+5, false);
	rep(i,0,N){
		int cnt = 2;
		if (is_appeared[inputs[i]])
			cnt = 1;
		while(inputs[i]*cnt <= maxi+1){
			dp[inputs[i]*cnt] = true;
			cnt++;
		}
		is_appeared[inputs[i]] = true;
	}
	int ans = 0;
	rep(i,0,N){
		if (!dp[inputs[i]]){
			ans++;
			dp[inputs[i]] = true;
		}
	}
	cout << ans << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int n; cin >> n;
  vector<int> c(n,0);
  rep(i,n){
    int a; cin >> a;
    c[a]++;
  }
  
  mint ans=0;

  if(n%2==1 && c[0]!=1){
    cout << 0 << endl;
    return 0;
  }

  for(int i=1+(n&1); i<n; i=i+2){
    if(c[i]!=2){
      cout << 0 << endl;
      return 0;
    }
  }

  ans=1;
  rep(i,n/2) ans*=2;
  cout << ans.x << endl;

return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans = min(2 * ans, ans + k);
    }
    cout << ans << endl;
    return 0;
}

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

#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define pb  push_back
#define clr(a, n) memset(a, n, sizeof a)

typedef vector<int> vi;
typedef long long ll;
const int mod = 1e9+7;
const int N = 3e5 + 9;
const int MAXNODES = 1e5+9;

int main() {

	int n, k;
	cin >> n >> k;
	vi v;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		v.pb(x);
	}
	ll tot = 0;
	sort(v.begin(), v.end());
	for(int i = 0; i < n - k; ++i) {
		tot += v[i];
	}
	cout << tot << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
 
struct edge_t {
    int from;
    int to;
    int cost;
};
typedef struct edge_t Edge;
 
int main(void) {
    int num, i, k, from, to, cost, update, nedge = 0;
    int dis[10000];
    Edge *edges, *p;
 
    edges = malloc(sizeof(Edge)*500000);
 
    scanf("%d", &num);
 
    for (i = 0; i < num; i++) {
        scanf("%d %d", &from, &k);
 
        while (k--) {
            scanf("%d %d", &to, &cost);
 
            p = &edges[nedge++];
            p->from = from;
            p->to = to;
            p->cost = cost;
        }
 
        dis[i] = INT_MAX;
    }
    dis[0] = 0;
 
    update = 1;
    while (update) {
        update = 0;
        for (i = 0; i < nedge; i++) {
            from = edges[i].from;
            to = edges[i].to;
            cost = edges[i].cost;
            if (dis[from] < INT_MAX && dis[to] > cost + dis[from]) {
                dis[to] = cost + dis[from];
                update = 1;
            }
        }
    }
 
    for (i = 0; i < num; i++) {
        printf("%d %d\n", i, dis[i]);
    }
    return 0;
}

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

int main(void)
{
	int N; cin >> N;
	long double sum = 0;
	for (int i = 0; i < N; i++) {
		double x; cin >> x;
		string s; cin >> s;
		if (s == "JPY")sum += x;
		else sum += (x*380000.0);
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }

    int isPrime(ll n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0)
                return 0;
        }
        return 1;
    }
    
    int n,m;
    int dp[1005][1<<12];
    vector<pair<int,int>>a;
    int ok(int id , int mask){
        if(mask==(1<<n)-1)
            return 0;
        if(id>=m)
            return (1e9);
        if(~dp[id][mask])
            return dp[id][mask];
        return dp[id][mask]=min(a[id].second+ok(id+1,mask|a[id].first),ok(id+1,mask));
    }
 
    void solve (){
        cin>>n>>m;
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<m;i++){
            int cost , keys_number;
            cin>>cost>>keys_number;
            int total=0;
            for(int j=0;j<keys_number;j++){
                int key;
                cin>>key;
                --key;
                total|=1<<key;
            }
            a.push_back({total,cost});
        }
        int ans=ok(0,0);
        if(ans==(int)(1e9))
            cout<<-1;
        else 
            cout<<ans;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 19792
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let n = input[0];
    let k = input[1];
    let ps = read_vec::<f64>();

    let mut cumsum: Vec<f64> = vec![0.; n];

    for (i, p) in ps.iter().map(|v| (1.+v)/2.).enumerate() {
        if i == 0 {
            cumsum[i] = p;
        } else {
            cumsum[i] = cumsum[i-1] + p;
        }
    }
    
    let mut max = 0.;
    for i in k-1..n {
        if i < k {
            max = f64::max(cumsum[i], max);
        } else {
            max = f64::max(cumsum[i]-cumsum[i-k], max);
        }
    }
    println!("{}", max);

}

Measured memory_bytes: 10996
n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)

sorted_arr = arr.sort_by { |item| item }

0.upto(n - 1) do |i|
    i.upto(n - 1) do |j|
        tmp_arr = arr.dup
        tmp_arr[i], tmp_arr[j] = tmp_arr[j], tmp_arr[i]
        if tmp_arr == sorted_arr
            puts "YES"
            exit
        end
    end
end

puts "NO"

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

int main () {
  while(1){
    int a , b , c ;
    cin >> a >> b >> c ;
    if( a == -1 && b == -1 && c == -1 ) break ;
    if( a == -1 || b == -1 ) {
      cout << "F" << endl ;
      continue ;
    }
    if( a + b >= 80) cout << "A" << endl ;
    else if( a + b >= 65) cout << "B" << endl ;
    else if( a + b >= 50) cout << "C" << endl ;
    else if( a + b < 30) cout << "F" << endl ;
    else {
      if( c >= 50) cout << "C" << endl ;
      else cout << "D" << endl ;
    }
  }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/

int main(){
    int mod=1000000007;
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        vector<int> l(3);
        for (auto&e:l) {
            scanf("%d",&e);
        }
        sort(l.begin(),l.end());
        printf((l[0]*l[0]+l[1]*l[1]==l[2]*l[2])?"YES\n":"NO\n");
    }
    return 0;
}

Measured memory_bytes: 3228
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#define fs first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int maxn=1e3+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;

char s[maxn];

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n/2;i++){
		if(s[i]!=s[n-i+1]){
			printf("No\n");
			return 0;
		}
	}
	int tmp=(n-1)/2;
	for(int i=1;i<=(n-1)/2;i++){
		if(s[i]!=s[tmp-i+1]){
			printf("No\n");
			return 0;
		}
	}
	tmp=(n+3)/2;
	for(int i=tmp;i<=n;i++){
		if(s[i]!=s[n-i+tmp]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

int main(){
  int n;
  scanf("%d",&n);
  int i;
  int t=0,x=0,y=0;
  
  for(i=0;i<n;++i){
    int nt,nx,ny;
    scanf("%d%d%d",&nt,&nx,&ny);
    int dt = nt-t, dx = x-nx, dy = y-ny;
    int sum = abs(dx)+abs(dy);
 
    if(sum>dt || (dt-dx-dy)%2){
      puts("No");
      return 0;
    }
    t=nt, x=nx, y=ny;
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 1644
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        int a = nextInt(), b = nextInt();
        int torep = Math.min(a, b);
        int count = Math.max(a, b);
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < count; i++) {
            stringBuilder.append(torep);
        }
        System.out.println(stringBuilder.toString());
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

Measured memory_bytes: 22356
N = int(input())
A = list(map(int, input().split()))
ans = 1

def gcd(m, n):
  x = max(m, n)
  y = min(m, n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x % y
      x = y
      y = z
    else:
      return z

L, R = {}, {}
for i in range(N):
  if i == 0:
    L[0] = A[0]
    R[N-(i+1)] = A[N-(i+1)]
  else:
    L[i] = gcd(L[i-1], A[i])
    R[N-(i+1)] = gcd(R[N-i], A[N-(i+1)])

for i in range(N):
  if i == 0:
    tmp = R[1]
  elif i == N-1:
    tmp = L[N-2]
  else:
    tmp = gcd(L[i-1], R[i+1])
  ans = max(tmp, ans)

print(ans)

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

typedef long long ll;
typedef pair<ll, ll> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int h,w,n,sr,sc;
string s,t;
int m_r[200001],s_r[200001];
int main() {
    cin >> h >> w >> n >> sr >> sc >> s >> t;
    sr--;
    sc--;

    string ans = "YES";
    // R
    int pos = sc;
    for (int i=0;i<n;i++) {
        if (s[i] == 'R') {
            pos++;
            if (pos == w) ans = "NO";
        }
        if (t[i] == 'L' && pos != 0) pos--;
    }
    // L
    pos = sc;
    for (int i=0;i<n;i++) {
        if (s[i] == 'L') {
            pos--;
            if (pos == -1) ans = "NO";
        }
        if (t[i] == 'R' && pos != w-1) pos++;
    }
    // D
    pos = sr;
    for (int i=0;i<n;i++) {
        if (s[i] == 'D') {
            pos++;
            if (pos == h) ans = "NO";
        }
        if (t[i] == 'U' && pos != 0) pos--;
    }
    // U
    pos = sr;
    for (int i=0;i<n;i++) {
        if (s[i] == 'U') {
            pos--;
            if (pos == -1) ans = "NO";
        }
        if (t[i] == 'D' && pos != h-1) pos++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 776
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void){

    int N; cin>>N;
    vector<int> X(N);

    for (int i = 0; i < N; ++i) {
        cin>>X[i];
    }
    vector<int> sortedX(N);
    sortedX = X;
    sort(sortedX.begin(), sortedX.end());

    ll mid = sortedX[N/2];
    for (int i = 0; i < N; ++i) {
        if(X[i]<mid){
            cout<<sortedX[(N+1)/2]<<endl;
        }else{
            cout<<sortedX[(N-1)/2]<<endl;
        }
    }
}

Measured memory_bytes: 3712
#include<iostream>

template<class T>
struct binary_serch_tree{
  struct tree{
    T id;
    tree* left;
    tree* right;
    tree* parent;
  };
  tree* root;
  tree original;
  tree* null=&original;
  binary_serch_tree(){
    this->root=this->null;
    root->right=this->null;
    root->left=this->null;
  }

  void set_tree(tree* tr,tree* root){
    tree* null=this->null;
    tree* left=root->left;
    tree* right=root->right;
    if(root->id>tr->id){
      if(left==null){
        root->left=tr;
        tr->parent=root;
        tr->left=null;
        tr->right=null;
      }else{
        set_tree(tr,left);
      }
    }else{
      if(right==null){
        root->right=tr;
        tr->parent=root;
        tr->left=null;
        tr->right=null;
      }else{
        set_tree(tr,right);
      }
    }
  }

  void insert(T a){
    tree* tr=new tree;
    tr->id=a;
    if(this->root==this->null){
      this->root=tr;
      tr->left=this->null;
      tr->right=this->null;
      tr->parent=this->null;
    }else{
      set_tree(tr,this->root);
    }
  }
  void go_pre(tree* root){
    std::cout<<" "<<root->id;
    tree* left=root->left;
    tree* right=root->right;
    tree* null=this->null;
    if(left==null&&right==null){
      //do nothing
    }else if(left==null){
      go_pre(right);
    }else if(right==null){
      go_pre(left);
    }else{
      go_pre(left);
      go_pre(right);
    }
  }
  void print_pre(){
    go_pre(this->root);
  }
  void go_in(tree *root){
    tree* left=root->left;
    tree* right=root->right;
    tree* null=this->null;
    if(left==null&&right==null){
      std::cout<<" "<<root->id;
    }else if(left==null){
      std::cout<<" "<<root->id;
      go_in(right);
    }else if(right==null){
      go_in(left);
      std::cout<<" "<<root->id;
    }else{
      go_in(left);
      std::cout<<" "<<root->id;
      go_in(right);
    }
  }
  void print_in(){
    go_in(this->root);
  }
};



int main(){
  int n;
  std::cin>>n;
  binary_serch_tree<int> T;
  for(int i=0;i<n;i++){
    std::string s;
    std::cin>>s;
    if(s=="insert"){
      int a;
      std::cin>>a;
      T.insert(a);
    }else{
      T.print_in();
      std::cout<<std::endl;
      T.print_pre();
      std::cout<<std::endl;
    }
  }
}



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

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] h = new int[n];

		int X = -1;
		int Y = -1;
		int H = -1;
		for(int i = 0; i < n; i++) {
			x[i] = ni();
			y[i] = ni();
			h[i] = ni();			
		}

		for(int i = 0; i < n; i++) {
			if(h[i] > 0) {				
				X = x[i];
				Y = y[i];
				H = h[i];
				break;
			}
		}

		for(int i = 0; i <= 100; i++) {
			for(int j = 0; j <= 100; j++) {
				int tmpH = H + Math.abs(X - i) + Math.abs(Y - j);
				boolean ok = true;				
				for(int k = 0; k < n; k++) {
					if(h[k] != Math.max(0, tmpH - Math.abs(x[k] - i) - Math.abs(y[k] - j))) {
						ok = false;
						break;
					}
				}
				if(ok) {
					System.out.println(i + " " + j + " " + tmpH);
					return;
				}
			}
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21332
// abc144_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


struct Graph {

    int n;

    vector<vector<int>> edges;
    vector<double> exp;
    vector<P> candidate;

    Graph(int n): n(n), edges(n){}

    void add_edge(int u, int v){
        edges[u].emplace_back(v);
    }

    double calc(){

        exp.assign(n, INF);
        exp[n-1] = 0;


        REP_REV(v, n-1){
            exp[v] = 0;
            int tmp = -1;
            double mx = 0;
            for (auto e: edges[v]){
                exp[v] += exp[e];
                if (exp[e] > mx){
                    tmp = e;
                    mx = exp[e];
                }
            }
            candidate.emplace_back(v, tmp);
            exp[v] /= edges[v].size();
            exp[v] += 1;
        }
        return exp[0];
    }

    double calc2(){

        double ans = INF;
        for (auto p: candidate){
            int u = p.first;
            int t = p.second;

            REP_REV(v, n-1){
                exp[v] = 0;
                int num = 0;
                for (auto e: edges[v]){
                    if (v == u && e == t) continue;
                    exp[v] += exp[e];
                    num++;
                }
                exp[v] /= num;
                exp[v] += 1;
            }
            ans = min(ans, exp[0]);
        }

        return ans;
    }
};


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    Graph g(N);
    REP(i, M){
        int s,t;
        cin >> s >> t; s--; t--;
        g.add_edge(s, t);
    }

    bool flag = false;
    REP(i, N){
        if (g.edges[i].size() > 1){
            flag = true;
            break;
        }
    }
    double tmp = g.calc();

    if (not flag) {
        print(tmp);
        return 0;
    }

    double ans = g.calc2();
    print(ans);



    return 0;
}


Measured memory_bytes: 1408
// 1_abc141_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#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 SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[0] == 'S') cout << "Cloudy";
    else if(s[0] == 'C') cout << "Rainy";
    else cout << "Sunny";
    cout << endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N;
    long long temp;
    long long dif = 0;
    cin>>N;
    vector<long long> l;
    for(int i = 0; i<N;i++){
        cin>>temp;
        l.push_back(temp);
    }
    sort(l.begin(),l.end());
    int i = 0;
    dif = l[N-1]-l[0];
    for(; i<N/2-1;i++) {
        dif += l[N - i - 1] - l[i + 1] + l[N - 1 - i - 1] - l[i];
    }
    if(N&1)
        dif+=max(l[N/2]-l[N/2-1],l[N/2+1]-l[N/2]);
    cout<<dif<<endl;

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6 + 5;

vector<pair<int, int>> mv = {{0, 0}, {-1, 1}, {1, -1}, {1, 1}, {-1, -1}, {-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int n, m, k;
ll ans[10];
map<pair<int, int>, bool> c;

bool check(int x, int y) {
  if (x < 2 || y < 2 || x >= n || y >= m) {
    return 0;
  }
  return 1;
}

void rec(int x, int y) {
  if (!check(x, y)) {
    return;
  }
  int cnt = 0;
  for (auto& cv : mv) {
    int cx = x + cv.first, cy = y + cv.second;
    cnt += c[{cx, cy}];
  }
  ans[cnt]++;
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> k;
  vector<pair<int, int>> v;
  for (int i = 1, x, y; i <= k; i++) {
    cin >> x >> y;
    c[{x, y}] = 1;
    v.push_back({x, y});
  }
  for (auto& cm : v) {
    int x = cm.first, y = cm.second;
    for (auto& cv : mv) {
      int cx = x + cv.first, cy = y + cv.second;
      rec(cx, cy);
    }
  }
  deque<int> res;
  ll sum = 0;
  for (int i = 1; i <= 9; i++) {
    ans[i] /= i;
    sum += ans[i];
  }
  ans[0] = 1ll * (n - 2) * (m - 2) - sum;
  for (int i = 0; i < 10; i++) {
    cout << ans[i] << '\n'; 
  }
}

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

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

	int i,k;
	ll H;
	ll ans=0;
	ll ctr=0;

	cin >> H;

	while(H>1){
		H/=2;
		ctr++;
	}
	
	rep(i,ctr+1) ans+=pow(2.0,i);

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4012
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)

int main(){
  int count=0;
  std::string s,t;
  std::cin >> s >> t;
  
  rep(i,s.size()){
    if(s[i] != t[i]){count++;}
  }
  
  std::cout << count << std::endl;
  
  return 0;
}


Measured memory_bytes: 3920
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 19:11:35 2019

@author: yuta
"""

def div(n):
    count = 0
    while n % 2 == 0:
        n /= 2
        count += 1
    return count

x = int(input())
y = list(range(1,(x + 1)))

mapped_list = list(map(div, y))
max_div = max(mapped_list)
print(y[mapped_list.index(max_div)])

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

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

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

    // start
    rep(i, 3)
    {
        char n;
        cin >> n;
        if (n == '1')
            cout << '9';
        else
            cout << '1';
    }
    cout << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int i,hess,bell=0;
  long long int m,n,money=0;
  while(1){
    cin >> money;
    if(money==0){
      break;
    }
    for(i=1;i<=12;i++){
      cin >> m >> n;
      money-=m-n;
      if(money<=0 && bell==0){
	bell++;
	hess=i;
      }
    }
    if(bell!=0){
      cout << hess << endl;
      bell=0;
    }
    else{
      cout << "NA" << endl;
    }
  }
  return (0);
}

Measured memory_bytes: 1160
#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>;

int main() {
    int v[3];
    rep(i,3) cin >> v[i];
    int64_t ans;
    sort(v, v+3);
    if (v[0] % 2 == 0 || v[1] % 2 == 0 || v[2] % 2 == 0) ans = 0;
    else ans = (int64_t)v[0] * v[1];
    cout << ans << endl;
}

Measured memory_bytes: 256
#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,C;
  cin>>A>>B>>C;
  int D=A-B;
  if(C<D)cout<<0<<endl;
  else cout<<C-D<<endl;
  input();
  solve();
  output();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define mod 998244353
#define pi 3.1415926535
#define fi first
#define se second
#define vll vector<ll>
#define vpll vector<pair <ll,ll> >
#define vvll vector< vll >
#define str string
#define umap unordered_map
#define uset unordered_set
#define rep(i,n) for(ll i=0;i<n;i++)
#define repA(i,s,n) for(ll i=s;i<=n;i++)
#define repD(i,s,n) for(ll i=s;i>=n;i--)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define elif else if
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ALL(v) v.begin(),v.end()
#define sortA(v) sort(ALL(v))
#define sortD(v) sort(ALL(v),greater <ll> ())
#define print(v) for(auto itr:v) cout<<*itr<<" ";
#define sz size()
#define nl cout<<"\n";
using namespace std;
ll factorial(ll n){return (n==1||n==0)?1:n*factorial(n-1);}
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;}
ll powerMod(ll x,ll y,ll m){if(y==0)return 1;ll p=powerMod(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll modInverse(ll a,ll m){return powerMod(a,m-2,m);}
ll gcd(ll a,ll b){if(a==0){return b;}else if(b==0){return a;}else{if(a>b){return gcd(a%b,b);}else{return gcd(b%a,a);}}}

int main(){
    fast
    char c;
    cin>>c;
    if(c>='A' && c<='Z') cout<<"A";
    else cout<<"a";
    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, res;

int main()
{
	in>>N;

	LL N_=N;
	while(N>0)
	{
		res+=N%10;
		N/=10;
	}
	if(N_%res==0)
	{	out<<"Yes"<<std::endl;}
	else out<<"No"<<std::endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

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

const int MAXN = 1e5+3; //AREGLAAAAAAAAR!!!!
vector<int>G[MAXN];
int main(){
	int n,m;
	rii(n,m);
	FOR(i,0,m){
		int a,b;
		rii(a,b);
		a--; b--;
		G[a].pb(b);
		G[b].pb(a);
	}	
	priority_queue<int>q;
	int ans=0;
	FOR(i,0,n){
		if(!q.empty() && q.top()==-i){
			while(!q.empty()) q.pop();
			ans++;
		}
		FOR(j,0,G[i].size()){
			if(G[i][j]>i) q.push(-G[i][j]);
		}

	}
	printf("%d\n",ans);
}


Measured memory_bytes: 6268
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt();
            if(i % 2 == 1 && a % 2 == 1)ans++;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 35760
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int op(int a, int b) { return max(a, b); }

int z(){
	return 0;
}
#define N 312345
segtree<int, op, z> seg(N);

int main(){
	int n, k; scanf("%d%d", &n, &k);
	REP(i, n){
		int a; scanf("%d", &a);
		seg.set(a, seg.prod(max(0, a-k), min(N, a+k+1)) + 1);
	}
	printf("%d\n", seg.prod(0, N));
}


Measured memory_bytes: 8376
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 1000000;

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

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/




int main()
{
	int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
	int n;
	set<int> weights;
	
	
	while (cin >> n)
	{
		for (int i=9; i>=0; i--)
		{
			if (n >= weight[i])
			{
				weights.insert(weight[i]);
				n -= weight[i];
			}
		}
		bool first_flag = true;
		set<int>::iterator it = weights.begin();
		while (it != weights.end())
		{
			if (first_flag)
			{
				cout << *it;
				first_flag = false;
			} else {
				cout << " " << *it;
			}
			it++;
		}
		cout << endl;
		weights.clear();
	}
	
	return 0;
}

Measured memory_bytes: 1196
N,K=map(int,input().split())
if K==0:
  print(N**2)
  exit(0)
ans=0
for i in range(K+1,N+1):
  cur=0
  base=i-(K-1)-1
  cur+=(N//i)*base
  rest=N%i
  cur+=max(rest-(K-1),0)
  ans+=cur
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> pic(H + 2);
    string buf;
    for (int i = 0; i < W + 2; i++)
    {
        buf.push_back('#');
    }
    pic[0] = pic[H + 1] = buf;
    rep(i, H)
    {
        string tmp;
        cin >> tmp;
        string s = '#' + tmp + '#';
        pic[i + 1] = s;
    }
    for (auto str : pic)
    {
        cout << str << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int[] c = new int[27];
        int[] t = new int[D+1];
        int[] last_day = new int[27];
        Arrays.fill(last_day, 0);
        int[][] s = new int[D + 1][27];
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 1; i <= D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        for (int i = 1; i <= D; i++) {
            t[i] = sc.nextInt();
        }
//        int m = sc.nextInt();
//        for(int i = 0;i<m;i++){
//            t[sc.nextInt()] = sc.nextInt();
//        }


        long ans[] = new long[D+1];
        ans[0] = 0;
        for (int i = 1; i <= D; i++) {
            last_day[t[i]] = i;
            ans[i] = ans[i - 1] + calcS(c, s, t[i], i,last_day);
            System.out.println(ans[i]);
        }
        System.exit(0);


    }

    private static long calcS(int[] c, int[][] s, int kaisai, int day,int[] last_day) {

        long loss = 0;
        for (int i = 1; i <= 26; i++) {
            if (i == kaisai) {
                last_day[i] = day;
                continue;
            }
            loss -= c[i] * (day - last_day[i]);
        }

        long plus = s[day][kaisai];
        return plus + loss;
    }

}


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

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


Measured memory_bytes: 1024
#! python3
# linear_search.py

n = int(input())
S = [int(x) for x in input().split(' ')]
q = int(input())
T = [int(x) for x in input().split(' ')]

c = 0
for t in T:
    for s in S:
        if t == s:
            c += 1
            break

print(c)



Measured memory_bytes: 6552
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int H, W;
vector<string> mp;

_int mem[2010][2010][4];
_int used[2010][2010][4];

Int dx[] = {1, -1, 0, 0};
Int dy[] = {0, 0, 1, -1};
Int calc(Int y, Int x, Int dir){

  if(y < 0 || x < 0 || y >= H || x >= W || mp[y][x] == '#') return 0;
  if(used[y][x][dir]++) return mem[y][x][dir];
  Int res = 1 + calc(y + dy[dir], x + dx[dir], dir);
  return mem[y][x][dir] = res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>H>>W;
  mp.resize(H);
  cin>>mp;

  Int ans = -INF;
  for(Int i=0;i<H;i++)
    for(Int j=0;j<W;j++){
      if(mp[i][j] == '#') continue;
      Int sum = 0;
      for(Int d=0;d<4;d++) sum += calc(i, j, d);
      sum -= 3;
      Max(ans, sum);
    }
  cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 130560
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, x, y; scanf("%d%d%d", &n, &x, &y); x--; y--;

	std::vector<int> cnt(n);
	for(int i = 0; i < n; i++) {
		std::queue<int> qu({i});
		std::vector<int> dist(n, 1 << 30); dist[i] = 0;
		while(!qu.empty()) {
			auto v = qu.front(); qu.pop();

			if(v == x or v == y) {
				int to = v ^ x ^ y;

				if(dist[to] > dist[v] + 1) {
					dist[to] = dist[v] + 1;
					qu.push(to);
				}
			}
			if(v + 1 < n) {
				int to = v + 1;
				if(dist[to] > dist[v] + 1) {
					dist[to] = dist[v] + 1;
					qu.push(to);
				}
			}
			if(v - 1 >= 0) {
				int to = v - 1;
				if(dist[to] > dist[v] + 1) {
					dist[to] = dist[v] + 1;
					qu.push(to);
				}
			}
		}

		for(auto v: dist) cnt[v]++;
	}

	cnt.erase(begin(cnt));
	for(auto v: cnt) printf("%d\n", v >> 1);
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut enable = vec![true; n];
    for i in 0..m {
        let a = read::<usize>();
        enable[a - 1] = false;
    }
    let big_int = 1000000007;
    let mut dp = vec![0; n + 1];
    dp[0] = 1;
    for i in 1..n + 1 {
        if enable[i - 1] {
            dp[i] += dp[i - 1];
            dp[i] %= big_int;
            if i > 1 {
                dp[i] += dp[i - 2];
                dp[i] %= big_int;
            }
        }
    }
    // debug!(dp);

    println!("{:?}", dp[n]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  vvi a(n, vi(3));
  rep(i, 0, n) cin >> a[i][0] >> a[i][1] >> a[i][2];

  vvi dp(n+1, vi(3));
  rep(i, 0, n){
    rep(j, 0, 3){
      rep(k, 0, 3) if(j != k){
        chmax(dp[i+1][k], dp[i][j]+a[i][k]);
      }
    }
  }

  int ans = max({dp[n][0], dp[n][1], dp[n][2]});
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136