akhauriyash/Code-Regression huggingface dataset:
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];

		for(int i=0;i<N;i++) {

			S[i] = sc.next();
		}

		int M = sc.nextInt();

		String[] T = new String[M];

		for(int i=0;i<M;i++) {

			T[i] = sc.next();
		}

		//全探索
		String tkhs = "";

		int ans = 0;

		int score = 0;

		for(int i=0;i<N;i++) {

			tkhs = S[i];

			score = 0;

			for(int j=0;j<N;j++) {

				if(S[j].equals(tkhs)) score++;
			}
			for(int j=0;j<M;j++) {

				if(T[j].equals(tkhs)) score--;
			}

			ans = Math.max(ans, score);
		}
		System.out.println(ans);
	}

}


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

void trip(int cnt,int nw,int f,vector<vector<int>>&ab,vector<int>&qq,vector<int>&ans){
	cnt+=qq.at(nw);
	ans.at(nw)=cnt;
	for(auto&&i:ab.at(nw)){
		if(i==f)continue;
		trip(cnt,i,nw,ab,qq,ans);
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,q; cin>>n>>q;
	vector<vector<int>>ab(n+1);
	for(int i=1;i<n;++i){
		int a,b; cin>>a>>b;
		ab.at(a).emplace_back(b);
		ab.at(b).emplace_back(a);
	}
	vector<int>qq(n+1,0);
	for(int i=0;i<q;++i){
		int p,x; cin>>p>>x;
		qq.at(p)+=x;
	}
	vector<int>ans(n+1,0);
	trip(0,1,-1,ab,qq,ans);
	for(int i=1;i<=n;++i)cout<<ans.at(i)<<"\n"s;
}


Measured memory_bytes: 31420
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()


struct tree {
  using T = i64;
  static T ope(T a, T b) {
    return a + b;
  }

  static T ide() { return 0; }

  i64 n;
  vector<T> node;

  tree(const vector<T> init) {
    n = 1;
    while(n < init.size()) n *= 2;
    node.resize(2 * n);
    rep(i,0,init.size()) node[i + n] = init[i];
    for(int i = n - 1;i >= 1;i--) node[i] = ope(node[i * 2], node[i * 2 + 1]);
  }

  void update(i64 i, T x) {
    i += n;
    node[i] += x;
    while(i > 1) {
      i = i / 2;
      node[i] = ope(node[i * 2], node[i * 2 + 1]);
    }
  }

  T sum(i64 l, i64 r) {
    T lx = ide();
    T rx = ide();
    l += n;
    r += n - 1;
    while(l < r) {
      if(l & 1) { lx = ope(lx, node[l]); }
      if(!(r & 1)) { rx = ope(node[r], rx); }
      l = (l + 1) >> 1;
      r = (r - 1) >> 1;
    }
    if(l == r) { lx = ope(lx, node[l]); }
    return ope(lx, rx);
  }
};

int main() {
  i64 n;
  cin >> n;
  vector<i64> L(n);
  rep(i,0,n) cin >> L[i];

  sort(begin(L), end(L));

  tree seg(vector<i64>(1000 + 100, 0));


  i64 sum = 0;
  rep(i,0,n) {
    rep(j,i + 1, n) {
      i64 a = L[j];
      i64 b = L[i];
      sum += seg.sum(a - b + 1, a + b);
    }
    seg.update(L[i], 1);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

int main() {
	ll X, D, K;
	cin >> X >> K >> D;
	X = abs(X);
	if (X / D >= K) { cout << X - K * D << endl; return 0; }
	
	X += D * (K % 2);
	cout << min(X % (2 * D), 2 * D - X % (2 * D)) << endl;

}


Measured memory_bytes: 3600
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		int N = in.nextInt();
		long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
		
		for(int numP = 0; numP <= N-1; numP++){
			int numM = N - 1 - numP;
			if(A + D * numP - C * numM >= B && A + C * numP - D * numM <= B){
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

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


public class Main{
	public static int max(int a,int b){
		if(a>b)return a;
		else return b;
	}
	public static double max(double a,double b){
		if(a>b)return a;
		else return b;
	}
	public static String fun(String a,String b){
				int n=a.length();
				int m=b.length();


				int [][]dp=new int[n+1][m+1] ;
				for(int i=1;i<=n;i++){
					for(int j=1;j<=m;j++){
						if(a.charAt(i-1)==b.charAt(j-1)){
							dp[i][j]=1+dp[i-1][j-1];
						}
						else{
							dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
						}
					}
				}
				//System.out.println(dp[n][m]);

String ans="";
int i=n;
int j=m;
try{
while(i>0&&j>0){
	if(a.charAt(i-1)==b.charAt(j-1)){
		ans+=a.charAt(i-1);
		i--;
		j--;
	}
	else{
		if(dp[i][j-1]<dp[i-1][j]){
			i--;
		}
		else{
			j--;
		}
	}
}}
catch(Exception e){
	System.out.println(i+" "+j);
}
StringBuilder sb =new StringBuilder();
for(int ii=ans.length()-1;ii>=0;ii--){
	sb.append(ans.charAt(ii));
}

return sb.toString();

	} 
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		System.out.println(fun(a,b));
	}
}


Measured memory_bytes: 99636
#include "bits/stdc++.h"
using namespace std;
const long long INF = (long long)(1e18) + 1;

int f(int n) {
	int ans = 0;
	while(n != 0) {
		ans++;
		int ncopy = n;
		int tmp =0;
		while (0 != ncopy) {
			tmp += ncopy % 2;
			ncopy /= 2;
		}
		n %= tmp;
	}
	return ans;
}

int main() {
	int N;
	string X;
	cin >> N >> X;
	int d = 0;
	for (int n = 0; n < N; ++n) {
		if ('1' == X[n]) {
			d++;
		}
	}

	vector<int>D1(N);
	int sumD1 = 0;
	{
		int num = 1;
		for (int n = 0; n < N; ++n) {
			D1[N - 1 - n] = num;
			if ('1' == X[N-1-n]) {
				sumD1 += num;
				sumD1 %= (d + 1);
			}
			num *= 2;
			num %= (d + 1);
		}
	}
	vector<int>D2(N); 
	int sumD2 = 0;
	{
		int num = 1;
		if (1 != d) {
			for (int n = 0; n < N; ++n) {
				D2[N - 1 - n] = num;
				if ('1' == X[N - 1 - n]) {
					sumD2 += num;
					sumD2 %= (d - 1);
				}
				num *= 2;
				num %= (d - 1);
			}
		}
	}

	for (int n = 0; n < N; ++n) {
		int dcopy = d;
		int sumDcopy = 0;
		if ('0' == X[n]) {
			dcopy++;
			sumDcopy = sumD1 + D1[n];
			sumDcopy %= (dcopy);
		}
		else {
			dcopy--;
			if (0 == dcopy) {
				cout << 0 << endl;
				continue;
			}
			sumDcopy = sumD2 + (dcopy)-D2[n];
			sumDcopy %= (dcopy);
		}
		if(0 == sumDcopy){
			cout << 1 <<endl;
		}
		else {
			cout << f(sumDcopy) + 1 <<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[0]!='A'){
        printf("WA\n");
        return 0;
    }
    int cnt=0;
    for(int a=1;a<s.length();a++){
        if(a==1||a==s.length()-1){
            if(s[a]<'a'||s[a]>'z'){
                printf("WA\n");
                return 0;
            }
        }
        else{
            if(s[a]=='C') cnt++;
            if(cnt>1){
                printf("WA\n");
                return 0;
            }
        }
    }
    if(cnt==1)printf("AC\n");
    else printf("WA\n");
}


Measured memory_bytes: 256
a=[int(input()) for i in range(5)]
ans=0
b=sorted([a[i]%10 for i in range(5)])
for i in range(5):
    #print(ans)
    ans+=((a[i]+9)//10)*10
for i in range(5):
    if b[i]!=0:
        ans+=b[i]-10
        break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;
int main( void )
{
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  if( A > 0 ){
    cout << "Positive" << endl;
    return 0;
  }
  if( B >= 0 ){ // A <= 0
    cout << "Zero" << endl;
    return 0;
  }
  // B < 0
  if( (B - A) % 2 == 1 ){
    cout << "Positive" << endl;
  } else {
    cout << "Negative" << endl;
  }
}

Measured memory_bytes: 256
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    S = S.replace("BC", "X")
    cnt_a = 0
    answer = 0
    for s in S:
        if s == "A":
            cnt_a += 1
        elif s == "X":
            answer += cnt_a
        else:
            cnt_a = 0
    print(answer)


if __name__ == "__main__":
    main()


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

int main() {
	int a, b, d;
	cin >> a >> b;
	d = (a + b) / 2;
	double c = (a + b) / 2.0;
	if (c > d) {
		cout << d + 1;
	}
	else {
		cout << d;
	}
}

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

int main() {
	int N, K;
	string S;
	cin >> N >> S >> K;
	string T="";
	for(int i=0; i<N; ++i){
	    T += (S[i]==S[K-1] ? S[i] : '*');
	}
	cout << T << endl;
	return 0;
}


Measured memory_bytes: 256
l,a[25];
i,n;
main(){
	for(;scanf("%d",&l),l;){
		for(i=0;i<l;i++)
			scanf("%d",a+i);
		n=32;
		i=0;
		for(;n>0;){
			n-=(n-1)%5;
			printf("%d\n",n);
			n-=a[i];
			i=(i+1)%l;
			printf("%d\n",n>0?n:0);
		}
	}
	exit(0);
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int64_t a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    int64_t dist = a-b;
    if(dist < 0) dist *= -1;
    if(w >= v){ cout << "NO" << endl; return 0; }
    if(dist <= (v-w)*t){ cout << "YES" << endl; return 0;}
    cout << "NO" << endl;
    return 0;
}

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

using namespace std;

int main(){
	int n; cin >> n;
	int sum=0;
	vector<int> pos,neg;
	for(int i=0,a;i<n;i++){
		cin >> a;
		sum+=abs(a);
		if(a>=0){
			pos.push_back(abs(a));
		}
		else{
			neg.push_back(abs(a));
		}
	}
	sort(pos.begin(),pos.end());
	sort(neg.begin(),neg.end());
	if(pos.size()==0){
		cout << sum-2*neg[0] << endl;
		int cv=-neg[0];
		for(int i=1;i<n;i++){
			cout << cv << " " << -neg[i] << endl;
			cv=cv+neg[i];
		}
	}
	else if(neg.size()==0){
		cout << sum-2*pos[0] << endl;
		int cv=pos[0];
		for(int i=1;i<n-1;i++){
			cout << cv << " " << pos[i] << endl;
			cv=cv-pos[i];
		}
		cout << pos[n-1] << " " << cv << endl;
	}
	else if(neg.size()==1){
		cout << sum << endl;
		int cv=-neg[0];
		for(int i=0;i<n-2;i++){
			cout << cv << " " << pos[i] << endl;
			cv=cv-pos[i];
		}
		cout << pos[n-2] << " " << cv << endl;
	}
	else if(pos.size()==1){
		cout << sum << endl;
		int cv=pos[0];
		for(int i=0;i<n-1;i++){
			cout << cv << " " << -neg[i] << endl;
			cv=cv+neg[i];
		}
	}
	else {
		cout << sum  << endl;
		int cv=-neg[0];
		for(int i=1;i<pos.size();i++){
			cout << cv << " " << pos[i] << endl;
			cv=cv-pos[i];
		}
		
		int cva=pos[0];
		for(int i=1;i<neg.size();i++){
			cout << cva << " " << -neg[i] << endl;
			cva=cva+neg[i];
		}
		cout << cva << " " << cv << endl;
	}
	return 0;
}

Measured memory_bytes: 2424
#include <iostream>

int main()
{
    int x,y;

    while(true){
        std::cin >> x >> y;
        if (x == 0 && y == 0){
            break;
        } else if (x <= y){
            std::cout << x << " " << y << std::endl;
        } else {
            std::cout << y << " " << x << std::endl;
        }
    }
    return 0;
}

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

using namespace std;

int main() {
int n, t, a;
cin >> n >> t >> a;

vector<int> h(n);

for(int i=0; i<n; i++){
cin >> h[i];
h[i] = a* 1000 - ( t * 1000 - h[i] * 6);
if(h[i] <= 0){
h[i] = -1 * h[i];
}
}

int min = h[0], r;

for(int i=0; i<n; i++){
if(min >= h[i]){
min = h[i];
r = i+1;
}
}

cout << r << endl;

return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct UnionFind{
	vi data;
	UnionFind(int size):data(size,-1){}
	int Find(int n){
		return data[n]<0?n:(data[n]=Find(data[n]));
	}
	void Unite(int a,int b){
		int ra=Find(a),rb=Find(b);
		if(ra!=rb){
			if(-data[ra]<-data[rb])
				swap(ra,rb);
			data[ra]+=data[rb];
			data[rb]=ra;
		}
	}
	int Size(int n){
		return -data[Find(n)];
	}
};

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
	bool operator<(const Edge& e)const{return weight<e.weight;}
	bool operator>(const Edge& e)const{return weight>e.weight;}
};
typedef vector<vector<Edge> > Graph;

int Kruskal(const Graph& g,vector<Edge>& forest)
{
	forest.clear();
	
	vector<Edge> es;
	rep(i,g.size()) rep(j,g[i].size())
		es.push_back(g[i][j]);
	sort(all(es));
	
	UnionFind uf(g.size());
	int res=0;
	rep(i,es.size())
		if(uf.Find(es[i].src)!=uf.Find(es[i].dst)){
			uf.Unite(es[i].src,es[i].dst);
			res+=es[i].weight;
			forest.push_back(es[i]);
		}
	return res;
}

int main()
{
	for(int m,n;cin>>m>>n,m|n;){
		Graph g(m+n+1);
		rep(i,m) rep(j,n){
			int w; cin>>w;
			if(!w) continue;
			g[i].emplace_back(i,m+j,w);
			g[m+j].emplace_back(m+j,i,w);
		}
		rep(i,n) repi(j,i+1,n){
			int w; cin>>w;
			if(!w) continue;
			g[m+i].emplace_back(m+i,m+j,w);
			g[m+j].emplace_back(m+j,m+i,w);
		}
		rep(i,m)
			g[m+n].emplace_back(m+n,i,0);
		
		vector<Edge> forest;
		cout<<Kruskal(g,forest)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1356
s = input()
t = input()
ls = []
lt = []
lists=[]

for i in s:
  ls.append(i)
  
for j in t:
  lt.append(j)

ls2 = set(ls)
lt2 = set(lt)

n = len(ls)

for i in range(n):
  list1 = [ls[i],lt[i]]
  lists.append(list1)

lists2 = list(map(list, set(map(tuple, lists))))
  
  
if len(set(ls2)) != len(set(lt2)):
  print('No')
elif len(lists2) != len(set(lt2)):
  print('No')
else:
  print('Yes')

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

const int N = 200010;
typedef long long ll;

ll dp[N][5];
int a[N];

void update(ll &a, ll b){
    if (a == -1 || a > b){
        a = b;
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i){
        scanf("%d", &a[i]);
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 1; i <= n + 1; ++ i){
        for (int j = 0; j <= 0; ++ j){
            if (dp[i - 1][j] != -1){
                update(dp[i][0], dp[i - 1][j] + a[i]);
            }
        }
        for (int j = 0; j <= 1; ++ j){
            if (dp[i - 1][j] != -1){
                update(dp[i][1], dp[i - 1][j] + (a[i] == 0 ? 2 : a[i] & 1));
            }
        }
        for (int j = 0; j <= 2; ++ j){
            if (dp[i - 1][j] != -1){
                update(dp[i][2], dp[i - 1][j] + !(a[i] & 1));
            }
        }
        for (int j = 0; j <= 3; ++ j){
            if (dp[i - 1][j] != -1){
                update(dp[i][3], dp[i - 1][j] + (a[i] == 0 ? 2 : a[i] & 1));
            }
        }
        for (int j = 0; j <= 4; ++ j){
            if (dp[i - 1][j] != -1){
                update(dp[i][4], dp[i - 1][j] + a[i]);
            }
        }
    }
    printf("%lld\n", dp[n + 1][4]);
    return 0;
}

Measured memory_bytes: 8960
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, ans, a, b, c,d;
    
    cin >> a >> b >> c;
    ans = 0;
    d=0;
    for(i=a; i<=b; i++)
    {
        if(ans== c % i )
        d++;
    }
    cout << d << endl;
}


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

int main() {
    int N, X, T;
    cin >> N >> X >> T;

    int cnt = N / X;
    if(N % X == 0) {
        cout << cnt * T << endl;
    } else {
        cout << cnt * T + T << endl;
    }

    return 0;
}

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

using i64 = std::int64_t;

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

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

using P = pair<i64, i64>;

i64 collect(const vector<vector<i64>> &G, const vector<i64> &H, i64 u, i64 v, i64 p) {
  if (u == v) return 0;
  for (auto e : G[u]) {
    i64 t = H[e] ^ u;
    if (t == p) continue;
    i64 s = collect(G, H, t, v, u);
    if (s != -1) {
      return s | (1LL << e);
    }
  }
  return -1;
}

signed main() {
  i64 n = io::scan();
  auto G = vector<vector<i64>>(n);
  auto H = vector<i64>(n);
  REP(i, n - 1) {
    i64 a = io::scan() - 1;
    i64 b = io::scan() - 1;
    G[a].push_back(i);
    G[b].push_back(i);
    H[i] = a ^ b;
  }
  i64 m = io::scan();
  auto paths = vector<i64>(m, 0);
  REP(j, m) {
    i64 u = io::scan() - 1;
    i64 v = io::scan() - 1;
    paths[j] = collect(G, H, u, v, -1);
  }
  i64 ans = 0;
  REP(s, 1LL << m) {
    i64 mask = 0;
    REP(j, m) {
      if ((s >> j) & 1) {
        mask |= paths[j];
      }
    }
    if (__builtin_parityll(s)) {
      ans -= 1LL << (n - 1 - __builtin_popcountll(mask));
    } else {
      ans += 1LL << (n - 1 - __builtin_popcountll(mask));
    }
  }
  io::print(ans);
  io::flush();
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    int num;
    cin >> num;
    num--;
    a[i] = num;
  }
  
  int t = 0;
  int bt = 1;
  set<int> tcnt;
  t = a[0];
  tcnt.insert(t);
  while(t != 1) {
    t = a[t];
    if(tcnt.count(t) == 0) {
      tcnt.insert(t);
      bt++;
    }
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << bt << endl;
  return 0;
}

Measured memory_bytes: 8220
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 200005
#define mod 1000000007
using namespace std;
ll a[N],sum[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sum[n]=a[n];
    for(int i=n-1;i>0;i--) sum[i]=(sum[i+1]+a[i])%mod;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll p=(sum[i+1]*a[i])%mod;
        ans=(ans+p)%mod;
    }
    cout<<ans;
}
int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int a, b;
    cin >> a >> b;
    if(a < 1 || a > 9){
        cout << -1 << endl;
        return 0;
    }
    if(b < 1 || b > 9){
        cout << -1 << endl;
        return 0;
    }
    cout << a * b << endl;
}


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

int main(void) {
    int x, y;
    cin >> x >> y;

    bool ans = false;
    rep(i, 0, x + 1) {
        int tsuru = i;
        int kame = x - i;

        if (tsuru * 2 + kame * 4 == y) ans = true;
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  string s;
  cin >> s;
  int ans = 0;
  int tmp = 0;
  for(int i = 0; i < s.length(); ++i){
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
      ++tmp;
      ans = max(tmp , ans);
    } else {
      tmp = 0;
    }
  }

  cout << ans << endl;
}


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

public class Hello{
    public static void Main(){
        int [] str=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int x=str[0];
        int y=str[1];
        int a;//小さいほう
        int b;//大きいほう
        int ans=1;
        if(x>=y)
        {
            //x%=y;
            a=y;
            b=x;
        }else{
            //y%=x;
            a=x;
            b=y;
        }
        for(int i=2;i<=a;i++)
        {
            if(a%i==0&&b%i==0)ans=i;
        }
        Console.WriteLine(ans);
    }
}



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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<char>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int N;
    cin>>N;
    vector<vector<int>> R(N,vector<int>(2)),B(N,vector<int>(2));
  	vector<int> g(2*N,-1);
    rep(i,N) cin>>R[i][0]>>R[i][1];
    rep(i,N) {
      cin>>B[i][0]>>B[i][1];
      g[B[i][1]]=B[i][0];
    }
    sort(R.begin(),R.end());
    reverse(R.begin(),R.end());
    int ans = 0;
    for(auto x:R){
        for(int i = x[1]+1; i < 2*N; i++){
          if(g[i]>x[0]) {
            ans++;
            g[i]=-1;
            break;
          }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 210
/*------------------------------------------------------------*/
int n,m;
int a[maxn][maxn];
int main(){
	int n,m;
	in2(n,m);
	FOR(i,0,9)
		FOR(j,0,9){
			in(a[i][j]);
		}
	FOR(k,0,9)
		FOR(i,0,9)
			FOR(j,0,9){
				if(i!=j&&j!=k&&i!=k){
					if(a[i][k]+a[k][j]<a[i][j]){
						a[i][j]=a[i][k]+a[k][j];
					}
				}
			}
	int ans=0;
	FOR(i,1,n)
		FOR(j,1,m){
			int c;
			in(c);
			if(c!=-1){
				ans+=a[c][1];
			}
		}
	out(ans);
}

Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2019-12-16 20:31:52
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool bitpare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> k(M), p(M);
    vector<vector<int>> s(M);
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            int temp;
            cin >> temp;
            temp -= 1; // 0 to N-1
            s[i].push_back(temp);
        }
    }
    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }

    // end input
    int ans = 0;

    for (int bit = 0; bit < (1<<N); bit++) {
        // each combination from every sequences of i/o of the switches
        int ok = 1;
        for (int bulb = 0; bulb < M; bulb++) {
            // check if the interested combination satisfies the condition
            int cnt = 0;
            for (int i = 0; i < k[bulb]; i++) {
                if (bit & (1<<s[bulb][i])) {
                    cnt++;
                }
            }

            if (cnt % 2 != p[bulb]) {
                ok = 0;
            }
        }

        if (ok) ans++;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include "vector"
#include "algorithm"
#include "set"
#include "map"
#include "cmath"
#include "queue"

using namespace std;

// DEFINITIONS

#define y second
#define x first
#define pb push_back
#define mk make_pair
#define sz size()
#define ln length()
#define beg begin()
#define end end()
#define F(i,a,b) for(int i=a;i<=b;i++)
#define FOR(a,b) for(auto a: b)



// USINGS

using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi  = vector<int>;
using vvi = vector<vector<int> >;
using vch = vector<char>;
using vll = vector<ll>;
using vpii = vector<pii>;

// FUNCTIONS

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

// CONSTANTS



const ll M = 1e9+7;
const int N = 1e6+7;


int main(){
    int n;
    ll res = 0;
    cin>>n;
    int a[n];
    map<int, int> mp;
    for(int i=0;i<n;i++) {
        cin>>a[i];
        res += a[i];
        mp[a[i]]++;
    }
    int q;
    cin>>q;
    while(q--){
        int b, c;
        cin>>b>>c;
        res += (c-b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout<<res<<endl;
    }
}



Measured memory_bytes: 8220
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; 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;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  int n;
  cin >> n;
  cout << n/2+n%2 << endl;
  return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47344
// include
//#include <bits/stdc++.h> // last resort
#include <algorithm>     // sort, binary-search, etc.
#include <bitset>        // fixed-length bitset
#include <cmath>         // pow, log, etc.
#include <complex>       // complex number
#include <cstring>       // memset, memcpy
#include <deque>         //
#include <functional>    //
#include <iomanip>       // setprecision
#include <iostream>      // i/o
#include <iterator>      // operations for set
#include <map>           // map or dict
#include <numeric>       // iota, gcd, lcm
#include <queue>         //
#include <set>           //
#include <stack>         //
#include <string>        //
#include <unordered_map> //
#include <unordered_set> //
#include <utility>       // pair
#include <vector>        // variable-length array

// typedef and const
typedef long long ll;
const int DEFMOD = 1e9 + 7; // default modulus
const int INF = INT32_MAX;  // ~1e9
const ll LINF = INT64_MAX;  // ~1e18

//namespace
using namespace std;

// macros
// read and initialize
#define FILL(array, number) memset(array, number, sizeof(array))
#define RMI(array)             \
    for (auto &item : (array)) \
    cin >> item
// loop
#define FOREACH(item, array) for (auto &(item) : (array))
#define REP(index, time) for (int index = 0; index < (int)(time); ++index)
#define REPD(index, time) for (int index = time; 0 < index; --index)
#define SIZE(array) ((int)(array).size())
// write and presentation
#define COUTS(variable) cout << (variable) << " "
#define DUMP(variable) cout << #variable << ": " << (variable) << endl
#define ENDL cout << endl
#define WM(array)              \
    for (auto &item : (array)) \
    {                          \
        COUTS(item);           \
        ENDL;                  \
    }
// abbreviation
#define ALL(array) (array).begin(), (array).end()
#define M_ map<int, int>
#define MP make_pair
#define P_ pair<int, int>
#define PB(item) push_back(item)
#define PQ priority_queue<int>
#define PQG priority_queue<int, V, greater>
#define S_ set<int>
#define TO(condition, true, false) ((condition) ? (true) : (false))
#define V_ vector<int>

void func(std::string S)
{
    cout << TO(equal(ALL(S), "ABC"), "ARC", "ABC") << endl;
}

int main()
{
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>

void maxHeapify(int);

int i,n, A[500001];



int main(){

  scanf("%d",&n);

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

  for(i = n / 2 ; i >= 1 ; i--) maxHeapify(i);

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

  printf("\n");



  return 0;
}

void maxHeapify(int b){
  int ri, le, large;
  int a;
  le = 2 * b;
  ri = 2 * b+ 1;

  if(le <= n && A[le] > A [b]) large = le;
  else large = b;

  if(ri <= n && A[ri] > A[large]) large = ri;

  if(large != b){
    a = A[b];

    A[b] = A[large];

    A[large] = a;

    maxHeapify(large);
  }
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, k;
  string s;
  cin >> n >> s >> k;
  rep(i, n) {
    if (s.at(i) == s.at(k-1)) cout << s.at(i);
    else cout << '*';
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<vector<ll>> dist;
void warshall_floyd(int n) {
  rep(i, n) rep(j, n) rep(k, n) {
    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, r; cin >> n >> m >> r;
  vector<int> R(r);
  rep(i, r) {
    cin >> R[i];
    R[i]--;
  }
  dist = vector<vector<ll>>(n, vector<ll>(n, longinf));
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    int a, b; ll c;
    cin >> a >> b >> c;
    a--; b--;
    dist[a][b] = c;
    dist[b][a] = c;
  }
  warshall_floyd(n);
  ll ans = longinf;
  auto dfs = [&](auto dfs, int prev, int done, ll cost) -> void {
    if(done==(1<<r)-1) {
      ans = min(cost, ans);
      return;
    }
    rep(i, r) {
      if((done>>i)&1) continue;
      dfs(dfs, i, done|(1<<i), cost+dist[R[prev]][R[i]]);
    }
  };
  rep(i, r) dfs(dfs, i, 1<<i, 0);
  cout << ans << "\n";
  return 0;
}


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

int main(void){
    int M,D;
    int a=2,b=2,count=0;
    scanf("%d %d",&M,&D);
    while(1){
        if(D < a*10 + b){
            break;
        }else{
            if(a * b <= M) count++;
        }
        if(b == 9){
            a++;
            b = 1;
        }
        b++;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
l = tuple(map(int, input().split()))
x, y = l[0], l[1]
#x, y = 3, 20
#x, y = 25, 100
#x, y = 314159265, 358979323846264338
max_len, max_i = 0, 0

for i in range(x, x+10000):
    cnt, A = 0, i
    while A <= y:
        A = A * 2
        cnt += 1
    # print('i:{}, cnt:{}'.format(i, cnt))
    if max_len < cnt: max_len, max_i = cnt, i
print('{}'.format(max_len))


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int n, ans = 1;
	string s;
	vector<int> cnt(26, 0);
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		int x = s[i] - 'a';
		cnt[x]++;
	}
	for (auto i : cnt) ans = (ans * (i + 1)) % mod;
	cout << (ans - 1) % mod;
	return 0;
}

Measured memory_bytes: 3768
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
const int N = 100001;

vector<int> ruiseki(N);
vector<int> is_prime(N, 1);  // 1 true; 0 false

bool is_like2017(int n) {
  if (n % 2 == 0) {
    return false;
  }
  if (is_prime[n] == 1 and is_prime[(n + 1) / 2] == 1) {
    return true;
  } else {
    return false;
  }
}

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

  is_prime[1] = 0;
  for (int i = 2; i < N; ++i) {
    if (is_prime[i] == 0) continue;
    int count = 2 * i;
    while (count < N) {
      is_prime[count] = 0;
      count += i;
    }
  }
  ruiseki[0] = 0;
  ruiseki[1] = 0;
  for (int i = 2; i < N; ++i) {
    if (is_like2017(i)) {
      ruiseki[i] = ruiseki[i - 1] + 1;
    } else {
      ruiseki[i] = ruiseki[i - 1];
    }
  }
  for (int i = 0; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << ruiseki[r] - ruiseki[l - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
  
char dict[30600000];
  
char word[26];
void insert(const char* );
int find_h(const char*);
long encode(const char*);
  

int main(void) {
  long n,i;
  word['A'] = 1;
  word['C'] = 2;
  word['G'] = 3;
  word['T'] = 4;
  scanf("%ld\n",&n);
  for(i=0;i<n;i++){
    char cmd[8], str[14]; scanf("%s %s\n",cmd, str);
    if(cmd[0]=='i') {
      insert(str);
    }
    else {
      if(find_h(str)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}
void insert(const char *key2) {
  long key=encode(key2);
  long keta=key/8;
  dict[keta]=(dict[keta]|(1<<(key%8)));
}
int find_h(const char *key2) {
  long key=encode(key2);
  return (dict[key/8] & 1<<(key%8));
}
    
long encode(const char *key){
  int n=strlen(key),i;
  long sum=0;
  long keta=1;
  for(i=0;i<n;i++){
    int keyi=key[i];
    sum = sum + keta * word[keyi];
    keta=(keta<<2)+keta;
  }
  return (sum);
}
  

Measured memory_bytes: 1432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll NN = 1e6+10;

ll a,b;
int main(){
	cin>>a>>b;
	ll ma = -1e10;
	ma = max(ma,a+b);
	ma = max(ma,a-b);
	ma = max(ma,a*b);
	cout<<ma<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<59)

struct data{
    int y,x,num;
};

class UF{
private:
    vector<int> par,rank,elm;
    vector<vector<int>> elmList;	//don't be validated
public:
    int groups;
    
    UF(int __size):par(__size) , rank(__size,0) , elm(__size,1) , groups(__size), elmList(__size){
        rep(i,__size)elmList[i] = vector<int>(1,i);
        for(int i=0;i<__size;i++)par[i]=i;
    }
    
    int getElements(int n){ return elm[find(n)]; }
    vector<int> getElementsList(int n){ return elmList[find(n)]; }
    
    int find(int x){
        if(par[x]==x) {
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        
        groups--;
        if(rank[x]<rank[y]){
            par[x]=y;
            elm[y]+=elm[x];
            for(auto &e:elmList[x])elmList[y].pb(e);
            
        }else{
            par[y]=x;
            elm[x]+=elm[y];
            for(auto &e:elmList[y])elmList[x].pb(e);
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    
    bool isSame(int x,int y){
        return find(x)==find(y);
    }
};

#define MAX_V 100000
struct edge{int to,cost;};
int kruskal(int v, vector<edge> G[MAX_V]){
    int ret=0;
    vector<pair<int,pii>> edges;
    
    rep(i,MAX_V)for(auto &e:G[i])edges.pb(make_pair(e.cost,pii(i,e.to)));
    
    sort(all(edges));
    
    UF uf(v);
    rep(i,edges.size()){
        int c,u,v;
        c = edges[i].first;
        tie(u,v) = edges[i].second;
        
        if(!uf.isSame(u,v)){
            uf.unite(u,v);
            ret+=c;
        }
    }
    return ret;
}

int cost(data a, data b ){
    return min(abs(a.y-b.y),abs(a.x-b.x));
}

void add_edge( data a, data b, vector<edge> G[MAX_V] ){
    G[a.num].pb(edge{b.num,cost(a,b)});
    G[b.num].pb(edge{a.num,cost(a,b)});
}


signed main(){
    vector<edge> G[MAX_V];
    int n;
    cin>>n;

    vector<data> v(n);
    rep(i,n){
        int x,y;
        cin>>x>>y;
        v[i] = data{y,x,(int)i};
    }

    sort(all(v),[](data a, data b){ return a.y<b.y; });
    rep(i,v.size()){
        if(i-1>=0) add_edge(v[i],v[i-1], G);
        if(i+1<v.size()) add_edge(v[i],v[i+1], G);
    }

    sort(all(v),[](data a, data b){ return a.x<b.x; });
    rep(i,v.size()){
        if(i-1>=0) add_edge(v[i],v[i-1], G);
        if(i+1<v.size()) add_edge(v[i],v[i+1], G);
    }
    
    cout<<kruskal(n,G)<<endl;

}

Measured memory_bytes: 56084
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll i,n,m,s;
vi v;
ll a[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,0,m) cin>>a[i];
    if(n >= m) cout<<0;
    else{
        sort(a,a + m);
        rep(i,1,m) v.pb(a[i] - a[i - 1]);
        sort(all(v),[&](ll a,ll b){
            return a > b;
        });
        s = a[m - 1] - a[0];
        rep(i,0,n - 1) s -= v[i];
        cout<<s;
    }
    return 0;
}

Measured memory_bytes: 2168
# include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
//# include<prettyprint.hpp>
using namespace std;
# define ll long long
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll a, b, c, k; cin >> a >> b >> c >> k;
    ll ans = 0;
    if (k >= a){
        k-=a;
        ans+=a;
    }else{
        ans+=k;
        k = 0;
    }
    k-=b;
    if (k > 0){
        if (k >= c){
            k-=c;
            ans-=c;
        }else{
            ans-=k;
            k = 0;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int A, B, C;

	cin >> A >> B >> C;
	if (A + B + C > 21)
		puts("bust");
	else
		puts("win");
}



Measured memory_bytes: 256
n=7**6;P=[0,0]+[1]*n;S=[0]*n;r=range(2,n)
for i in r:
  for j in range(2*i,n,i):P[j]=0
for i in r:S[i]+=(P[i]==P[(i+1)//2]==1)+S[i-1]
for _ in "_"*int(input()):l,r=map(int,input().split());print(S[r]-S[l-1])

Measured memory_bytes: 13292