akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int K;

ll GCD(ll a, ll b){
    if(b==0) return a;

    return GCD(b, a % b);
}

void solve(){
    rep(i, K){
        rep(j, K){
            rep(k, K){
                ans += GCD(i+1, GCD(j+1, k+1));
            }
        }
    }

    cout << ans << endl;
}

int main(){
    cin >> K;

    solve();
}


Measured memory_bytes: 3188
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Map {

    final char[][] map;
    int x;
    int y;

    Map( char[][] map ) {
	this.map = map;

	for ( int i = 0; i < map.length; i++ ) {
	    for ( int j = 0; j < map[0].length; j++ ) {
		if ( map[i][j] == 'S' ) {
		    y = i;
		    x = j;
		}
	    }		
	}
    }    
}

class Point {

    final int x;
    final int y;

    Point( int y, int x ) {
	this.x = x;
	this.y = y;
    }    
}

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );
	final String[] input = stdin.nextLine().split( " " );

	final int H = Integer.parseInt( input[0] );
	final int W = Integer.parseInt( input[1] );
	final int N = Integer.parseInt( input[2] );

	char[][] mapArray = new char[H][];
	for ( int i = 0; i < H; i++ ) {
	    mapArray[i] = stdin.nextLine().toCharArray();
	}

	final Map map = new Map( mapArray );
	int sum = 0;
	for ( int i = 1; i <= N; i++ ) {
	    final char goal = ( char )( '0' + i );
	    sum += bfs( map, goal );
	}
	System.out.println( sum );
    }

    static int[] dx = { -1, 0, 1, 0 };
    static int[] dy = { 0, 1, 0, -1 };
    
    static int bfs ( Map map, char goal ) {

	final boolean[][] visited = new boolean[ map.map.length ][ map.map[0].length ];

	ArrayList<Point> after = new ArrayList<Point>();
	ArrayList<Point> cur = new ArrayList<Point>();
	cur.add( new Point( map.y, map.x ) );
	visited[ map.y ][ map.x ] = true;

	int step = 0;
	while ( !cur.isEmpty() ) {
	    step++;
	    for ( Point p : cur ) {
		for ( int i = 0; i < 4; i++ ) {
		    final int ny = p.y + dy[i];
		    final int nx = p.x + dx[i];

		    if ( 0 <= ny && ny < map.map.length &&
			 0 <= nx && nx < map.map[0].length ) {
			
			if ( map.map[ ny ][ nx ] == goal ) {
			    map.y = ny;
			    map.x = nx;
			    return step;
			} else if ( map.map[ ny ][ nx ] != 'X' &&
				    !visited[ ny ][ nx ] ) {
			    
			    after.add( new Point( ny, nx ) );
			    visited[ ny ][ nx ] = true;
			}
		    }
		}
	    }
	    cur.clear();
	    cur.addAll( after );
	    after.clear();
	}
	return step;
    }
}

Measured memory_bytes: 67140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
typedef complex<double> xy_t;

double x[4], y[4];

double dot_product(xy_t a, xy_t b)
{
    return (conj(a) * b).real();
}

double cross_product(xy_t a, xy_t b)
{
    return (conj(a) * b).imag();
}

int main()
{
    while (true)
    {
        rep(i, 4) cin >> x[i] >> y[i];
        if (!cin)
            break;
        xy_t a(x[0], y[0]), b(x[1], y[1]), c(x[2], y[2]), p(x[3], y[3]);
        double pab = cross_product(a - p, b - p), pbc = cross_product(b - p, c - p), pca = cross_product(c - p, a - p);
        bool ok = pab * pbc > 0 && pbc * pca > 0;
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}


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

template <const long long M>
class mint {
   private:
	long long x;

   public:
	constexpr mint(long long x = 0) : x((x % M + M) % M) {}
	constexpr long long value() { return x; }
	constexpr mint operator-() const { return mint(-x); }
	constexpr mint &operator+=(const mint &a) {
		if ((x += a.x) >= M) x -= M;
		return *this;
	}
	constexpr mint &operator-=(const mint &a) {
		if ((x += M - a.x) >= M) x -= M;
		return *this;
	}
	constexpr mint &operator*=(const mint &a) {
		(x *= a.x) %= M;
		return *this;
	}
	constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
	constexpr mint operator+(const mint &a) const {
		mint res(*this);
		return res += a;
	}
	constexpr mint operator-(const mint &a) const {
		mint res(*this);
		return res -= a;
	}
	constexpr mint operator*(const mint &a) const {
		mint res(*this);
		return res *= a;
	}
	constexpr mint operator/(const mint &a) const {
		mint res(*this);
		return res /= a;
	}
	constexpr mint pow(long long t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	constexpr mint inv() const { return pow(M - 2); }
	constexpr bool operator==(const mint &a) const { return x == a.x; }
	constexpr bool operator!=(const mint &a) const { return x != a.x; }
	friend istream &operator>>(istream &in, mint &a) {
		in >> a.x;
		if (a.x < 0) a.x += M;
		a.x %= M;
		return in;
	}
	friend ostream &operator<<(ostream &out, const mint &a) {
		out << a.x;
		return out;
	}
};

#define MAX 100000

int main() {
	int N, A[MAX];
	mint<1000000007> ans;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	bool vld = true;
	if (N % 2 == 0) {
		for (int i = 1; i <= N / 2 && vld; i++) {
			if (A[2 * i - 2] == 2 * i - 1 && A[2 * i - 1] == 2 * i - 1) {
				continue;
			} else {
				vld = false;
			}
		}
	} else if (N % 2 == 1) {
		vld = A[0] == 0;
		for (int i = 1; i <= N / 2 && vld; i++) {
			if (A[2 * i - 1] == 2 * i && A[2 * i] == 2 * i) {
				continue;
			} else {
				vld = false;
			}
		}
	}
	if (vld) {
		ans = 1;
		for (int i = 0; i < N / 2; i++) {
			ans *= 2;
		}
	} else {
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int n = Integer.parseInt(st.nextToken());
      int m = Integer.parseInt(st.nextToken());
      
      ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>(n+1);
      for(int k = 0; k <= n; k++) adj.add(new ArrayList<Integer>());
      
      st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
      }
      
      int answer = 0;
      for(int k = 0; k < m; k++){
         st = new StringTokenizer(f.readLine());
      
         int a = Integer.parseInt(st.nextToken());
         int b = Integer.parseInt(st.nextToken());
         
         adj.get(a).add(b);
         adj.get(b).add(a);
      }
      
      for(int k = 1; k <= n; k++){
         boolean good = true;
         
         for(int nei : adj.get(k)){
            if(array[nei] >= array[k]) good = false;
         }
         
         if(good) answer++;
      }
      
      out.println(answer);
      
      
      
      out.close();
   }
   
      
}

Measured memory_bytes: 68300
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
        FastIO

        int n,x,y,i,j;

        cin>>n>>x>>y;

        vi a(n);
        for(i=1;i<=n;i++)
        {
        	for(j=i+1;j<=n;j++)
        	{
        		int dis= min(abs(i-j), min(abs(i-x)+1+abs(j-y), abs(i-y)+1 + abs(j-x)));
        		a[dis]++;
        	}
        }

        for(i=1;i<=n-1;i++)
        	cout<<a[i]<<"\n";
        return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

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

    int Alice = 0; int Bob = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            Alice += A[i];
        } else {
            Bob += A[i];
        }
    }

    cout << Alice - Bob << endl;
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  string S="";
  while(N){
    N--;
    char C='a'+(N%26);
    S+=C;
    N/=26;
  }
  reverse(S.begin(),S.end());
  cout << S << endl;
}


Measured memory_bytes: 3628
#include <cmath>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
struct vec{
    double x,y;
    vec(){x=y=0.0;};
    vec(double x, double y): x(x), y(y){};
    inline double add(double a, double b){
        return abs(a+b)<(1e-10)*(abs(a)+abs(b))?0.0:a+b;
    }
    vec operator-(vec b){
        return vec(add(x,-b.x),add(y,-b.y));
    }
    vec operator+(vec b){
        return vec(add(x,b.x),add(y,b.y));
    }
    vec operator*(double d){
        return vec(x*d,y*d);
    }
    bool operator==(vec b){
        return x==b.x&&y==b.y;
    }
    bool operator!=(vec b){
        return x!=b.x||y!=b.y;
    }
    double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    double norm(){
        return hypot(x,y);
    }
};

pair<vec,vec> cross_point(vec&C1, vec&C2, double r1, double r2){
    vec e1,e2,P1,P2;
    double d=(C2-C1).norm();
    e1=(C2-C1)*(1/d);
    double theta = acos((r1*r1+(C2-C1).dot(C2-C1)-r2*r2)/(2*r1*d));
    e2.x=cos(theta)*e1.x-sin(theta)*e1.y, e2.y=sin(theta)*e1.x+cos(theta)*e1.y;
    P1=C1+e2*r1;
    e2.x=cos(theta)*e1.x+sin(theta)*e1.y, e2.y=-sin(theta)*e1.x+cos(theta)*e1.y;
    P2=C1+e2*r1;
    if(P1.x==P2.x){
        if(P1.y<P2.y) return make_pair(P1,P2);
        else return make_pair(P2,P1);
    }else{
        if(P1.x<P2.x)return make_pair(P1,P2);
        else return make_pair(P2,P1);
    }
}

double radius(double h, double l){
    return sqrt(l*l-h*h);
}
int n;
vector<vec> V;
vector<double> L;

bool iswrap(vec point, vector<double> &LL){
    for(int i=0;i<n;i++){
        double d = (V[i]-point).norm();
        if(LL[i]+1e-9<d) return false;
    }
    return true;
}

bool test(double h){
    vector<double> LL(n);
    for(int i=0;i<n;i++) LL[i]=radius(h,L[i]);
    for(int i=0;i<n;i++){
        if(iswrap(V[i],LL)) return true;
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            //??¢?????????
            double d = (V[i]-V[j]).norm();
            if(d>LL[i]+LL[j]){
                return false;
            }
            //??????
            if(d+min(LL[i],LL[j])<max(LL[i],LL[j])){
                continue;
            }
            //??????
            auto PP = cross_point(V[i],V[j],LL[i],LL[j]);
            if(iswrap(PP.first,LL)||iswrap(PP.second,LL)) return true;
        }
    }
    return false;
}

int main(){
    cout<<fixed;
    cout.precision(7);
    while(cin>>n,n){
        V.clear();
        L.clear();
        for(int i=0;i<n;i++){
            int x,y,l;
            cin>>x>>y>>l;
            V.emplace_back(x,y);
            L.push_back(l);
        }
        double lb=1,ub=1000;
        for(auto l:L) ub=min(ub,l);
        int cnt=50;
        while(cnt--){
            double mid=(ub+lb)/2;
            if(test(mid)){
                lb=mid;
            }else{
                ub=mid;
            }
        }
        cout<<ub<<endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
bool arr[12];
bool check(int n){
 while(n!=0){
   int rem=n%10;
   if(arr[rem]){
    return false ;
   }
   n=n/10;
 }
 return true ;
}
int main(){
 int N , k;
 cin >> N >> k ;
 for(int i=1;i<=k;i++){
   int x;
   cin >> x;
   arr[x]=true ;
 }
 for(int i=N;i<=1000000000;i++){
   if(check(i)){
     cout << i <<endl;
     return 0;  
   }
 } 
 return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int h[25][2];

int main()
{
	int n;
	cin >> n;
	long long int a;
	long long int L = 1000000000;
	long long int sum = 0;
	int ct = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		sum += abs(a);
		if (a <= 0)ct++;
		if (abs(a)<L)L = abs(a);
	}
	if(ct%2==1)cout << sum - 2 * L << endl;
	else cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int sum=0;
  for(int i=0; i<s.size(); i++){
    sum += (int)s[i]-48;
  }
  if(sum%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3736
#include <stdio.h>

int main(void)
{
	int A, B, C, D, P;
	
	scanf("%d %d %d %d %d", &A, &B, &C, &D, &P);
	
	if (P > C){
		if ( A * P > B + ((P - C) * D)){
			printf("%d\n", B + ((P - C) * D));
		}
	
		else if( A * P < B + ((P - C) * D)){
			printf("%d\n", A * P);
		}
	}
	
	else {
		if ( A * P > B ){
			printf("%d\n", B);
		}
	
		else if( A * P < B ){
			printf("%d\n", A * P);
		}
	}
	return (0);
}

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

ll dp[100001][13];

int main(){
	string s;
	cin >> s;
	int n = s.size();
	const ll mod = 1000000007;
	
	REP(i,13) dp[0][i] = 0;
	dp[0][0] = 1;
	
	REP(i,n){
		if(s[i]=='?'){
			REP(j,13){
				REP(k,10){
					int now = (10*j+k)%13;
					dp[i+1][now] += dp[i][j];
					dp[i+1][now] %= mod;
				}
			}
		}else{
			REP(j,13){
				int now = (10*j+(int)(s[i]-'0'))%13;
				dp[i+1][now] += dp[i][j];
				dp[i+1][now] %= mod;
			}
		}
	}
	
	cout << dp[n][5] << endl;
	
	return 0;
}

Measured memory_bytes: 13868
function main(input){
  var nums = input.split('\n')[1].split(' ').map((n) => parseInt(n,10));
  var count = 0;
  while(nums.every((n) => (n % 2) === 0)) {
        count++;
        nums = nums.map((n) => n / 2);
    }

  console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

int main()
{
	int i, j, temp, n, a, b, c;
	cin >> n;
	vector<int> v[n], dp[n];

	for(i=0;i<n;i++)
	{
		cin >> a >> b >> c;
		v[i].push_back(a);
		v[i].push_back(b);
		v[i].push_back(c);
	}

	dp[0].push_back(v[0][0]);
	dp[0].push_back(v[0][1]);
	dp[0].push_back(v[0][2]);

	for(i=1;i<n;i++)
	{
		for(j=0;j<3;j++)
		{
			//cout << "j: " << j << endl;
			//cout << dp[i-1][(j+1)%3] << " " << v[i][j] << endl;
			//cout << dp[i-1][(j+2)%3] << " " << v[i][j] << endl;
			dp[i].push_back(max(dp[i-1][(j+1)%3] + v[i][j], dp[i-1][(j+2)%3] + v[i][j]));
		}
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return 0;

	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int A, B, Q;
ll s[100000], t[100000], x[100000];

ll solve(ll start){
    ll u[2], v[2];
    auto s_itr = lower_bound(s, s + A, start);
    auto t_itr = lower_bound(t, t + B, start);
    u[0] = (s_itr - s - 1 < 0) ? -1 : *(s_itr - 1);
    u[1] = (s_itr < s + A) ? *s_itr : -1;
    v[0] = (t_itr - t - 1 < 0) ? -1 : *(t_itr - 1);
    v[1] = (t_itr < t + B) ? *t_itr : -1;
    ll ret = INT64_MAX;
    REP(i, 2){
        REP(j, 2){
            if(u[i] == -1 || v[j] == -1) continue;
            ret = min(ret, min(abs(u[i] - start) + abs(v[j] - u[i]), abs(v[j] - start) + abs(u[i] - v[j])));
        }
    }
    return ret;
}

signed main(){
    cin >> A >> B >> Q;
    REP(i, A) cin >> s[i];
    REP(i, B) cin >> t[i];
    REP(i, Q) cin >> x[i];
    REP(i, Q){
        PRINT(solve(x[i]));
    }
    return 0;
}

Measured memory_bytes: 3712
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
long long v[123456];
int n;
long long a, b;
bool can(long long x) {
	long long cnt = 0;
	long long c = a - b;
	for(int i = 0; i < n; i++) {
		long long y = v[i] - x * b;
		if(y > 0) cnt += (y + c - 1) / c;
	}
	return cnt <= x;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++) {
		cin >> v[i];
	}
	long long left = 1, right = 1LL * 1e10;
	while(right - left > 1) {
		long long mid = (left + right) / 2;
		if(can(mid)) right = mid;
		else left = mid;
	}
	cout << (can(left) ? left : right) << endl;
	return 0;	
}

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

#define INF 1000000010
#define INFLL ((1LL<<62)-5)
#define FO(i,a,b) for (int (i) = (a); (i) < (b); ++(i))
#define OF(i,a,b) for (int (i) = (a)-1; (i) >= (b); --(i))
#define SZ(v) int(v.size())

using namespace std;
//PAIRS:
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pii;
typedef long long ll;

/*~~~~TEMPLATE END~~~~*/


int N;
ll x;
ll a[2005];
ll cst[2005][2005];
ll totCost;

int main() {
    scanf ("%d %lld", &N, &x);
    FO (i,0,N) scanf ("%lld", &a[i]);
    FO (i,0,N) {
        cst[i][0] = a[i];
        int cPlc = i;
        FO (p,1,N) {
            cPlc--;
            if (cPlc < 0) cPlc += N;
            cst[i][p] = min (cst[i][p-1], a[cPlc]);
        }
    }
    FO (i,0,N) {
        ll cCost = i*x;
        FO (p,0,N) {
            cCost += cst[p][i];
        }
        if (i == 0) totCost = cCost;
        totCost = min (cCost, totCost);
    }
    printf ("%lld\n", totCost);
    return 0;
}


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

int main() {
  ll n,lim,ans;
  cin>>n;
  lim=sqrt(n);
  for(ll i=1; i<=lim; i++) {
    if(n%i == 0) ans=i;
  }
  cout<<ans+(n/ans)-2;
}

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

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> DP(W+1,0);
  for(int i = 0; i < N; ++i){
    int v, w, m;
    cin >> v >> w >> m;
    for(int k = 0; m > 0; ++k){
      int c = min(m, (1<<k));
      m -= c;
      vector<int> DP_ = DP;
      for(int j = 0; j <= W; ++j){
        if(j + c*w > W) break;
        DP_[j+c*w] = max(DP_[j+c*w], DP[j] + c*v);
      }
      DP = DP_;
    }
  }
  int ans = 0;
  for(int i = 0; i <= W; ++i) ans = max(ans, DP[i]);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main()
{
  
        string str;
	cin>>str;
	int len = str.length();
	for(int i =0;i<len;i++)
		if(i%2==0)
			cout<<str[i];
	cout<<"\n";

   return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}


struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};




int main(){
  ll n,m; cin >> n >> m;
  UnionFind UF(n);
  
  rep(i,m){
    ll a,b; cin >> a >> b; a--; b--;
    UF.unite(a,b);
  }
  
  ll ans = 0;
  
  rep(i,n){
    ans = max(ans,ll(UF.size(i)));
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 4068
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
const int N=100005;
struct node
{
	int id,dep;
};
bool operator <(node a,node b)
{
	if(a.dep!=b.dep)
		return a.dep>b.dep;
	return a.id<b.id;
}
set<node> st;
int n,K,i,j,fa[N],ans,head[N],adj[N],nxt[N],dep[N];
bool v[N];
void dfs(int x)
{
	for(int y=head[x];y;y=nxt[y])
	{
		dep[adj[y]]=dep[x]+1;
		dfs(adj[y]);
	}
}
void work(int x)
{
	v[x]=true;
	st.erase((node){x,dep[x]});
	for(int y=head[x];y;y=nxt[y])
		if(!v[adj[y]])
			work(adj[y]);
}
int main()
{
	scanf("%d%d",&n,&K);
	for(i=1;i<=n;++i)
		scanf("%d",fa+i);
	if(fa[1]!=1)
	{
		fa[1]=1;
		ans=1;
	}
	for(i=2;i<=n;++i)
	{
		adj[i-1]=i;
		nxt[i-1]=head[fa[i]];
		head[fa[i]]=i-1;
	}
	dfs(1);
	for(i=1;i<=n;++i)
		st.insert((node){i,dep[i]});
	while(!st.empty())
	{
		i=(st.begin())->id;
		if(dep[i]<=K)
			break;
		++ans;
		for(j=1;j<=K-1;++j)
			i=fa[i];
		work(i);
	}
	printf("%d",ans);
	return 0;
}


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

template<class t> void vin(vector<t>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll sum[303030];

int main() {
    ll N, X;
    cin >> N >> X;
    vector<ll> x(N);

    if (N == 1) {
        cout << 2*X + x[0]*5 << endl;
        return 0;
    }

    rep(i, N) cin >> x[i];
    rep(i, N) {
        sum[i+1] = x[i] + sum[i];
    }
    ll ans = 1LL<<62;
    for (int k=1; k<=N; ++k) {
        ll result = k*X;
        ll n = N, b = 5;
        while (n > 0) {
            bool ok = false;
            if (b == 5) {
                if (n-k*2 < 0) break;
                result += b * (sum[n] - sum[n-k*2]);
                n -= k*2;
                ok = true;
            }
            else {
                if (n-k < 0) break;
                result += b * (sum[n] - sum[n-k]);
                n -= k;
                ok = true;
            }
            if (!ok) break;
            b += 2;
            if (result < 0) break;
        }
        if (n >= 0) {
            result += b * sum[n];
            if (result > 0LL) ans = min(ans, result);
        }
    }
    cout << ans+N*X << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int n1,n2=100005;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		long long a,b;
		cin>>a>>b;
		if(a>n1)
		  n1=a;
		if(b<n2)
		  n2=b;
	}
	cout<<max(n2-n1+1,0);
	return 0;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter
import collections
import math

def r(n, a):
    d = [0] * n
    for aa in a:
        d[aa-1] = d[aa-1] + 1
    for nn in range(n):
        print(d[nn])


def main():
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    r(n, a)

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 33508
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, p;
    cin >> a >> p;
    cout << (3 * a + p)/2;
    return 0;
}

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

int main(void)
{

    string s;
    cin >> s;

    int n = s.size();

    string word = "keyence";

    bool check = false;
    for (int i = 0; i < word.size(); i++)
    {
        string a = word.substr(0, i + 1);
        string b = word.substr(i + 1);


        auto x = s.find(a);
        auto y = s.find(b);

        if(x == 0 && s.substr(n-b.size(),n)==b){
            check = true;
            break;
        }

        if (x < n && y < n && x < y){
            if(x > 0 && x+word.size() == n){
                check = true;
                break;
           }
            if (x == 0 && y+b.size() == word.size()){
                check = true;
                break;
            }
            if (x == 0 && y + b.size() == n){
                check = true;
                break;
            }
        }
    }

    if (check)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    auto a_it = lower_bound(a.begin(), a.end(), b[i]);
    auto c_it = upper_bound(c.begin(), c.end(), b[i]);
    ans += (a.size()-(a.end()-a_it))*(c.end()-c_it);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    cout << (h <= accumulate(v.begin(), v.end(), 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def Print(array):
    for r in range(len(array)):
        print(array[r])
    print()


def Gauss(array):
    # for r in range(len(array)):
    #     array[r].append(r)

    for r in range(len(array)):
        # array.sort(key=lambda x: x[r], reverse=True)
        div = array[r][r]
        for c in range(r, len(array) + 1):
            array[r][c] /= div
        for r2 in range(r + 1, len(array)):
            head = array[r2][r]
            for c in range(r, len(array) + 1):
                array[r2][c] -= head * array[r][c]

    result = [0] * len(array)
    for r in range(len(array) - 1, -1, -1):
        result[r] = array[r][
            len(array)] - sum([result[x] * array[r][x] for x in range(r + 1, len(array))])
    return result


for line in sys.stdin:
    [a, b, c, d, e, f] = [int(x) for x in line.split()]
    result = Gauss([[a, b, c], [d, e, f]])
    for i in range(len(result) - 1):
        print("{0:.3f}".format(result[i]), end=" ")
    print("{0:.3f}".format(result[-1]))

Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  set<int>A;
  for(int i=0;i<N;i++){int a;cin>>a;A.insert(a);}
  cout<<(A.size()%2==1? A.size():A.size()-1)<<endl;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, bads = 0;
    cin >> N;
    for (int temp, i = 1; i <= N; i++) {
        cin >> temp;
        if (i != temp) {
            bads++;
        }
    }
    if (bads > 2) {
        cout << "NO" << "\n";
    } else {
        cout << "YES" << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x, a, b;std::cin >> x >> a >> b;
  if(a>=b) std::cout << "delicious" << '\n';
  else if(b-a<=x) std::cout << "safe" << '\n';
  else std::cout << "dangerous" << '\n';
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define MAX 100010
string s,t;
int nex[MAX][26];

void compute() {

}

int bf() {
  int cnt = 0;
  int ptr = 0;
  rep(i,(int)t.size()) {
    while( s[ptr] != t[i] ) {
      ++ptr;
      ++cnt;
      ptr %= (int)s.size();
    }
    ++ptr;
    ++cnt;
    ptr %= (int)s.size();
  }
  return cnt;
}

int main() {
  memset(nex,-1,sizeof nex);
  cin >> s >> t;
  int n = s.size();
  map<int,int> mp;
  string u = s + s;
  for(int i=(int)u.size()-1;i>=0;--i) {
    if( i >= n ) {
      mp[u[i]-'a'] = i;
      continue;
    }
    rep(j,26) {
      if( mp.count(j) ) {
	int p = mp[j];
	if( p - n >= 0 ) {
	  nex[i][j] = mp[j] - n;
	} else {
	  nex[i][j] = p;
	}
      }
    }
    mp[u[i]-'a'] = i;
  }
  long long ans = 0;
  int m = t.size();
  int pos = -1;
  rep(i,n) {
    if( s[i] == t[0] ) {
      pos = i;
      ans = pos;
      break;
    }
  }
  if( pos == -1 ) { puts("-1"); return 0; }
  REP(i,1,m) {
    int v = t[i] - 'a';
    int npos = nex[pos][v];
    if( npos == -1 ) { puts("-1"); return 0; }
    if( pos < npos ) {
      ans += (ll)( npos - pos );
    } else {
      ans += (ll)( n - pos + npos );
    }
    pos = npos;
  }
  cout << ans + 1LL << endl;
  //cout << "ANS : "<< bf() << endl;
  compute();
  return 0;
}


Measured memory_bytes: 10880
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

string s;
string ans;

bool dfs(int n, int t,string e){
    if(n==4){
        if(t==7){
            ans = e;
            return true;
        }
        return false;
    }
    if(dfs(n+1,t+(s[n]-'0'),e+'+')) return true;
    if(dfs(n+1,t-(s[n]-'0'),e+'-')) return true;
    
    return false;
}
int main(){
    cin >> s;
    dfs(1,s[0]-'0',"");
    cout << s[0]<<ans[0]<<s[1]<<ans[1]<<s[2]<<ans[2]<<s[3]<<"=7"<<endl;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

bool pairCompare(const pair<ll, ll>& firstElof, const pair<ll, ll>& secondElof) {
    return firstElof.first < secondElof.first;
}

int main() {
    ll n, m;
    cin >> n >> m;
    int ans = 0;
    if ( m == 0 ) {
        if ( n != 1 ) {
            ans = pow(10, n-1);
        }
        cout << ans << endl;
        return 0;
    }
    ll s[m], c[m];
    ll Ans[n] = {};
    vector<pair<ll, ll> > pairs;

    int j = 1;
    rep(i, m) {
        cin >> s[i] >> c[i];
        if ( n != 1 && s[i] == 1 && c[i] == 0 ) {
            j = 0;
        }
        pairs.push_back( make_pair(s[i], c[i]) );
    }
    if (!j) {
        cout << -1 << endl;
        return 0;
    }

    sort(ALL(pairs), pairCompare);

    rep(i, m) {
        if ( i == 0 ) {
            Ans[pairs.at(i).first-1] = pairs.at(i).second;
        } else {
            if ( Ans[pairs.at(i).first-1] != 0 ) {
                if ( Ans[pairs.at(i).first-1] != pairs.at(i).second ) {
                    j = 0;
                    break;
                }
            } else {
                Ans[pairs.at(i).first-1] = pairs.at(i).second;
            }
        }
    }

    if (!j) {
        cout << -1 << endl;
        return 0;
    }
    if ( n > 1 && Ans[0] == 0 ) {
        Ans[0] = 1;
    }

    if ( Ans[0] != 0 || Ans[1] != 0 || Ans[2] != 0 ) {
        rep(i, n) {
            cout << Ans[i];
        }
    } else {
        ans += pow(10, n-1);
      	cout << ans << endl;
    }
  
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

int main() {
  string s;
  cin >> s;
  // Kを決めると
  // 両端からn-Kは自由に決められる

  int n = (int)s.size();
  vector<int> one(n + 1);

  rep(i, 0, n) one[i + 1] = one[i] + (s[i] == '1');
  if (one[n] == 0 || one[n] == n) {
    cout << n << endl;
    return 0;
  }

  int ans = 1;
  rep(k, 1, n) {
    int free = n - k;
    // 左からn-k個、右からn-k個のみ自由に反抗できる
    int l = free;
    int r = n - free;
    int cnt = one[r] - one[l];
    if (cnt == 0 || cnt == r - l) ans = max(ans, k);
  }
  cout << ans << endl;
  return 0;
}

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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


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

    while(true){
        c -= b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a -= d;
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
    }



}



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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(),a.end())
#define NP(a) next_permutation(a.begin(),a.end())

typedef pair<int,int> pi;
typedef pair<ll,ll> pl; 

const ll mod = 1000000007;
ll pangkat(ll a,ll x)
{
  if(x==1)
    return a;
  else
  {
    ll p = pangkat(a,x/2),y;
    if(x%2==0){
      y = p % mod;
      return (y*y)%mod;
    }
    else{
      y = (p * p)%mod;
      y = (y*a)%mod; 
      return (y)%mod;
    }
  }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout<<"input"<<endl;freopen("input.txt","r",stdin);
    //cout<<"output"<<endl;freopen("output.txt","w",stdout);
    
    ll s;
    cin>>s;
    ll a = pangkat(10,s);
    ll b = 2*pangkat(9,s);
    ll c = pangkat(8,s);
    ll final = (a-b+c)%mod;
    final = (final +1000000007)%mod;
    if(s <= 1)
        cout<<0<<endl;
    else
        cout<< final <<endl;
    
}

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

int min( int a, int b )
{
    if( a < b )
        return a;
    else
        return b;
}

int max( int a, int b )
{
    if( a > b )
        return a;
    else
        return b;
}

int main()
{
    int n, a, b, c, d;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> a >> b >> c >> d;

        cout << min( a * c + b * d, ( a * max( c, 5 ) + b * max( d, 2 ) ) * 4 / 5 ) << endl;
    }

    return 0;
}



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

// #include <atcoder/all>

// #LIB#

using namespace std;
// using namespace atcoder;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#ifdef ONLINE_JUDGE
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');
#endif

int main() {
  string s;
  cin >> s;
  ll n = s.length();
  cout << s << (s[n - 1] == 's' ? "es" : "s") << endl;
}


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

using namespace std;

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

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

int n;

double a[10005], mn = INT_MAX, id;


int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    double sum = 0;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sum = sum / (double)(n);
    for(int i = 1; i <= n; i++) {
        if(abs(sum - a[i]) < mn) {
            mn = abs(sum - a[i]);
            id = i;
        }
    }
    cout << id - 1 << "\n";
}



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

int A[1000000],n;

int binarySearch(int key)
{
    int left = 0;
    int right = n;


    while( left < right)
    {
        int mid = (left + right)/2;
        if( A[mid] == key)
            return 1;
        else if(A[mid] < key)
            left = mid +1;
        else right =mid;
    }
    return 0;
}

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

    scanf("%d",&m);
    for(i = 0; i < m; i++)
    {
        scanf("%d",&key);
        if(binarySearch(key))
            sum++;
    }

    printf("%d\n",sum);

    return 0;
}



Measured memory_bytes: 2952
#include <iostream>
#include <string>
#define R return

using namespace std;

char convert (int cnt, int num)
{
    int d;
    switch (num)
    {
    case 1:
        d=cnt%5;
        if (d==1) R '.';
        if (d==2) R ',';
        if (d==3) R '!';
        if (d==4) R '?';
        if (d==0) R ' ';
    case 2:
        d=cnt%3;
        if (d==1) R 'a';
        if (d==2) R 'b';
        if (d==0) R 'c';
    case 3:
        d=cnt%3;
        if (d==1) R 'd';
        if (d==2) R 'e';
        if (d==0) R 'f';
    case 4:
        d=cnt%3;
        if (d==1) R 'g';
        if (d==2) R 'h';
        if (d==0) R 'i';
    case 5:
        d=cnt%3;
        if (d==1) R 'j';
        if (d==2) R 'k';
        if (d==0) R 'l';
    case 6:
        d=cnt%3;
        if (d==1) R 'm';
        if (d==2) R 'n';
        if (d==0) R 'o';
    case 7:
        d=cnt%4;
        if (d==1) R 'p';
        if (d==2) R 'q';
        if (d==3) R 'r';
        if (d==0) R 's';
    case 8:
        d=cnt%3;
        if (d==1) R 't';
        if (d==2) R 'u';
        if (d==0) R 'v';
    case 9:
        d=cnt%4;
        if (d==1) R 'w';
        if (d==2) R 'x';
        if (d==3) R 'y';
        if (d==0) R 'z';
    }
}

int main()
{
    int n, c, p;
    string s, ans[200]={};
    cin>>n;
    for (int i=0; i<n; i++)
    {
        c=0; p=0;
        cin>>s;
        for (int j=0; j<s.size(); j++)
        {
            if (s[j]=='0' && p!=0) { ans[i]+=convert(c, p); c=0; p=0; }
            if (s[j]=='0' && p==0) { c=0; }
            else if (s[j]==p) { c++; }
            else { p=s[j]-48; c++; }
        }
    }
    for (int i=0; i<n; i++) cout<<ans[i]<<'\n';
    R 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  long n, t = 26; int c = 1; cin >> n;
  string s = "";
  while(n - t > 0){
    n -= t;
    t *= 26;
    ++c;
  }
  --n;
  rep(i, c){
    s += (char)('a'+n%26);
    n /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppKEYENCEBeginning
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int[] n = new int[input.Count()];
            for(int i = 0; i < input.Count(); i++)
            {
                n[i] = int.Parse(input[i]);
            }
            //
            string ans="NO";
            for(int j = 0; j<input.Count(); j++)
            {
                if(n[j%4]*1000+ n[(j+1)%4]*100+n[(j + 2) % 4] *10+n[(j + 3) % 4] ==1974)
                {
                    ans = "YES";
                }
                if (n[j % 4] * 1000 + n[(j + 1) % 4] * 100 + n[(j + 3) % 4] * 10 + n[(j + 2) % 4] == 1974)
                {
                    ans = "YES";
                }
                if (n[j % 4] * 1000 + n[(j + 2) % 4] * 100 + n[(j + 1) % 4] * 10 + n[(j + 3) % 4] == 1974)
                {
                    ans = "YES";
                }
                if (n[j % 4] * 1000 + n[(j + 2) % 4] * 100 + n[(j + 3) % 4] * 10 + n[(j + 1) % 4] == 1974)
                {
                    ans = "YES";
                }
                if (n[j % 4] * 1000 + n[(j + 3) % 4] * 100 + n[(j + 1) % 4] * 10 + n[(j + 2) % 4] == 1974)
                {
                    ans = "YES";
                }
                if (n[j % 4] * 1000 + n[(j + 3) % 4] * 100 + n[(j + 2) % 4] * 10 + n[(j + 1) % 4] == 1974)
                {
                    ans = "YES";
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11220
import math
N,M = list(map(int,input().split(" ")))
towns = {}
ans = [0] * M
for i in range(M):
    temp = list(map(int,input().split(" ")))
    num = temp[0]
    year = temp[1]
    if num not in towns:
        towns[num] = [(year,i)]
    else:
        towns[num].append((year,i))

# print(towns)
for k,v in towns.items():
    # print("key:",k)
    i1 = str(k).zfill(6)
    v_sorted = sorted(v,key = lambda x:x[0])
    # print("v:",v_sorted)
    for i,town in enumerate(v_sorted):
        # print("town:",town)
        i2 = str(i+1).zfill(6)
        # print(i1 + i2)
        ind = town[1]
        ans[ind] = i1 + i2
# print("ans","---"*20)
for a in ans:
    print(a)
    

Measured memory_bytes: 43320
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,c,h[200005],dp[200005];
typedef pair<int,int> func;
vector<func>stk;
void show(){
	cerr<<"show func:"<<endl;
	for(int i=0;i<stk.size();i++){
		cerr<<-stk[i].first<<" "<<-stk[i].second<<endl;
	}
	cerr<<"end"<<endl;
}
void add_stack(int x){
	//a=h[i],b=h[i]^2+dp[i]
	func f3=make_pair(2ll*h[x],-h[x]*h[x]-dp[x]);
	while(stk.size()>=2){
		func f2=stk.back();stk.pop_back();
		func f1=stk.back();stk.pop_back();
		if((f3.second-f1.second)*(f2.first-f1.first)>(f2.second-f1.second)*(f3.first-f1.first)){
			stk.push_back(f1);
		}else{
			stk.push_back(f1);
			stk.push_back(f2);
			break;
		}
	}
	stk.push_back(f3);
}
int f(func f,int v){
	return -v*f.first-f.second;
}
int query(int v){
	int l=0,r=stk.size();
	while(r-l>1){
		int mid=(l+r)/2;
		if(f(stk[mid],v)<f(stk[mid-1],v))l=mid;
		else r=mid;
	}
	return f(stk[l],v);
}
signed main(){
	cin>>n>>c;
	for(int i=1;i<=n;i++)cin>>h[i];
	dp[1]=0;add_stack(1);
	for(int i=2;i<=n;i++){
		dp[i]=h[i]*h[i]+c+query(h[i]);
		add_stack(i); 
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 8432
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long ans = 0, i, j, k, ct = 0;
	string s;
	cin >> s;
	for (auto ch : s) {
		if (ch == 'B') ct++;
		else ans += ct;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 1080