akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n,k;
    int x;
	cin >> n>> k;
    int v[n];
    ll max=0;
    fr(i,n){
      cin >> v[i];
    }
    fr(a,k+1){
     fr(b,k-a+1){
       if(a+b>0&&a+b<=n){
        int x[a+b];
        ll sum=0;
        fr(i,a){x[i]=v[i];}
        fr(i,b){x[i+a]=v[n-1-i];}
        sort(x,x+a+b);
        fr(i,min(a+b,k-a-b)){
          if(x[i]<0)x[i]=0;
          else break;
        }
        fr(i,a+b){
          sum+=x[i];
        }
        if(sum>max)max=sum;
       }
     }
    }
      cout << max << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=2100000 +117;
const int MM=22;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
string s[MM]={};
int dp[MM][NN]={};
int res[NN]={};
int trans[NN][2]={};
int lg[NN]={};
char op[NN]={};
void gettrans(){
	for(int i=1;i<1<<(n+1);++i){
		for(int j=lg[i]-1;j>=0;--j){
			if(i&(1<<j)){
				trans[i][1]=i&((1<<(j+1))-1);
				trans[i][1]|=1<<(j+1);
				break;
			}
		}
		for(int j=lg[i]-1;j>=0;--j){
			if((i&(1<<j))==0){
				trans[i][0]=i&((1<<(j+1))-1);
				trans[i][0]|=1<<(j+1);
				break;
			}
		}
	}
}
int main(){
	//open();
	n=read();
	int k=read();
	for(int i=0;i<=n;++i){
		cin>>s[i];
		for(int j=0;j<(1<<i);++j){
			if(s[i][j]-'0')dp[0][j+(1<<i)]=1;
		}
	}
	int all=1<<(n+1);
	for(int i=0;i<=n;++i){
		lg[1<<i]=i;
	}
	for(int i=2;i<all;++i){
		if(!lg[i])lg[i]=lg[i-1];
	}
	gettrans();
	for(int i=0;i<=n;++i){
		for(int j=1<<(i);j<all;++j){
			int len=lg[j];
			int las=j&((1<<(len-i))-1);
			las|=1<<(len-i);
			int now=j>>(len-i);
			res[now]+=dp[i][j];
			//if(dp[i][j])cerr<<now<<" "<<las<<" "<<dp[i][j]<<endl;
			if(trans[las][0]){
				int xtl=lg[trans[las][0]];
				int xt=trans[las][0]-(1<<xtl);
				xt=xt|(now<<xtl);
				dp[i+1][xt]+=dp[i][j];
			}
			if(trans[las][1]){
				int xtl=lg[trans[las][1]];
				int xt=trans[las][1]-(1<<xtl);
				xt=xt|(now<<xtl);
				dp[i+1][xt]+=dp[i][j];
			}
		}
	}
	for(int len=n;len>=0;--len){
		for(int j=1<<len;j<1<<(len+1);++j){
			int now=j;
			if(res[now]>=k){
				for(int i=len-1;i>=0;--i){
					op[i]=now&1;
					now>>=1;
				}
				for(int i=0;i<len;++i){
					putchar(op[i]+'0');
				}
				putchar('\n');
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
	close();
	return 0;
}

Measured memory_bytes: 207488
import collections
def solve(n, a_list):

    count = collections.Counter()
    for a in a_list:
        count[a] += 1

    count[0] += 1
    c = [False] * n
    for k, v in count.items():
        c[k] = (v == 2)

    if n % 2 == 1:
        tmp = all([v for i, v in enumerate(c) if i % 2 == 0])
    else:
        tmp = all([v for i, v in enumerate(c) if i % 2 == 1])

    if tmp:
        return (2 ** (n//2) ) % (10**9+7)
    else:
        return 0

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))


Measured memory_bytes: 14812
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count=0;
        for(int i=1;i<N;i++){
            count += N/i;
            if(N%i==0)count--;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35688
#include <stdio.h>
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=1&&a>=-1){
		if(b>=0) printf("%d\n",a+b);
		else printf("%d\n",a-b );
	}
	else{
		if(a<0){
			if(b<=0) printf("%d\n",a*b );
			else printf("%d\n",a+b );
		}
		else{
			if(b<=0)printf("%d\n",a-b );
			else{
				if(b==1) printf("%d\n",a+b );
				else printf("%d\n",a*b );
			}
		}
	}
}

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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;

const string YES = "Yes";

const string NO = "No";

const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;

void solve(long long N, long long K, long long Q, std::vector<long long> A) {
    vl p(N, K);
    ll s = 0;
    for (auto&& i : A) {
        s++;
        p[i - 1] += 1;
    }
    for (auto&& i : p) {
        if (i - s <= 0) print(NO);
        else
            print(YES);
    }
}
signed main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> A(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, K, Q, std::move(A));

    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>

#define MAX 100020
using namespace std;

class Stack{
	int *t;
	int high;
public:
	Stack(int sz):high(1){ t = new int[sz]; t[0] = 0; }
	~Stack(){ delete [] t; }
	void push(const int &p){
		t[high] = p;
		++high;
	}
	int pop(){
		int ret = t[high-1];
		--high;
		if( high < 1 ) high = 1;
		return ret;
	}
	int top(){
		return t[high-1];
	}
};

int main(){
	while(true){
		int n;
		int ans = 0;
		int most_right_white = 0;
		int most_right_black = 0;
		int a[MAX] = {0,};

		scanf("%d", &n);
		if( n == 0 )
			break;

		for(int i = 1; i <= n; ++i){
			int c;
			
			scanf("%d", &c);

			if( i % 2 == 0 ){
				if( c == 0 ){
					if( a[i-1] != c ){
						for(int d = most_right_white + 1; d < i; ++d){
							a[d] = c;
						}
						most_right_black = 0;
						for(int d = most_right_white - 1; d > 0; --d){
							if( a[d] == 1 ){
								most_right_black = d;
								break;
							}
						}
					}
				}else{
					if( a[i-1] != c ){
						for(int d = most_right_black + 1; d < i; ++d){
							a[d] = c;
						}
						most_right_white = 0;
						for(int d = most_right_black - 1; d > 0; --d){
							if( a[d] == 0 ){
								most_right_white = d;
								break;
							}
						}
					}
				}
			}
			a[i] = c;
			if( c == 0 ){
				most_right_white = i;
			}else{
				most_right_black = i;
			}
		}
		ans = 0;
		for(int i = 1; i <= n; ++i){
			if( a[i] == 0 ) ++ans;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  int ans = 1;
  for(int i=1; i<N; i++){
    if(d.at(i)>d.at(i-1)) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

using llu = uint64_t;

int is_eq(llu a, llu k, int u)
{
    llu b = a | k;

    llu m = 0;

    for(int i = 0; i < u; i++)
        m |= llu(1) << i;

    m = ~m;

    b &= m;
    k &= m;

    return b == k;
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n; cin >> n;
    llu k; cin >> k;

    map<llu, llu> mp;

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

        mp[a] += b;
    }

    llu ans = 0;

    for(auto& pr : mp)
    if(is_eq(pr.first, k, 0))
        ans += pr.second;

    for(int i = 0; i < 30; i++) if(k & (llu(1) << i))
    {
        llu s = 0;

        for(auto& pr : mp) if( !(pr.first & (llu(1) << i)) )
        if(is_eq(pr.first, k, i + 1))
            s += pr.second;

        ans = max(ans, s);
    }

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

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  ll n;
  cin >> n;
  ll sum = 0;
  ll cur;
  rep(i, n){
    ll num;
    cin >> num;
    if(i == 0) cur = num;
    else{
      if(num < cur) sum += cur-num;
      else cur = num;
    }
  }
  cout << sum << endl; 
  return 0;
}
    
    
    

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

int main() {

  int h=0, w=0;

  while(1) {

    cin >> h >> w;

    if(h==0 && w==0) {

      break;
      
    }

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

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

        if(i==0 || i==h-1 || j==0 || j==w-1) {

          cout << "#";
          
        } else {

          cout << ".";
          
        }

        if(j==w-1) {

          cout << endl;
          
        }
      }

      if(i==h-1) {

        cout << endl;
        
      }
      
    }
    
  }

  return 0;
  
}


Measured memory_bytes: 3056
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int n,p;
    cin >> n >> p;
    long long int odd = 0,even = 0;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        if(a % 2 == 1)
        {
            odd++;
        }
        else
        {
            even++;
        }
    }
    if(odd == 0)
    {
        if(p == 0)
        {
            cout << (long long int)pow(2,even) << "\n";
        }
        else
        {
            cout << "0\n";
        }
    }
    else
    {
        cout << (long long int)pow(2,n - 1) << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;

  if(A > 8 || B > 8){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int a[4], b[4], s = 0,t=0;
using namespace std;

int main() {
	for (int i = 0;i < 4;i++) {
		cin >> a[i];
		s += a[i];
	}
	for (int j = 0;j < 4;j++) {
		cin >> b[j];
		t += b[j];
	}
	if (s >= t) cout << s << endl;
	else cout << t << endl;
	cin >> s;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

ll X[18], Y[18], P[18], N;
ll R[18];

void dfs(vector<int>& XX, vector<int>& YY, int c, int k) {
	if (c == N) {
		ll xd = MOD, yd = MOD, S = 0;
		for (int i = 0;i < N;i++) {
			xd = MOD, yd = MOD;
			for (ll x : XX) {
				xd = min(xd, abs(x - X[i]));
			}
			for (ll y : YY) {
				yd = min(yd, abs(y - Y[i]));
			}
			S += min(xd, yd) * P[i];
		}
		R[k] = min(R[k], S);
		return;
	}

	XX.push_back(X[c]);
	dfs(XX, YY, c + 1, k + 1);
	XX.pop_back();

	YY.push_back(Y[c]);
	dfs(XX, YY, c + 1, k + 1);
	YY.pop_back();

	dfs(XX, YY, c + 1, k);
}

int main() {
	cin >> N;

	for (int i = 0;i < N;i++) {
		cin >> X[i] >> Y[i] >> P[i];
		R[i] = INT64_MAX;
	}
	R[N] = INT64_MAX;
	vector<int> BX = { 0 };
	vector<int> BY = { 0 };
	dfs(BX, BY, 0, 0);
	
	for (int i = 0;i <= N;i++) {
		cout << R[i] << endl;
	}
}

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

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> ball(N);
    for(int i=0;i<N;i++)cin>>ball[i];
    vector<int> num(200001);
    for(int i=0;i<N;i++){
        num[ball[i]]++;
    }
    sort(num.begin(),num.end());
    reverse(num.begin(),num.end());
    int count=0;
    for(int i=K;num[i]!=0;i++){
        count+=num[i];
    }
    cout<<count<<endl;

}
    


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>  // assert(x>=10), 部分点問題
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <set>

#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(all(x))
#define FILL(v, value) (v+(sizeof(v) / sizeof *(v)), value);
#define inf 999999999
#define dbg(x) cout<<#x<<":"<<x<<endl;
#define pb(a) push_back((a))
#define mp(a) make_pair((a))
#define pi 2*acos(0.0)
#define in scanf
#define out printf
#define fi first
#define se second

// --
#define bit(n) (1LL<<(n)) // 左bitシフト
// --

using namespace std;

typedef long long llong;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<llong, pll> plp;

const int MOD=1000000007;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};  // 右下左上


int main(int argc, char**argv){
    int a, b;
    char op;
    cin >> a >> op >> b;

    if (op == '+') cout << a + b << endl;
    if (op == '-') cout << a - b << endl;

    return 0;
}




Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
    int len,i,x=0,y=0,s=0;
	string a;
    cin>>a;
    len=a.size();
    for(i=0;i<len;i++){
    if(x==y){
    x++;
    if(a[i]=='p'){
	s--;
    }}
    else{
    y++;
    if(a[i]=='g'){
	s++;
    }}}
    cout<<s<<endl;
    return 0;
}

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

int main() {
	int H, W, RH, RW;
	string S;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> S;
			if (S == "snuke") RH = i, RW = j;
		}
	}
	char X = RW + 65;
	cout << X << RH  + 1 << endl;
}

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

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

int main(){
    int N, tmp, ans=0;
    cin >>  N;
    int A[N];
    int left[N], right[N];
    
    for(int i=0; i<N; i++){
	cin >> A[i];
    }
    
    left[0] = A[0];
    right[N-1] = A[N-1];

    for(int i=1; i<N; i++){	
	left[i] = gcd(left[i-1], A[i]);
    }
    for(int i=N-2; i>=0; i--){	
	right[i] = gcd(right[i+1], A[i]);
    }

    ans = max(ans, right[1]);
    for(int i=0; i<N-2; i++){	
	tmp = gcd(left[i], right[i+2]);
	ans = max(ans, tmp);
    }
    ans = max(ans, left[N-2]);

    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <map>
#include <tuple>


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

using lli = long long int;


std::map<int, int> Map;


int main(void){
    // 入力
    int n; scanf("%d", &n);
    REP(i, n) {
        int k;
        scanf("%d", &k);
        Map[k]++;
    }

    // 実装
    int ans = 0;
    // 逆順
    for(auto itr = Map.rbegin(); itr != Map.rend(); ++itr){
        int a, b; std::tie(a, b) = *itr;
        int t = 1;
        while(t <= a) t *= 2;
        if(Map.find(t - a) != Map.end()){
            // 自身を参照する場合
            if(t == 2 * a){
                Map[a] = b % 2;
                ans += b / 2;
                continue;
            }
            int bb = Map[t-a];
            // 小さい方
            int mn = (bb > b) ? b : bb;
            Map[a] -= mn;
            Map[t-a] -= mn;
            ans += mn;
        }
    }
    // 出力
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		long K = scan.nextLong();
		scan.close();
		int l = S.length();
		int []num = new int[S.length()];
		for(int i = 0; i < l; i++) {
			num[i] = Integer.parseInt(S.substring(i, i + 1));
		}
//		long[]k = new long[S.length()];
		long sum = l;
		if(sum >= K) {
			int cnt1 = 0;
			for(int i = 0; i < l; i++) {
				if(num[i] == 1) {
					cnt1++;
				}else {
					break;
				}
			}
			if(cnt1 >= K) {
				System.out.println(1);
				System.exit(0);
			}
		}
		long cnt = 1;

		int ans = 0;
		for(int i = 0; i < l; i++) {
			if(num[i] != 1) {
				ans = num[i];
				break;
			}
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 23252
#include <stdio.h>

int a, b;

int main(void) {
    scanf("%d%d", &a, &b);
    
    if (a < b) {
        printf("a < b\n");
    } else if (a > b) {
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <map>
using namespace std;

int pi[233333],pp[233333];
map<int,int> pk;

int main()
{
	int n,k; scanf("%d%d",&n,&k);
	for(int i=1; i<=n; i++) scanf("%d",&pi[i]);
	int p=0; pk[0]++; long long sum=0;
	for(int i=1; i<=n; i++)
	{
		p=(p+pi[i])%k; pp[i]=p;
		if(i-k>=0) pk[(pp[i-k]+k-(i-k)%k)%k]--;
		sum+=pk[(p+k-i%k)%k];
		pk[(p+k-i%k)%k]++;
	}
	printf("%lld\n",sum);
	return 0;
}

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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            998244353
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n,k;
    cin>>n>>k;
    int dp[n+1];
    dp[0]=0;
    vector<pair<int,int>>v;
    for(int p=0;p<k;p++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    dp[1]=1;
    for(int i=2;i<=n;i++)
    {
        dp[i]=dp[i-1];
        for(int p=0;p<k;p++)
        {
            int l=v[p].first;
            int r=v[p].second;
            dp[i]=(dp[i]+(((i>=l)?dp[i-l]:0)-((i>=r+1)?dp[i-r-1]:0)+mod)%mod)%mod;
        }
    }
//    for(int i=0;i<=n;i++)
//        cout<<dp[i]<<endl;
    cout<<(dp[n]-dp[n-1]+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 5200
program ABC051B
    implicit none
    integer(8)::K,S,h,i,j
    integer(8)::result=0

    read(5,*) K,S
    
    do i=0,K
        do j=0,K
            if(S-i-j>=0 .and. S-i-j<=K)then
                result=result+1
            end if
        end do
    end do

    print'(i0)',result
end program ABC051B

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

int main(){
  int A,B;
  cin >> A >> B;
  
  if(13 <= A)cout << B << endl;
  else if(6 <= A && A <= 12)cout << B / 2 << endl;
  else if(A <= 5)cout << 0 << endl;
  
  return 0;
}

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

int main()
{
	string X;
	cin >> X;
	int ans =750;//ansに大きな数を入れる//

	for (int i = 0; i <= X.size()-3; i++) {//Xの長さよりも３回少なくループする。iは０から始まり１ずつふえる//

		int MIN = min(ans, abs(753 - stoi(X.substr(i, 3))));
		//ansとXから抜き出したiから三番目までの数を比べ、小さいほうをint MINに代入する。//
		//初回は大きな数と比べるため必ず抜き出した数がint MINに代入される//
		ans = abs(MIN);
		//int MINを絶対値にしてansに代入し、ループする//
	}
	//上のfor文で最も小さいansを出力する//
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<vector>
typedef long long ll;
using namespace std;

vector<vector<int>> memo;
int n;
ll MOD = 1e9 + 7;

int conv(string s){
    string t = "AGCT";
    int cc = 0;
    for(int i=0;i<4;i++)
        for(int j=0;j<4;j++)
            for(int k=0;k<4;k++){
                if(t[i]==s[0] && t[j]==s[1] && t[k]==s[2]) return cc;
                cc++;
            }
    return 0;
}

bool ok(string last4){
    for(int i=0;i<4;i++){
        string t = last4;
        if(i>=1){
            char swp = t[i];
            t[i] = t[i-1];
            t[i-1] = swp;
        }
        if(t.find("AGC") != string::npos){
            return false;
        }
    }
    return true;
}

ll dfs(int cur, string last3){
    if(memo[cur][conv(last3)] > 0){
        return memo[cur][conv(last3)];
    }
    if(cur==n){
        return 1;
    }
    ll ret = 0;
    string acgt = "ACGT";
    for(char c : acgt){
        if(ok(last3 + c)){
            string tt = last3;
            tt.erase(tt.begin());
            tt.push_back(c);
            ret = (ret + dfs(cur+1, tt)) % MOD;
        }
    }
    memo[cur][conv(last3)] = ret;
    return ret;
}

int main(){
    cin >> n;
    memo.assign(101, vector<int>(4*4*4,0));
    cout << dfs(0, "TTT") << endl;
}

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

const ll inf = 1e18 + 1;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin>>n;
	string s;
	cin>>s;

	ll preR[n] = {0};
	ll preG[n] = {0};
	ll preB[n] = {0};
	vector<ll> Ra, Ga, Ba;
	
	ll rt[n] = {0};
	
	for(ll i=0;i<n;i++){
		if(s[i] == 'R'){
			preR[i] = 1;
			Ra.pb(i);
		}
		if(s[i] == 'G'){
			preG[i] = 1;
			Ga.pb(i);
		}
		if(s[i] == 'B'){
			preB[i] = 1;
			Ba.pb(i);
			rt[i] = 1;
		}
	}
	for(ll i=1;i<n;i++){
		preR[i]+=preR[i-1];
		preG[i]+=preG[i-1];
		preB[i]+=preB[i-1];
	}
	ll ans=0;
	ll Rs = Ra.size();
	ll Gs = Ga.size();
	ll Bs = Ba.size();
	//print(preB, n);
	ll tot = preB[n-1];
	for(ll i=0;i<Rs;i++){
		for(ll j=0;j<Gs;j++){
			ll l = min(Ra[i], Ga[j]);
			ll r = max(Ra[i], Ga[j]);
			//ll dis = r-l;
			//cout<<l<<" "<<r<<"\n";

			ans += tot;
		    
			//cout<<ans<<"\n";
			if((((r-l)&1) == 0) && rt[(l+r)/2]==1) ans--;
			if(2*r-l <n && rt[2*r-l]) ans--;
			if(2*l-r >=0 && rt[2*l-r]) ans--;
			
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3788
def main():
    N, D = map(int, input().split())
    cnt = 0
    while True:
        a, b = divmod(N, (2*D+1))
        cnt += a
        if 2*D + 1 > b:
            if b > 0:
                cnt += 1
            break
    print(cnt)
main()

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n, k;
    cin >> n >> k;
    cout << ceil(log10(n + 1) / log10(k)) << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 640
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

int main()
{
int a;
int b;
cin>>a>>b;
int c=a*b;
if(c%2==0)cout<<"Even";
if(c%2!=0)cout<<"Odd";
system("pause");
return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    string grid[n];
    for (int i = 0; i < n; i++) {
        cin >> grid[i];
    }
    int answer = 0;
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < (1 << m); j++) {
            string t[n];
            for (int x = 0; x < n; x++) {
                t[x] = grid[x];
            }
            for (int x = 0; x < n; x++) {
                if ((i & (1 << x)) > 0) {
                    for (int y = 0; y < m; ++y) {
                        t[x][y] = '.';
                    }
                }
            }
            for (int x = 0; x < m; x++) {
                if ((j & (1 << x)) > 0) {
                    for (int y = 0; y < n; y++) {
                        t[y][x] = '.';
                    }
                }
            }
            int cnt = 0;
            for (int x = 0; x < n; x++) {
                for (int y = 0; y < m; y++) {
                    cnt += (t[x][y] == '#');
                }
            }
            if (cnt == k) {
                answer++;
            }
        }
    }
    cout << answer;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int count = 0;
  for(int i = 0; i < A+1; i ++){
    for(int j = 0; j < B+1; j ++){
      for(int k = 0; k < C+1; k ++){
        if(500 * i + 100 * j + 50 * k == X)
          count++;
      }
    }
  }
  cout << count << endl;
}

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

int main(void) {
	static const int target[5] = {5, 7, 5, 7, 7};
	int n;
	while (scanf("%d", &n) == 1 && n > 0) {
		int wlen[40];
		int i;
		char w[12];
		int start;
		for (i = 0; i < n; i++) {
			if (scanf("%s", w) != 1) return 1;
			wlen[i] = strlen(w);
		}
		for (start = 0; start < n; start++) {
			int ok = 0;
			int current_phase = 0;
			int current_num = 0;
			for (i = start; i < n; i++) {
				current_num += wlen[i];
				if (current_num > target[current_phase]) {
					break;
				} else if (current_num == target[current_phase]) {
					current_phase++;
					current_num = 0;
					if (current_phase == 5) {
						ok = 1;
						break;
					}
				}
			}
			if (ok) {
				printf("%d\n", start + 1);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int arr[1000];
int main()
{
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k)
	cout<<s<<endl;
	else
	{
		string s1="";
		for(int i=0;i<k;i++)
		cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3536
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
 
#define INF 1e9
#define LINF 1e18
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;


ll dp[100010][15];
int main(){
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i, n){
    rep(j, 13){
      if(s[i] == '?'){
        rep(k, 10){
          dp[i + 1][(10 * j + k) % 13] = (dp[i + 1][(10 * j + k) % 13] + dp[i][j]) % MOD;
          if(dp[i + 1][(10 * j + k) % 13] < 0)dp[i + 1][(10 * j + k) % 13] += MOD;
        }
      }
      else dp[i + 1][(10 * j + s[i] - '0') % 13] = (dp[i + 1][(10 * j + s[i] - '0') % 13] + dp[i][j]) % MOD;
      if(dp[i + 1][(10 * j + s[i] - '0') % 13] < 0)dp[i + 1][(10 * j + s[i] - '0') % 13] += MOD;
    }
  }

  cout << dp[n][5] << endl;
  /*
  rep(i, n + 1){
    rep(j, 13)cout << dp[i][j] << " ";
    cout << endl;
  }
  */
}
 

Measured memory_bytes: 15460
r1,c1,r2,c2=map(int, raw_input().split())

N=r2+c2+1
mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod

ans=0
for r in range(r1,r2+1):
    ans+=ncr(r+c2+1,r+1)-ncr(r+c1,r+1)
    ans%=mod

print ans


Measured memory_bytes: 132016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    string s; cin>>s;
    vector<int> zero,zero2;
    if(s.front()=='0')zero.push_back(0);
    rep(i,n-1){
        if(s.at(i)=='1' and s.at(i+1)=='0')zero.push_back(i+1);
        else if(s.at(i)=='0' and s.at(i+1)=='1')zero2.push_back(i);
    }
    if(s.back()=='0')zero2.push_back(n-1);
    if(zero.size()<=k){
        cout<<n<<endl;
        return 0;
    }
    int ans=0;
    for(int i=0; i+k<=zero.size(); i++){
        if(i==0){
            chmax(ans, zero.at(i+k));
        }else if(i+k==zero.size()){
            chmax(ans, n-zero2.at(i-1)-1);
        }else{
            chmax(ans, zero.at(i+k)-zero2.at(i-1)-1);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S,a,b,c,d;
  cin >> S;
  a=S/100;
  b=S-a*100;
  if(a<13 && 0<a) c=1;
  else if(12<a) c=2;
  else c=2;
  if(b<13 && 0<b) d=1;
  else if(12<b) d=2;
  else d=2;
  if(d==1&c==2) cout << "YYMM" << endl;
  else if(d==2&&c==1) cout << "MMYY" << endl;
  else if(c==1&&d==1) cout << "AMBIGUOUS" << endl;
  else if(c==2&&d==2) cout << "NA" << endl;
}  

Measured memory_bytes: 256
N,M = map(int,input().split())
H = list(map(int,input().split()))
li = ["○"]*N
count = 0
for i in range(M):
    A,B = map(int,input().split())
    A_height,B_height = H[A-1],H[B-1]
    if A_height>B_height:
        li[B-1] = "x"
    elif A_height<B_height:
        li[A-1] = "x"
    else:
        li[A-1] = "x"
        li[B-1] = "x"
print(li.count("○"))

Measured memory_bytes: 20116
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
#define MOD 1000000007
ll dp[100005];
ll RS(ll x,ll y,ll mod){
    if(y==0) return 1;
    else if(y&1) return x*RS(x,y-1,mod)%mod;
    else {
        ll p= RS(x,y/2,mod);
        return p*p%mod;
    }
}
int main(){
    ll n,k;
    cin >> n >> k;
    dp[1]=1;
    dp[2]=RS(2,n,MOD)-1;
    for(ll i=3; i<=k; i++){
        dp[i]=RS(i,n,MOD);
        for(ll j=2; j<=sqrt(i); j++){
            dp[i]-=dp[i/j];
            while(dp[i]<0) dp[i]+=MOD;
        }
        for(ll j=1;j<=i/((int)sqrt(i)/1+1);j++){
            dp[i]-=dp[j]*(i/j-i/(j+1));
            while(dp[i]<0) dp[i]+=MOD;
        }
    }
    ll ans=0;
    for(ll i=1; i<=k; i++){
        ans+=dp[k/i]*i;
        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4460
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N,x;
    int a[101]={};
    int dpmax[101]={};//最大値
    int dpama[101]={};//あまり
    cin>>N>>x;
    for(int i=1;i<=N;i++){
        cin>>a[i];
    }
    sort(a,a+N+1);
    dpmax[0]=0;
    dpama[0]=x;
    // cout<<"dp:"<<0<<" num:"<<dpmax[0]<<" ama:"<<dpama[0]<<endl;

    dpmax[1] = x>=a[1] ? 1 : 0 ;
    dpama[1] = x>=a[1] ? x-a[1] : x ;
    // cout<<"dp:"<<1<<" num:"<<dpmax[1]<<" ama:"<<dpama[1]<<endl;

    int jmax=0,amax=0,jnum=0;
    for(int i=2; i<=N ;i++){
        jmax=0;
        amax=0;
        for(int j=0; j<i ;j++){
            if(dpama[j]>=a[i]){
                // cout<<"t";
                if(jmax<dpmax[j]+1){
                    // cout<<"t";
                    jmax=dpmax[j]+1;
                    amax=dpama[j]-a[i];
                }else if(jmax==dpmax[j]+1){
                    if(amax<=dpama[j]-a[i]){
                        amax=dpama[j]-a[i];
                    }
                }else{
                    // cout<<"f";
                }
            }else{
                
                // // cout<<"f";
                if(jmax<dpmax[j]){
                //     // cout<<"t";
                    jmax=dpmax[j];
                    amax=dpama[j];
                }else if(jmax==dpmax[j]){
                    if(amax<dpama[j]){
                        amax=dpama[j];
                    }
                }else{
                //     // cout<<"f";
                }
            }
        }
        dpmax[i]=jmax;
        dpama[i]=amax;
        // cout<<"  dp:"<<i<<" num:"<<dpmax[i]<<" ama:"<<dpama[i]<<endl;
    }
    if(dpama[N]>0){
        if(dpmax[N]==N)dpmax[N]--;
        else ;
    }
    // cout<<"ans:"<<dpmax[N]<<endl;

    cout<<dpmax[N]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b) {
	return b?gcd(b,a%b):a;
}
int n,X,x;
int main() {
	scanf("%d%d",&n,&X);
	int ans=0;
	for(int i=1;i<=n;i++) {
		scanf("%d",&x);
		ans=gcd(ans,abs(X-x));
	}
	return !printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int sum1 = 0, sum2 = 0, a, b;
	scanf("%d %d", &a, &b);
	sum1 = a * b;
	sum2 = 2 * a + 2 * b;
	printf("%d %d\n", sum1, sum2);
	return 0;
}

Measured memory_bytes: 596
import java.util.*;


public class Main {
    public static void main(String args[]){
            Scanner sc = new Scanner(System.in);
           
            int n = sc.nextInt();
            int c = 0;
            int h = sc.nextInt();
            int w = sc.nextInt();
            int[] he = new int[n];
            int[] wi = new int[n];

            for (int i = 0; i < n; i++) {
                he[i] = sc.nextInt();
                wi[i] = sc.nextInt();
            }
            for (int i = 0; i < n; i++) {
                if (he[i] >= h && wi[i] >= w) {
                    c++;
                }
            }


            System.out.println(c);
            sc.close();
        }
    
}



Measured memory_bytes: 27748
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int N;
	vector<ll> times;
	
	cin>>N;

	REP(i,N){
		ll a;
		cin>>a;
		times.push_back(a);
	}
	
	sort(times.begin(),times.end());
	
	ll lc = times[0];
	for(int i = 1; i < N; i++){
		
		
		ll a = lc;
		ll b = times[i];
		ll r = 1;

		while(1){
			r = a % b;
			if(r == 0)break;
			a = b;
			b = r;
		}

		lc = lc *  (times[i] /  b);
	}
	
	cout<<lc<<endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n,a,c=0;
    cin >> n;
    vector <int> values;
    if(1>n || n>100)
        return 0;
    for(int i=0;i<n;i++){
        cin >> a;
        if(1>a || a>100)
            return 0;
        values.push_back(a);
    }
    for(int i=0;i<n;i=i+2){
            if(values[i]%2==1)
                c++;
    }
    cout << c;

    return 0;
}


Measured memory_bytes: 3532
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int f(int m){
	int used[11]={};
	while(m>0){
		int t=m%10;
		m/=10;
		used[t]=1;
	}
	if(used[3]&&used[5]&&used[7])return 1;
	return 0;
}

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

	int l=s.length();
	if(l<3){
		cout<<0<<endl;
		return 0;
	}
	int n=stoi(s),ans=0;
	cerr<<n<<endl;
	queue<int> tmp;
	FOR(i,1,10){
		tmp.push(0);
		FOR(j,0,i){
			queue<int> tmp2;
			while(tmp.size()){
				int m=tmp.front()*10;
				tmp.pop();
				FOR(k,0,3){
					if(k==0){
						tmp2.push(m+3);
					}else if(k==1){
						tmp2.push(m+5);
					}else{
						tmp2.push(m+7);
					}
				}
			}
			tmp=tmp2;
		}
		while(tmp.size()){
			int m=tmp.front();
			tmp.pop();
			if(!f(m))continue;
			if(m<=n){
				//cerr<<m<<endl;
				ans++;
			}
		}
	}
	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {
  
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  rep(i,A+1) rep(j,B+1) rep(k,C+1) {
    if (i * 500 + j * 100 + k * 50 == X) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<int> nums(n,0);
	for (int i = 1; i < n; i++) { cin >> nums[i]; nums[i]--; }
	vector<int> ans(n, 0);
	for (int i = 1; i < n; i++)ans[nums[i]]++;
	for (int i = 0; i < n; i++)cout << ans[i] << '\n';
}

Measured memory_bytes: 4780
#include <iostream>
using namespace std;
int main(void){
    string s,p;
    int i,j,k,len_s,len_p;
    cin >> s >> p;
    len_s=(int)s.length();
    len_p=(int)p.length();
    for(i=0;i<len_s;i++){
        if(s[i]==p[0]){
           for(j=0;j<len_p;j++){
               k=i+j;
               if(k>=len_s) k-=len_s;
               if(s[k]!=p[j]) break;
           }
        }
        if(j==len_p) break;
    }
    if(j==len_p) cout << "Yes" <<endl;
    else cout << "No" << endl;    
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define INF 1e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  ll T1,T2,A1,A2,B1,B2;
  cin>>T1>>T2>>A1>>A2>>B1>>B2;
  ll p=(A1-B1)*T1, q=(A2-B2)*T2;
  if(p>0){
    p*=(-1);
    q*=(-1);
  }
  if(p+q<0){
    cout<<"0"<<endl;
  }
  else if(p+q==0){
    cout<<"infinity"<<endl;
  }
  else{
    ll S,T;
    S=-p/(p+q);
    T=-p%(p+q);
    if(T==0){
      cout<<2*S<<endl;
    }
    else{
      cout<<2*S+1<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	int n;
	cin >> n;
	VEC nums(n);
	lint sum = 0;
	loop(i, n)
	{
		cin >> nums[i];
		sum += nums[i];
	}
	sort(nums.begin(), nums.end());
	cout << nums[0] << " " << nums[n - 1] << " " << sum << endl;
}


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	int count = 0;
	int ans = 0;
	for(int j=1;j<=n;j++){
		if(j%2==0){
			continue;
		}
		else{
			count = 0;
			for(int i=1;i<=n;i++){
				if(j%i == 0){
					count++;
				}
			}
		}
		if(count == 8){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {
				
		int N=sc.nextInt();
		int a[]=new int[N];
		long allsum=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			allsum+=a[i];
			
		}
		
		long tmp=0;
		long mae=0;
		
		long mae2=0;
		for(int i=0;i<N;i++) {
			if(allsum/2<mae+a[i]) {
				tmp=i;
				mae2=mae+a[i];
				break;
			}
			mae+=a[i];
		}
		//i to i-1
		long usiro=allsum-mae;
		long usiro2=allsum-mae2;
		p(Math.min(Math.abs(usiro-mae), Math.abs(usiro2-mae2)));
		
		
		
		
		
		
		
	}
	
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int32_t main() {
    int n; cin >> n;
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i ++) cin >> arr[i];
    int money = 1000;
    int ans = 1000;
    int stocks = 0;
    for(int i = 1; i < n; i ++) {
        if(arr[i] > arr[i-1]) {
            stocks = money/arr[i-1];
            money = money + ((stocks) * (arr[i] - arr[i-1]));
            ans = max(ans, money);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
# include <cstdio>
# include <cmath>

using namespace std;

const int MAX_N = 311;
const int MAX_M = 311;

int n, m, d;

int x[MAX_N * MAX_M], y[MAX_N * MAX_M];
int s[MAX_N * MAX_M];

int main ()
{
    int i, j, a;
    scanf ("%d%d%d", &n, &m, &d);
    for (i = 1; i <= n; i ++)
        for (j = 1; j <= m; j ++)
        {
            scanf ("%d", &a);
            x[a] = i;
            y[a] = j;
        }
    for (i = d + 1; i <= n * m; i ++)
        s[i] = s[i - d] + abs (x[i] - x[i - d]) + abs (y[i] - y[i - d]);
    int q, l, r;
    scanf ("%d", &q);
    while (q --)
    {
        scanf ("%d%d", &l, &r);
        printf ("%d\n", s[r] - s[l]);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int mink = 1;
	int maxk = 1;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] < a[mink]) mink = i;
		if (a[i] > a[maxk]) maxk = i;
	}
	vector<pair<int, int>> ans;
	if (abs(a[maxk]) <= abs(a[mink]))
	{
		for (int i = 1; i <= n; i++)
		{
			if (i == mink) continue;
			ans.emplace_back(mink, i);
		}
		for (int i = n - 1; i >= 1; i--)
			ans.emplace_back(i + 1, i);
	}
	else
	{
		for (int i = 1; i <= n; i++)
		{
			if (i == maxk) continue;
			ans.emplace_back(maxk, i);
		}
		for (int i = 1; i < n; i++)
			ans.emplace_back(i, i + 1);
	}
	printf("%d\n", ans.size());
	for (auto& p : ans)
		printf("%d %d\n", p.first, p.second);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;

int main(){
    int L;
    cin >> L;
    double ans = pow((double)L/3.0, 3.0);
    cout << fixed <<  ans << endl;
}


Measured memory_bytes: 384