akhauriyash/Code-Regression huggingface dataset:
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int main(){
  ll n, s;
  cin >> n >> s;
  if (n == s) cout << n + 1 << endl, exit(0);
  ll res = inf_ll;
  rep(i, 2, n){
    if (i * i > n) break;
    ll x = n, t = 0;
    while (x) t += x % i, x /= i;
    if (s == t) chmin(res, i);
  }
  rep(i, 1, n){
    if (i * i >= n) break;
    if ((n - (s - i)) % i) continue;
    ll b = (n - (s - i)) / i;
    if (s - i >= b) continue;
    if (i * b + s - i != n) continue;
    if (s - i < 0) continue;
    chmin(res, b);
  }
  cout << (res == inf_ll ? -1 : res) << endl;
}



Measured memory_bytes: 384
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
MOD = 10 ** 9 + 7
ans = 0
bit_matrix = [[0] * N for _ in range(61)]
for i in range(len(A)):
    n = 0
    while 2 ** n <= A[i]:
        if A[i] >> n & 1:
            bit_matrix[n][i] = 1
        n += 1
#print(bit_matrix)
#bit_matrix_T = []
'''
for j in range(60):
    tmp = []
    for i in range(N):
        tmp.append(bit_matrix[i][j])
    bit_matrix_T.append(tmp)
'''
#print(bit_matrix_T)
for i in range(len(bit_matrix)):
    tmp = Counter(bit_matrix[i])
    a = list(tmp.values())
    if len(a) == 2:
        ans += (2 ** i) * a[0] * a[1]
        ans %= MOD
print(ans)


Measured memory_bytes: 185932
n,y = map(int,input().split())


i5000 = 0
i10000 = 0
N = n + 1
for i1000 in range(N):
    for i5000 in range(N - i1000):
        i10000 = n - i1000 - i5000
        sum = i10000*10000 + i5000*5000 + i1000*1000
        if sum == y:
            print(i10000,i5000,i1000)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

int main(){
  int a,b,h,m;
  double pai,ans2,ans;
  scanf("%d %d %d %d",&a,&b,&h,&m);
  pai=(fabs(30*h+0.5*m - 6*m)/180)*3.14159265358979;
  ans2=a*a+b*b-2*a*b*cos(pai);
  ans=sqrt(ans2);
  printf("%.12f",ans);
}

Measured memory_bytes: 2640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,t;
	cin>>n>>t;
	int a[200010];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	long int sum=0;
	for(int i=1;i<n;i++){
		if(a[i]-a[i-1]>t){
			sum+=t;
		}
		else{
			sum+=(a[i]-a[i-1]);
		}
	}
	sum+=t;
	cout<<sum<<endl;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define sp << ' ' << 
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353

typedef struct quad{
    int a, b, c, d;
}qua;

int main()
{
    boost;
    ll tt = 1, n, m, k = 0, i, j;
    ll q, l = 0, r = 0, x, y, z, h, a, b, c, d;

    bool poss = true;
    // string m;

    // cin >> tt;
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> a >> b >> n;

        x = min(n, b - 1);

        cout << floor(1.0*a*x/b) - a*floor(1.0*x/b) << nl;

    }   
    return 0;
}

Measured memory_bytes: 3784
import fractions
import functools
def pin(type=int):
    return map(type,input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)
N,=pin()
As=list(pin())

L=(lcm_list(As))
B=[L//As[i] for i in range(N)]
print(sum(B) % 1000000007)

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

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

  if (s[0] == '0' || s[s.size() - 1] == '1') {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 0; i < (s.size() - 1) / 2; ++i) {
    if (s[i] != s[s.size() - i - 2]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int c = 1;
  int v = 1;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '1') {
      for (int j = 1; j <= c; ++j) {
        cout << v << " " << v + j << endl;
      }
      v += c;
      c = 1;
    } else {
      ++c;
    }
  }

  return 0;
}


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

int N;
int L[210];

int main(){
    cin>>N;

    for (int i = 0; i < 2*N; i++)
    {
        cin>>L[i];
    }

    sort(L,L+2*N,greater<int>());

    int ans=0;
    for (int i = 1; i < 2*N; i+=2)
    {
        ans += L[i];
    }
        
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
    int n;
    cin>>n;
    vector<int> k(n);
    for (int i = 0; i < n; i++)
    {
        cin>>k[i];
    }
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j: {i+1,i+2}){
            if(j<n){
                dp[j] = min(dp[j],dp[i]+abs(k[i]-k[j]));
            }
        }
    }
    cout<< dp[n-1]<<endl;
}

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

int     main() {
        long H, W, N;
        cin >>H >>W >>N;
        vector<vector<long>> B(0, vector<long> ());
        vector<long> C(10, 0);
        if (0<N) {
                for (long i=0; i<N; i++) {
                        long a, b;
                        cin >>a >>b;
                        for (long i=-1; i<=1; i++)
                                for (long j=-1; j<=1; j++)
                                        B.push_back({a+i, b+j});
                }
                sort(B.begin(), B.end());
                long h=0;
                long w=0;
                int CC=0;
                long I=0;
                while (I<B.size()) {
                        long h1=B.at(I).at(0);
                        long w1=B.at(I).at(1);
                        if ((h==h1)&&(w==w1)) {
                                CC++;
                        } else {
                                if ((h>1)&&(h<H)&&(w>1)&&(w<W))
                                        C.at(CC)++;
                                CC=1;
                                h=h1;
                                w=w1;
                        }
                        I++;
                }
                if ((h>1)&&(h<H)&&(w>1)&&(w<W))
                        C.at(CC)++;

        }
        C.at(0)=(H-2)*(W-2);
        for (int i=1; i<=9; i++)
                C.at(0) -=C.at(i);
        for (int i=0; i<=9; i++)
                cout <<C.at(i) <<endl;
        return 0;
};

Measured memory_bytes: 51364
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<int> p(n);
   rep(i, 0, n) cin >> p[i];
   vector<int> q(n);
   rep(i, 0, n) cin >> q[i];
   vector<int> P(n);
   rep(i, 0, n) P[i] = i + 1;

   map<vector<int>, int> mp;
   int cnt = 1;
   do {
      mp[P] = cnt++;
   } while (next_permutation(P.begin(), P.end()));
   int ans = abs(mp[p] - mp[q]);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#define N 201000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
int n, m;
struct node {
	int l, r;
	inline bool operator <(const node &a) const {
		return l < a.l || (l == a.l && r < a.r);
	}
}nd[N];
bool vis[N];
priority_queue<int, vector<int>, greater<int> > q;
int h[N], htot;
bool cmp(const int x, const int y) {
	return x > y;
}
int main() {
	read(n); read(m);
	for (int i = 1; i <= n; ++i)	read(nd[i].l), read(nd[i].r);
	sort(nd + 1, nd + 1 + n);
	int ptr = 1;
	for (int i = 1; i <= n; ++i) {
		int l = nd[i].l;
		if (ptr <= m && l >= ptr)	vis[ptr] = true, ++ptr, q.push(nd[i].r);
		else {
			q.push(nd[i].r); h[++htot] = q.top(); q.pop();
		}
	}
	sort(h + 1, h + 1 + htot, cmp);
	ptr = m;
	while (ptr && vis[ptr])	--ptr;
	int ct = 0;
	for (int i = 1; i <= htot; ++i) {
		int r = h[i];
		if (ptr && r <= ptr) {
			vis[ptr] = true;
			--ptr;
			while (ptr && vis[ptr])	--ptr;
		} else ++ct;
	}
	printf("%d\n", ct);
	return 0;
}


Measured memory_bytes: 5924
x, n = map(int, input().split())
#if n==0:
#    print(x)
p = list(range(n))
p = list(map(int, input().split()))
p_2 = list(range(n))
for i in range(n):
    p_2[i] = x-p[i]
for i in range(100):
    h = p_2.count(i)
    h_2 = p_2.count(-i)
    if h==0 and h_2!=0:
        print(x-i)
        break
    elif h!=0 and h_2==0:
        print(x+i)
        break
    elif h==0 and h_2==0:
        print(x-i)
        break
#if n==0:
#    print(x)

Measured memory_bytes: 9072
#include<stdio.h>
int main(){
    int H,W,i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0) break;
        for(i=1;H>=i;i++){
            for(j=1;W>=j;j++){
                if((i+j)%2==0){
                printf("#");
                }
                else printf(".");
                if(W==j) printf("\n");
            }
        }
    printf("\n");
    } 
}

Measured memory_bytes: 1808
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef pair<int, int> P;

int main(){
  int n; double ma, mb; cin >> n >> ma >> mb;
  int a[n], b[n], c[n];
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  int dp[45][450][450];
  rep(i, 45)rep(j, 450)rep(k, 450) dp[i][j][k] = 5000;
  dp[0][0][0] = 0;
  rep(i, n)rep(j, 401)rep(k, 401){
    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
    dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
  }
  int ans = 5000;
  rep(j, 401)rep(k, 401)if((j!=0 || k!=0) && k*ma==j*mb) ans = min(ans, dp[n][j][k]);
  cout << (ans < 5000 ? ans : -1) << endl;
}

Measured memory_bytes: 35840
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
vmax = max(v)
dp = [[0]*(N * vmax + 1) for i in range(N + 1)]
dp[0][0] = 0
for j in range(N * vmax):
    dp[0][j + 1] = float("inf")

for i in range(N):
    for j in range(N * vmax + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else: 
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])

ans = 0
for j in range(N * vmax + 1):
    if dp[N][j] <= W:
        ans = j
print(ans)

Measured memory_bytes: 310936
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)

int main() {
	ll ans = 0;
	string s;
	cin >> s;
	repi(i, 0, 3) if (s[i] == '1') ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int A, B;
    cin >> A >> B;

    int ans = (A-1) * (B-1);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
a_list = list(map(int, input().split()))
l_dict = {}
ans = 0
for i in range(0, n):
    a = a_list[i]
    ri = i - a
    if ri in l_dict:
        ans += l_dict[ri]
    li = i + a
    if li in l_dict:
        l_dict[li] += 1
    else:
        l_dict[li] = 1
print(ans)

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

int main(void){
    ll a,b,c;
    cin >> a >> b >> c;
    if (c <= a+b) {
        cout << b+c << endl;
    } else {
        cout << a+b+1 + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100100
const ll inf = (ll)1e10;
ll a[MAXN], b[MAXN], c[MAXN];
ll dp[MAXN][4];
int n;
ll solve( int pos, int color ) {
	if ( pos > n ) return 0;
	if ( dp[pos][color] != -1 ) return dp[pos][color];
	ll ret = 0;
	if ( color == 1 ) {
		ret = max(solve(pos+1,2)+b[pos],solve(pos+1,3)+c[pos]);
	}
	else if ( color == 2 ) {
		ret = max(solve(pos+1,1)+a[pos],solve(pos+1,3)+c[pos]);
	}
	else if ( color == 3 ) {
		ret = max(solve(pos+1,1)+a[pos],solve(pos+1,2)+b[pos]);
	}
	return dp[pos][color] = ret;
}
int main()
{
	#ifdef __APPLE__
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for ( int i = 1; i <= n; i++ ) cin >> a[i] >> b[i] >> c[i];
	memset(dp,-1,sizeof(dp));
	cout << max(solve(1,1),max(solve(1,2),solve(1,3))) << endl;
	return 0;
}



Measured memory_bytes: 10368
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

ll f(ll sum)
{
	if(sum==1) return 1;
	return 2*f(sum/2)+1;	
}

int main()
{
	ll sum;
	cin>>sum;
	cout<<f(sum)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define mod 1e9 +7;
typedef long long ll;
typedef vector<ll> vll;
const double phi = (1 + sqrt(5)) / 2;
const double phi_ = (1 - sqrt(5)) / 2;
ll fib(ll n){
    double res = pow(phi, n+1) - pow(phi_, n+1);
    return res / sqrt(5);
}
ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}
ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}
string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<8>(n); //任意の桁数<m>
    string s = ss.str();
    return s;
}
int main()
{
    ll n, k, ans = 0;
    cin >> n >> k;
    if(k == 0){
        cout << n*n << endl;
        return 0;
    }
    REP(b,1,n+1){
        ll p = n/b, r = n%b;
        ans += p*max(b-k, (ll)0) + max(r-k+1, (ll)0);
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int tong[10];
int main(){
	int n,i,g;
	memset(tong,0,sizeof(tong));
	while(cin>>n){
		
		for(i=0;i<n;i++){
		cin>>g;
		if(g>=1&&g<400)
			tong[1]=1;
		else if(g>=400&&g<800)
			tong[2]=1;
		else if(g>=800&&g<1200)
			tong[3]=1;
		else if(g>=1200&&g<1600)
			tong[4]=1;
		else if(g>=1600&&g<2000)
			tong[5]=1;
		else if(g>=2000&&g<2400)
			tong[6]=1;
		else if(g>=2400&&g<2800)
			tong[7]=1;
		else if(g>=2800&&g<3200)
			tong[8]=1;
		else if(g>=3200&&g<=4800)
			tong[9]++;
	}
	int sum=0;
	for(i=1;i<=8;i++)
		if(tong[i]==1)
			sum++;
	int min=sum,max=sum;
		max=sum+tong[9];
	if(sum==0&&tong[9])
		min=1;
	cout<<min<<" "<<max<<endl; 
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    --a, --b, --c, --d;
    int cnt = 0;
    bool ok = true;
    if (c < d) {
        for (int i = b; i < d; ++i) {
            if (s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        s[d] = '#';
        for (int i = a; i < c; ++i) {
            if (s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else {
        bool x = false;
        for (int i = b; i <= d; ++i) {
            if (s[i-1] == '.' and s[i] == '.' and s[i+1] == '.') {
                x = true;
                break;
            }
        }
        if (!x) s[b] = '#';
        for (int i = a; i < c; ++i) {
            if (s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        s[c] = '#';
        s[b] = '.';
        for (int i = b; i <= d-1; ++i) {
            if (s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
A,B,C=map(int,input().split())

yo=[0]*100

i=1
while True:
    temp=(A*i)%B
    if temp==C:
        print("YES")
        exit()
    else:
        if yo[temp]==0:
            yo[temp]=1
        else:
            print("NO")
            exit()
    i+=1

Measured memory_bytes: 2940
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
map<int,int> cnt;
signed main(void)
{
	reg int x,ans=0;
	int n;cin>>n;
	for(int i=1;i<=n;++i)
	{
		read(x);
		ans+=cnt[i-x];
		++cnt[i+x];
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 26340
process.stdin.resume();
process.stdin.setEncoding("utf8");
// 自分の得意な言語で
// Let's チャレンジ！！
    var lines = [];
    var reader = require("readline").createInterface({
        input: process.stdin,
        output: process.stdout
    });
reader.on("line", (line) => {
    lines.push(line);
});
reader.on("close", () => {
//入力をスペース区切りで配列に変換
    var e = lines[0].split(" "), h = Number(e[0]), a = (Number(e[1]));
    var t = h / a;
    console.log(Math.ceil(t));
    
});

Measured memory_bytes: 8644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


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

	cin >> A >> B >> C;

	ans = min(B /A, C);

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

	return 0;
}



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

char solver(char a[9]){
    for(int i=0; i<9; i+=3)
        if(a[i] == a[i+1] && a[i+1] == a[i+2] && a[i] != 's') return a[i];
    for(int i=0; i<3; ++i)
        if(a[i] == a[i+3] && a[i+3] == a[i+6] && a[i] != 's') return a[i];
    if(a[0] == a[4] && a[4] == a[8] && a[0] != 's') return a[0];
    if(a[2] == a[4] && a[4] == a[6] && a[2] != 's') return a[2];
    return 'd';
}

int main(){
    char a[9];
    while(scanf("%s", a) != EOF){
        char result = solver(a);
        cout << result << endl;
    }
    return 0;
}

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

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    int a, b;
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> ans(N, -1);
    queue<int> q;
    q.push(0);
    while ( !q.empty() ) {
        int v = q.front();
        q.pop();
        for ( int u : G[v] ) {
            if ( ans[u] >= 0 ) continue;
            ans[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << "\n";
    for ( int i = 1; i < N; i++ ) {
        cout << ans[i]+1 << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 10124
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

LL = [[-1] * 2 for _ in range(N)]
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if D[a] < D[b]:
    LL[b] = [a, i]
  elif D[a] > D[b]:
    LL[a] = [b, i]
  else:
    LL[a] = [b, i]
    LL[b] = [a, i]

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M

for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x][0] == -1:
      print(-1)
      exit()
    else:
      n, m = LL[x]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

for i in range(N):
  if L[i] == 1:
    L[i] = "B"
  else:
    L[i] = "W"
print("".join(list(map(str, L))))
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])


Measured memory_bytes: 123244
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
int main()
{
    string s;
    ll q,t,f;
    char c;
    cin>>s>>q;
    bool x=0;
    rep(jjj,q)
    {
        cin>>t;
        if(t==1) x=!x;
        else
        {
            cin>>f>>c;
            if((f+x)%2==1) s.insert(s.begin(),c);
            else s.insert(s.end(),c);
        }
    }
    if(x) reverse(s.begin(),s.end());
    cout<<s;
}


Measured memory_bytes: 1028
#include <cstdio>
#include <algorithm>
using namespace std;

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

    int s[100002] = {};
    for (int i = 0; i < n; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        for (int j = a; j <= b; ++j)
            ++s[j];
    }

    /*
    for (int i = 0; i <= n + 1; ++i)
        printf("%6d: %d\n", i, s[i]);
    */

    int ans = 0;
    for (int i = 0; i <= n + 1; ++i)
        if (i - 1 <= s[i])
            ans = i - 1;
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  int i,j;
  int max = 0;
  for(i=0;i<s.size()-t.size()+1;i++){
    int cnt = 0;
    for(j=0;j<t.size();j++){
      if(s[i+j]==t[j]) cnt++;
    }
    if(max<cnt) max=cnt;
  }
  cout << t.size()-max << "\n";
  return 0;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>

using u4t = std::uint32_t;
using i4t = std::int32_t;
using u8t = std::uint64_t;
using i8t = std::int64_t;

int main() {
  int N,M;
  std::cin>>N>>M;
  std::vector<int> node_ends(N,0);
  for(int i=0;i<M;i++){
    int a,b;
    std::cin>>a>>b;
    a--;b--;
    node_ends[a]++;
    node_ends[b]++;
  }
  bool noflag = false;
  for(int i=0;i<N;i++){
    if (node_ends[i]&1)noflag=true;
  }
  std::cout<<(noflag?"NO":"YES")<<std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void primer(vector<int>& U, int N) {//素因数分解
	for (size_t j = 2; j <= N; j++)
	{
		while (N%j==0)
		{
			N /= j;
			U.at(j)++;
		}
	}
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N+1,1);
	for (size_t i = 1; i <= N; i++)
	{
		primer(A, i);
	}
	long long ans=1;
	for (size_t i = 2; i <= N; i++)
	{
		ans *= A.at(i) % mod;
		ans %= mod;
	}
	//cout << A.at(2) << endl;
	cout << ans;
}


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

using namespace std;

int main()
{
	unsigned long long X;
	cin >> X;

	unsigned long long total = 0;
	unsigned long long ureshisa = 0;
	while (1)
	{
		if (X - total >= 500)
		{
			total += 500;
			ureshisa += 1000;
		}
		else if (X - total >= 5)
		{
			total += 5;
			ureshisa += 5;
		}
		else
		{
			break;
		}
	}
	cout << ureshisa;
}




Measured memory_bytes: 256
A6 = []
A2 = []
A3 = []
for i in range(2, 30001)[::-1]:
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = []
    S.append(A2.pop())
    S.append(A2.pop())
    S.append(A3.pop())
    S.append(A3.pop())
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
        else:
            break
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #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
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

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

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)
  bool f(ll K){

  }

  ll binary_search(ll ok, ll ng){
    while(abs(ok - ng) > 1){
      ll mid = (ok + ng) / 2;
      if(f(mid)) ok = mid;
      else ng = mid;
    }
    return ok;
  }



int main(){

  int N, A, B;
  cin >> N >> A >> B;

  if((B - A) % 2 == 0) print("Alice");
  else print("Borys");

}

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 INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if((c-a-b)<=0)cout << "No" << endl;
  else if(4*a*b<(c-a-b)*(c-a-b))cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

long long calc_target(long long x)
{
    long long target = 1;
    long long exp = 0;
    while (x > 0)
    {
        if (~x & 1)
        {
            target += (1 << exp);
        }
        exp++;
        x >>= 1;
    }
    return target;
}

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

    long long A;
    map<long long, int> m;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        m[A]++;
    }

    long long ans = 0;
    for (auto itr = m.rbegin(); itr != m.rend(); itr++)
    {
        long long target = calc_target(itr->first);
        while (itr->second > 0)
        {
            itr->second--;
            if (m[target] > 0)
            {
                m[target]--;
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 25216
#include<stdio.h>
int main(void)
{
	char a[5],b[5];
	scanf("%s %s",a,b);
	if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

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

typedef long lint;
typedef long long llint;

 static const llint MAX = 2e5+5;
// static const int NIL = -1;
// static const ll INF = 1<<21;
 static const llint MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n, k;
    cin >> n >> k;

    llint ans=0, tmp, s, g;
    for(llint in=k;in<=n+1;in++) {
        s=0;
        g=0;
        s = (in)*(in-1)/2;
        g = n*in-(in)*(in-1)/2;
        g=min(n*(n+1)/2, g);
        tmp = g - s + 1;
        tmp %= MOD;
        ans += tmp;
        // cout << s << g <<tmp << endl;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans = 0;
  string s ;
  cin >> s;
  for (int i=0 ; i<3;i++){
    if(s.at(i) =='1'){
      ans++;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 2005
#define inf 0x3f3f3f3f
int n;
int fir[N], tar[N << 1], nex[N << 1], cnt;
int mn[N], mx[N], siz[N];
int now, tot, ans = inf;
char S[N];
void Add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
void Dfs(int r, int fa, int d)
{
	if (S[r] == '1')
		now += d;
	for (int i = fir[r]; i; i = nex[i])
	{
		int v = tar[i];
		if (v == fa)
			continue;
		Dfs(v, r, d + 1);
	}
}
void Dfs1(int r, int fa, int d)
{
	if (S[r] == '1')
		tot += d;
	for (int i = fir[r]; i; i = nex[i])
	{
		int v = tar[i];
		if (v == fa)
			continue;
		Dfs1(v, r, d + 1);
	}
}
void Dfs2(int r, int fa)
{
	int tot = 0, p = 0;
	siz[r] = S[r] - '0';
	for (int i = fir[r]; i; i = nex[i])
	{
		int v = tar[i];
		if (v == fa)
			continue;
		Dfs2(v, r);
		if (mn[v] > mn[p])
			p = v;
		tot += mx[v];
		siz[r] += siz[v];
	}
	mx[r] = tot;
	tot -= mx[p];
	mn[r] = max(0, mn[p] - tot);
	if (fa)
	{
		mn[r] += siz[r];
		mx[r] += siz[r];
	}
}
void Solve(int r)
{
	tot = 0;
	Dfs1(r, 0, 0);
	if (tot & 1)
		return;
	Dfs2(r, 0);
	if (mn[r] > 0)
		return;
	ans = min(ans, tot / 2);
}
int main()
{
	scanf("%d%s", &n, S + 1);
	for (int i = 1; i < n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		Add(a, b), Add(b, a);
	}
	for (int i = 1; i <= n; i++)
		Solve(i);
	if (ans == inf)
		puts("-1");
	else
		printf("%d\n",ans);
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a, b, c;
	int x, y, z;
	int n = 0;
	scanf("%d %d %d", &a,&b,&c);

	if (a == b&&b == c){
		if(a%2==0)printf("-1\n");
		else printf("0\n");
		return 0;
	}
	else{
		for (;;){
			if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
				x = (b / 2) + (c / 2);
				y = (c / 2) + (a / 2);
				z = (a / 2) + (b / 2);
				a = x;
				b = y;
				c = z;
				n++;
			}
			else {
				printf("%d\n", n);
				break;
			}
		}
	}
	

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,x;
  cin>>N>>x;
  vector<long long> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  long long sum=0,ans=N;
  for(int i=0;i<N;i++){
    sum+=a.at(i);
  }
  while(sum>x){
    sum-=a.at(ans-1);
    ans--;
    if(ans==0){
    break;
    }
  }
  if(ans==N&&sum!=x){
    ans--;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var output = 0;
  var list = new Array(50);
  for(var i = 0; i < 50; i++){
    list[i] = new Array(50).fill(0);
  }
  var twoList = new Array(N).fill(0);
  var fiveList = new Array(N).fill(0);
  for(var i = 0; i < N; i++){
    var Ai = Math.round(parseFloat(next()) * 1000000000);
    while(Ai % 2 == 0){
      twoList[i]++;
      Ai = Math.floor(Ai / 2);
    }
    while(Ai % 5 == 0){
      fiveList[i]++;
      Ai = Math.floor(Ai / 5);
    }
  }
  for(var i = 0; i < N; i++){
    list[twoList[i]][fiveList[i]]++;
  }
  for(var i = 49; i >= 0; i--){
    for(var j = 48; j >= 0; j--){
      list[i][j] += list[i][j + 1];
    }
  }
  for(var i = 48; i >= 0; i--){
    for(var j = 49; j >= 0; j--){
      list[i][j] += list[i + 1][j];
    }
  }
  for(var i = 0; i < N; i++){
    var count2 = Math.max(18 - twoList[i], 0);
    var count5 = Math.max(18 - fiveList[i], 0);
    output += list[count2][count5];
    if(count2 <= twoList[i] && count5 <= fiveList[i]){
      output--;
    }
  }
  myout(output / 2);
}


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

using namespace std;

bool is_matched(vector<string> &va, vector<string> &vb, int y, int x) {
  bool ans = true;
  for (int i = 0; i < va.size() && ans; ++i) {
    for (int j = 0; j < va.size(); ++j) {
      if (vb[i + y][j + x] != va[i][j]) {
        ans = false;
        break;
      }
    }
  }

  return ans;
}

bool solve(vector<string> &va, vector<string> &vb) {
  if (va.size() > vb.size()) {
    return solve(vb, va);
  }

  int diff = vb.size() - va.size();
  bool ans = false;
  for (int i = 0; i <= diff && !ans; ++i) {
    for (int j = 0; j <= diff; ++j) {
      // 始点をi,jに固定
      if (is_matched(va, vb, i, j)) {
        ans = true;
        break;
      }
    }
  }

  return ans;
}

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<string> va(n), vb(m);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  for (int i = 0; i < m; ++i) {
    cin >> vb[i];
  }

  cout << (solve(va, vb) ? "Yes" : "No") << '\n';
  return 0;
}

Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int N = sc.nextInt();
            int M = sc.nextInt();
            if(N+M==0)break;
            int[][]p =new int[N][2];
            long ans=0;
            for (int i = 0; i < N; i++) {
                p[i][0]=sc.nextInt();
                p[i][1]=sc.nextInt();
                ans+=(long)p[i][0]*p[i][1];
            }
            Arrays.sort(p,new Comparator<int[]>(){
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    return arg1[1]-arg0[1];
                }
            });
            for (int i = 0; i < p.length; i++) {
                ans = ans - p[i][1]*Math.min(p[i][0], M);
                M = M - p[i][0];
                if(M<=0)break;
            }
            System.out.println(ans);
        }
    }

}

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

int main() {
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        
    }
    int b[n+1][3]={0},k,l,m;
    for(int i=1;i<n+1;i++)
    {
        k=max(b[i-1][1],b[i-1][2])+a[i-1][0];
        l=max(b[i-1][0],b[i-1][2])+a[i-1][1];
        m=max(b[i-1][0],b[i-1][1])+a[i-1][2];
        b[i][0]=k;
        b[i][1]=l;
        b[i][2]=m;
        
    }
    k=max({b[n][0],b[n][1],b[n][2]});
    cout<<k;
}

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

int main(){
  string S;
  cin >> S;
  
  int K1[200010]={};
  int K2[200010]={};
  
  for(int i=S.size()-1; i>=0; i--){
    if(i==S.size()-1){
      K1[i]=1;
      K2[i]=0;
    }else if(i==S.size()-2){
      K1[i]=(S[i]==S[i+1]?0:2);
      K2[i]=1;
    }else if(i==S.size()-3){
      K1[i]=1+max(S[i]==S[i+1]?0:K1[i+1],K2[i+1]);
      K2[i]=1+K1[i+2];
    }else{
      K1[i]=1+max(S[i]==S[i+1]?0:K1[i+1],K2[i+1]);
      K2[i]=1+max(K1[i+2],S.substr(i,2)==S.substr(i+2,2)?0:K2[i+2]);
    }
  }
  cout << max(K1[0],K2[0]) << endl;
}

Measured memory_bytes: 2180
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod



MOD = 998244353

n,a,b,k = li()

# 二項係数の準備
inv = inv_mod(n,MOD)
fac = fact(n,MOD)
facInv = fact_inv(n,inv,MOD)

ans = 0

for red in range(n+1):
    res = k - red*a
    if res%b != 0:
        continue
    else:
       blue = res//b
       
       ans = (ans + nCr(n,red,MOD,fac,facInv) * nCr(n,blue,MOD,fac,facInv)) % MOD

print(ans)       
       

Measured memory_bytes: 38732
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

void Ini(vector<ll> & d) {
	ll i;
	d[0] = d[1] = 1;
	for (i = 2; i < d.size(); i++)
		d[i] = d[i - 1] * i % MOD;
	return;
}

ll Pow(ll n, ll k) {
	ll ans = 1, a = n % MOD;
	while (k > 0) {
		if (k & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		k >>= 1;
	}
	return ans;
}

ll Inverse(ll a) {
	return Pow(a, MOD - 2);
}

ll Combi(int n, int k, vector<ll>& d) {
	chmin(k, n - k);
	if (k < 0)
		return 0;
	if (k == 0)
		return 1;
	ll ans = d[n] * Inverse(d[k]) % MOD;
	ans *= Inverse(d[n - k]);
	return ans % MOD;
}

int main(void) {
	int num, i, v;
	ll ans = 0, min = 0, x;
	cin >> num >> v;
	vector<ll> d(num), k(num + 1);
	Ini(k);
	rep(i, num)
		cin >> d[i];
	sort(d.begin(), d.end());
	v--;

	rep(i, num) {
		x = Combi(i, v, k);
		ans += d[i] * x;
		ans %= MOD;
		min += d[num - i - 1] * x;
		min %= MOD;
	}
	ans -= min;
	ans += MOD;
	ans %= MOD;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
num_list = []


def dfs(num, add_num):
    num *= 10
    num += add_num

    if num > N:
        return

    num_list.append(num)

    dfs(num, 7)
    dfs(num, 5)
    dfs(num, 3)

    return num_list


dfs(3, 3)
dfs(3, 5)
dfs(3, 7)
dfs(5, 3)
dfs(5, 5)
dfs(5, 7)
dfs(7, 3)
dfs(7, 5)
dfs(7, 7)


ans = 0
tmp = 0
target = set(['7', '5', '3'])
# print(num_list)
for n in num_list:
    tmp = 0
    for t in target:
        if t in str(n):
            tmp += 1
    if tmp == 3:
        ans += 1
print(ans)


Measured memory_bytes: 4340
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define lint long long

using namespace std;

pair<int,int> f(int x)
{
  int a = x%10;
  int b = 1;
  while(x){
    b = x;
    x /= 10;
  }
  pair<int,int> p(a,b);
  return p;
}


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

  map<pair<int,int>,int> freq;
  for(int i=1;i<=n;i++){
    freq[f(i)]++;
  }

  int answer = 0;
  for(int i=1;i<=n;i++){
    pair<int,int> q(f(i).second,f(i).first);
    answer += freq[q];
  }
  cout << answer << endl;
  return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    int n; cin >> n;
    vector<int> a;
    vector<int> cnt(1000001, 0);
    for (int i = 0; i < n; i++) {
        int x; cin >> x; ++cnt[x];
        a.push_back(x);
    }

    if (cnt[1] == 1) {
        cout << 1 << endl; return 0;
    } else if (cnt[1] > 1) {
        cout << 0 << endl; return 0;
    }

    int ans = 0;
    for (auto& i : a) {
        if (cnt[i] != 1) continue;
        vector<int> f;
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) {
                f.push_back(j);
                f.push_back(i/j);
            }
        }
        bool ok = true;
        for (auto& j : f) {
            if (cnt[j]) {
                ok = false; break;
            }
        }
        if (ok) ++ans;
    }
    cout << ans << endl;

    return 0;
}

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

aa=list(map(int,input().split()))
q = int(input())
b=[]
c=[]
from collections import Counter as cnt
ans = sum(aa)

a = dict(cnt(aa))
for i in range(q):
    bb,cc=list(map(int,input().split()))
    b.append(bb)
    c.append(cc)
    if bb not in a:
        a[bb]=0
    if cc not in a:
        a[cc]=0



for i in range(q):
    ans += a[b[i]]*(c[i]-b[i])
    a[c[i]] += a[b[i]]

    a[b[i]] = 0
    print(ans)

Measured memory_bytes: 27792
n = int(input())
la = list(map(int,input().split()))
if n%2 == 0:
  for i in range(n-1,-1,-2):
    print(la[i],end=' ')
  for i in range(0,n,2):
    print(la[i],end=' ')
  print()
else:
  for i in range(n-1,-1,-2):
    print(la[i],end=' ')
  for i in range(1,n,2):
    print(la[i],end=' ')
  print()

Measured memory_bytes: 26020
// In The Name OF Allah
// Mehrkish Makuei
// Islamic Republic Of Iran

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

typedef long long ll;
#define Mehrkish ios::sync_with_stdio(false),		cin.tie(0),		cout.tie(0)
#define pb push_back

const int maxx = 2e5 + 19;
int n, m, a[maxx], c[maxx], b[maxx], ans, jvb, sum, z, l, x, y, k, minn = 99999999;
string s[119], t, w;
bool flag = true;
vector <ll> v;

void Input(){
	cin >> n >> m >> k;
}

void Solve(){
	for ( int i = n; i <= k; i += n )
		ans += m;
	cout << ans << endl;
}


int main(){
	Mehrkish;
	Input(),	Solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int ll
int32_t main()
{
    int l, r;
    cin >> l >> r;
    if (r - l > 2020)
    {
        cout << 0 << '\n'; return 0;
    } 
    else 
    {
        int ans = 2018;
        for (int i = l; i<=r; i++)
        {
            for (int j = i+1; j<=r; j++)
            {
                ans = min(ans, (i*j)%2019);
            }
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 256