akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main() {
  int i;
  long long int number_of_people, total_time = 0, min = 1000000000000000;
  long long int temp[6];
  scanf("%lld", &number_of_people);
  for(i = 0; i < 5; i++) {
    scanf("%lld", &temp[i]);
    if(min > temp[i])
      min = temp[i];
  }
  total_time = (number_of_people % min == 0)? (number_of_people / min + 4) : (number_of_people / min + 5);
  printf("%lld\n", total_time);
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))


ans = 1
flag = 0
for i in a:
    ans *= i
    if ans > 10**18:
        flag = 1
        ans = 0
    if i == 0:
        print(0)
        exit()
if flag == 1:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

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

int main(){
  int N;
  ll X;
  cin >> N >> X;
  ll x[N+1];
  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  x[N]=X;
  sort(x,x+N+1);
  ll p = x[1]-x[0];
  for(int j=1;j<N;j++){
    ll sub = x[j+1]-x[j];
    p = gcd(sub,p);
  }
  cout << p << endl;
}


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

int main() {
  string s;
  cin >> s;
  string previous;
  string now;
  int total = 0;
  for(int i=0;i<s.size();i++) {
    now += s[i];
    if(now == previous) continue;
    else {
      total++;
      previous = now;
      now = "";
    }
  }

  cout << total << endl;
}

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

typedef long long ll;
typedef int64_t i6;

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

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

int main() {
    ll h, w, n;
    cin >> h >> w >> n;
    if ( h < w ) {
        if ( n%w == 0 ) {
            // cout << "a" << endl;
            cout << n/w << endl;
        } else {
            // cout << "b" << endl;
            cout << (n/w)+ 1 << endl;
        }
    } else {
        if ( n%h == 0 ) {
            // cout << "c" << endl;
            cout << n/h << endl;
        } else {
            // cout << "d" << endl;
            cout << (n/h)+ 1 << endl;
        }
    }
    return 0;
}


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

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

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

	int ans=0,cnt=0;
	for (int i = 0; i < s.size(); ++i){
		if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){
			cnt++;
			ans=max(ans,cnt);
		}else{
			cnt=0;
		}
	}
	ans=max(ans,cnt);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;


template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

const ll INF = 1e18;


int a[300010];
int L[300010], R[300010];

signed main() {
    int n;
    while (cin >> n && n) {
        rep(i, n+n+n) {
            cin >> a[i];
        }

        {
            priority_queue<int> q;
            int s = 0;
            rep(i, n*3) {
                s += a[i];
                q.push(-a[i]);
                if ((int)q.size() > n) {
                    int x = -q.top();
                    q.pop();
                    s -= x;
                }
                L[i] = s;
            }
        }
        {
            priority_queue<int> q;
            int s = 0;
            rrep(i, n*3) {
                s += a[i];
                q.push(a[i]);
                if ((int)q.size() > n) {
                    int x = q.top();
                    q.pop();
                    s -= x;
                }
                R[i] = s;
            }
        }

        int ans = -INF;
        rep(i, n*3) {
            if (n-1 <= i && i < n+n) {
                dump(L[i], R[i+1]);
                ans = max(ans, L[i] - R[i+1]);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 9076
N = int(input())
NUM = list(map(int,input().split()))
MAX = max(NUM)
MIN = min(NUM)
COSTLIST = []
for i in range (MIN,MAX+1):
    COST = 0
    for j in NUM:
        COST += (j-i)**2
    COSTLIST.append(COST)
MINIMUM = min(COSTLIST)

print(MINIMUM)


Measured memory_bytes: 3060
n,qq=gets.split.map(&:to_i)
if n==1
  puts qq
  exit
end
a=1
i=2
q=qq
while q>1&&i**2<=qq
  c=0
  while q%i==0
    q/=i
    c+=1
  end
  a*=i**(c/n) if c>0
  i+=1
end
puts a


Measured memory_bytes: 14340
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sum=0
for i in range(n-1):
    x=B[i]-A[i]
    if x>0:
        if A[i+1]-(x)<0:
            
       #     print(A[i]+A[i+1])
            sum+=A[i]+A[i+1]
            A[i+1]=0
        else:
            A[i+1]+=-(x)
      #      print(B[i])
            sum+=B[i]
    else:
     #   print(B[i])
        sum+=B[i]

if B[n-1]<A[n-1]+A[n]:
    #print(B[n-1])
    sum+=B[n-1]
else:
    #print(A[n-1]+A[n])
    sum+=A[n-1]+A[n]
print(sum)


Measured memory_bytes: 19000
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

//return x's divisor as vector
vector<ll> divisor(ll x){
  vector<ll> res;
  for(ll i=1;i*i<=x;++i){
    if(x%i==0){
      res.push_back(i);
      if(i!=x/i){
	res.push_back(x/i);
      }
    }
  }
  sort(res.begin(), res.end());
  return res;
}



int main()
{
  ll n,k;cin >> n >> k;
  vector<mint> res(k+1);
  mint ans;
  for(ll i = k; i > 0;--i) {
    mint tmp;
    ll x = k / i;
    mint mx = (mint)x;
    tmp += mx.pow(n);
    res[i] += tmp;
    vector<ll> div = divisor(i);
    rep(j,div.size()) {
      if(div[j] == i) continue;
      res[div[j]] -= res[i];
    }
    // rep(j,p.size() ) {
    //   ll y = i * p[j];
    //   if(y > k) break;
    //   ll z = k / y;
    //   mint mz = (mint)z;
    //   tmp -= mz.pow(n);
    // }
    // res += (mint)i * tmp;
    ans += res[i] * (mint)i;
  }

  // rep1(i,k) {
  //   cout << i << ":" << res[i].x << "\n";
  // }
   cout << ans.x << "\n";
  return 0;
}


Measured memory_bytes: 4000
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r<0||x+r>W||y-r<0||y+r>H){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cmath>
using namespace std;

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

	int price = (A * X) + (B * Y);

	int mixX = X * 2 * C;
	int mixY = Y * 2 * C;
	if (X > Y) {
		int mod = (X - Y) * A;
		cout << min(mixX, min(mixY + mod, price));
	}
	else {
		int mod = (Y - X) * B;
		cout << min(mixY, min(mixX + mod, price));
	}

	return 0;
}

Measured memory_bytes: 256
main = do
 getLine
 ts <- map read . words <$> getLine
 getLine
 pxs <- map (map read . words) . lines <$> getContents
 let tsum = sum ts
 mapM_ (print . drink tsum ts) pxs

drink tsum ts [p,x] = tsum + (x - ts!!(p-1))

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define INF 1LL<<30
#define MAXN 1000002
#define pb push_back
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
#define fst first
#define snd second
#define B 127
#define endl '\n'
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
string T;
string P;
int b[MAXN];
int n,m;
void kmpPreprocess(){
    int i = 0, j = -1;
    b[0] = -1;
    while(i < m){
        while(j >= 0 && P[i] != P[j]) j = b[j];
        i++,j++;
        b[i] = j;
    }
}
void kmpSearch(){
    int i = 0,j = 0;
    while(i < n){
        while(j>=0 && T[i] != P[j]) j = b[j];
        i++,j++;
        if(j == m){
            cout << i - j << endl;
        }
    }
}
int main(){
    optimizar_io;
    cin >> T;
    cin >> P;
    n = T.size();
    m = P.size();
    kmpPreprocess();
    kmpSearch();



    return 0;

}



Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
  string s; cin >> s;
  if(s.size() == 2) cout << s << endl;
  else reverse(ALL(s)), cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin>>n>>m,n+m){
    map<ll,ll>hoge;
    for(int i=0;i<n;i++){
      ll d,v;cin>>d>>v;
      hoge[d] = max(hoge[d],v);
    }
    ll ans=0;
    for(auto a:hoge)
      ans += a.S;
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

ll calc2(const vector<int>& t, int d1, int d2){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d1 && i!=d2){
      res += s[i][t[i]];
      lst[t[i]] = i;
    }
    else if(i==d1){
      res += s[i][t[d2]];
      lst[t[d2]]=i;
    }
    else if(i==d2){
      res += s[i][t[d1]];
      lst[t[d1]]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);


  rep(d,D){
    int m=0;
    rep(x,26){
      if(chmax(m,s[d][x])) t[d]=x;
    }
  }
  ll now = calc(t,-1,-1);
  while(1){
    int d1=mt()%365, d2=mt()%365, q=mt()%26;
    int flag = mt()&1;
    if(flag){
      if(chmax(now,calc(t,d1,q))){
        t[d1]=q;
      }
    }
    else{
      if(d1!=d2) {
        if(chmax(now,calc2(t,d1,d2))){
          int tmp = t[d1];
          t[d1]=t[d2];
          t[d2]=tmp;
        }
      }
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3704
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int k, s;
	cin >> k >> s;

	int cnt = 0;
	
	REP(i, k + 1) {
		REP(j, k + 1) {
			int v = s - (i + j);
			if (v <= k && 0 <= v) cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
    int n;
    cin >> n;
    
        if(n == 0)  break;
    vector<int> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    
    sort(a.begin(),a.end());
    
    int min, d;
    min = 1000000;
    
    for(int i=0; i<n-1; i++){
        d = (a.at(i) - a.at(i+1) > 0 ? a.at(i)-a.at(i+1):a.at(i+1)-a.at(i));
        if(min > d) min = d;
    }
    
    cout << min << endl;
    }
}



Measured memory_bytes: 3032
h,w  = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
res = []
for _ in range(h):
    res.append([])
line = 0

def insert(res,i,l):
    if l %2 == 0:
        res[l].append(str(i+1))
    else:
        res[l].insert(0,str(i+1))

for i in range(0,n):
    ammount=a[i]
    while len(res[line]) < w and ammount > 0:
        insert(res,i,line)
        ammount -= 1
    if len(res[line]) == w:
        line += 1
    while ammount >= w:
        res[line] = [str(i+1) for _ in range(w)]
        ammount -= w
        line += 1
    if ammount > 0:
        res[line] = [str(i+1) for _ in range(ammount)]

for i in range(0,h):
    print(' '.join(res[i]))

Measured memory_bytes: 3700
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, a[20020], b[20020], p;

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> p;
        a[i] += 30000ll * (i + 1);
        b[i] += 30000ll * (N - i);
        a[p - 1] += i;
    }
    for(int i = 0; i < N; i++){
        printf("%lld", a[i]);
        if(N - 1 > i)printf(" ");
    }
    printf("\n");
    for(int i = 0; i < N; i++){
        printf("%lld", b[i]);
        if(N - 1 > i)printf(" ");
    }
    printf("\n");


    return 0;
}
/*


*/


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	int c1 = 0;
	int c2 = 0;
	int c4 = 0;
	rep(i, N) {
		if (A[i] % 4 == 0) {
			c4++;
		}
		else if (A[i] % 2 == 0) {
			c2++;
		}
		else {
			c1++;
		}
	}
	if (c2 == 0 && c4 >= c1 - 1) {
		cout << "Yes" << endl;
	}
	else if (c2 != 0 && c4 >= c1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}




Measured memory_bytes: 640
n=int(input())
res=0
blue=[]
for i in range(n):
  blue.append(input())
m=int(input())
red=[]
for j in range(m):
  red.append(input())

res=0
for i in range(0,n):
  bl=blue.count(blue[i])
  re=red.count(blue[i])
  if bl-re>res:
    res=bl-re
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)//Count set bits

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}


int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("chkkki.txt", "r", stdin);
	freopen("chkkko.txt", "w", stdout);
#endif
	fio;

	int n;
	cin >> n;

	if (n == 7 || n == 5 || n == 3)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

//#define int long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF int(1e9)

int main(void) {
    static string s, t = "  ", tmp = "", k = "";
    bool flag = false;

    cin >> s;
    s+="  ";
    k = s;
    for (int i = s.size()-5; i >= 0; i--) {
        if (s.substr(i,6) == "eraser") {
            tmp = s.substr(i,6);
            tmp += t;
            t = tmp;
            s.erase(i,6);
            continue;
        } else if (s.substr(i,7) == "dreamer") {
            tmp = s.substr(i,7);
            tmp += t;
            t = tmp;
            s.erase(i,7);
            continue;
        } else if (s.substr(i,5) == "dream" || s.substr(i,5) == "erase") {
            tmp = s.substr(i,5);
            tmp += t;
            t = tmp;
            s.erase(i,5);
            continue;
        }
    }

    if (k == t) flag = true;
    if (flag) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


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

public class Main{
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        try {
            String line = br.readLine();
            while (line != null) {
                char c;
                int offset = 0;
                while (offset < 26) {
                    for (int i = 0; i < line.length(); i++) {
                        c = line.charAt(i);
                        if (97 <= (int) c && (int) c <= 122) {
                            c = (char) (((int) c - 97 + offset) % 26 + 97);
                        }
                        sb.append(c);
                    }
                    if (sb.toString().contains("that")
                            || sb.toString().contains("the")
                            || sb.toString().contains("this")) {
                        System.out.println(sb.toString());
                        sb.delete(0, sb.toString().length());
                        line = br.readLine();
                        break;
                    }
                    sb.delete(0, sb.toString().length());
                    offset++;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 23932
#include<stdio.h>
int N, M;
char c, O[51];
int main(){
  c=getchar();
  while(c!=10){
    O[N]=c;
    c=getchar(); N++;
  }
  c=getchar();
  while(c!=10){
    putchar(O[M]);
    putchar(c);
    c=getchar(); M++;
  }
  if(N!=M){
    putchar(O[N-1]);
  }
  putchar(10);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int issosu[300000];
  issosu[0]=0;
  issosu[1]=0;
  for(int i=2;i<300000;i++){
    int flag=1;
    for(int j=2;j*j<=i;j++){
      if(i%j==0)flag=0;
    }
    issosu[i]=flag;
  }
  for(int i=1;i<300000;i++)issosu[i]+=issosu[i-1];
  while(1){
    int n;
    scanf("%d", &n);
    if(n==0)break;
    printf("%d\n", issosu[n*2]-issosu[n]);
  }
  return 0;
}



Measured memory_bytes: 4320
pp = list(map(int, input().split()))
n = int(input())

def cross(a, b):
    return a[0]*b[1]-a[1]*b[0]
        
def dot(a, b):
    n = len(a)
    if n != len(b):
        return None
    ans = 0
    for i, j in zip(a, b):
        ans += i*j
    return ans
    
for i in range(n):
    bb = list(map(int, input().split()))
    a = (pp[2]-pp[0], pp[3]-pp[1])
    b = (bb[0]-pp[0], bb[1]-pp[1])
    if cross(a, b) > 0:
        print("COUNTER_CLOCKWISE")
    elif cross(a, b) < 0:
        print("CLOCKWISE")
    else:
        if dot(a,b)<0:
            print("ONLINE_BACK")
        elif dot(a, (b[0]-a[0],b[1]-a[1]))>0: 
            print("ONLINE_FRONT")
        else:
            print("ON_SEGMENT")


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

using namespace std;
typedef long long ll;

void solve(){
    ll n, x, m;
    cin >> n >> x >> m;
    map<ll, int> mp;
    vector<int> p(1);
    ll t = 1;
    int s = 0;
    for(int i = 1; i <= m + 1; ++i){
        t = (t * x) % m;
        if(mp.count(t)){
            s = mp[t];
            break;
        }
        mp[t] = i;
        p.push_back(t);
    }
    int w = p.size() - 1;
    int cl = w + 1 - s;
    t = 1;
    map<ll, int> mp2;
    vector<int> p2(1);
    s = 0;
    for(int i = 1; i <= m + 1; ++i){
        while(t > w){
            t -= cl;
        }
        if(mp2.count(t)){
            s = mp2[t];
            break;
        }
        mp2[t] = i;
        p2.push_back(t);
        t = t * 2;
    }
    cl = p2.size() - s;
    ll ans = 0;
    for(int i = 1; i < s; ++i)
        ans += p[p2[i]];
    for(int i = s; i < s + cl; ++i){
        ans += p[p2[i]] * ((n - s + 1) / cl);
        if((n - s + 1) % cl > i - s)
            ans += p[p2[i]];
    }
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 13180
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, T;
    cin >> N >> T;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll mi = LINF;
    ll res = 0;
    ll now = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] < mi) {
            mi = A[i];
        } else {
            if(A[i] - mi > now) {
                res = 1;
                now = A[i] - mi;
            }

            else if(A[i] - mi == now) {
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

#define int long long int 

int32_t main()
{
  int a,b,n;
  cin>>a>>b>>n;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    v.push_back(x);
  }
  vector<pair<int,int>> path;
  int dir=1;
  for(int i=0;i<a;i++)
  {
    for(int j=0;j<b;j++)
    {
      if(dir)
      path.push_back({i,j});
      else
      path.push_back({i,b-1-j});
    }
    dir=!dir;
  }
  int ans[a][b];
  int cal=0;
  for(auto [x,y]:path)
  {
    if(v[cal]==0)
    cal++;
    ans[x][y]=cal+1;
    --v[cal];
  }
  for(int i=0;i<a;i++)
  {
    for(int j=0;j<b;j++)
    cout<<ans[i][j]<<" ";
    cout<<endl;
  }
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	vl v(n+3);
	v[0]=2; v[1]=1;
	rep(i,2,n+3){
		v[i]=v[i-1]+v[i-2];
	}
	cout<<v[n]<<endl;
	
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define l first
#define r second
#define int long long

using namespace std;

const int maxn = 1e6 + 1;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    cout << fixed << setprecision(10) <<(n/3.) * (n/3.) * (n/3.);
    return 0;
}


Measured memory_bytes: 256
l,r = input().split()
l = int(l)
r = int(r)
 

 
if r - l >= 2019:
    print(0)
else:
    l_mod = l % 2019
    r_mod = r % 2019
    min_val = 2020
    for i in range(r_mod - l_mod + 1):
        for j in range(r_mod - l_mod + 1):
            if i >= j:
                continue
            min_val = min([min_val, ((l_mod+i)*(l_mod+j))%2019])
            
    print(min_val)

Measured memory_bytes: 40924
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const int mx = 2e5 + 9;
const ll inf = 1e18;

int n;
ll a[mx];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++) a[i] = a[i] - i;

    ll ans = 0;
    sort(a + 1, a + 1 + n);
    if (n & 1) {
        ll median = a[(n + 1) / 2];
        for (int i = 1; i <= n; i++) {
            ans += abs(a[i] - median);
        }

    } else {
        ll b1 = a[n / 2], b2 = a[n / 2 + 1];
        ll ans1 = 0, ans2 = 0;
        for (int i = 1; i <= n; i++) {
            ans1 += abs(a[i] - b1);
        } 

        for (int i = 1; i <= n; i++) {
            ans2 += abs(a[i] - b2);
        }

        ans = min(ans1, ans2);
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 5368
import itertools
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in itertools.combinations(L, 3):
    #print(i)
    if i[0] + i[1] > i[2] and i[1] + i[2] > i[0] and i[0] + i[2] > i[1]:
        if i[0] != i[1] and i[1] != i[2] and i[2] != i[0]:
            ans += 1
print(ans)





Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

// [0, k) に至るまでに必要な歩数 : x/d

int main(){
	ll x, k, d; scanf("%lld%lld%lld", &x, &k, &d);
	if(x < 0) x *= -1;
	ll ans;
	if(x / d >= k){
		ans = x - d*k;
	} else {
		ll y = x%d;
		k -= x/d;
		if(k%2) ans = d-y;
		else ans = y;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3828
n = gets.to_i
s = gets.chomp.split('').map &:to_s

$w_rui = [0]
$e_rui = [0]
(1..n).each do |i|
  $w_rui.push s[i-1] === 'W' ? $w_rui[-1] + 1 : $w_rui[-1]
  $e_rui.unshift s[n-i] === 'E' ? $e_rui[0] + 1 : $e_rui[0]
end

puts [$w_rui[0, n] , $e_rui[1, n+1]].transpose.map{|x| x.sum}.min




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

int H,W;
int a[500][500];
vector<string> ans;

void move(int x, int y, int nx, int ny){
  if(ny == H) return;
  if(a[y][x]%2 == 0) return;
  a[y][x]--, a[ny][nx]++;
  string tmp = to_string(y+1) + ' ' + to_string(x+1) + ' ' + to_string(ny+1) + ' ' + to_string(nx+1);
  ans.push_back(tmp);
}

void visit(int x, int y){
  if(y == H) return;
  // even
  if(y%2 == 0){
    if(x == W-1){
      move(x, y, x, y+1);
      visit(x, y+1);
    }
    else{
      move(x, y, x+1, y);
      visit(x+1, y);
    }
  }
  // odd
  else{
    if(x == 0){
      move(x, y, x, y+1);
      visit(x, y+1);
    }
    else{
      move(x, y, x-1, y);
      visit(x-1,y);
    }
  }
}

int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      cin>>a[i][j];
  visit(0, 0);
  cout<<ans.size()<<endl;
  for(string u : ans) cout<<u<<endl;
  return 0;
}


Measured memory_bytes: 11892
import heapq

K = int(input())
Q=list(range(1,10))
heapq.heapify(Q)
for _ in range(K):
    q = heapq.heappop(Q)
    if q%10!=0:
        heapq.heappush(Q,q*10+(q%10)-1)
    if q%10!=9:
        heapq.heappush(Q,q*10+(q%10)+1)
    heapq.heappush(Q,q*10+(q%10))
print(q)


Measured memory_bytes: 11712
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    s = input()
    q = int(input())
    d = deque()
    d.append(s)
    reverse_count = 0

    for i in range(q):
        qi = input().split()

        if qi[0] == '1':
            reverse_count += 1
        else:
            if reverse_count % 2 == 0:
                if qi[1] == '1':
                    d.appendleft(qi[2])
                else:
                    d.append(qi[2])

            else:
                if qi[1] == '1':
                    d.append(qi[2])
                else:
                    d.appendleft(qi[2])

    c = ''.join(map(str, d))

    if reverse_count % 2 == 1:
        c = c[::-1]

    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7140
//https://atcoder.jp/contests/abc084/tasks/abc084_d
//D - 2017-like Number
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//int N;
//エラトステネスの篩
//bool is_prime[ 10000 + 1 ];
vector<int> P;
auto Eratosthenes( const int N )
{
    unordered_map<ll,bool> result;
    vector<bool> is_prime(N+1,true);
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            result.emplace( i,true );
        }
    }
    return result;
}

int main() {
#if LOCAL&0
    std::ifstream in("./input.txt"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll Q; cin>>Q;
    vector<pair<ll,ll>> lrq(Q);
    for(auto&& lr:lrq){
        cin>>lr.first>>lr.second;
    }

    auto lst = Eratosthenes(1e+5);
    vector<ll> l2017;
    for(const auto& p:lst){
        auto v2 = (p.first + 1) / 2;
        if (lst.count(v2) > 0){
            l2017.push_back(p.first);
        }
    }
    sort(l2017.begin(),l2017.end());

    for(const auto& lr: lrq){
        auto it = lower_bound(l2017.begin(), l2017.end(), lr.first);
        ll st = std::distance(l2017.begin(), it);

        it = upper_bound(l2017.begin(), l2017.end(), lr.second);
        ll ed = std::distance(l2017.begin(), it);
        ll ans = (ed-st);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>
#include <string.h>
#define Maxn 100005
int n,ans,a[Maxn],rmq[Maxn*4],s[Maxn];
void add(int x) {for (;x<Maxn*4;x+=x&-x) rmq[x]++;}
int sum(int x) {int res=0;for (;x;x-=x&-x) res+=rmq[x];return res;}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;++i) scanf("%d",a+i);
	for (int l=0,r=1e9;l<=r;)
	{
		memset(rmq,0,sizeof(rmq));
		int mid=l+r>>1;
		long long S=0;
		add(n+1);
		for (int i=0;i<n;++i)
		{
			s[i]=(i?s[i-1]:0)+(a[i]>=mid?1:-1);
			S+=sum(s[i]+n+1);
			add(s[i]+n+1);
		}
		if (S>=1LL*n*(n+1)/2-S) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

// dp[i] = i円引き出すのに必要な最小の回数

int dp[110000];

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

  int n;
  cin >> n;

  FOR(i, 1, 110000) dp[i] = n;
  dp[0] = 0;

  FOR(i, 1, n+1) {
    for (int pow6 = 1; pow6 <= i; pow6 *= 6) {
      dp[i] = min(dp[i], dp[i-pow6]+1);
    }

    for (int pow9 = 1; pow9 <= i; pow9 *= 9) {
      dp[i] = min(dp[i], dp[i-pow9]+1);
    }
  }

  cout << dp[n] << endl;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int h,w,k;
    int d[4] = {0,1,0,-1};
    cin >> h >> w >> k;
    string a[800];
    for (int i = 0;i < h;++i) cin >> a[i];
    vector<vector<int>> dist(h,vector<int>(w,650000));
    deque<P> que1,que2;
    for (int i = 0;i < h;++i) for (int j = 0;j < w;++j) if (a[i][j] == 'S') {
        que1.push_back(P(i,j));
        dist[i][j] = 0;
        break;
    }
    while (!que1.empty()) {
        P t = que1.front();
        que1.pop_front();
        if (dist[t.first][t.second] == k) continue;
        for (int i = 0;i < 4;++i) {
            int x = t.first+d[i],y = t.second+d[i^1];
            if (x < 0 || x >= h || y < 0 || y >= w) continue;
            if (a[x][y] == '.' && dist[x][y] == 650000) {
                dist[x][y] = dist[t.first][t.second]+1;
                que1.push_back(P(x,y));
            }
        }
    }
    for (int i = 0;i < h;++i) for (int j = 0;j < w;++j) if (dist[i][j] < 650000) {
        dist[i][j] = 0;
        que2.push_back(P(i,j));
    }
    while (!que2.empty()) {
        P t = que2.front();
        que2.pop_front();
        for (int i = 0;i < 4;++i) {
            int x = t.first+d[i],y = t.second+d[i^1];
            if (x < 0 || x >= h || y < 0 || y >= w) continue;
            if (dist[x][y] == 650000) {
                dist[x][y] = dist[t.first][t.second]+1;
                que2.push_back(P(x,y));
            }
        }
    }
    int ans = 1000;
    for (int i = 0;i < h;++i) ans = min(ans,min(dist[i][0],dist[i][w-1]));
    for (int i = 0;i < w;++i) ans = min(ans,min(dist[0][i],dist[h-1][i]));
    cout << (ans+k-1)/k+1 << endl;
    // for (int i = 0;i < h;++i) p_ary(dist[i],0,w,j);
    return 0;
}

Measured memory_bytes: 8704
#include <stdio.h>
 #include <vector>

  using namespace std;

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

  int main()
  {
      int N;

      vector<int> color(8, 0);
      int over3200 = 0;

      scanf(" %d", &N);

      for (int i = 0; i < N; i++) {
          int a;
          scanf(" %d", &a);

          if (a < 3200) {
              color[a / 400]++;
          } else {
              over3200++;
          }
      }

      int color_min = 0;

      for (int i = 0; i < 8; i++) {
          if (color[i])
              color_min++;
      }

      int color_max = color_min + over3200;

      if(color_min == 0 && over3200) {
          color_min = 1;
      }

      printf("%d %d\n", color_min, color_max);
  }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n=in.nextInt();
		long sum=0;
		for(long i=0;i<=n;i++) {
			if(i%3!=0 && i%5!=0)sum+=i;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 35592
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

S1 = list(S[:N])
# 左右同じものを目指す形にしたいので、片方はリバースしておく
S2 = list(S[N:])[::-1]

d1 = Counter()
d2 = Counter()
# 半分に分けた両方を組み合わせ全列挙
for i in range(1<<N):
    s1_1, s1_2 = [], []
    s2_1, s2_2 = [], []
    for j in range(N):
        if i>>j & 1:
            s1_1 += [S1[j]]
            s2_1 += [S2[j]]
        else:
            s1_2 += [S1[j]]
            s2_2 += [S2[j]]
    # 文字列ペアをキーとして、その通り数を数えておく
    d1[(''.join(s1_1), ''.join(s1_2))] += 1
    d2[(''.join(s2_1), ''.join(s2_2))] += 1

ans = 0
for k, v in d1.items():
    # 左文字列ペア = 右文字列ペア になるような通り数を数え上げる
    ans += v * d2[k]
print(ans)


Measured memory_bytes: 177652
#include <iostream>
using namespace std;
int main(){
  int N, K, min, k, cnt=0, i;
  cin>>N>>K;
  k=K-1;
  int a[N];
  for(i=0;i<N;i++){
    cin>>a[i];
    if(a[i]==1)min=i;
  }
  if(N!=K){
    for(i=min;i>0;i-=k){
      cnt++;
    }
    if(i<0){
      min-=i;
    }
    for(i=min;i<N-1;i+=k){
      cnt++;
    }
    cout<<cnt<<endl;
  }
  else cout<<1<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(long i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
const long mod=1e9+7;
long power(long a,long b){
	long ans=1;
	rep(i,0,32){
		if(b&(1<<i)){
			(ans*=a)%=mod;
		}a=(a*a)%mod;
	}return ans;
}
long reverse(long n){
	return power(n,mod-2);
}
long pattern(int h,int w){
	long pro=1;
	rep(i,h+1,h+w+1) (pro*=i)%=mod;
	rep(i,1,w+1) (pro*=reverse(i))%=mod;
	return pro;
}
int main(){
	int H,W,A,B;cin>>H>>W>>A>>B;
	long res=0;
	long s[H-A],t[H-A];
    s[0]=pattern(0,B-1);t[0]=pattern(H-1,W-B-1);
	rep(i,1,H-A){ s[i]=(s[i-1]*(i+B-1))%mod;(s[i]*=reverse(i))%=mod; }
	rep(i,1,H-A){ t[i]=(t[i-1]*(H-i))%mod;(t[i]*=reverse(H+W-B-i-1))%=mod; }
	rep(i,0,H-A) (res+=s[i]*t[i])%=mod;
	cout<<res<<endl;
    //print(s,H-A);print(t,H-A);
    /*cout<<power(3,4)<<endl;
    cout<<reverse(1)<<endl;
    cout<<pattern(2,2)<<endl;*/
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int aa[200];
int main()
{
    long long int n,a,b,c,i,j,k;
    cin>>a>>b>>c;
    if(2*c>=b-a+2){
        for(i=a; i<=b; i++){
            cout<<i<<endl;
        }
    }
    else{
        for(i=1; i<=c; i++){
            cout<<a<<endl;
            a++;
        }
        k=b-c+1;
        for(i=1; i<=c; i++){
            cout<<k<<endl;
            k++;
        }

    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w,m;
//struct pos{
//	int x,y;
//	friend bool operator < (pos a,pos b){
//		if(a.x==b.x)return a.y<b.y;
//		return a.x<b.x;
//	}
////	pos(){}
////	pos(int a,int b):x(a),y(b){}
////	bool operator < (const pos &o) const{
////		return key<o.x||y<o.y;
////	}
//};
struct kkk{
	int num,sum;
};
kkk lie[300005],hang[300005];
kkk ly[300005],hy[300005];
bool cmp(kkk a,kkk b){
	return a.sum>b.sum;
}
int xx[300005],yy[300005];
//map<pos,int> p;

int main(){
	scanf("%d%d%d",&h,&w,&m);
//	pos tmp;
	for(int i=1;i<=h;i++){
		hang[i].num=i;
	}
	for(int i=1;i<=w;i++){
		lie[i].num=i;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&xx[i],&yy[i]);
//		tmp.x=xx,tmp.y=yy;
//		p[tmp]=1;
		lie[yy[i]].sum++;
		hang[xx[i]].sum++;
	}
	for(int i=1;i<=h;i++){
		hy[i].sum=hang[i].sum;
	}
	for(int i=1;i<=w;i++){
		ly[i].sum=lie[i].sum;
	}
	sort(hang+1,hang+h+1,cmp);
	sort(lie+1,lie+w+1,cmp);
	int maxn=hang[1].sum+lie[1].sum;
	long long cnt=0;
	for(int i=1;i<=m;i++){
		if(hy[xx[i]].sum+ly[yy[i]].sum==maxn){
			cnt++;
		} 
	}
//	printf("cnt:%d\n",cnt);
	long long ch=0,cl=0;
	for(int i=1;i<=h;i++){
		if(hang[i].sum==hang[1].sum)ch++;
	}
	for(int i=1;i<=w;i++){
		if(lie[i].sum==lie[1].sum)cl++; 
	}
//	printf("ch:%d\tcl:%d\n",ch,cl);
	if(ch*cl-cnt>0){
		printf("%d",hang[1].sum+lie[1].sum);
	}else{
		printf("%d",hang[1].sum+lie[1].sum-1);
	}

//	cout<<endl;
//	for(int i=1;i<=h;i++){
//		for(int j=1;j<=w;j++){
//			if(hang[i].sum+lie[j].sum<maxn)break;
//			if(p[i][j]==0)printf("%d",hang[i].sum+lie[j].sum);
//		}
//	}
//	printf("%d",maxn);
	return 0;
} 

Measured memory_bytes: 15488
N = int(input())
A = list(map(int,input().split()))
ans = 10**9
for x in A:
    if x % 2 == 1:
        print(0)
        exit()
    c = 0
    while x % 2 == 0:
        x //= 2
        c += 1
    ans = min(ans, c)
print(ans)

Measured memory_bytes: 9144
import math
A,B,C,D=map(int,input().split())
res = B-A+1
mid = 0
cd = C * D // math.gcd(C, D)
miniNumC = A//C
if A%C==0:
  miniNumC += -1
miniNumD = A//D
if A%D==0:
  miniNumD += -1
maxNumC = B//C
maxNumD = B//D
miniNumCD = A//cd
maxNumCD = B//cd
if A%cd==0:
  miniNumCD += -1
mid += maxNumC -miniNumC + maxNumD -miniNumD -maxNumCD +miniNumCD 
print(res-mid)

Measured memory_bytes: 9144
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Queue<Long> pq = new PriorityQueue<Long>(N);
		for (int i = 0; i < N; i++) {
			pq.add(sc.nextLong());
		}
		Map<Long, Integer> tm = new TreeMap<Long, Integer>(Collections.reverseOrder());
		for (int i = 0; i < M; i++) {
			int b = sc.nextInt();
			long c = sc.nextLong();
			// treeMapに値を入れる
			if (tm.containsKey(c)) {
				int prev = tm.get(c);
				tm.put(c, prev + b);
			} else {
				tm.put(c, b);
			}
		}
		sc.close();

		tm.forEach((k, v) -> {
			int cnt = 0;
			while (true) {
				if (k > pq.peek()) {
					pq.poll();
					pq.add(k);

					cnt++;
					if (cnt == v) {
						return;
					}
				} else {
					break;
				}
			}
		});

		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += pq.poll();
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 105452
#include<stdio.h>

#define N 200000
int main(){
  int max;
  int min;
  int R[N];
  int i,j,n;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }

  for(j=1;j<=n-1;j++){
    for(i=0;i<=j-1;i++){
      if(max<R[j]-R[i]){
	max=R[j]-R[i];
      }
    }
  }

  min=R[0];
  max=R[1]-R[0];
  for(j=1;j<=n-1;j++){
    if(max<R[j]-min){
      max=R[j]-min;
    }
    if(min>R[j]){
      min=R[j];
    }
  }

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

  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n, d;
  cin >> n >> d;
  
  ll ans = 0;
  for (int i = 0; i < n; i++){
    double x, y;
    cin >> x >> y;
    
    if (x*x + y*y <= d*d)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int A, B;
    cin >> A >> B;
    bool flag = false;

    for (int i = 0; i < 5000; i++){
        if( i * 8 / 100 == A  && i * 10 / 100 == B ){
            cout << i << endl;
            flag = true;
            break;
        } 
    
    }
    if(flag == false){
        cout << -1 << endl;
    }

} 

Measured memory_bytes: 256
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;

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

int n, t;
int dp[7001];
pii ab[7001];

int main(){
  cin >> n >> t;
  for(int i = 1; i <= n; ++i){
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab + 1, ab + 1 + n, [](pii a, pii b){
    return make_pair(a.first, -a.second) < make_pair(b.first, -b.second);
  });
  for(int i = 1; i <= n; ++i){
    int a = ab[i].first;
    int b = ab[i].second;
    for(int j = t - 1; j >= 0; --j){
      if(dp[j] || j == 0)
        dp[j + a] = max(dp[j + a], dp[j] + b);
    }
  }
  cout << *max_element(dp, dp + 7001) << "\n";
  return 0;
}


Measured memory_bytes: 256
<?php
  list($n, $m) = explode(" ", trim(fgets(STDIN)));
  $ans = array_fill(1, $n, 1);
  $height = explode(" ", trim(fgets(STDIN)));
  array_unshift($height, 0);
  for($i = 0; $i < $m; $i++){
    list($tmpa, $tmpb) = explode(" ", trim(fgets(STDIN)));
    if($height[$tmpa] < $height[$tmpb]){
      $ans[$tmpa] = 0;
    } elseif($height[$tmpa] > $height[$tmpb]) {
      $ans[$tmpb] = 0;
    } else {
      $ans[$tmpa] = 0;
      $ans[$tmpb] = 0;
    }
  }
  $cnt = 0;
  for($i = 1; $i <= $n; $i++){
    if($ans[$i] == 1){
      $cnt++;
    }
  }
  echo $cnt;
?>

Measured memory_bytes: 30440