akhauriyash/Code-Regression huggingface dataset:
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> K;
  ll now = 0, r = 0;
  
  REP(i, 10000000) {
    now = (now * 10 + 7) % K;
    r++;
    if (now == 0)
      return r;
  }


  return -1LL;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int main(){
	int n;
	LL a,b,c,d,e;
	LL sa=1,sb=1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		c=((sa+sb-1)/(a+b)+1)*a;
		d=((sa+sb-1)/(a+b)+1)*b;
		if(c<sa){
			sa=((sa-1)/a+1)*a;
			sb=((sa-1)/a+1)*b;
		}else if(d<sb){
			sa=((sb-1)/b+1)*a;
			sb=((sb-1)/b+1)*b;
		}else sa=c,sb=d;
	}
	cout<<sa+sb<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  VB ct(10, false);
  REP(i, 4)
  {
    int n;
    cin >> n;
    ct[n] = true;
  }
  if (ct[1] && ct[9] && ct[7] && ct[4]) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define mp make_pair
#define pb push_back
#define all(name) (name.begin(), name.end())
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) power(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
ll dp[105][100005];
int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
	{
		ll n, wt;
		cin >> n >> wt;
		ll val[n+5], w[n+5];
		rep(i, 1, n+1)cin >> w[i] >> val[i];
		rep(i, 1, n+1){
			rep(j, 1, wt+1){
				if(j >= w[i])dp[i][j] = max(dp[i-1][j-w[i]] + val[i], dp[i-1][j]);
				else dp[i][j] = dp[i-1][j];
			}
		}
		cout << dp[n][wt];
	}
}

Measured memory_bytes: 79360
def power_mod(a,b,mod=10**9+7):
    i,temp,box=0,b,[]
    while(2**i<=b):
        i+=1
    for j in range(i-1,-1,-1):
        box=[[j,temp//2**j]]+box
        temp-=2**j*(temp//2**j)
    box[0].append(a)
    ans=box[0][1]*a%mod
    for j in range(1,i):
        box[j].append(box[j-1][2]**2%mod)
        if box[j][1]==1:
            ans=(ans*box[j][2])%mod
    return ans
def n_func(n,mod=10**9+7):
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%mod
    return ans
def nPr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)
    ans=power_mod(ans,mod-2,mod)
    return ans*n_func(n,mod)%mod
def nCr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)*n_func(r,mod)%mod
    ans=power_mod(ans,mod-2,mod)
    return ans*n_func(n,mod)%mod

N,M,K=map(int,input().split())
keisuu=nCr(N*M-2,K-2)
mod=10**9+7

sum_=0
for i in range(N):
    a=min(abs(i),abs(N-i-1))
    b=max(abs(i),abs(N-i-1))
    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))
for i in range(M):
    a=min(abs(i),abs(M-i-1))
    b=max(abs(i),abs(M-i-1))
    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))
print((keisuu * (sum_//2))%mod)

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int i=1;
		while(n>=i) {
			i*=2;
		}
		System.out.println(i/2);

	}
}

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

int main() {
  int A,B;
  cin >>A>>B;
  int ans=0;
  if(A>B){
    ans+=A;
    A-=1;
  }
  else{
    ans+=B;
    B-=1;
  }
  ans+=max(A,B);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    x,y = map(int, input().split())
    A.append([x+y,x-y])
A.sort()
now = -float('inf')
ans = 0
for a,b in A:
    if b>=now:
        ans += 1
        now = a
print(ans)

Measured memory_bytes: 20104
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> A(n), P(n), Q(n);
    for(int i = 0; i < n; i++){
        cin >> P[i];
    }
    for(int i = 0; i < n; i++){
        cin >> Q[i];
    }
    for(int i = 0; i < n; i++){
        A[i] = i;
        A[i]++;
    }
    int a = 0;
    map<vector<int>, int> M;
    do{
        a++;
        M[A] = a;
    }while(next_permutation(A.begin(), A.end()));
    //cout << M[P] << " " << M[Q] << endl;
    cout << abs(M[P] - M[Q]);
    return 0;
}

Measured memory_bytes: 5248
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
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()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  ll ans = 0;
  FOR(i, 1, n) {
    ans += max(a[i - 1] - a[i], 0);
    chmax(a[i], a[i - 1]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3984
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,W; cin >> n >> W;
    ll w[n], v[n];
    rep(i,n) cin >> w[i] >> v[i];

    // ll dp[n+1][W+10];
    ll dp[2][W+10];
    rep(i,W+10) dp[0][i] = 0;

    REP(i,1,n+1) rep(j, W+1)
    {
        if (j-w[i-1]>=0)
        {
            dp[i%2][j] = max(dp[(i-1)%2][j], dp[(i-1)%2][j-w[i-1]]+v[i-1]);
        }
        else
        {
            dp[i%2][j] = dp[(i-1)%2][j];
        }
    }
    ll ans = 0;
    rep(i,W+1)
    {
        ans = max(ans, dp[n%2][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d||(abs(a-b)<=d && abs(b-c)<=d))
  {
    cout<<"Yes";
  }
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <queue>
#include <deque>

int main() {
  int N, K;
  scanf("%d %d", &N, &K);

  if (K == 1) {
    puts("0");
  } else {
    printf("%d\n", N-K);
  }
}


Measured memory_bytes: 128
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 18;
int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

set<pair<long long, long long>> st[maxn][maxn];

void solve() {
  for (int i = 0; i + 1 < n; i++) {
    st[i][i + 1].clear();
    st[i][i + 1].insert(make_pair(0ll, 0ll));
  }
  for (int len = 3; len <= n; len++) {
    for (int i = 0; i + len <= n; i++) {
      int j = i + len - 1;
      auto &cst = st[i][j];
      cst.clear();
      for (int k = i + 1; k < j; k++) {
        for (auto itl = st[i][k].begin(); itl != st[i][k].end(); itl++) {
          for (auto itr = st[k][j].begin(); itr != st[k][j].end(); itr++) {
            long long l = itl->first, m = itl->second + a[k] + itr->first, r = itr->second;
            l += m;
            r += m;
            cst.insert(make_pair(l, r));
          }
        }
      }
      long long prv = -1;
      for (auto it = cst.begin(); it != cst.end();) {
        if (prv != -1 && it->second >= prv) {
          auto del = it;
          it++;
          cst.erase(del);
          continue;
        }
        prv = it->second;
        it++;
      }
    }
  }
  long long res = -1;
  for (auto it = st[0][n - 1].begin(); it != st[0][n - 1].end(); it++) {
    long long cur = a[0] + it->first + it->second + a[n - 1];
    if (res == -1 || cur < res) {
      res = cur;
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int f(ll n){
    int sum = 0;
    while(n){
        n/=10;
        sum++;
    }
    return sum;
}

int main(){
    ll n;
    cin>>n;
    int ans = 1e9;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            ans = min(ans, f(n/i));
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

i64 gcd(i64 a, i64 b) { return b ? gcd(b, a%b) : a; }

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

  i64 n, k;
  cin >> n >> k;

  vector<i64> a(n+5);
  i64 maxv = 0;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == k) {
      cout << "POSSIBLE" << "\n";
      return 0;
    }
    maxv = max(maxv, a[i]);
  }

  i64 G = a[0];
  for (int i = 1; i < n; ++i) {
    G = gcd(G, a[i]);
  }

  if (k % G == 0 && k <= maxv) cout << "POSSIBLE" << "\n";
  else cout << "IMPOSSIBLE" << "\n";

  return 0;
}

Measured memory_bytes: 1024
l = map(int, raw_input().split())
k = raw_input()
listed = list(k)
if (len(k) == (l[0] + l[1] + 1)) and (listed[l[0]] == "-"):
    if (str("".join(listed[0:l[0]])).isdigit() == True) and (str("".join(listed[l[0]+1:len(listed)])).isdigit() == True):
        print "Yes"
        exit()
    print "No"
else:
    print "No"


Measured memory_bytes: 2568
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,int> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=1e18;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]<rank[ry]){
            par[rx]=ry;
        }else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[ry]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

struct edge{
    int to;
    ll cost;
};

int n;
vector<vector<edge> > Tree(MAXN);
vector<int> color(MAXN,-1);

void dfs(int u,int c){
    color[u]=c;
    for(auto e:Tree[u]){
        if(color[e.to]!=-1) continue;
        if(e.cost%2==0) dfs(e.to,c);
        else dfs(e.to,1-c);
    }
    return ;
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v,w;cin>>u>>v>>w;
        u--;v--;
        Tree[u].push_back(edge{v,w});
        Tree[v].push_back(edge{u,w});
    }
    dfs(0,1);
    for(int i=0;i<n;i++){
        cout<<color[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 12628
import bisect

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

timeA=[0]*(N+1)
timeB=[0]*(M+1)
for i in range(N):
    timeA[i+1]=timeA[i]+A[i]
for i in range(M):
    timeB[i+1]=timeB[i]+B[i]

ans=0
for i in range(N+1):
    time=K-timeA[i]
    if time<0:
        break
    num=bisect.bisect_right(timeB,time)
    ans=max(ans,i+num-1)
print(ans)

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

int main(void)
{
    string x;
    cin>>x;
    sort(x.begin(),x.end());
    for(int i=0;i<x.length()-1;++i)
    {
        if(x[i]==x[i+1])
        {
            cout <<"no"<<endl;
            return 0;
        }
    }
    cout <<"yes"<<endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>
#include <time.h>
using namespace std;


int main(){
	int A, B, K;
	cin >> A >> B >> K;

	for (int i = 0; i < K; ++i){
		if (A & 1 == 1){
			--A;
		}
		A >>= 1;
		B += A;

		++i;
		if (i >= K)
			break;

		

		if (B & 1 == 1){
			--B;
		}
		B >>= 1;
		A += B;
	}

	cout << A << " " << B << endl;
		
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	long long del=0x3f3f3f3f,sum=0;
	int n;
	bool f=false;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		long long a,b;
		scanf("%lld%lld",&a,&b);
		if(a-b)f=true;
		sum+=a;
		if(b<a)
			del=del<b?del:b;
	}
	if(!f)	printf("0\n");
	else printf("%lld\n",sum-del);
return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll mod = 1000000007;
const ll INF = 1ll << 50;


ll n,k;
string s;
ll ans;

int main(){
  cin >> n >> k;
  cin >> s;
  ll from = 0;
  ll to = n;
  while(s[from] == 'L') from++;
  while(s[to-1] == 'L') to--;
  for(ll i = from;i < to;i++){
    if(s[i] == 'L' && k > 0){
      k--;
      while(s[i] == 'L'){
        s[i] = 'R';
        i++;
      }
    }
  }
  if(k >= 1){
    for(ll i = from;i < to;i++) s[i] = 'L';
  }
  for(ll i = 0;i < n;i++){
    if(s[i] == 'R'){
      if(i < n-1 && s[i+1] == 'R') ans++;
    }
    if(s[i] == 'L'){
      if(i > 0 && s[i-1] == 'L') ans++;
    }
  }
  cerr << s << endl;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <array>
#include <cstddef>
#include <iostream>
#include <vector>

const int nmax = 300000;
int main()
{
    int n;
    std::cin >> n;

    std::array<long long unsigned int, nmax> As;
    std::array<long long unsigned int, nmax> counts;
    counts.fill(0);

    long long unsigned int a;
    for (size_t i = 1; i <= n; ++i)
    {
        std::cin >> a;
        As[i] = a;
        counts[a]++;
    }

    long long unsigned int total = 0;
    for (size_t k = 1; k <= n; ++k)
    {
        long long unsigned count = counts.at(k);
        if (count >= 2)
        {
            total += count * (count - 1) / 2;
        }
    }

    for (size_t k = 1; k <= n; ++k)
    {
        a = As.at(k);
        long long unsigned int ans = total;
        if (counts.at(a) >= 2)
        {
            ans += 1 - counts.at(a);
        }
        std::cout << ans << std::endl;
    }
}


Measured memory_bytes: 7296
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    set<char> s;
    rep(i, N) {
        char c;
        cin >> c;
        s.insert(c);
    }
    if (s.size() == 4) {
        print("Four");
    } else {
        print("Three");
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 1, tot = 0, cur = 1;
  cin >> n;
  vector<ll> a(n + 1);
  rep(i, n + 1) cin >> a[i], tot += a[i];

  if (n == 0) {
    if (a[0] == 1)
      cout << 1 << endl;
    else
      cout << -1 << endl;
    return 0;
  }
  
  if(a[0]!=0){
    cout << -1 << endl;
    return 0;
  }

  for (int i = 1; i < n + 1; ++i) {
    cur *= 2;

    if (cur < a[i]) {
      cout << -1 << endl;
      return 0;
    }

    ans += min(cur, tot);
    cur = min(cur, tot) - a[i];
    tot -= a[i];
  }

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


Measured memory_bytes: 3976
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[10][10];
int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>dp[i][j];
		}
	}
	int n=10;
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)continue;
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	int ans=0;
	lol(i,h)lol(j,w){
		int a;cin>>a;
		if(a>-1){
			ans+=dp[a][1];
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n;
V<int> v, c;

int main(){
    INIT;
    cin >> n;
    v.resize(n+1);
    c.resize(n+1);
    REP(i,n) cin >> v[i];
    REP(i,n) cin >> c[i];

    V<int> xy;
    REP(i,n) {
        xy.push_back(v[i]-c[i]);
    }
    std::sort(ALL(xy), DESC(int));

    int ans = 0;
    REP(i,n) {
        if(xy[i] < 0) break;
        ans += xy[i];
    }
    cout << ans << "\n";
}

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

const int MX = 100005;

int main(){
  int n;
  cin >> n;
  vector<ll> cnt(MX,0);
  rep(i,n){
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll tot = 0;
  rep(i,MX) tot += i*cnt[i];

  int q;
  cin >> q;
  rep(i,q){
    int b,c;
    cin >> b >> c;
    tot += (c-b)*cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << tot << endl;
  }

  return 0;
}


Measured memory_bytes: 4024
int main() {
  long a, b, r;
  scanf("%ld %ld", &a, &b);
  long x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a < b){
    long tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  printf("%ld\n", x/b);
  return 0;
}

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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n;
char a[555][555];
int white_col;
int black_row;
int black_row_ok;

int main()
{
	scanf("%d\n", &n);
	for(int i=0; i<n; i++) {
		scanf("%s\n", a[i]);
	}
	for(int j=0; j<n; j++) {
		int wh=0;
		for(int i=0; i<n; i++) {
			if(a[i][j]=='.') wh=1;
		}
		white_col+=wh;
	}
	for(int i=0; i<n; i++) {
		int bl=0;
		for(int j=0; j<n; j++) {
			if(a[i][j]=='#') bl++;
		}
		int ok=0;
		for(int ii=0; ii<n; ii++) {
			if(a[ii][i]=='#') ok=1;
		}
		if(bl>black_row) {
			black_row=bl;
			black_row_ok=ok;
		} else if(bl==black_row) {
			black_row_ok=max(black_row_ok, ok);
		}
	}
	if(black_row==0) {
		printf("-1\n");
	} else {
		printf("%d\n", (n-black_row)+(1-black_row_ok)+white_col);
	}

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a<=0 && b>=0) cout << "Zero" << "\n";
  else if(a>0 && b>0) cout << "Positive" << "\n";
  else{
    if(abs(a-b)%2==0) cout << "Negative" << "\n";
    else cout << "Positive" << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int H, W, M; cin >> H >> W >> M;

    map<pair<int, int>, bool> mp; 
    vector<pair<int, int>> hcnt(H), wcnt(W);
    // vector<int> hcnt(H), wcnt(W)
    REP(i, 0, M) {
        int h, w; cin >> h >> w; h--; w--;
        mp[{h, w}] = true;
        hcnt[h].first++;
        hcnt[h].second = h;
        wcnt[w].first++;
        wcnt[w].second = w;
    }

    sort(ALL(hcnt), greater<>());
    sort(ALL(wcnt), greater<>());

    int ans = 0;
    int maxh = hcnt[0].first;
    int maxw = wcnt[0].first;
    int i = 0, j = 0;
    while (i < H && hcnt[i].first == maxh) {
        bool ok = false;
        j = 0;
        while (j < W && wcnt[j].first == maxw) {
            int nh = hcnt[i].second;
            int nw = wcnt[j].second;
            // cout << "# h : " << nh + 1 << ", cnt : " << hcnt[i].first << endl;
            // cout << "# w : " << nw + 1 << ", cnt : " << wcnt[j].first << endl;
            if (mp[{nh, nw}]) {
                ans = hcnt[i].first + wcnt[j].first - 1; 
            } else {
                ans = hcnt[i].first + wcnt[j].first;
                ok = true;
            }
            // cout << "--> ans : " << ans << endl;
            j++;
            if (ok) break;
        }
        if (ok) break;
        i++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 26668
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

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

int main()
{


vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k ; cin>>k;
cout<<v[k-1]<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <fstream>
#include <limits>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define mod 1000000007
#define infinity (ll)1e18+1
#define pdd pair<double,double>
#define pll pair<ll, ll>
#define MP make_pair
#define vi vector<ll>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

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

int f(int a, int b)
{
	return a > b;
}

int main()
{

	int n;
	cin >> n;

	vi a(3 * n);
	FOR(i, 0, 3 * n)
		cin >> a[i];

	sort(ALL(a), f);
	ll b1 = 0;
	FOR(i, 0, n)
		b1 += a[2 * i + 1];

	cout << b1;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
using namespace std;
 
template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}
 

struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    }
    return a.second > b.second;
  }

}comp_functor;
 
 
int main() 
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    
    long long int h[3000006],a,b,c=0,temp;
    
    cin>>a>>b;
    temp=a;
    while(temp<=b)
    {
        c++;
        temp*=2;
    }
    
    cout<<c;
    
    return 0;
}    

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc081/tasks/abc081_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();

		int count = str.length() - str.replaceAll("1", "").length();
		System.out.println(count);

		scanner.close();
	}
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int A, B;
    cin >> A >> B;
    cout << (A+B)%24 << '\n';
}


Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

		int N = in.nextInt();
		int[] A = new int[N];
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (int i=0;i<N;i++) {
			A[i] = in.nextInt();
			if (map.containsKey(A[i])) {
				map.put(A[i], map.get(A[i])+1);
			} else {
				map.put(A[i], 1);
			}
		}
		long ans = 0L;
		ArrayList<Integer> key = new ArrayList<Integer>(map.keySet());
		ArrayList<Integer> vall = new ArrayList<Integer>(map.values());
		for (int i=0;i<key.size();i++) {
			ans += (long)key.get(i)*vall.get(i);
		}
		int Q = in.nextInt();
		int[] B = new int[Q];
		int[] C = new int[Q];
		for (int i=0;i<Q;i++) {
			B[i] = in.nextInt();
			C[i] = in.nextInt();
			if (map.containsKey(B[i])) {
				int val = map.get(B[i]);
				ans -= (long)B[i]*val;
				ans += (long)C[i]*val;
				map.remove(B[i]);
				if (map.containsKey(C[i])) {
					map.put(C[i], map.get(C[i])+val);
				} else {
					map.put(C[i], val);
				}
			}
			out.println(ans);
		}
		out.close();
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


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

int isprime(int n){
  if(n<2)return 0;
  if(n==2)return 1;
  if(n%2==0)return 0;
  for(int i=3;i*i<=n;i+=2){
    if(n%i==0)return 0;
  }
  return 1;
}

int main(){
  int a,n[10001]={0},k;
  k=0;
  for(int i=1;k<=10000;i++){
    if(isprime(i)){
      k++;
      n[k]=n[k-1]+i;
    }
  }
  while(cin>>a){
    if(a==0)break;
    cout<<n[a]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3020
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<double, P> PP;
struct edge { int to; int cost; };
int a[100006];
int b[100006], c[100006];
signed main() {
	int q; cin >> q;
	int suma = 0, sumb = 0;
	int mna = inf;
	set<P>S1, S2;
	int sum1 = 0, sum2 = 0;
	rep(i, q) {
		int w; cin >> w;
		if (w == 1) {
			int a, b; cin >> a >> b;
			sum1 += a;
			sumb += b;
			if (!i)S1.insert(P(a, i));
			else {
				int t = S1.rbegin()->first;
				if (t < a) {
					S2.insert(P(a, i));
					sum1 -= a;
					sum2 += a;
				}
				else S1.insert(P(a, i));
			}
			if (S1.size() > S2.size() + 1) {
				auto itr = S1.rbegin();
				sum1 -= itr->first;
				sum2 += itr->first;
				S2.insert(*itr);
				S1.erase(*itr);
			}
			else if (S1.size() < S2.size()) {
				auto itr = S2.begin();
				sum2 -= itr->first;
				sum1 += itr->first;
				S1.insert(*itr);
				S2.erase(*itr);
			}
		}
		else if (w == 2) {
			int t = S1.rbegin()->first;
			int z2 = S2.size();
			int z1 = S1.size();
			cout << t << ' ' << sumb + (sum2 - t*z2) + (t*z1 - sum1) << endl;
		}
	}
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  int n;
  cin>>n;


  int64_t out=1;
  for(int i=0;i<n;i++){
    int64_t t;
    cin>>t;

    out=lcm(out,t);
  }

  cout<<out<<endl;

	return 0;
}

Measured memory_bytes: 3624
n,a,b = [int(_) for _ in input().split()]

result = []
for seisu in range(1,n+1):

  wa = 0
  first_seisu = seisu

  while seisu != 0:
    wa = wa + seisu % 10
    seisu = int(seisu/10)

  if a <= wa <= b:
    result.append(first_seisu)

print(sum(result))

Measured memory_bytes: 3300
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    S = readstr()
    T = readstr()
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9576
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#define io ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define ll long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

using namespace std;

string s;

ll dp[105][5][2];

int main()
{
	int k;
	cin >> s >> k;
	int len = s.size();
	dp[len - 1][1][0] = s[len-1] - '0';
	dp[len - 1][1][1] = 9;
	for (int i = len - 1; i >= 0; i--)
		dp[i][0][1] = dp[i][0][0] = 1;
	for (int i = len-2; i >= 0; i--)
		for (int j = 1; j <= k; j++)
		{
			dp[i][j][1] = dp[i + 1][j][1] + dp[i + 1][j - 1][1] * 9;
			if (s[i] - '0')
				dp[i][j][0] = dp[i + 1][j - 1][1] * (s[i] - '1') + dp[i + 1][j - 1][0] + dp[i + 1][j][1];
			else
				dp[i][j][0] = dp[i + 1][j][0];
		}
	cout << dp[0][k][0];
	return 0;
 }

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <complex>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
#define un using namespace
un std;
#define pb push_back
#define pf pop_front

#define mp make_pair

#define c0 first
#define c1 second
#define sqr(x) ((x)*(x))
#define clr(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define clr80(x) memset(x, 0x80, sizeof(x))
#define clr7F(x) memset(x, 0x7F, sizeof(x))

#define LL long long
#ifdef __unix__
#define LLD "%lld"
#else
#define LLD "%I64d"
#endif
#define pii pair<int, int>
#define pip pair<int, pii>
#define vi vector<int>
#define vpi vector<pii>
#define pq priority_queue

template<typename T>
inline bool chkmin(T &a, T b){return a > b ? a = b, 1 : 0;}
template<typename T>
inline bool chkmax(T &a, T b){return a < b ? a = b, 1 : 0;}

#define P 1000000007

#define getint(x){\
	char __next__char__;bool __nega__int__=0;\
	while(!isdigit(__next__char__=getchar())&&__next__char__!='-');\
	__next__char__=='-'?(x=0,__nega__int__=1):(x=__next__char__-48);\
	while(isdigit(__next__char__=getchar()))x=x*10+__next__char__-48;\
	if(__nega__int__)x=-x;\
}
#define getint2(x1,x2){getint(x1);getint(x2);}
#define getint3(x1,x2,x3){getint(x1);getint(x2);getint(x3);}
#define getint4(x1,x2,x3,x4){getint(x1);getint(x2);getint(x3);getint(x4);}
#define getint5(x1,x2,x3,x4,x5){getint(x1);getint(x2);getint(x3);getint(x4);getint(x5);}
#define getint6(x1,x2,x3,x4,x5,x6){getint(x1);getint(x2);getint(x3);getint(x4);getint(x5);getint(x6);}

void solve() {
	int x, y;
	getint2(x, y);
	int ans = ~0U >> 1;
	if (y > x) {
		ans = min(ans, y - x);
	}
	if (y >= -x) {
		ans = min(ans, y + x + 1);
	}
	if (-y >= x) {
		ans = min(ans, -y - x + 1);
	}
	if (y < x) {
		ans = min(ans, x - y + 2);
	}
	printf("%d\n", ans);
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k;
string s,s1,s2;

int main(){
  int n,m; cin >> n >> m;
  int wa[n] = {};
  int ac[n] = {};
  rep(i,m){
    string s; int p; cin >> p >> s;
    if(s == "WA" && ac[p-1] == 0) wa[p-1]++;
    else ac[p-1] = 1;
  }
  int ans1 = 0; int ans2 = 0;
  rep(i,n){
    if(ac[i]){
      ans1++; ans2 += wa[i];
    }
  }
  cout << ans1 << " " << ans2 << "\n";
}

Measured memory_bytes: 1024
import numpy as np
N, K = map(int, input().split())
mod = 2*K
field = [[0]*(2*K+1) for _ in range(2*K+1)]

def gen_pattern(x):
    if x < K-1:
        return [[0, x+1], [x+K+1, 2*K]]
    else:
        return [[x-K+1, x+1]]

for _ in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'W':
        y += K
    x %= mod
    y %= mod
    for tmp in [0, K]:
        for l, r in gen_pattern((x+tmp) % mod):
            for b, t in gen_pattern((y+tmp) % mod):
                field[l][b] += 1
                field[l][t] -= 1
                field[r][b] -= 1
                field[r][t] += 1
print(np.max(np.cumsum(np.cumsum(field, axis=0), axis=1)))

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

#define int long long

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

	int a, b;
	cin >> a >> b;
	if(a <= b) {
		cout << "unsafe";
	} else {
		cout << "safe";
	}

	return 0;
}	

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


def find_value(n):
    for x in range(1, n + 1):
        if int(x * 1.08) == n:
            return x
    else:
        return


def main():
    n = int(input())
    x = find_value(n)
    if x is None:
        print(":(")
    else:
        print(x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n;
  cin>>n;
  int x[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  sort(x,x+n);
  cout<<x[n-1]-x[0]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

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

vector<string> field;

int DP1[2100][2100];
int DP2[2100][2100];

/* if bfs

   queue<pair<int, int> > que
   que.push(start x, start y);

   int dist[x][y];
   memset(dist, -1, sizeof(dist));
   dist[start x][start y] = 0;
*/


// int N; cin >> N;
// field.resize(N);

int main() {
  int H, W; cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string S; cin >> S;
    field.push_back(S);
  }

  memset(DP1, 0, sizeof(DP1));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '#') {
        DP1[i][j] = 0;
      } else {
        DP1[i][j] += (j - 1 >=0 ? DP1[i][j-1] + 1 : 1);
      }
    }
  }

  for (int i = H - 1; i >= 0; i-- ) {
    for (int j = W - 1; j >= 0; j--) {
      if (DP1[i][j] == 0) {
        continue;
      } else {
        DP1[i][j] = max(DP1[i][j], (j + 1 < W ? DP1[i][j+1] : 0));
      }
    }
  }


  memset(DP2, 0, sizeof(DP2));

  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      if (field[i][j] == '#') {
        DP2[i][j] = 0;
      } else {
        DP2[i][j] += (i - 1 >= 0 ? DP2[i-1][j] + 1 : 1);
      }
    }
  }

  for (int j = W - 1; j >= 0; j--) {
    for (int i = H - 1; i >= 0; i--) {
      if (DP2[i][j] == 0) {
        continue;
      } else {
        DP2[i][j] = max(DP2[i][j], (i + 1 < H ? DP2[i+1][j] : 0));
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      // cout << DP1[i][j] << " ";
      DP1[i][j] += DP2[i][j] - 1;
    }
    // cout << endl;
  }
  // cout << endl;

  int m = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      m = max(m, DP1[i][j]);
      // cout << DP2[i][j] << " ";
    }
    // cout << endl;
  }

  cout << m << endl;
}


Measured memory_bytes: 39168
import java.util.Scanner;

public class Main {
    static Scanner sc;

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

    private void run() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (b - a == c - b) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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

int main(){
  string a; cin>>a;
  int i;
  int ans=0;
  for(i=0;i<=3;i++){
    if(a[i]=='+'){
      ans++;
    }else{
      ans--;
    }
  }
    cout<<ans;
    return 0;
  }

      

Measured memory_bytes: 256
s=list(input())
t=input()

for i in range(len(s)-len(t)+1):
    flag=0
    i=len(s)-len(t)-i
    #print(i)
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!="?":
            flag=1
            #print(j,t[j],s[i+j])
    if flag==0:
        for j in range(len(t)):
            s[i+j]=t[j]
        result=""
        for item in s:
            result=result+str(item)
        result=result.replace("?","a")
        print(result)
        exit()
print("UNRESTORABLE")

Measured memory_bytes: 3192
import collections

def calc(n):
  cnt_2=0
  cnt_5=0
  while n%2==0 and cnt_2<18:
    cnt_2+=1
    n//=2
  while n%5==0 and cnt_5<18:
    cnt_5+=1
    n//=5
  return [cnt_2,cnt_5]

n=int(input())
dic=collections.defaultdict(int)
ans=0
for _ in range(n):
  tmp=input()
  if '.' in tmp:
    pos=tmp.index('.')
    d=len(tmp)-(pos+1)
    tmp=tmp[:pos]+tmp[pos+1:]+'0'*(9-d)
  else:
    tmp+='0'*9
  tmp=int(tmp)
  cnt_2,cnt_5=calc(tmp)
  dic[(cnt_2,cnt_5)]+=1
  if 18<=min(cnt_2*2,cnt_5*2):
    ans-=1
for a1,b1 in dic.keys():
  for a2,b2 in dic.keys():
    if min(a1+a2,b1+b2)>=18:
      ans+=dic[(a1,b1)]*dic[(a2,b2)]
print(ans//2)

Measured memory_bytes: 9496
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>

using namespace std;

typedef long long    ll;
typedef long double  ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

template <typename T> bool chmax(T &a, T& b) {if (a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, T& b) {if (a > b) {a = b; return true;} return false;}
#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define mset(x, val) memset(x, (val), sizeof(x))
#define cons(a, b) make_pair((a), (b))
#define car first
#define cdr second

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll solve(int N, ll K, const vector<ll> & A) {
  vector<ll> tbl(200010, 0);
  rep(i, N) ++tbl[A[i]];
  sort(all(tbl), greater<ll>());

  ll res = 0;
  rep3(i, K, 200010) res += tbl[i];
  return res;
}

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

  ll N;
  ll K;
  cin >> N;
  vector<ll> A(N);
  cin >> K;
  rep (i, N) {
    cin >> A[i];
  }

  auto ans = solve(N, K, A);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6052
def gi; gets.split.map(&:to_i); end
H,W,D=gi

h = {}
H.times do |y|
    arr = gi
    W.times do |x|
        h[arr[x]] = [x,y]
    end
end

cache = [0] * (D+1)
1.upto(H*W-D) do |i|
    x1,y1 = h[i]
    x2,y2 = h[i+D]
    cost = (x1-x2).abs + (y1-y2).abs
    cache << cache[i] + cost
end

Q=gets.to_i
Q.times do
    l,r=gi
    puts cache[r]-cache[l]
end

Measured memory_bytes: 25168
#include <iostream>

using namespace std;

int divs[101];
int nums[101];

int N;

int main () {

  cin >> N;
  for (int i = 2; i <= N; i++) {
    int k = i;
    int d = 2;
    while (k > 1) {
      if (k%d == 0) {
        divs[d]++;
        k /= d;
      } else d++;
    }
  }

  for (int i = 1; i <= 100; i++) divs[i] += 1;
  for (int i = 1; i <= N; i++) nums[divs[i]]++;
  for (int i = 100; i >= 1; i--) nums[i-1] += nums[i];

  int ans = 0;
  ans += nums[75];
  ans += nums[5]*(nums[5]-1)*(nums[3]-2) / 2;
  ans += nums[15] * (nums[5]-1);
  ans += nums[25] * (nums[3]-1);
  cout << ans << endl;

}


Measured memory_bytes: 256
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())

N=int(input())
A=list(map(int,input().split()))
if N==1:
    print(1)
    print(1)
    exit()
mod=10**9+7
fac=[1,1]
for i in range(2,N+2):
    fac.append(fac[i-1]*i%mod)
ifac=[pow(i,mod-2,mod) for i in fac]


def comb(a,b):
    if a<b:
        return(0)
    if a==0 or b==0:
        return(1)


    return(fac[a]*ifac[a-b]*ifac[b]%mod)



data=[[] for i in range(N+1)]
for i in range(len(A)):
    data[A[i]].append(i)
a,b=[i for i in data if len(i)>=2][0]

z=a+len(A)-b-1


for n in range(1,N+2):
    #print(N+1,n,z,n-1)
    print((comb(N+1,n)-comb(z,n-1))%mod)


Measured memory_bytes: 32948