akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h = [int(x) for x in input().split()]
ans = 0
tmp = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        tmp += 1
    else:
        if ans < tmp:
            ans = tmp
        tmp = 0
if ans < tmp:
    ans = tmp
print(ans)

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N,Q; cin >> N >> Q;
    vector<tuple<int,int,int>> xst(N);
    rep(i,N){
        int s,t,x; cin >> s >> t >> x;
        xst[i] = tie(x,s,t);
    }
    sort(xst.begin(),xst.end());
    vector<int> ans(Q,-1);
    set<Pi> st;
    rep(i,Q){
        int d; cin >> d;
        st.insert(Pi(d,i));
    }
    rep(i,N){
        int x,s,t;
        tie(x,s,t) = xst[i];
        auto f = st.lower_bound(Pi(s-x,0));
        auto e = st.upper_bound(Pi(t-x-1,Q));
        for(auto it = f; it != e; it++){
            ans[it->second] = x;
        }
        st.erase(f,e);
    }
    rep(i,Q){
        cout << ans[i] << endl;
    }
}


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

using namespace std;

int main()
{
    string s,t;
    int c=0;

    cin>>s;
    cin>>t;

    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
        {
            c++;
        }
    }

    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

ll modnum = 1000000007;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


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

    string prev = s.substr(0, (s.size()-1)/2 );
    string back = s.substr(((s.size()+3)/2) - 1);

    // チェック
    rep(i, s.size()/2) {
        if(s[i] != s[s.size()-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i, prev.size()/2) {
        if(prev[i] != prev[prev.size()-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i, back.size()/2) {
        if(back[i] != back[back.size()-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
f = n.times.map{gets.chomp.split(" ").map(&:to_i)}
p = n.times.map{gets.chomp.split(" ").map(&:to_i)}
ans = -(10**9)
for i in 1..1023
  combi = []
  10.times do |j|
    combi[j] = i%2
    i /= 2
  end
  temp = 0
  for j in 0..n-1
    same = 0
    10.times do |k|
      if combi[k] == 1 && f[j][k] == 1
        same += 1
      end
    end
    temp += p[j][same]
  end
  if ans < temp
    ans = temp
  end
end
puts ans

Measured memory_bytes: 2044
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int c = n, sum = 0;
  while(c){
    sum += c % 10;
    c /= 10;
  }
  if(n % sum){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N;
    while(cin>>N)
    {
        long long a[N+10];
        for(int i=0; i<N; i++) cin>>a[i];
        sort(a,a+N);
        long long cnt=0,n,m;
        for(int i=N-1; i>0; i--)
        {
            if(a[i]==a[i-1])
            {
                cnt++,i--;
                if(cnt==1) n=a[i];
                if(cnt==2){
                    m=a[i];
                    break;
                }
            }
        }
        if(cnt==2) cout<<n*m<<endl;
        else cout<<0<<endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(pair<ll,ll>a,pair<ll,ll>b){return a.first>b.first;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     int n,m;cin >> n >> m;
     vector<ll>a(n);
     for(int i = 0;i<n;i++) cin >> a[i];
     sort(a.begin(),a.end());
     vector< pair<ll,ll> >p;
     for(int i = 0;i<m;i++){
        int v,u;cin >> v >> u;
        p.push_back({u,v});
     }
     sort(p.begin(),p.end(),cmp);
     bool ok = 0;
     int idx = 0;
     for(int i = 0;i<m;i++){
        for(int j = 0;j<p[i].second;j++){
            if(idx==n){ok = 1;break;}
            if(p[i].first>a[idx]){
                a[idx] = p[i].first;
                 idx++;}
            else {
                ok = 1;break;
            }
        }
        if(ok) break;
     }
     ll sum = 0;
     for(int i = 0;i<n;i++) sum += a[i];
     cout << sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

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

int main () {
  int n, m; cin >> n >> m;
  string base[n], in[m];
  for (int i = 0 ; i < n; i++) cin >> base[i];
  for (int i = 0; i < m; i++) cin >> in[i];
  int nl = base[0].size();
  int ml = in[0].size();
  if (ml > nl || m > n) {
    cout << "No" << endl;
  } else {
    bool ok = false;
    for (int i = 0; i < n-m+1; i++) {
      for (int j = 0; j < nl-ml+1; j++) {
        bool oks = true;
        for (int ii = 0; ii < m; ii++) {
          for (int jj = 0; jj < ml; jj++) {
            if (base[i+ii][j+jj] != in[ii][jj]) oks = false;
          }
        }
        ok |= oks;
      }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

//Simple UF
inline int Arrange(const int start,vector<int> &par,vector<int> &size){
	if(start==par[start]) return start;
	int r=Arrange(par[start],par,size);
	size[start]=size[r];
	return par[start]=r;
}

inline void Unify(const int x,const int y,vector<int> &par,vector<int> &size){
	int r=Arrange(x,par,size);
	par[r]=Arrange(y,par,size);
	size[Arrange(y,par,size)]+=size[r];
	return ;
}

inline vector<int> unionfind(const int n,const vector<pair<int,int>> edge,vector<int> &size){
	vector<int> par;
	size.resize(n);
	for(int i=0;i<n;i++){ par.push_back(i); size[i]=1; }
	for(int i=0;i<edge.size();i++) Unify(edge[i].first,edge[i].second,par,size);
	for(int i=0;i<n;i++) Arrange(i,par,size);
	return par;
}

//Weighted UF
template<class Abel> struct UnionFind{
	vector<int> par;
	vector<int> size;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n) {
		init(n);
	}

	void init(int n) {
		par.resize(n);
		size.resize(n);
		rank.resize(n);
		diff_weight.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			size[i] = 1;
			rank[i] = 0;
		}
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		} else { 
			int r = root(par[x]);
			size[x] = size[r];
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}
	
	int scale(int x){
		return size[root[x]];
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	} 

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	} 

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, int w = 0) {
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			swap(x,y);
			w = -w;
		}
		if (rank[x] == rank[y]) rank[x]++;
		size[x] += size[y];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
};
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N,M; cin>>N>>M;
	int A[100000]; for(int i=0;i<N;i++) cin>>A[i];
	UnionFind<int> uf(N);
	for(int i=0;i<M;i++){
		int x,y; cin>>x>>y;
		uf.merge(x-1,y-1);
	}
	int ans=0;
	for(int i=0;i<N;i++) if(uf.issame(i,A[i]-1)) ans++;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 2176
import sys
sys.setrecursionlimit(20000)

times = int(input())
n, a, b, c, d = list(), list(), list(), list(), list()
for t in range(times):
    x = list(map(int, input().split()))
    n.append(x[0])
    a.append(x[1])
    b.append(x[2])
    c.append(x[3])
    d.append(x[4])


def f(N):
    if N == 0:
        return 0
    if N == 1:
        return D
    if N in dic:
        return dic[N]

    if N%2 == 0:
        N2 = f(N // 2) + A
    elif N%2 == 1:
        N2 = min(f((N-1) // 2) + D, f((N+1) // 2) + D) + A

    if N%3 == 0:
        N3 = f(N // 3) + B
    elif N%3 == 1:
        N3 = min(f((N-1) // 3) + D, f((N+2) // 3) + 2*D) + B
    elif N%3 == 2:
        N3 = min(f((N-2) // 3) + 2*D, f((N+1) // 3) + D) + B

    if N%5 == 0:
        N5 = f(N // 5) + C
    elif N%5 == 1:
        N5 = min(f((N-1) // 5) + D, f((N+4) // 5) + 4*D) + C
    elif N%5 == 2:
        N5 = min(f((N-2) // 5) + 2*D, f((N+3) // 5) + 3*D) + C
    elif N%5 == 3:
        N5 = min(f((N-3) // 5) + 3*D, f((N+2) // 5) + 2*D) + C
    elif N%5 == 4:
        N5 = min(f((N-4) // 5) + 4*D, f((N+1) // 5) + D) + C

    Y = min(N2, N3, N5, N*D)
    dic[N] = Y
    return Y


for t in range(times):
    N, A, B, C, D = n[t], a[t], b[t], c[t], d[t]
    dic = {}
    print(f(N))



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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


ll f(ll s){
	ll rt=0;
	for(; s>0; s/=10) rt += s%10;
	return rt;
}

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, ans = 1LL<<60;
	cin >>n;
	
	rep2(a,1, n){
		ll b = n-a;
		ans = min(ans, f(a) + f(b));
	}
	
	cout << ans  << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    cout << s[0] << s.length() - 2 << s[s.length() -1] << endl;
}

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

int main(){
    using namespace std;
    string S, T;
    cin >> S >> T;
    unsigned long ans{numeric_limits<unsigned long>::max()};
    for(unsigned long i{0}; i + size(T) <= size(S); ++i)ans = min(ans, inner_product(begin(T), end(T), begin(S) + i, 0UL, plus<>(), [](auto i, auto j){return i != j;}));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
d, g = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(d)]
r = float('inf')
for b in range(1<<d):
    x = n = 0
    j = -1
    for i in range(d):
        if b & 1<<i:
            p, c = a[i]
            x += p*(i+1)*100+c
            n += p
        else:
            j = i
    if j != -1:
        p, c = a[j]
        y = 100*(j+1)
        m = max(0,g-x+y-1)//y
        if m < p:
            x += m*y+c
            n += m
    if x >= g:
        r = min(r, n)
print(r)

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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  N -= K;
  int ans = 1;
  while(N - K + 1 >= 0){
    N -= K - 1;
    ans++;
  }
  if(N < K && N > 0){
    ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n, m, q int
	fmt.Scanf("%d %d %d", &n, &m, &q)

	req := make([][]int, q)
	for i := 0; i < q; i++ {
		var a, b, c, d int
		fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
		req[i] = []int{a - 1, b - 1, c, d}
	}

	max := 0
	cases := generate(1, m, n)
	for _, c := range cases {
		score := 0
		for _, r := range req {
			if c[r[1]]-c[r[0]] == r[2] {
				score += r[3]
			}
		}
		if score > max {
			max = score
		}
	}

	fmt.Printf("%d\n", max)
}

func generate(min, max, length int) [][]int {

	if length == 0 {
		return [][]int{{}}
	}

	res := [][]int{}
	for i := min; i <= max; i++ {
		rec := generate(i, max, length-1)
		for _, r := range rec {
			c := append([]int{i}, r...)
			res = append(res, c)
		}
	}

	return res
}


Measured memory_bytes: 28816
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF 1000000000
struct data{
	int cost,time;
};
int main(){
	int n,m;
	while(cin >> n >> m,m+n){
		data d[110][110];
		for(int i = 0; i < 110; i++){
			for(int j = 0; j < 110; j++){
				d[i][j].cost = INF;
				d[i][j].time = INF;
			}
		}
		for(int i = 1; i <= n; i++){
			int a,b,c,t;
			cin >> a >> b >> c >> t;
			d[a][b].cost = c;
			d[a][b].time = t;
			d[b][a].cost = c;
			d[b][a].time = t;
		}
		for(int k = 1; k <= m; k++){
			for(int i = 1; i <= m; i++){
				for(int j = 1; j <= m; j++){
					d[i][j].cost = min(d[i][j].cost,d[i][k].cost+d[k][j].cost);
					d[i][j].time= min(d[i][j].time,d[i][k].time+d[k][j].time);
				}
			}
		}
		int k;
		int p,q,r;
		cin >> k;
		for(int i = 0; i < k; i++){
			cin >> p >> q >> r;
			if(r == 0)cout << d[p][q].cost << endl;
			else cout << d[p][q].time << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1252
@n = gets.to_i
@a = gets.split.map(&:to_i)
@q = gets.to_i
@m = gets.split.map(&:to_i)

def solve(i, m)
  return true if m == 0
  return false if i >= @n
  res = solve(i+1, m) || solve(i+1, m-@a[i])
  return res
end

@m.each do |mm|
  puts solve(0, mm) ? 'yes' : 'no'
end

Measured memory_bytes: 8768
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#n = int(input())
n,m = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for _ in range(m):
    s,t = [int(i)-1 for i in readline().split()]
    g[s].append(t)

L = [len(gi) for gi in g]

p = [0]*n
p[0] = 1
for i in range(n-1):
    c = p[i]/L[i]
    for v in g[i]:
        p[v] += c

dp0 = [0]*(n)
dp1 = [1000000]*(n)

for i in range(n-2,-1,-1):
    res = 0
    m = 0
    for v in g[i]:
        res += dp0[v]
        if m<dp0[v]: m = dp0[v]
    dp0[i] = 1 + res/L[i]

    if L[i] >= 2:
        dp1[i] = 1 + (res-m)/(L[i]-1)
    
res = max((dp0[i] - dp1[i])*p[i] for i in range(n))

print(dp0[0]-max(0,res))












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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++) 
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout) 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const int N=1e6+5;
int spf[N];
void fun(){
    for(int i=4;i<N;i+=2) spf[i]=2;
    for(int i=3;i*i<N;i+=2){
        if(spf[i]!=i) continue;
        for(int j=i*i;j<N;j+=2*i)
            spf[j]=i;
    }
}
int main()
{
	boost;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    for1(1,N,1) spf[i]=i;
    fun();
    int n; cin>>n;
    ll fact=1; ll ans=0;
    for(int i1=1;i1<n;i1++){
        ll res=1;
        int i=i1;
        while(i>1){
            ll cnt=0;
            int j=spf[i];
            while(i%j==0){
                cnt++;
                i/=j;
            }
            res*=(cnt+1);
        }
        //trace(i1,res);
      //  cout<<"i1= "<<i1<<" res= "<<res<<endl;
        ans+=res;
    }
    cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 7556
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    d = collections.defaultdict(int)
    d["SUN"] = 7
    d["MON"] = 6
    d["TUE"] = 5
    d["WED"] = 4
    d["THU"] = 3
    d["FRI"] = 2
    d["SAT"] = 1
    print(d[str(readline().rstrip().decode('utf-8'))])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>
#include<math.h>
#define ll long long int

void sort(int array[],ll n){

ll i,j,temp;

for(i=0;i<n;i++)
{

    for(j=0;j<n;j++)
    {

        if (array[j] > array[j + 1])
            {
                temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }

    }



}




}



int main()
{

char a[1000];
char b[10000];

scanf("%s",a);
scanf("%s",b);

printf("%s%s",b,a);




    return 0;
}


Measured memory_bytes: 128
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int from,to,cost;};
vector<edge> G;
double pi = 3.141592653589793;
P sg[10];
int a[55],b[55];
int n,m;
int d[16][16];
int dp[55][55]={};//i番目までの数でj個選んだ状態のsum
signed main(){
    int n;cin>>n;
    char s[114];
    bool t[4]={};
    rep(i,0,n){
        cin>>s[i];
        if(s[i]=='G')t[0]=1;
        if(s[i]=='W')t[1]=1;
        if(s[i]=='Y')t[2]=1;
        if(s[i]=='P')t[3]=1;
    }
    int ans=0;
    rep(i,0,4){
        if(t[i])ans++;
    }
    if(ans==3)cout<<"Three"<<endl;
    else cout<<"Four"<<endl;
    return 0;
}


Measured memory_bytes: 256
INT_MIN = 0

def init(n_):
    n = 1
    while n < n_:
        n *= 2
    dat = [INT_MIN] * (2*n-1)
    return n, dat

def update(k, a):
    k += n-1
    dat[k] = a
    while k > 0:
        k = (k-1) // 2
        dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2])

def query(l, r, n):
    res = INT_MIN
    l += n
    r += n
    while l < r:
        if l & 1:
            res = max(res, dat[l-1])
            l += 1
        if r & 1:
            r -= 1
            res = max(res, dat[r-1])
        l >>= 1
        r >>= 1
    return res

N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
MAX_Ai = 3*10**5+1
n, dat = init(MAX_Ai)

for ai in A:
    max_len = query(max(ai-K, 0), min(ai+K+1, MAX_Ai), n)
    update(ai, max_len+1)
ans = query(0, MAX_Ai, n)
print(ans)

Measured memory_bytes: 145484
#include<bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<stdlib.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;

int main(void){
  int i,j,N,A,B;
  cin >> A >> B;
  if((A+B)%2==1){
      cout << "IMPOSSIBLE";
  }else{
      cout << (A+B)/2;
  }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n; cin >> n;
  vector<int> v(n+1);
  ll ans = 0;
  repr(i,1,n+1){
    for(int j = i; j <= n+1; j += i){
      v[j]++;
    }
    ans += (ll)i*v[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 42328
#include<stdio.h>
using namespace std;

int main(){
    int n,x;
    scanf("%d %d", &n,&x);
    while(n!=0 || x!=0){
        int sum=0;
        for(int i=1; i<=n; i++){
            for(int j=i+1;j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k==x) sum++;
                }
            }
        }
        printf("%d\n", sum);
        scanf("%d %d", &n,&x);
    }
    return 0;
}



Measured memory_bytes: 2768
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
	int n;
	int a[200000];
	int b[200000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	if(n%2==0){
		int c=a[n/2-1]+a[n/2];
		int d=b[n/2-1]+b[n/2];
		cout<<d-c+1<<endl;
	}else{
		int c=a[(n+1)/2-1];
		int d=b[(n+1)/2-1];
		cout<<(d-c)+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 5204
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
A = LI()
B = LI()
C = LI() + [0]
ans = sum(B)

for i in range(n-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i] - 1]




print(ans)

Measured memory_bytes: 39664
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// 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>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[]={0,1,0,-1};
//int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size())cout<<v[i][j];
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a<=k)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;

    
}
/*

*/


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

template <typename T>
void dfs(const T& list, int s, vector<int>& v, vector<bool>& passed) {
	if (passed[s]) return;

	passed[s] = true;
	v.push_back(s);
	for (int i = 0; i < list[s].size(); i++) {
		dfs(list, list[s][i], v, passed);
	}
}

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	vector<vector<int>> list1(N);
	vector<vector<int>> list2(N);
	for (int i = 0; i < K; i++) {
		int p, q;
		cin >> p >> q;
		list1[p - 1].push_back(q - 1);
		list1[q - 1].push_back(p - 1);
	}
	for (int i = 0; i < L; i++) {
		int r, s;
		cin >> r >> s;
		list2[r - 1].push_back(s - 1);
		list2[s - 1].push_back(r - 1);
	}

	vector<int> ar(N);
	vector<bool> passed(N, false);
	int num = 0;
	for (int i = 0; i < N; i++) {
		if (passed[i]) continue;

		vector<int> v;
		passed[i] = true;
		v.push_back(i);
		for (int j = 0; j < list1[i].size(); j++) {
			dfs(list1, list1[i][j], v, passed);
		}

		for (int j = 0; j < v.size(); j++) {
			ar[v[j]] = num;
		}
		num++;
	}

	for (int i = 0; i < N; i++) passed[i] = false;
	vector<int> br(N);
	num = 0;
	for (int i = 0; i < N; i++) {
		if (passed[i]) continue;

		vector<int> v;
		passed[i] = true;
		v.push_back(i);
		for (int j = 0; j < list2[i].size(); j++) {
			dfs(list2, list2[i][j], v, passed);
		}

		for (int j = 0; j < v.size(); j++) {
			br[v[j]] = num;
		}
		num++;
	}

	map<pair<int, int>, int> mp;
	for (int i = 0; i < N; i++) {
		pair<int, int> p(ar[i], br[i]);
		mp[p]++;
	}

	for (int i = 0; i < N; i++) {
		pair<int, int> p(ar[i], br[i]);
		cout << mp[p] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 27800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
double coin(double a,int score,int k){
  if(score>=k)return a;
  bool ok=true;
  if(ok){
    a*=0.5;
    score*=2;
    coin(a,score,k);
  }
  
}
int main(){
  int n,k;
  cin>>n>>k;
  int score;
  double rate =(double)1/n;
  double ans=0;
  for(int i=1;i<=n;i++){
    score=i;
    double c =coin(rate,score,k);
    ans+=c;
  }
  printf("%.10f",ans);
}

Measured memory_bytes: 256
fun main() {
    val r = nextInt()
    println(when {
        r < 1200 -> "ABC"
        r < 2800 -> "ARC"
        else -> "AGC"
    })
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 34416
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    const double PI = acos(-1);
    int n;
    cin >> n;
    cout << fixed << setprecision(10) << 2.0 * PI * n;
    return 0;
}

Measured memory_bytes: 3804
list=input().split(" ")
N=int(list[0])
K=int(list[1])

def sum_to_N(start,goal):
    return int((start+goal)*(goal-start+1)/2)

count=0
for i in range(K,N+2):
    count+=sum_to_N(N-i+1,N) - sum_to_N(0,i-1) + 1
    

print(count%1000000007)

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

class Point {
public:
    int y, x;
    Point(int i = -1, int j = -1) :y(i), x(j) {}
    bool operator==(Point& p) {return y == p.y && x == p.x;}
};

Point NEXT[4] = {
    Point(1, 0),
    Point(0, 1),
    Point(-1, 0),
    Point(0, -1),
};
Point NEXT_OTHER[8][4] = {
    {Point(1, 0), Point(0, 1), Point(-1, 0), Point(0, -1),},
    {Point(0, 1), Point(-1, 0), Point(0, -1), Point(1, 0),},
    {Point(-1, 0), Point(0, -1), Point(1, 0), Point(0, 1),},
    {Point(0, -1), Point(1, 0), Point(0, 1), Point(-1, 0),},
    {Point(1, 0), Point(0, -1), Point(-1, 0), Point(0, 1),},
    {Point(0, -1), Point(-1, 0), Point(0, 1), Point(1, 0),},
    {Point(-1, 0), Point(0, 1), Point(1, 0), Point(0, -1),},
    {Point(0, 1), Point(1, 0), Point(0, -1), Point(-1, 0),},
};

bool clear(vector<vector<int>> &r) {
    for(auto& line: r) for(auto& v: line) if(v) return false;
    return true;
}

bool dfs(vector<vector<int>>& r, Point Tatsuya, Point Kazuya, int direction) {
    r[Tatsuya.y][Tatsuya.x] = r[Kazuya.y][Kazuya.x] = 0;
    if(clear(r)) return true;
    for(int i = 0; i < 4; ++i) {
        Point next_Tatsuya(Tatsuya.y + NEXT[i].y, Tatsuya.x + NEXT[i].x);
        Point next_Kazuya(Kazuya.y + NEXT_OTHER[direction][i].y, Kazuya.x + NEXT_OTHER[direction][i].x);
        if(!r[next_Tatsuya.y][next_Tatsuya.x]) continue;
        if(!r[next_Kazuya.y][next_Kazuya.x]) continue;
        if(next_Tatsuya == next_Kazuya) continue;
        if(dfs(r, next_Tatsuya, next_Kazuya, direction)) return true;
    }
    return false;
}

bool solve(vector<vector<int>>& r) {
    int h = r.size();
    int w = r[0].size();
    Point Tatsuya, Kazuya;
    for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) {
        if(!r[i][j]) continue;
        Tatsuya = Point(i, j);
        for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) {
            if(!r[i][j]) continue;
            Kazuya = Point(i, j);
            if(Tatsuya == Kazuya) continue;
            for(int direction = 0; direction < 8; ++direction) {
                vector<vector<int>> dup(r);
                if(dfs(dup, Tatsuya, Kazuya, direction)) return true;
            }
        }
    }
    return false;
}

int main() {
    int w, h;
    while(cin >> w >> h, w | h) {
        vector<vector<int>> r(h + 2, vector<int>(w + 2, 0));
        for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j) cin >> r[i][j];
        cout << (solve(r) ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main() {
int n,x,t;
cin>>n>>x>>t;
//ans=(n/x)*t;
if(n%x!=0){
    cout<<((n/x)+1)*t;
}else{
    cout<<(n/x)*t;
    }

//cout<<ans;
        return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const int maxn = 80, delta = 160 * maxn;
short f[maxn][maxn][2 * delta], a[maxn][maxn], b[maxn][maxn];
int h, w;
int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a[i][j];
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> b[i][j];
	for(int i = 0; i < 2 * delta; i++) f[h - 1][w - 1][i] = abs(i - delta);
	for(int i = h - 1; i >= 0; i--){
		for(int j = w - 1; j >= 0; j--){
			if(i == h - 1 && j == w - 1) continue;
			for(int k = 0; k < 2 * delta; k++){
				short r = (1<<15) - 1;
				for(int sig : {1, -1}){
					if(i + 1 < h){
						int nk = k + sig * a[i + 1][j] - sig * b[i + 1][j];
						if(nk >= 0 && nk < 2 * delta){
							r = min(r, f[i+1][j][nk]); 
						}
					}
					if(j + 1 < w){
						int nk = k + sig * a[i][j + 1] - sig * b[i][j + 1];
						if(nk >= 0 && nk < 2 * delta){
							r = min(r, f[i][j+1][nk]);
						}
					}
				}
				f[i][j][k] = r;
			}
		}
	}
	cout << f[0][0][delta + a[0][0] - b[0][0]] << endl;
	return 0;
}


Measured memory_bytes: 320256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long a, b;
    char op;
    scan(a, op, b);
    // writeln(a);
    // writeln(op);
    // writeln(b);
    if (op == '+')
    {
        writeln(a + b);
    }
    else
    {
        writeln(a - b);
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3672
# Generated by AtcoderGreedy on 2018-04-21
# ARC094 C
# Your code here

nums = gets.chomp.split(' ').map(&:to_i)

nums.sort!

biggest = nums.last
missings = nums[0..1].map { |i| biggest - i }.reduce(&:+)

ops = missings/2
residue = missings % 2
ops += 2 unless residue.zero?

puts ops


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


int main(void){
    int i;
    string s;
    vector <int> ans;
    
    cin >> s;
    
    for(i = 0; i < s.length(); i++){
        if(s[i] == '0')
            ans.push_back(0);
        else if(s[i] == '1')
            ans.push_back(1);
        else{
            if(ans.size() > 0)
                ans.pop_back();
        }
    }
    
    for(i = 0; i < ans.size(); i++){
        cout << ans[i];
    }
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <cstdlib>

using namespace std;

int main()
{
    int64_t n, k;
    cin >> n >> k;

    int64_t mod = n % k;

    if (mod < abs(mod - k))
    {
        cout << mod << endl;
    }
    else
    {
        cout << abs(mod - k) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys

s, t = sys.stdin.readline().split()
a, b = map(int, sys.stdin.readline().split())
u = sys.stdin.readline().rstrip()

def main():
    if u == s:
        return a - 1, b
    else:
        return a, b - 1

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Measured memory_bytes: 3060
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 110
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int f[N][N];
char ch[N][N];
int main()
{
	int h=read(),w=read();
	memset(f,48,sizeof(f));
	for(int i=1;i<=h;i++)
		scanf("%s",ch[i]+1);
	f[1][1]=ch[1][1]=='#';
	for(int i=1;i<=h;i++)	for(int j=1;j<=w;j++) if(i!=1||j!=1)
		f[i][j]=min(f[i-1][j]+(ch[i-1][j]!=ch[i][j]&&ch[i][j]=='#'),f[i][j-1]+(ch[i][j-1]!=ch[i][j]&&ch[i][j]=='#'));
	printf("%d\n",f[h][w]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>

typedef long long ll;
#define fi first
#define se second

using namespace std;

////////////////////////////////
//
//
////////////////////////////////

///////////////////////////////
//////////////////////////////

int dpS[112345];
int dpT[112345];
int a[112345];
int b[112345];
int c[112345];
int d[112345];

string S;
string T;


int main(){
  
  cin>>S;
  cin>>T;
  

  
  int i;
  int j;
  
  for( i = 0; i < S.size(); i++ ){
    if( i ) dpS[i] = dpS[i-1];
    if( S[i] == 'A' ) dpS[i]++;
    else{             dpS[i]+=2;}
    //cout<<dpS[i]<<endl;
  }
  
  for( i = 0; i < T.size(); i++ ){
    if( i ) dpT[i] = dpT[i-1];
    if( T[i] == 'A' ) dpT[i]++;
    else{             dpT[i]+=2;}
    //cout<<dpT[i]<<endl;
  }
  
  
  
  int q;
  
  cin>>q;
  

  int dT, dS;
  
  for( i = 0; i < q; i++ ){
    scanf("%d %d %d %d", a+i, b+i, c+i, d+i);
  }
  
  for( i = 0; i < q; i++ ){
    if( a[i] > 1 ) dS = dpS[b[i]-1] - dpS[a[i]-2];
    else{   dS = dpS[b[i]-1];}
    if( c[i] > 1 ) dT = dpT[d[i]-1] - dpT[c[i]-2];
    else{   dT = dpT[d[i]-1];}
    if( (dT%3) == (dS%3) ) puts("YES");
    else{                  puts("NO");}
  }
  
  
  return 0;
}

Measured memory_bytes: 3200
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{
	set<int> s;

	int n;
	cin >> n;

	rep(i, n)
	{
		int a;
		cin >> a;

		if (s.count(a) > 0)
		{
			cout << "NO" << endl;
			return 0;
		}

		s.insert(a);
	}

	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 9728
N = int(input())

def NumOfFractional(n):
    ct = 0
    for i in range(1,n+1):
        if n%i==0:
            ct+=1
    return ct

ct=0
for n in range(1,N+1):
    if n%2!=0 and NumOfFractional(n)==8:
        ct+=1
print(ct)

Measured memory_bytes: 3060
// Problem : D - Knapsack 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define maxn 100000
ll w[101]; ll v[101]; ll dp[101][maxn+1];
ll n=0,wt=0;

ll fun(ll i,ll wt){
	if(wt==0 || i==n) return 0;
	if(dp[i][wt]>-1) return dp[i][wt];
	ll ans=0;
	if(w[i]<=wt){
		ans=max(v[i]+fun(i+1,wt-w[i]),fun(i+1,wt));
	}
	else ans=fun(i+1,wt);
	dp[i][wt]=ans;
	return ans;
}

int main(){
	fast
	cin>>n>>wt;
	for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
	
	memset(dp,-1,sizeof(dp));
	cout<<fun(0,wt);
	return 0;
}

Measured memory_bytes: 79232
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_sum = sum(a)
aa = np.array(np.cumsum(a),dtype="object")
all_a = sum(a)

mod = 1000000007

ans = 0
for i in range(n-1):
    ans += (a[i] * (all_a - aa[i]))

print(ans%mod)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << (s[0] == s[1] && s[2] == s[3] && s[1] != s[2] ? "Yes" : "No");
    return 0;
}
                

Measured memory_bytes: 256
# >0<
s = input()
if s[0] ==">":
    s = "<"+s
if s[-1]=="<":
    s = s +">"
#末端の処理
l=len(s)
upp = 0
dwn = 0
ans = 0
U = []
D = []
for i in range(l):
    if s[i] == "<":
        if dwn:
            D.append(dwn)
            ans += dwn*(dwn+1)//2
            dwn = 0
        upp+=1
    else:
        if upp:
            U.append(upp)
            ans += upp*(upp+1)//2
            upp=0
        dwn += 1
ans += dwn*(dwn+1)//2

#前回からの変更点
##D足すのが自然
D.append(dwn)
###
for i in range(len(D)):
    ans -= min(U[i],D[i])

#不自然なans-1から戻ったが
#前のとは<<終端に>足した場合は同値
#>>>>終末では
print(ans)

Measured memory_bytes: 53888
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main(){
  lli A=0,B=0,C=0,D=0,E=0,F=INF,G=INF,H=0,N,M;
  cin >> N >> M;
  vector<int>P;
  if(M%2==1){
    rep(i,1,N+1){
      if(i%M==0)A++;
    }
  }
  else{
    rep(i,1,N+1){
      if(i%M==0)A++;
      if(i%M==M/2)B++;
    }
  }
  C+=A+B;
  if(A>1)C+=A*(A-1)*3;
  if(B>1)C+=B*(B-1)*3;
  if(A>2)C+=A*(A-1)*(A-2);
  if(B>1)C+=B*(B-1)*(B-2);
  Out(C);
}
  

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>

using namespace std;

const int MAXN = 100000;

int parity[1 + MAXN];

int main () {
    //ifstream cin("input.in");
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        parity[a] ^= 1;
        parity[b] ^= 1;
    }
    for (int i = 1; i <= n; i++)
        if (parity[i]) {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";
    return 0;
}





Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String c1j=scan.next();
		String c2j=scan.next();
		if((c1j.charAt(0)==c2j.charAt(2)) && (c1j.charAt(1)==c2j.charAt(1)) && (c1j.charAt(2)==c2j.charAt(0))) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 35596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 998244353;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define sz(A) (int)A.size()
#define N 3159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

#define in input_int()
#define ins input_string()
int input_int(){int a;cin>>a;return a;}
string input_string(){string s;cin>>s;return s;}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};



int n,m,k,a,b,c,d,x,y,arr[N];
string s;

int dp[N][N];

int get(int idx,int sum)
{
    if(sum>k)return 0;
    if(idx == n+1)
    {
        if(sum==k)return 1;
        return 0;
    }
    int&ans=dp[idx][sum];
    if(ans!=-1)return ans;
    
    ans=get(idx+1,sum+arr[idx]);
    ans%=MOD;
    ans+=(2*get(idx+1,sum))%MOD;
    ans%=MOD;
    return ans;
}

void solve()
{
    st(dp,-1);
    cin>>n>>k;
    forn(i,1,n)cin>>arr[i];
    cout<<get(1,0);

}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}
//       clang++ c.cpp ; ./a.out < a.txt ;  

Measured memory_bytes: 81756
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

ll aa[10005];

int main(int argc, char* argv[])
{
    ll x, y;
    scanf("%lld%lld", &x, &y);

    long count=0;
    while(x<=y) {
        x*=2;
        count++;
    }
    printf("%ld\n", count);

    return 0;
}


Measured memory_bytes: 128
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

ans = []
ope = []
def operate(i, j, k, l):
    a[i][j] -= 1
    a[k][l] += 1
    ans.append([i+1, j+1, k+1, l+1])

for j in range(0, w):
    for i in range(0, h-1):
        if a[i][j]%2 == 1:
            operate(i, j, i+1, j)
for j in range(0, w-1):
    if a[h-1][j]%2 == 1:
        operate(h-1, j, h-1, j+1)

print(len(ans))
for i in range(0, len(ans)):
    print(ans[i][0],ans[i][1],ans[i][2],ans[i][3],end="")
    print()

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

int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> score(N);
  int t;
  for (int i = 0; i < Q; i++){
    scanf("%d\n", &t);
    score.at(t-1) += 1;
  }
  for (int i = 0; i < N; i++){
    if (score.at(i) - Q + K >= 1){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
}

Measured memory_bytes: 1024