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

using namespace std;

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

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

string s;

int main(){
  cin >> s;
  int ans = 0;
  int now = 0;
  for(int i = 0; i < (int)s.size(); ++i){
    if(s[i] != '1'){
      ans = max(ans, now + (s[i] - '0' - 1) + ((int)s.size() - i - 1) * 9);
    }
    now += s[i] - '0';
  }
  ans = max(ans, now);
  ans = max(ans, ((int)s.size() - 1) * 9);
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 110
int INF = 1 << 28;
struct edge{int to,cap,rev;};
vector<edge> G[MAX_V*2+2];
bool used[MAX_V*2+2];
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}
 
int dfs(int v,int t,int f){
  if(v==t) return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0 ){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    } 
  }
  return 0;
}
 
int max_flow(int s,int t){
  int flow=0;
  for(;;){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0) return flow;
    flow+=f;
  }
}
 
int main(){
  int v,e,a,b,c;
  cin>>v>>e;
  for(int i=0;i<e;i++){
    cin>>a>>b>>c;
    add_edge(a,b,c);
  }
  cout << max_flow(0,v-1) << endl;
  return 0;
} 

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <functional>
#include <queue>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;
typedef pair<int, Q> R;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int hyou2[1005] = {0};
		priority_queue<R> pq;
		R r;
		for (int i = 0; i < n; i++) {
			cin >> ((r.second).second).first >> ((r.second).second).second >> r.first >> (r.second).first;
			pq.push(r);
		}
		vector<int> hyou;
		while (!pq.empty()) {
			R rr = pq.top();
			pq.pop();
			priority_queue< Q, vector<Q>, greater<Q> > pqq;
			pqq.push(rr.second);
			while (!pq.empty() && (pq.top()).first == rr.first) {
				pqq.push((pq.top()).second);
				pq.pop();
			}
			while (!pqq.empty()) {
				Q q = pqq.top();
				pqq.pop();
				priority_queue< P, vector<P>, greater<P> > pqp;
				pqp.push(q.second);
				while (!pqq.empty() && (pqq.top()).first == q.first) {
					pqp.push((pqq.top()).second);
					pqq.pop();
				}
				while (!pqp.empty()) {
					P p = pqp.top();
					pqp.pop();
					if (hyou.size() < 10) {
						if (hyou2[p.second] < 3) {
							hyou.push_back(p.first);
							hyou2[p.second]++;
						}
					} else if (hyou.size() < 20) {
						if (hyou2[p.second] < 2) {
							hyou.push_back(p.first);
							hyou2[p.second]++;
						}
					} else if (hyou.size() < 26) {
						if (hyou2[p.second] < 1) {
							hyou.push_back(p.first);
							hyou2[p.second]++;
						}
					}
				}
			}
		}
		for (int i = 0; i < hyou.size(); i++) {
			cout << hyou[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(0,N-1):
  s = A[i+1] - A[i]
  B.append(s)
l = K-A[N-1] + A[0]
B.append(l)
print(K-max(B))

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

using namespace std;

int main(){
    
    int N, M;
    cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    
    int a = 1, b = N;
    
    
    
    for (int i = 0; i < M; i++) {
        
        cin >> L[i] >> R[i];
        if (L[i] > a) {
            a = L[i];
        }
        if (R[i] < b) {
            b = R[i];
        }
        
    }
    
    if (a <= b) {
        cout << b-a+1 << endl;
    }else{
        cout << 0 << endl;
    }
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 1024
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next

  val map = s.foldLeft(Map.empty[Char, Int])((acc, v) => setOrUpdated(acc, v, 1, (a: Int, b: Int) => a + b))
  val ans = if (map.size == 2 && map.head._2 == 2) "Yes" else "No"

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

ll a,b,c,d,len,l,r,mid,he,ta,mia,mib;
string s;

ll up(ll x,ll y){
	return (x+y-1)/y;
}
bool ck(){
	if (!mid) return 1;
	ll la=a-mid*len, lb=b-mid;
	if (!la) return !lb;
	if (lb<0) return 0;
	if (max(up(la,lb+1),up(lb,la))>len) return 0;
	return 1;
}

char cal(ll p){
	if (p<=(len+1)*he) return p%(len+1)? 'A': 'B';
	if (a+b-p+1<=(len+1)*ta) return (a+b-p+1)%(len+1)? 'B': 'A';
	return p<=(len+1)*he+mia? 'A': 'B';
}

void realmain(){
	s="";
	len=max(up(a,b+1),up(b,a+1));
	l=0; r=a/len;
	for (;l<=r;ck()? l=(he=mid)+1: r=mid-1) mid=l+r>>1;
	ll la=a-he*len, lb=b-he;
	ta=lb/len; mib=lb%len; mia=la-ta;
	for (ll i=c;i<=d;++i) s+=cal(i);
	cout<<s<<endl;
}

int main(){
	int T;
	for (cin>>T;T--;){
		cin>>a>>b>>c>>d;
		realmain();
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define int long long
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};

signed main(){
    string S;
    cin >> S;
    ll N = S.size();
    ll ans = 0;
    ll sum[N] = {0};
    FOR(i,0,N)if(S[i] == 'W')sum[i]++;
    REP(i,0,N-1)sum[i] += sum[i+1];
    FOR(i,0,N)if(S[i] == 'B')ans += sum[i];
    cout << ans << endl;
}

Measured memory_bytes: 2180
import math
N = int(input())
A = list(map(int,input().split()))
M = max(A)
cnt = [0 for i in range(M)]
for i in range(N):
    if cnt[A[i]-1] != 0:
        cnt[A[i]-1] = 2
    else:
        j = A[i]-1
        while j<M:
            cnt[j] += 1
            j += A[i]

ans = 0
for i in range(N):
    if cnt[A[i]-1] == 1:
        ans += 1
        
print(ans)   

Measured memory_bytes: 33036
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<long long>num(n,0);
  for(int i=0;i<n;i++){
    cin >> num[i];
  }
  
  bool can = true;
  int max = 0;
  for(int i=0;i<n - 2;i++){
    if(num[i] - num[i + 1] > 0 && num[i + 1] - num[i + 2] > 0)
      can = false;
  }
  for(int i=0;i<n - 1;i++){
    if(num[i] - num[i + 1] > 1)
      can = false;
  }
  
  for(int i=0;i<n;i++){
      if(num[i] > max)
      max = num[i];
      if(num[i] <= max - 2)
      can = false;
  }
  
  if(can){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
  
  return 0;
}

  
    
    

Measured memory_bytes: 1024
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

ll calc(const string &S, ll &idx) {
    if (S[idx] == '[') {
        V<ll> recs;
        idx++;
        while (true) {
            recs.push_back(calc(S, idx));
            if (S[idx] == ']') break;
        }
        idx++;
        sort(ALL(recs));
        ll ret = 0;
        for (ll i = 0; i < (recs.size() + 1) / 2; i++) ret += recs[i];
        return ret;
    } else {
        ll ret = 0;
        while (true) {
            char c = S[idx];
            if (!('0' <= c && c <= '9')) break;
            ret = ret * 10 + (c - '0');
            idx++;
        }
        return (ret + 1) / 2;
    }
}

void solve() {
    string S;
    cin >> S;
    ll idx = 0;
    cout << calc(S, idx) << endl;
}

int main() {
    ll N;
    cin >> N;
    while (N--) solve();
    return 0;
}



Measured memory_bytes: 3236
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

ll N,h,w,ans;
int main(void) {
	cin >> N>>h>>w;
	FOR(i, 0, N) {
		ll H, W;
		cin >> H >> W;
		if (H >= h && W >= w)ans++;
	}
	ct(ans);
	return 0;
}

Measured memory_bytes: 256
def aux(f, a, b, d)
  s = 0.0
  n = ((b-a)/d).to_i
  n.times {|i|
    s += f.call(i*d)
  }
  return s*d
end

def main
  fh=STDIN
  #fh=File.new("x.txt", "r")
  while fh.gets
    f=lambda{|x| x**2}
    d = $_.chomp.to_i
    puts format("%.0f", aux(f, 0, 600, d))
  end
end

if $0 == __FILE__ then
  main
end


Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
#define UF_SIZE 1 // 1/0: 同値類のサイズを記録する/しない

struct UnionFind{
// 同値関係をサポートするデータ構造
// 併合,所属する同値類の代表元:O(logN), 集合の分割はNG
// 経路圧縮する場合,各クエリはO(a(n)) (a(n): アッカーマン関数A(m,n)について,f(n)=A(n,n)としたときの逆関数)
  vector<int> m_root;
#if (UF_SIZE==1)
  vector<int> m_size;
#endif
  int Nv;

  UnionFind(int N)
  : m_root(2*N)
#if (UF_SIZE==1)
  , m_size(2*N,1)
#endif
  , Nv(N)
  { iota(m_root.begin(), m_root.end(), 0); }

  int find(int a){
    if(m_root.at(a)==a){
      return a;
    }
    else{
      return m_root.at(a)= find(m_root.at(a));
    }
  }

  void unify(int a, int b){
    int r_a= find(a);
    int r_b= find(b);
#if (UF_SIZE==1)
    if(r_a != r_b){
      if(m_size.at(r_a) < m_size.at(r_b)){
        m_root.at(r_a)= r_b;
        m_size.at(r_b)+= m_size.at(r_a);
        return;
      }
      else{
        m_root.at(r_b)= r_a;
        m_size.at(r_a)+= m_size.at(r_b);
        return;
      }
    }
#else
    if(r_a != r_b){
      m_root.at(r_b)= r_a;
      return;
    }
#endif
  }
  
  bool are_comrade(int a, int b){
    return find(a)==find(b);
  }

#if (UF_SIZE==1)
  int get_size(int a){
    return m_size.at(find(a));
  }
#endif

  void connect(int v1, int v2, int w){
    if(w%2==0){
      unify(v1   , v2);
      unify(v1+Nv, v2+Nv);
    }
    else{
      unify(v1+Nv, v2);
      unify(v1   , v2+Nv);
    }
  }
};

int main(){
  int N;
  cin >> N;

  UnionFind uf(N);
  int v1,v2,w;
  for(int i=0; i<N-1; i++){
    cin >> v1 >> v2 >> w;
    v1--; v2--; // 1-indexed -> 0-indexed
    uf.connect(v1,v2,w);
  }

  for(int i=0; i<N; i++){
    int color= (uf.are_comrade(0,i)) ? 0
                                     : 1;
    cout << color << endl;
  }
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int ans[] = {11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};
    int N;
    cin >> N;
    for(int i = 0;i < N;i++)cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A = []
for i in range(N):
  A.append(list(map(int,input().split())))
A.sort(key=lambda x:x[0])
cnt = 0
pn = 0
for i in range(N):
  if (cnt + A[i][1]) >=  M:
    pn += A[i][0]*(M-cnt)
    break
  else:
    cnt += A[i][1]
    pn += A[i][0]*A[i][1]
print(pn)

Measured memory_bytes: 29024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var xy = Sarray();
            var x = xy[0];
            var y = xy[1];
            var absx = Abs(x);
            var absy = Abs(y);
            var gen = Abs(absx - absy);
            var hosei = 0L;
            if (0 <= x && x <= y) hosei = 0;
            else if (x <= y && y <= 0) hosei = 0;
            else if (x <= 0 && 0 <= y) hosei = 1;
            else if (y <= 0 && 0 <= x) hosei = 1;
            else hosei = 2;
            WriteLine(gen + hosei);
            
            //Out.Flush();
        }
    }
}

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

using namespace std;

typedef long long int ll;

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

typedef pair<int,int> pair;

int main(){
    string s; cin >> s;
    int leng=s.size();

    int ans=0;
    for(int i=0;i<leng/2;i++){
        //printf("%c,%c\n",s[i],s[leng-i-1]);
        if(s[i]!=s[leng-i-1]){
            ans++;
        }
    }
    //cout << leng << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  string f=s.substr(0,s.size()/2);
  string b;
  while(1){
    s.pop_back();
    s.pop_back();
    f.pop_back();
    b=s.substr(f.size(),f.size());
    if(f==b)
      break;
  }
  cout<<s.size()<<endl;
}

Measured memory_bytes: 256
import sys
N, Y = map(int, input().split(' '))

for x in range(Y//10000 + 1)[::-1]:
    for y in range((Y-10000*x)//5000 + 1)[::-1]:
        z = N - x - y
        if 10000*x + 5000*y + 1000*z == Y:
            print(x, y, z) 
            sys.exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include <cstring>
#include <functional>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iostream>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    unordered_map<int, vector<int> > adj[n];
    struct edge { int src, dst, col; };
    edge edges[m];
    for (int i = 0; i < m; i++) {
        int p, q, c; cin >> p >> q >> c;
        p--; q--;
        edges[i] = {p, q, c};
        adj[p][c].push_back(i);
        adj[q][c].push_back(i);
    }
    int dist[n];
    constexpr int INF = 1<<30;
    fill(dist, dist+n, INF);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    bool used[m];
    memset(used, 0, sizeof used);
    function<void(int, int, int)> dfs = [&](int i, int col, int d) {
        auto it = adj[i].find(col);
        if (it == adj[i].end()) return;
        for (int e : it->second) {
            if (used[e]) continue;
            else used[e] = true;

            int j = (edges[e].src == i ? edges[e].dst : edges[e].src);
            if (dist[j] > d) {
                dist[j] = d;
                q.push(j);
            }
            if (dist[j] >= d) dfs(j, col, d);
        }
    };

    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (auto &x : adj[i]) {
            dfs(i, x.first, dist[i] + 1);
        }
    }
    cout << (dist[n-1] == INF ? -1 : dist[n-1]) << endl;
}


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

int main(){
	int a, b;
 		 a = b = 0;
  	long long x;
 		 cin >> x;
 	 
  rep(i, 150){
    long long y = pow(i, 5);
    for(int j = -150; j <= i; j++){
    	long long z = pow(j, 5);
      if( y - z == x ){
        a = i, b = j;
        break;
      }
    }
  }
  
  cout << a << " " << b << endl;

    return 0;
  }

Measured memory_bytes: 4064
class Bit:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1) )- 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """
        (a0+a1+...+ai < x となる最大の i (存在しない時は -1 ) , その時の a0+a1+...+ai )
        a0+a1+...+ai <= x としたい場合は equal = True
        二分探索であるため、ai>=0 を満たす必要がある
        """
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x: # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i+1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i+1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2))


####################################################################################################

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
A = map(int, input().split())
B = Bit(N)
B.built(A)
for _ in range(Q):
    a, b, c = map(int, input().split())
    if a: print(B.get(b,c))
    else: B.add(b,c)

Measured memory_bytes: 120088
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

int main(){
    long long n, m;
    cin>>n>>m;
    multimap<long, long> mp;
    for(long long i=0; i<n; i++){
        long long a, b;
        cin>>a>>b;
        mp.insert(pair<long, long>(a, b));
    }
    long long sum=0, ans=0;
    for(auto i=mp.begin(); i!=mp.end(); ++i){
        if(sum+(*i).second<m){
            sum+=(*i).second;
            ans+=((*i).first)*((*i).second);
        }else if(sum+(*i).second==m){
            sum+=(*i).second;
            ans+=((*i).first)*((*i).second);
            break;
        }else {
            ans+=(m-sum)*((*i).first);
            break;
        }
        
        
        
    }
    cout<<ans<<endl;
        
    
    
}


Measured memory_bytes: 6528
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){

    ll k;
    cin >> k;
    
    ll now = 7;
    ll ans = 1;
    while(now % k != 0){
        now *= 10;
        now %= k;
        now += 7;
        now %= k;
        ans++;
        if(ans >= 2 * 1e6){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3616
/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "D"
#define MOD 1000000007
#define endl "\n"
#define pii pair <int,int>
using namespace std;
int n;
int level[100005],p[100005];
long long res;
struct point
{
    int x,y,idx;
} a[100005];
struct data
{
    int x,y;
    long long w;
} edge[200005];
int Find(int u)
{
    if (p[u]==u)
        return u;
    return p[u]=Find(p[u]);
}
void Group (int u,int v)
{
    int x=Find(u);
    int y=Find(v);
    if (x==y)
        return;
    else
    {
        if (level[x]>level[y])
        {
            p[y]=x;
            return;
        }
        if (level[x]<level[y])
        {
            p[x]=y;
            return;
        }
        if (level[x]==level[y])
        {
            p[y]=x;
            level[x]++;
            return;
        }
    }
}
bool cmp1 (point A,point B)
{
    return A.x<B.x;
}
bool cmp2 (point A,point B)
{
    return A.y<B.y;
}
bool edgecmp (data A,data B)
{
    return A.w<B.w;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i].x>>a[i].y;
        p[i]=i;
        a[i].idx=i;
    }
    sort(a+1,a+1+n,cmp1);
    for (int i=1; i<=n-1; i++)
    {
        edge[i].x=a[i].idx;
        edge[i].y=a[i+1].idx;
        edge[i].w=abs(a[i].x-a[i+1].x);
    }
    sort(a+1,a+1+n,cmp2);
    for (int i=1; i<=n-1; i++)
    {
        edge[i+n-1].x=a[i].idx;
        edge[i+n-1].y=a[i+1].idx;
        edge[i+n-1].w=abs(a[i].y-a[i+1].y);
    }
    sort(edge+1,edge+2*n-1,edgecmp);
    for (int i=1; i<=2*n-2; i++)
    {
        int u=edge[i].x,v=edge[i].y;
        if (Find(u)!=Find(v))
        {
            res+=edge[i].w;
            Group(u,v);
        }
    }
    cout<<res;
}


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

int main() 
{
  ll n;
  cin>>n;
  ll sum=0;
  for(int i=1;i<=n;i++)
  {
    if(i%3==0 && i%5==0)continue;
    else if(i%3==0)continue;
    else if(i%5==0)continue;
    else sum+=i;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
int day,jap,mat,j,m,i,jd,md;
scanf("%d %d %d %d %d",&day,&jap,&mat,&j,&m);
jd=jap/j;
md=mat/m;
if(jap%j!=0)jd=jd+1;
if(mat%m!=0)md=md+1;
if(jd<=md){
    printf("%d\n",day-md);
}
else printf("%d\n",day-jd);

return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


vector<ll> dp(100010,-1);

ll rec(ll n){


    if(n == 0) return 0;
    if(dp[n] != -1) return dp[n];

    ll Min = MAX;

    for(int i = 1; i <= n; i *= 6) Min = min(Min,rec(n-i)+1);
    for(int i = 1; i <= n; i *= 9) Min = min(Min,rec(n-i)+1);

    return dp[n] = Min;
}

int main() {

    ll n; cin >> n;

    rec(n+1);

    cout << dp[n];

}


Measured memory_bytes: 8740
import java.util.*;

public class Main {

    public static void main(String [] args) {
        final Scanner sc = new Scanner(System.in);
        final int n;
        final int k;
        n = sc.nextInt();
        k = sc.nextInt();
        final int [] number = new int[n];
        int minIdx = 0;
        for (int i = 0; i < n; ++i) {
            number[i] = sc.nextInt();
            if (number[i] == 1) {
                minIdx = i;
            }
        }
        if (k >= n) {
            System.out.println(1);
            return;
        }
        if (n == 1) {
            System.out.println(0);
            return;
        }

        int minCount = Integer.MAX_VALUE;
        for (int left = 1; left <= k; ++left) {
            int leftCount =
                    (minIdx + 1 - left) % (k - 1) == 0 ?
                    (minIdx + 1 - left) / (k - 1) + 1 :
                    (minIdx + 1 - left) / (k - 1) + 1 + 1;
            int right = k - left;

            int rightCount =
                    (n - 1 - minIdx - right) % (k - 1) == 0 ?
                    (n - 1 - minIdx - right) / (k - 1) :
                    (n - 1 - minIdx - right) / (k - 1) + 1;
            int currentCount = leftCount + rightCount;
            if (currentCount < minCount) {
                minCount = currentCount;
            }
        }
        System.out.println(minCount);
    }

}


Measured memory_bytes: 49284
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		char[] S = sc.next().toCharArray();
		sc.close();
		S[K - 1] = (char)(S[K - 1] + 32);
		String out = "";
		for(int i = 0; i < N; i++) {
			out += S[i];
		}
		System.out.println(out);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n,l,r,q[maxn];
ll h[maxn],dp[maxn],C;
ll sqr(ll x) { return x*x; }
double slope(int j,int k) {
	return (sqr(h[j])-sqr(h[k])+dp[j]-dp[k])*1.0/(h[j]-h[k]);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(C);
	for (int i=1;i<=n;i++) read(h[i]);
	dp[n]=0; l=r=1; q[1]=n;
	for (int i=n-1;i>=1;i--) {
		while (l<r&&slope(q[l+1],q[l])>=h[i]*2) l++;
		dp[i]=sqr(h[q[l]]-h[i])+C+dp[q[l]];
		while (l<r&&slope(q[r],q[r-1])<=slope(i,q[r])) r--;
		q[++r]=i;
	}
	printf("%lld\n",dp[1]);
	return 0;
}

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

vector<int>E[100];
bool used[200];
int match[200];

bool dfs(int u) {
	used[u] = true;
	for (int v : E[u]) {
		int w = match[v];
		if (w == -1 || (!used[w] && dfs(w))) {
			match[u] = v; match[v] = u;
			return true;
		}
	}
	return false;
}
int x[100], y[100], z[100], a[100], b[100];
double d[100][100];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, n)scanf("%d%d%d", &x[i], &y[i], &z[i]);
		rep(i, m)scanf("%d%d", &a[i], &b[i]);
		rep(i, n)rep(j, m)d[i][j] = hypot(x[i] - a[j], y[i] - b[j]) / z[i];
		double l = 0, r = 15000;
		rep(i, 43) {
			double t = (l + r) / 2;
			rep(j, n) {
				E[j].clear();
				rep(k, m) {
					if (d[j][k] <= t)E[j].push_back(n + k);
				}
			}
			int cnt = 0;
			memset(match, -1, sizeof(match));
			rep(j, n) {
				if (match[j] == -1) {
					memset(used, 0, sizeof(used));
					cnt += dfs(j);
				}
			}
			if (cnt == m)r = t;
			else l = t;
		}
		printf("%.14lf\n", l);
	}
}

Measured memory_bytes: 3252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a= sc.nextInt();
		int b = sc.nextInt();
		if (a*b==15) {
			System.out.println("*");
		} else if (a+b==15) {
			System.out.println("+");
		} else {
			System.out.println("x");
		}
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 81, inf = 1e7, dd = 80*80; int n, m;
int a[2][maxN][maxN];

int memo[maxN][maxN][2*maxN*maxN];
int solve(int i = 0, int j = 0, int da = 0, int db = 0)
{
  if (i == n - 1 && j == m - 1) return min(abs((da + a[0][i][j]) - (db + a[1][i][j])), abs((da + a[1][i][j]) - (db + a[0][i][j])));
  if (memo[i][j][da - db + dd] != -1) return memo[i][j][da - db + dd];
  int ans = inf;
  if (i + 1 < n)
    ans = min({ans, solve(i + 1, j, da + a[0][i][j], db + a[1][i][j]), solve(i + 1, j, da + a[1][i][j], db + a[0][i][j])});
  if (j + 1 < m)
    ans = min({ans, solve(i, j + 1, da + a[0][i][j], db + a[1][i][j]), solve(i, j + 1, da + a[1][i][j], db + a[0][i][j])});
  return memo[i][j][da - db + dd] = ans;
}

int main()
{
  while (scanf("%d %d", &n, &m) != EOF)
  {
    for (int i = 0; i < 2; i ++)
      for (int j = 0; j < n; j ++)
        for (int k = 0; k < m; k ++)
          scanf("%d", &a[i][j][k]);
    memset(memo, -1, sizeof(memo));
    int ans = solve();
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 336640
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
int N;
long long A[MAX_N];
long long ac[MAX_N];
char op[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N - 1; i++) {
        std::cin >> A[i] >> op[i];
    }
    std::cin >> A[N];

    std::vector<int> pos;

    for (int i = 1; i <= N; i++) {
        if (op[i] == '-') {
            pos.push_back(i+1);
        }
        ac[i] = ac[i-1] + A[i]; 
    }

    if (pos.size() == 0) {
        std::cout << ac[N] << std::endl;
        return 0;
    }

    std::vector<long long> cand;
    long long tmp = 0;
    for (int i = 0; i < pos.size(); i++) {
        if (i < pos.size() - 1) {
            //std::cout << "check:" << pos[i] << " " << pos[i+1] << " " << ac[pos[i+1] - 1] << " " << ac[pos[i] - 1] << std::endl;
            cand.push_back(tmp + ac[pos[i+1] - 1] - ac[pos[i] - 1]);
        }
        tmp += A[pos[i]];
    }
    cand.push_back(tmp);

    std::sort(cand.begin(), cand.end());

    std::cout << ac[N] - cand[0] * 2 << std::endl;
    
    return 0;
}

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

int main(void)
{
	int q, x;
	bool query;
	set<int> S;
    cin >> q;
    rep(i, q)
    {
        cin >> query >> x;
        if (query)
        {
            cout << S.count(x) << endl;
        }
        else
        {
            S.insert(x);
            cout << S.size() << endl;   
        }
    }
}


Measured memory_bytes: 12464
import sys
import math

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)

s = input().split(" ")
a = int(s[0])
b = int(s[1])
k = int(s[2])
c = gcd(a, b)
fac = []

for i in range(1, c+1):
	if c%i == 0:
		fac.append(i)

print(fac[-k])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pb push_back
using namespace std;

const int N = 100005;
ll n, m, t, a[N], k, l[N], r[N], ans, tong;
ll b[N];
vector<pll> kq;
string s;
priority_queue< pii, vector<pii>, greater<pii> > pr;
void sol()
{
    cin >> n >> s;
    s = " " + s;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        l[i] = i - 1;
        r[i] = i + 1;
    }
    for(int i = 2; i <= n; i ++)
    {
        if(s[i-1] != s[i])
        {
            k = abs(a[i] - a[i-1]);
            pii u;
            u.fi = k;
            u.se.fi = i-1;
            u.se.se = i;
            pr.push(u);
        }

    }
    while(!pr.empty())
    {
        pii u = pr.top();
        pr.pop();
        ll x = u.se.fi, y = u.se.se;
        if(b[x] == 1 || b[y] == 1)continue;
        b[x] = 1;
        b[y] = 1;

        l[r[y]] = l[x];
        r[l[x]] = r[y];
        kq.pb({x, y});
        if(l[x] > 0 && r[y] <= n && s[l[x]] != s[r[y]])
        {
            pii v;
            v.fi = abs(a[l[x]] - a[r[y]]);
            v.se.fi = l[x];
            v.se.se = r[y];
            pr.push(v);
        }
    }
    cout << kq.size() <<'\n';
    for(pll u : kq)cout << u.fi <<" "<<u.se<<'\n';
}
ll random(ll minn, ll maxn)
{
    return minn + rand() % (maxn + 1 - minn);
}
priority_queue<ll> st;
ll uoc(ll a, ll b)
{
    while(b != 0)
    {
        ll r = a % b;
        a = b;
        b = r;
    }
    return a;
}
map<ll, ll> mp;
void test()
{
   cin >> n;
    for(int i = 1;i <= n; i ++)
    {
        cin >> m;
        ans += m;
        ++mp[m];
    }
    cin >> t;
    while(t -- > 0)
    {
        cin >> m >> k;
        ans += (k - m) * mp[m];

        mp[k] += mp[m];
        mp[m] = 0;
        cout << ans <<'\n';
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    test();
}


Measured memory_bytes: 9580
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine() + "!";
		br.close();

		String t = "KIHBR!";
		int i = 0;
		for (int j = 0; j < t.length(); j++) {
			int cnt = 0;
			while (i < s.length() && s.charAt(i) != t.charAt(j)) {
				if (s.charAt(i) != 'A') {
					System.out.println("NO");
					return;
				}
				i++;
				cnt++;
			}
			if (cnt > 1) {
				System.out.println("NO");
				return;
			}
			if (cnt > 0) {
				if (j == 1 || j == 2) {
					System.out.println("NO");
					return;
				}
			}
			i++;
		}
		System.out.println("YES");
	}
}


Measured memory_bytes: 21332
import bisect

n = int(input())
s = list(map(int,input().split()))
l = sorted(s)
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        limit = l[i] + l[j]
        count += bisect.bisect_left(l,limit) - (j+1)

print(count)

Measured memory_bytes: 3188
// 
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 100005
int n;
ll a[MAX_N];
ll b[MAX_N];

const ll INF=1e18;



int main() {
	cin >> n;
	ll sum=0;
	rep(i,n+1){
		cin >> a[i];
		sum += a[i];
	}
	if(n==0){
		if(a[0]==1){
			outl(1);
		}else{
			outl(-1);
		}
		return 0;
	}
	if(a[0]>0 && n>0){
		outl(-1);
		return 0;
	}
	ll ans = 1;
	ll b=1;
	sum -= a[0];
	for(int i=1;i<n;i++){
		sum -= a[i];
		b = min(sum,2*b-a[i]);
		if(b<0){
			outl(-1);
			return 0;
		}
		ans += b+a[i];
	}
	if(b<(a[n]+1)/2 || a[n]<b){
		outl(-1);
		return 0;
	}
	ans += a[n];



	outl(ans);
    return 0;
}



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

char change(char s, int n)
{
  if ('A'<= s+n && s+n<='Z')
    return (s+n);
  else 
    return (s+n-'Z'+'A'-1);
}

int main()
{
  int N;
  string S;
  cin>>N;cin>>S;
  int len = (int)S.length();
  
  char T[len];
  for (int i=0;i<len;i++)
  {
    T[i] = change(S.at(i),N); 
    cout<<T[i];
  }
  
  cout<<endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
if H == 1 or W == 1:
	print(1)
elif H*W%2 == 0:
	print(H*W//2)
else:
	print(H*W//2+1)


Measured memory_bytes: 5832
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;

int main() {
  int x;
  cin >> x;
  if(400<=x && x<=599)
  cout << 8 << endl;
  else if(600<=x && x<=799)
  cout << 7 << endl;
  else if(800<=x && x<=999)
  cout << 6 << endl;
  else if(1000<=x && x<=1199)
  cout << 5 << endl;
  else if(1200<=x && x<=1399)
  cout << 4 << endl;
  else if(1400<=x && x<=1599)
  cout << 3 << endl;
  else if(1600<=x && x<=1799)
  cout << 2 << endl;
  else if(1800<=x && x<=1999)
  cout << 1 << endl;
}



Measured memory_bytes: 3644
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
void cntBomb(int* s,int i,int j)
{

}

int main() {

  string n;
  cin >> n;

  map<char,int> m;

  rep(i,3)
  {
    m[n[i]]++;
  }

  if(m['7'] > 0) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 3628
def binarySearch(a,key)
  left = 0
  right= a.length
  while left < right
    mid = (left +right)/2
    if a[mid]==key
      return mid
    elsif key<a[mid]
      right =mid
    else
      left =mid+1
    end
  end
  return false
end
gets;ss=gets.split.map(&:to_i);gets;ts=gets.split.map(&:to_i)
count=0
ts.each{|t|count+=1 if binarySearch(ss,t)!=false}
puts  count



Measured memory_bytes: 15356
mod = 1000000007
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
T_max = 0
T_max_i = 0
for i in range(N):
    if T[i] > T_max:
        T_max = T[i]
        T_max_i = i
A_max = 0
A_max_i = 0
for i in range(N):
    if A[i] >= A_max:
        A_max = A[i]
        A_max_i = i
if T_max != A_max or T_max_i > A_max_i:
    print(0)
else:
    ans = 1
    h = 0
    for i in range(T_max_i + 1):
    	if T[i] > h:
    		h = T[i]
    	else:
    		ans = (ans * h) % mod
    for i in range(T_max_i + 1, A_max_i):
    	ans = (ans * h) % mod
    for i in range(A_max_i + 1, N):
    	if A[i] < h:
    		h = A[i]
    	else:
    		ans = (ans * h) % mod
    print(ans)

Measured memory_bytes: 83556
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s[]=new String[n];
		String p="P";
		String w="W";
		String g="G";
		String y="Y";
		int count=0;
		for(int i=0;i<n;i++){
			s[i]=sc.next();
		}
		for(int i=0;i<n;i++){
			if(p.equals(s[i])){
				count++;
				p="";
			}
			if(w.equals(s[i])){
				count++;
				w="";
			}
			if(g.equals(s[i])){
				count++;
				g="";
			}
			if(y.equals(s[i])){
				count++;
				y="";
			}
		}
		switch(count){
		case 1:System.out.println("One");break;
		case 2:System.out.println("Two");break;
		case 3:System.out.println("Three");break;
		case 4:System.out.println("Four");break;
		default:break;
		}
		
	}

}

Measured memory_bytes: 23764
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int64_t read_int() {
    int64_t ret = 0, sgn = 1;
    int ch = getchar_unlocked();
    while (isspace(ch)) { ch = getchar_unlocked(); }
    if (ch == '-') { sgn = -1; ch = getchar_unlocked(); }
    for (; isdigit(ch); ch = getchar_unlocked())
        ret = (ret * 10) + (ch - '0');
    ungetc(ch, stdin);
    return sgn * ret;
}

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline void assign_min(T& x, const T& value) noexcept { x = min(x, value); }
template <typename T> inline void assign_max(T& x, const T& value) noexcept { x = max(x, value); }

constexpr char LF = '\n';

//-------------------------------------------------------------------------------------------------

int main() {
    auto N = read_int();
    vector<uint64_t> A(N);
    REP(i, N) A[i] = read_int();

    uint64_t all = 0;
    REP(i, N) all ^= A[i];

    REP(i, N) {
        if (i != 0) cout << ' ';
        cout << (A[i] ^ all);
    }
    cout << LF;
}


Measured memory_bytes: 4340
#pragma GCC optimize("O3", "unroll-loops")

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <limits>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

const int inf = (1 << 30) + 9e8;
const int MAXN = 1e5;
const int MAXN2 = 1e4;
const int P = 131;
const long long MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<bool> vb;

#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define all(a) a.begin(), a.end()
#define pb push_back
#define files(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define ppb pop_back
#define ppf pop_front
#define fs first
#define sd second
#define eb emplace_back

template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n, k;
    cin >> n >> k;
    vi h(n);
    cin >> h;
    vi dp(n, inf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= min(k, n - i); ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    // for (auto it : dp)
    //     cout << it << ' ';
    // cout << '\n';
    cout << dp[n - 1];
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    FAST;
    int q = 1;
    // cin >> q;
    // int st = clock();
    while (q--) {
        solve();
    }
    // int en = clock();
    // cout << en - st << "ms.";
    return 0;
}


Measured memory_bytes: 3960
#include<stdio.h>
#define N 500001
void Merge(int A[],int left,int mid,int fuck);
void MergeSort(int A[], int left, int right);
int count = 0;

int main(){
  int A[N];
  int i,n;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

 
      MergeSort(A, 0, n);
      for(i = 0; i < n; i++){
	if(i == n-1)	printf("%d\n",A[i]);
	else printf("%d ",A[i]);
      }
      printf("%d\n",count);
      return 0;
}

void Merge(int A[],int left,int mid,int right){
   
  int i, j = 0, k;
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];
  
  for (i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i = 0;
  
  for(k = left; k < right; k++){
    count++;
    if (L[i] <= R[j]){
      A[k] = L[i];
	i = i + 1;
	
    } else {
      A[k] = R[j];
      j = j + 1;
      }
  }
  
}

void MergeSort(int A[], int left, int right){
  int mid = 0;
  if(left + 1 < right){
    mid = (left + right)/2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
  
}

Measured memory_bytes: 4312