akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

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

    int k;
    cin >> k;

    if(k % 2 == 0 || k % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }

    int a = 7, ten = 1, num = 1;
    while(a % k != 0) {
        ten *= 10;
        ten %= k;
        a += 7 * ten;
        a %= k;
        num++;
    }

    cout << num << endl;
}

Measured memory_bytes: 3664
#include <iostream>
using namespace std;
#pragma warning (disable: 4996)

const int BACKET = 300;
long long N, A[1 << 17], B[1 << 17], C[1 << 15], OKIMOCHI[1 << 15];

void init() {
	for (int i = 0; i <= N / BACKET; i++) OKIMOCHI[i] = 1;
}

void refresh(int pos) {
	for (int i = pos * BACKET; i < (pos + 1)*BACKET; i++) B[i] *= OKIMOCHI[pos];
	OKIMOCHI[pos] = 1;
	C[pos] = 0;
	for (int i = pos * BACKET; i < (pos + 1)*BACKET; i++) C[pos] += A[i] * B[i];
}

void add(int pos, long long x) {
	A[pos] += x;
	refresh(pos / BACKET);
}

void flip(int l, int r) {
	int c1 = (l / BACKET), c2 = (r / BACKET);
	if (c1 == c2) {
		refresh(c1);
		for (int i = l; i < r; i++) B[i] *= -1;
		refresh(c1);
	}
	else {
		refresh(c1);
		for (int i = l; i < (c1 + 1)*BACKET; i++) B[i] *= -1;
		refresh(c1);

		refresh(c2);
		for (int i = c2 * BACKET; i < r; i++) B[i] *= -1;
		refresh(c2);

		for (int i = c1 + 1; i < c2; i++) OKIMOCHI[i] *= -1;
	}
}

long long getsum() {
	long long T = 0;
	for (int i = 0; i <= N / BACKET; i++) T += OKIMOCHI[i] * C[i];
	return T;
}

long long K, Q, L[1 << 17], R[1 << 17];
bool flag = false;

int main() {
	scanf("%lld%lld%lld", &K, &N, &Q);
	B[0] = 1;
	for (int i = 1; i <= N; i++) {
		scanf("%lld", &A[i]);
		if (A[i] == 0) {
			flag ^= true;
			B[i] = B[i - 1] * -1;
		}
		else B[i] = B[i - 1];
	}
	init();
	for (int i = 0; i <= N / BACKET; i++) refresh(i);

	for (int i = 1; i <= Q; i++) {
		scanf("%lld%lld", &L[i], &R[i]);
		
		long long D1 = A[L[i]], D2 = A[R[i]];
		add(L[i], D2 - D1);
		add(R[i], D1 - D2);
		if (((D1 == 0) ^ (D2 == 0)) == true) {
			flip(L[i], R[i]);
		}

		long long S = getsum(); S %= K;
		if (S < 0) S += K;
		S = K + 1LL - S; if (S == K + 1LL) S -= K;
		if (flag == true) S *= -1;

		printf("%lld\n", S);
	}
	return 0;
}


Measured memory_bytes: 6060
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

int ans=0;
int n;

void dfs(ll a=0,int b=0){
    if(a>n)return;
    if(b==7)ans++;
    
     dfs(a*10+3,b|1);
     dfs(a*10+5,b|2);
     dfs(a*10+7,b|4);
}   


int main(){
    cin>>n;
    dfs(0,0);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = 1e9 + 7;

int main()
{
    int n;
    cin>> n;
    vector<vector<int> > dp(n);
    for(int i = 0; i < n; i++){
        for(int j =0; j < 3; j++){
            int c;
            cin>> c;
            dp[i].push_back(c);
        }
    }
    for(int i = 1; i < n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] += max(dp[i - 1][(j + 1)% 3], dp[i - 1][(j + 2)% 3]);
        }
    }
    cout<< max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
    return 0;
}


Measured memory_bytes: 5760
n = int(input())
nums = list(map(int,input().split(" ")))

index = 0
ans = 0
while index < len(nums):
    start = index
    while index + 1 < len(nums) and nums[index] >= nums[index+1]:
        index +=1
    ans = max(ans,index - start)
    index += 1
print(ans)


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

int main() {
    int d;cin>>d;
    vector<int> c(27);
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    vector<vector<int>> s(d+1,vector<int>(27));
    for(int i=1;i<=d;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
    vector<int> t(d+1);
    for(int i=1;i<=d;i++){
        cin>>t[i];
    }
    vector<int> last(27);
    int manzoku=0;
    for(int i=1;i<=d;i++){
        manzoku+=s[i][t[i]];
        last[t[i]]=i;
        int sum=0;
        for(int j=1;j<=26;j++){
            sum+=c[j]*(i-last[j]);
        }
        manzoku-=sum;
        cout<<manzoku<<endl;
    }
    for(int i=1;i<=d;i++){
        //cout<<t[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3604
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500+j*100+k*50==x:
        count+=1
      
    
print(count)

Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
 
int N;
 
void mk_one(int zc,int oc){
  if( zc%2 == 0 ){//0 is even
    for(int i=0;i<zc;i++) cout << 0 << endl;
    for(int i=0;i<oc;i++) cout << 1 << endl;
  } else {// 0 is odd
    for(int i=0;i<zc-1;i++) cout << 0 << endl;
    if( oc-- ) cout << 1 << endl;
    cout << 0 << endl;
    for(int i=0;i<oc;i++) cout << 1 << endl;
  }
}
 
void mk_one2(int zc,int oc,int a){
  if( zc%2 == 0 ){//0 is even
    for(int i=0;i<zc;i++) cout << 0 << endl;
    for(int i=0;i<oc;i++) cout << 1 << endl;
    cout << a << endl;
  } else {// 0 is odd
    for(int i=0;i<zc-1;i++) cout << 0 << endl;
    bool f = false;
    if( oc == 0 ){
      cout << a << endl;
      f = true;
    } else{
      cout << 1 << endl;
      oc--;
    }
    cout << 0 << endl;
    for(int i=0;i<oc;i++) cout << 1 << endl;
    if( !f ) cout << a << endl;
  }
}
 
void mk_A(int zc,int oc,const vector<int>& A){
  cout << A[0] << endl;
  mk_one(zc,oc);
}
 
void mk_A2(int zc,int oc,const vector<int>& A){
  cout << max(A[0],A[1]) << endl;
  mk_one2(zc,oc,min(A[0],A[1]));
}
 
void mk_large(int zc,int oc,vector<int> A){
  sort(A.begin(),A.end());
   
  int ga = -1;
  if( zc%2==1 && oc==0 ){
    ga = A[0];
    A.erase(A.begin());
  }
 
  int n = A.size();
  if( A[n-2] == 2 &&  A[n-1] == 3 ){ 
    swap(A[n-2],A[n-1]);
  }
 
  for(int i=0;i<n;i++) cout << A[i] << endl;
 
  if( ga == -1 ){
    mk_one(zc,oc);
  } else {
    mk_one2(zc,oc,ga);
  }
 
}
 
int main(){
  vector<int> A;
  int zc = 0,oc = 0;
  cin >> N;
  for(int i=0;i<N;i++){
    int x; cin >> x;
    if( x>1 ) A.push_back(x);
    else if( x == 1 ){
      oc++;
    } else
      zc++;
  }
 
  if( zc == N ){//ALL0
    for(int i=0;i<N;i++) cout << 0 << endl;
  } else if( A.size()==0 || (A.size() == 1 && zc%2==1 && oc==0) ){
    //??????1?????????
    if( A.size() == 0 ){//0 or 1 only
      mk_one(zc,oc);
    } else { // 0 or 1 and X
      mk_one2(zc,oc,A[0]);
    }
  } else if( (A.size()==1 && (oc>=1 || zc%2==0) ) ||
         (A.size()==2 && oc==0 && zc%2==1 ) ){
    //??????A[0or1]?????????
    if(A.size()==1 && (oc>=1 || zc%2==0) ){
      mk_A(zc,oc,A);
    } else {
      mk_A2(zc,oc,A);
    }
  } else {
    //??????????????????
    mk_large(zc,oc,A);
  }
   
   
 
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int half = (B - A) / 2;

    if (half < K) {
        for (int i = 0; i < B - A + 1; i++) {
            cout << A + i << endl;
        }
    }
    else {
        for (int i = 0; i < K; i++) {
            cout << A + i << endl;
        }
        for (int i = B - K + 1; i <= B; i++) {
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int A,B,C,D,E,F,maxw{},ms{};
	cin>>A>>B>>C>>D>>E>>F;
	double m{};
	for(int a=0;a<F;a+=100*A)
	for(int b=0;a+b<F;b+=100*B)
	for(int c=0;c+a+b<=F;c+=C)
	{
		if(100.*c/(a+b+c)>E)break;
		
		for(int d=0;a+b+c+d<=F;d+=D)
		{
			double co=100*(c+d);
			co/=(double)(a+b+c+d);
			if(co>m)
			{
				if((c+d)>((a+b)/100)*E)break;
				//cout<<"Fuck\n";
				m=co;
				maxw=a+b+c+d;
				ms=c+d;
			}
		}
	}
	if(!maxw)maxw=100*A;
	cout<<maxw<<" "<<ms;
	
	
}

Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<vector<int> > dp(m + 1, vector<int>(1 << n, INF));
  dp[0][0] = 0;
  REP(i, m) {
    int a, b; cin >> a >> b;
    int mask = 0;
    while (b--) {
      int c; cin >> c; --c;
      mask |= 1 << c;
    }
    REP(j, 1 << n) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i + 1][j | mask] = min(dp[i + 1][j | mask], dp[i][j] + a);
    }
  }
  cout << (dp[m][(1 << n) - 1] == INF ? -1 : dp[m][(1 << n) - 1]) << '\n';
  return 0;
}


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


signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i=0; i<n; i++) cin>>a[i];
    for (int i=0; i<n; i++) cin>>b[i];

    reverse(b.begin(), b.end());

    vector<int> visited(n);
    int k = -1;
    int want = 0;
    vector<int> eq;
    for (int i=0; i<n; i++){
        if (a[i]==b[i]){
            eq.push_back(i);
            k = a[i];
            visited[i] = 1;
            want++;
        }
    }

//    for (auto e:eq) cout<<e<<" ";
//    cout<<endl;

    vector<int> avail;
    int can = 0;
    for (int i=0; i<n; i++){
        if (!visited[i]){
            if (a[i]!=k and b[i]!=k){
                avail.push_back(i);
                can++;
            }
        }
    }

//    for (auto e:avail) cout<<e<<" ";
//    cout<<endl;



    if (can>=want){
        for (int i=0; i<(int)eq.size(); i++){
            swap(b[avail[i]], b[eq[i]]);
        }
        cout<<"Yes"<<endl;
        for (int i=0; i<n; i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 10552
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll n,m;
char S[N],T[N];

int main(){
	scanf("%lld%lld",&n,&m);
	scanf("%s%s",S+1,T+1);
	ll l=n*m/__gcd(n,m),x=l/n,y=l/m,p=x*y/__gcd(x,y),k1=p/x,k2=p/y;
	for (int i=1,j=1; i<=n && j<=m; i+=k1,j+=k2)
		if (S[i]!=T[j]){ puts("-1"); return 0; }
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1000000007;
typedef pair<ll,ll> P;

ll N;
ll A[100001];
ll sum[100001];

int main(){
    cin>>N;
    repn(i,N) cin>>A[i];

    sort(A+1,A+N+1);

    repn(i,N) sum[i]=sum[i-1]+A[i];

    ll ans=1;
    repn(i,N-1){
        if(A[N-i+1]<=2*sum[N-i]) ans++;
        else break;
    }

    cout<<ans<<endl;
}

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


int main(){
  int N;
  cin >> N;
  vector<int> monster(N+1);
  for (int i=0; i < (N+1); i++)
    cin >> monster.at(i);
  
  long long count = 0;
  for(int i=0; i<N; i++){
    int A = monster.at(i);
    int B;
    cin >> B;
    int left = min(A, B);
    count += left;
    A -= left;
    B -= left;
    int right = min(monster.at(i+1), B);
    count += right;
    monster.at(i+1) -= right;
    B -= right;
  }
  /*for(int i=0; i < N; i++){
    int A = monster.at(i);
    int B;
    cin >> B;
    if(A >= B){
      count += B;
    }
    else{
      count += A;
      int Brest = B - A;
      int A2 = monster.at(i+1);
      if (A2 >= Brest){
        count += Brest;
        A2 -= Brest;
      }
      else{
        count += A2;
        A2 = 0;
      }
    }
  }*/
  
  cout << count << endl;
  
 
}


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

const int M = 1e5+10;
int a[M];

int main()
{
	int m;
	cin>>m;
	for(int i=0;i<m;i++)
		cin>>a[i];
	sort(a,a+m);
	int cnt=0;
	a[m] = a[0]-1;
	for(int i=0;i<m;i++)
		if(a[i] != a[i+1])
			cnt++;
		else
			i++;
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        string s;cin>>s;
        int n=sz(s);
        rep(i,n){
            if(s[i]=='?')s[i]='D';
        }
        cout<<s;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    vector<char> alph = {'M', 'A', 'R', 'C', 'H'};

    map<char, ll> mp;
    rep(i,n){
        mp[s[i][0]]++;
    }

    ll ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            for(int k = j+1; k < 5; k++){
                ans += mp[alph[i]] * mp[alph[j]] * mp[alph[k]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6364
#include <stdio.h>

int main() {
	
	int a;
	int b;
	int c;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	int ispoor = 0;
	
	if(a == b && b != c) ispoor = 1;
	if(b == c && c != a) ispoor = 1;
	if(c == a && a != b) ispoor = 1;
	
	if(ispoor){
		puts("Yes");
	}else{
		puts("No");
	}
	
  return 0;
}

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

int main(){

    string s; cin >> s;
    int d = 0;
    int ans = (int)s.size();
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == 'S'){
            d++;
        }else{
            if(d > 0) ans -= 2;
            d = max(0, d - 1);
        }
    }

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

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

int main() {
  int h,w; std::cin >> h >> w;
  vector<vector<char>> ans(h+2,vector<char>(w+2,'#'));
  for (int i = 1; i < h+1; i++) {
    for (int j = 1; j < w+1; j++) {
      cin >> ans.at(i).at(j);
    }
  }
  for (int i = 0; i < h+2; i++) {
    for (int j = 0; j < w+2; j++) {
      std::cout << ans.at(i).at(j);
      if (j==w+1) {
        std::cout <<'\n';
      }
    }
  }
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	string s;
	cin >> s;

	int acc = 0;

	for (char x: s)
		acc = (acc + x-'0') % 9;

	cout << (acc ? "No" : "Yes");

	return 0;
} 

Measured memory_bytes: 3748
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = getInt(sc);
		int[] p = getIntArray(sc);

		int count = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int pi = p[i];

			min = Math.min(min, pi);

			if (pi <= min) {
				count++;
			}
		}
		System.out.println(count);

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	long x;
	long tmpCoins;

	public Status(long x, long tmpCoins) {
		this.x = x;
		this.tmpCoins = tmpCoins;
	}
}


Measured memory_bytes: 57260
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main() {
    ll n,m;
    cin >> n >> m;
    if(abs(n-m) >= 2){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for (ll i = 1; i <= m;i++){
        ans = ans*i%mod;
    }
    for (ll i = 1; i <= n;i++){
        ans = ans*i%mod;
    }

    if(abs(n-m) == 1){
        cout << ans << endl;
        return 0;
    }else{
        cout << 2*ans%mod << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll amari_pow[(int)2e5];
void func(){
  amari_pow[0] = 1;
  REP(i,1,(int)1e5+7){
    amari_pow[i] = amari_pow[i-1] * 10 % 13;
  }
}
int main(){
  string s;
  cin >> s;
  ll length = s.size();
  ll ans[(int)2e5][13];
  memset(ans,0,sizeof(ans));
  func();
  ll sum = 0;
  ans[0][0] = 1;
  rep(i,length){
    if(s[i] == '?'){
      rep(j,13){
        rep(k,10){
          ans[i+1][(k* amari_pow[length-1-i] + j) % 13] += ans[i][j];
          ans[i+1][(k* amari_pow[length-1-i] + j) % 13] %=mod;
        }
      }
    }else{
      rep(j,13){
        ans[i+1][((s[i] - '0') * amari_pow[length-1-i] + j)%13] = ans[i][j];
        ans[i+1][((s[i] - '0') * amari_pow[length-1-i] + j)%13] %= mod;

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


Measured memory_bytes: 21504
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

void init()
{
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;

    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key)
{
    Node *cur = nil->next;
    while(cur != nil && cur->key != key)
        cur = cur->next;

    return cur;
}

void deleteNode(Node *t)
{
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void deleteKey(int key)
{
    deleteNode(listSearch(key));
}

int main(void)
{
    int n;
    char command[20];
    int k;

    init();

    cin >> n;
    for(int i = 0; i < n; i++)
    {
        scanf("%s %d", command, &k);
        if(command[0] == 'i')
            insert(k);
        else if(command[0] == 'd' &&  command[6] == 'F')
            deleteFirst();
        else if(command[0] == 'd' &&  command[6] == 'L')
            deleteLast();
        else if(command[0] == 'd')
            deleteKey(k);
        else
            cout << "Error: unknown command." << endl;
    }

    Node *cur = nil->next;
    cout << cur->key;
    cur = cur->next;
    while(cur != nil)
    {
        cout << " " << cur->key;
        cur = cur->next;
    }
    cout << endl;

    return 0;
}

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

using namespace std;

int vacation[100001][3];
int answer[100001][2];

int main(void)
{
	int n;
	cin>>n;
	int a[n], b[n], c[n];

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

	int dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];

	for(int i=1; i<n; i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0], dp[i-1][1]);
	}

	int result;
	result = max(dp[n-1][0],dp[n-1][1]);
	result = max(dp[n-1][2], result);
	cout<<result<<"\n";
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>

using namespace std;
typedef long long ll;

int main() {
	int N; cin >> N;
	vector<float> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v.begin(), v.end());
	for (int i = 0; i < N - 1; i++) {
		v[i + 1] = (v[i] + v[i + 1]) / 2;
	}
	cout << v[N - 1] << endl;
}


Measured memory_bytes: 3800
#include <stdio.h>

int main()
{
	int A, B;
	char op;
	scanf("%d %c %d", &A, &op, &B);
	if (op == '+') printf("%d\n", A + B);
	else printf("%d\n", A - B);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1724
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class UnionFind {
private:
	//ノードの数
	int size = 0;

	//ノードの親(根は自分自身)
	vector<int> par;

	//ノードの深さ(0～size)
	vector<int> rank;

	//キー値を入れる(必須ではない)
	vector<int> key;

public:
	vector<int> num;

public:
	//サイズを指定し、UnionFind木を作成し、init() を呼ぶ
	UnionFind(int V, int K = 0);

	//UnionFind木を初期化する(全てを分解する)
	void init();

	int get_size(int x);

	//ノードが属する部分木の根を求める
	int find(int x);

	//二つの部分木を合体する
	void unite(int x, int y);

	//二つのノードが同じ部分木に属しているか調べる
	bool same(int x, int y);

	//キー値をセットする
	void set_key(int index, int x);

	//キー値を取得する
	int get_key(int index);

	//デバッグ用
	void debug();
};

UnionFind::UnionFind(int V, int K) {
	if (V < 0) { V = 0; }
	size = V;
	par = vector<int>(V);
	rank = vector<int>(V);
	key = vector<int>(V, K);
	num = vector<int>(V, 1);
	init();
}

void UnionFind::init() {
	for (int i = 0; i < size; i++) {
		par[i] = i;
		rank[i] = 0;
		key[i] = 0;
		num[i] = 1;
	}
}

int UnionFind::find(int x) {
	//cout << "x = " << x << endl;
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void UnionFind::unite(int x, int y) {
	//cout << "x = " << x << " y = " << y << endl;
	x = find(x);
	y = find(y);
	if (x == y) { return; }
	int xs = num[x];
	int ys = num[y];
	num[x] += ys;
	num[y] += xs;
	if (rank[x] < rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank[x] == rank[y]) { rank[x]++; }
	}
}

int UnionFind::get_size(int x) {
	int n = find(x);
	return num[n];
}

bool UnionFind::same(int x, int y) {
	return find(x) == find(y);
}

void UnionFind::set_key(int index, int x) {
	key[index] = x;
}

int UnionFind::get_key(int index) {
	return key[index];
}

void UnionFind::debug() {
	cout << "UnionFindTree:" << endl;
	cout << "size = " << size << endl;
	for (int i = 0; i < size; i++) {
		cout << i << "番ノード:" << flush;
		cout << "値:" << get_key(i) << flush;
		cout << "親:" << find(i) << endl;
	}
}

int N, M, K;

int main() {
	cin >> N >> M >> K;
	UnionFind tree(N);
	vector<int> sum(N, 0);//各ユーザーの友好関係やブロック関係の数
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		sum[A]++; sum[B]++;
		tree.unite(A, B);
	}
	for (int i = 0; i < K; i++) {
		int C, D;
		cin >> C >> D;
		C--; D--;
		if (tree.same(C, D)) {
			sum[C]++;
			sum[D]++;
		}
	}
	for (int i = 0; i < N; i++) {
		//cout << i+1 << "人目" << endl;
		//cout << tree.get_size(i) << endl;
		//cout << sum[i] << endl;
		int ans = max(0, tree.get_size(i) - sum[i] - 1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 2816
n = int(input())
xy = [[]  for _ in range(n)]
ans = 0

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        xy[i].append(tuple([x - 1, y]))

for j in range(2 ** n):
    flag = True
    count = 0
    for k in range(n):
        if j >> k & 1 == 1:
            count += 1
            for x, y in xy[k]:
                if y == 0 and j >> x & 1 == 1: 
                    flag = False
                if y == 1 and j >> x & 1 == 0:
                    flag = False
    if flag == True:
        ans = max(count, ans)

print(ans)


Measured memory_bytes: 43884
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi mi(N),ma(N);
  rep(i,N) {
    cin >> mi[i] >> ma[i];
  }
  sort(rng(mi));
  sort(rng(ma));
  int a,b;
  if(N&1) {
    a = mi[N/2];
    b = ma[N/2];
  } else {
    a = mi[(N-1)/2]+mi[N/2];
    b = ma[(N-1)/2]+ma[N/2];
  }
  cout << (b-a+1) << endl;
  return 0;
}

Measured memory_bytes: 4796
import java.util.Scanner;
public class Main
{

	public static void main (String arg[]) {
		Scanner scan = new Scanner(System.in);
		double a = scan.nextDouble();
		double b = scan.nextDouble();
		scan.close();
		int su = waru((int)a,(int)b);
		int su2 = amari((int)a,(int)b);
		double su3 = kakeru(a,b);
		System.out.print(su+" "+su2+" ");
		System.out.printf("%5.5f",su3);


	}
	static int waru(int a,int b){
		int kekka = a / b;
		return kekka;
	}

	static int amari(int a,int b){
		int kekka = a % b;
		return kekka;
	}
	static double kakeru(double a,double b){//浮動小数点演算
		double kekka = a / b;
		return kekka;
	}

}


Measured memory_bytes: 28176
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); int A = sc.nextInt(); int B = sc.nextInt();
		int ans = 0;
		for(int i=1; i<=N; i++) {
			int tmp = i;
			int sum = 0;
			while(tmp>0) {
				sum += tmp % 10;
				tmp /= 10;
			}
			if(A<=sum&&sum<=B) ans+=i;
		}
		System.out.println(ans);
	}
	
	static int binarySearch(int[] A, int x) {
		int l = 0;
		int r = A.length;
		while(l<r) {
			int mid = (l+r)/2;
			if(A[mid] == x) return mid;
			else if(x<A[mid]) r = mid;
			else l = mid+1;
		}
		return -1;
	}
	
	static long upper_bound(int[] A, int b) {
		// bよりおおきい値がはじめて出てくるindexを返す
		return lower_bound(A, b+1);
	}

	static long lower_bound(int[] A, int b) {
		// b以上の値がはじめて出てくるindexを返す
		int lb=0;
		int ub=A.length;
		while(ub>lb) {
			int mid = (lb+ub)/2;
			if(A[mid]>=b) ub = mid;
			else lb = mid+1;
		}
		return lb;
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

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

int main(){
    int n;
    cin >> n;
    char c[n];
    rep(i, n) cin >> c[i];
    int cnt = 0, j = 0;
    while(j < n){
        char t = c[j];
        if(t == c[j])
            j++;
        if(t != c[j]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n, m, c;
ll b[500];
ll ans = 0;

int main()
{
    cin >> n >> m >> c;
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int i = 0; i < n; i++)
    {
        long long summ = 0;
        for (int j = 0; j < m; j++)
        {
            ll a;
            cin >> a;
            summ += a * b[j];
        }
        summ += c;
        if (summ > 0) ans++;
    }
    cout << ans;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
	int x; cin >> x;
	cout << 360 / __gcd(360, x) << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define s second
#define f first
long long const mod = pow(2,32);
#define inf 1000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}


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

    string s;
    cin>>s;
    ll n=s.length();
    bool f=true;
    for(ll i=0,j=n/2-1;i<=j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            f=false;
        }
    }
    if(f==true)
    {
        for(ll i=0,j=n-1;i<=j;i++,j--)
        {
            if(s[i]!=s[j])
            {
                f=false;
            }
        }
    }
    if(f)
        cout<<"Yes\n";
    else
    {
        cout<<"No\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())

ANS = [0] * (n+1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            tmp = (x + y + z)**2 - z*(x + y) - (x*y)
            if tmp > n: continue
            ANS[tmp] += 1

for ans in ANS[1:]:
    print(ans)

Measured memory_bytes: 9188
#include<iostream>
using namespace std;
int main()
{
  int k,x;
  std::cin>>k>>x;
  int start=x-k+1;
  int end=x+k-1;
  if(start<-1000000)
    start=-1000000;
  if(end>1000000)
    end=1000000;
  int i;
  for(i=start;i<=end;i++)
    std::cout<<i<<" ";
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		int[] A=new int[N];
		for (int i=0;i<N;++i) {
			A[i]=sc.nextInt();
		}
		Arrays.sort(A);
		boolean[] fail=new boolean[(int)1e6+1];
		Arrays.fill(fail, false);
		for (int i=0;i+1<N;++i) {
			if (A[i]==A[i+1]) fail[A[i]]=true;
		}
		for (int i=0;i<N;++i) {
			if (i+1<N && A[i+1]==A[i]) continue;
			for (int cur=2*A[i];cur<fail.length;cur+=A[i]) {
				fail[cur]=true;
			}
		}
		int ans=0;
		for (int i=0;i<N;++i) {
			if (!fail[A[i]]) {
				++ans;
			}
		}
		System.out.println(ans);
	}

	void tr(Object...o) {System.out.println(Arrays.deepToString(o));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
        	ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 43784
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         1000000007
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll l,r,i,j,mi=mod,p,q,x,flag=0,y;
    cin>>l>>r;
    x=l;
    y=r;
    l=l%2019;
    r=r%2019;
    for(i=l;i<=r;i++){
        for(j=l;j<=r;j++){
            if(i!=j){
                mi=min(mi,(i*j)%2019);   
            }
        }
    }
    for(i=x;i<=y;i++){
        if(i%2019==0){
            flag=1;
            cout<<0;
            break;
        }
    }
    if(flag==0){
        cout<<mi;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
    long n = 0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {n=(n<<1)+(n<<3)+c-'0'; c=getchar_unlocked();}
    long ans = 0;
    ++n;
    int u, v, i = 1;
    while(++i < n)
    {
        u = v = 0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {u=(u<<1)+(u<<3)+c-'0'; c=getchar_unlocked();}
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {v=(v<<1)+(v<<3)+c-'0'; c=getchar_unlocked();}
        switch(u > v)
        {
            case 1: ans -= v * (n - u); break;
            default: ans -= u * (n - v);
        }
    }
    printf("%ld", (n * n * (n + 1) >> 1) - (n * (n + 1) * ((n << 1) + 1) / 6) + ans);
    return 0;
}


Measured memory_bytes: 1604
#include<iostream>

int main(){
    int a,b;
    std::cin>>a>>b;
    
    std::cout<<"a ";
    if(a<b){
        std::cout<<"<";
    }
    else if(a>b){
        std::cout<<">";
    }
    else{
        std::cout<<"==";
    }
    std::cout<<" b"<<std::endl;
    
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double t     = 60 * h + m;
  double angle = M_PI * abs(m / 30 - t / 360);
  double ans   = sqrt(a * a + b * b - 2 * a * b * cos(angle));
  printf("%.16f\n", ans);
  return 0;
}


Measured memory_bytes: 4200
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define N 210
#define inf 1000000000
typedef struct
{
    int u,w,next;
}Node;
Node e[N*N*2];
int head[N],n,m,t,tot,sum;
int s[N][N],dis[N],vis[N],a[N];
void add(int u,int v,int w)
{
    e[tot].u=v;
    e[tot].w=w;
    e[tot].next=head[u];
    head[u]=tot;
    tot++;
}
void Spfa(int x)
{
    int i,j,k,l;
    queue<int> q;
    for(i=1;i<=n;i++)
    dis[i]=inf;
    memset(vis,0,sizeof(vis));
    dis[x]=0;
    vis[x]=1;
    q.push(x);
    while(!q.empty())
    {
        k=q.front();
        q.pop();
        vis[k]=0;
        for(i=head[k];i!=-1;i=e[i].next)
        {
            j=e[i].u;
            l=e[i].w;
            if(dis[j]>dis[k]+l)
            {
                dis[j]=dis[k]+l;
                if(vis[j]==0)
                {
                    vis[j]=1;
                    q.push(j);
                }
            }
        }
    }

}
void dfs(int x,int y,int z)
{
    int i,j,k;
    if(y==t)
    {
        sum=min(sum,z);
        return;
    }
    for(i=0;i<t;i++)
    {
        if(vis[i]==0)
        {
            vis[i]=1;
            dfs(i,y+1,z+s[x][i]);
            vis[i]=0;
        }
    }
}
int main()
{
    int i,j,x,y,z;
    scanf("%d%d%d",&n,&m,&t);
    for(i=0;i<t;i++)
    scanf("%d",&a[i]);
    tot=0;
    memset(head,-1,sizeof(head));
    for(i=0;i<m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        add(x,y,z);
        add(y,x,z);
    }
    for(i=0;i<t;i++)
    {
        Spfa(a[i]);
        for(j=0;j<t;j++)
        s[i][j]=dis[a[j]];
    }
    sum=inf;
    for(i=0;i<t;i++)
    {
        memset(vis,0,sizeof(vis));
        vis[i]=1;
        dfs(i,1,0);
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 768
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200, mod = 1e9 + 7;

int d[N][2], n;
vector <int> g[N];

void dfs(int v, int p = -1){
	int list = 1;
	for (auto to: g[v]){
		if (to != p){
			dfs(to, v);
		}
	}
	d[v][1] = d[v][0] = 1;
	for (auto to: g[v]){
		if (to != p){
			(d[v][1] *= (d[to][1] + d[to][0]) % mod) %= mod;
			(d[v][0] *= d[to][1]) %= mod;
		}
	}
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1);	
	cout << (d[1][0] + d[1][1]) % mod;
	return 0;
}












Measured memory_bytes: 17536
import numpy as np
import math
s = input().split()
N = int(s[0])
A = int(s[1])
B = int(s[2])

x = int(N/(A+B))
if N-x*(A+B)>=A:
  print(x*A+A)
else:
  print(x*A+N-x*(A+B))


Measured memory_bytes: 12424
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
 if(n<2){cout<<1<<endl;}
else if (n<4){cout<<2<<endl;}
  else if (n<8){cout<<4<<endl;}
  else if (n<16){cout<<8<<endl;}
  else if (n<32){cout<<16<<endl;}
  else if (n<64){cout<<32<<endl;}
  else if (n<=100){cout<<64<<endl;}
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    int n, k; cin >> n >> k;
    if(k == 1) cout << 0 << endl;
    else if(0 < n - k) cout << n - k << endl;
    else cout << 0 << endl;


    return 0;
}


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

int main() {
  long long int n,a,b;
  cin>>n>>a>>b;
  if((b-a)%2==0){
    cout<<min((b-a)/2,min(b-1,n-a))<<endl;
    return 0;
  }
  if(a==1||b==n){
    cout<<(b-a+1)/2<<endl;
    return 0;
  }
  cout<<min(a-1,n-b)+(b-a+1)/2<<endl;
}

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

using namespace std;

typedef vector<int> vint;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin() (x).end()
#define pb push_back

int n,q;
vint s,t;

bool bsearch(int x) {
    int l = -1, r = n;
    while(l < r) {
        int mid = (l + r) / 2;
        if(s[mid] == x)
            return true;
        else if(x < s[mid])
            r = mid;
        else
            l = mid + 1;
    }
    return false;
}

int main() {
    cin>>n;
    rep(i,n) {
        int a; scanf("%d",&a);
        s.push_back(a);
    }
    cin>>q;
    rep(i,q) {
        int a; scanf("%d",&a);
        t.push_back(a);
    }

    sort(s.begin(), s.end());

    int ans = 0;
    rep(i,q) {
        if(bsearch(t[i])) ans++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1856