akhauriyash/Code-Regression huggingface dataset:
Module Module083B

    Sub Main(ByVal args() As String)
        Dim N As Integer
        Dim A As Integer
        Dim B As Integer
        Dim i, j As Integer
        Dim i_str As String
        Dim tmp As Integer : tmp = 0
        Dim result As Integer : result = 0

        Dim arr(3) As String

        arr = Split(Console.ReadLine())
        N = Integer.Parse(arr(0))
        A = Integer.Parse(arr(1))
        B = Integer.Parse(arr(2))

        For i = 0 To N
            tmp = 0
            i_str = i.ToString
            For j = 0 To i_str.Length - 1
                tmp = tmp + Integer.Parse(i_str(j))
            Next
            If A <= tmp And tmp <= B Then
                result = result + i
            End If
        Next

        Console.Write(result)
    End Sub
End Module


Measured memory_bytes: 13408
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion


LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 



/*****************************************************************************/

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

	vi a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(all(a));
	a[0] = a[2] - a[0]; a[1] = a[2] - a[1]; a[2] = 0;
	int ans = 0;
	while (true) {
		if (a[0] == a[1] && a[1] == a[2]) {
			cout << ans;
			return 0;
		}
		ans += a[0] / 2;
		a[0] %= 2;
		ans += a[1] / 2;
		a[1] %= 2;
		if (a[0] == 1 && a[1] == 1) {
			cout << ans + 1;
			return 0;
		}ei(a[0] == 1 || a[1] == 1) {
			cout << ans + 2;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P==0) return 1;
    if(P < 0) return 0;
    if(P%2==0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) return N * RS(N,P - 1,M);
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    reverse(vec.begin(),vec.end());
    multiset<int> ms;
    for(int i = 0;i < N;i++) {
        auto itr = ms.upper_bound(vec.at(i));
        if(itr == ms.end()) {
            ms.insert(vec.at(i));
        }
        else {
            ms.erase(itr);
            ms.insert(vec.at(i));
        }
    }
    cout << ms.size() << endl;
}

Measured memory_bytes: 8164
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    LL n;
    LL m;
    LL ans=1;

    cin >> n >> m;
    if(abs(n-m)>=2){
        ans=0;
    }else{
        for(LL i=1; i<=n; i++){
            ans=(ans*i)%MOD;
        }
        for(LL i=1; i<=m; i++){
            ans=(ans*i)%MOD;
        }
        if(n==m){
            ans=(ans*2)%MOD;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b,c;
	t = 1;
	while(t--) {
	 cin >> a >> b >> c;
	 if(a == b)
	  cout << c << endl;
	 else if(a == c)
	  cout << b << endl;
	 else
	  cout << a << endl;
	}
	return 0;
}



Measured memory_bytes: 256
N = input()
H_list = list(map(int, input().split()))

for i in range(len(H_list) - 1):
  if H_list[i] < H_list[i + 1]:
    H_list[i + 1] -= 1
  if H_list[i] > H_list[i + 1]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 14396
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s, t, o = "";
  int i, j;
  cin >> s >> t;
  vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));

  for (i = 1; i <= s.size(); i++) {
    for (j = 1; j <= t.size(); j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }

  i = s.size();
  j = t.size();
  while (i > 0 && j > 0) {
    if (s[i - 1] == t[j - 1]) {
      o = s[i - 1] + o;
      i--;
      j--;
    } else if (dp[i - 1][j] > dp[i][j - 1]) {
      i--;
    } else {
      j--;
    }
  }
  cout << (o.size() > 0 ? o : "") << endl;
}


Measured memory_bytes: 38264
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ld n , d;
vector<vector<ld>> x(n,vector<ld>(d));

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ss = s.size();
    vector<vector<int>> a(3);
    for(int i=0;i<ss;i++){
        if(s.at(i)=='R') a.at(0).emplace_back(i);
        if(s.at(i)=='G') a.at(1).emplace_back(i);
        if(s.at(i)=='B') a.at(2).emplace_back(i);
    }
    ll ans = 0;

    for(int i=0;i<=n-3;i++){
        bool r = 0, g=0, b=0;
        if(s.at(i)=='R') r = 1;
        if(s.at(i)=='G') g = 1;
        if(s.at(i)=='B') b = 1;
        for(int j=i+1;j<=n-2;j++){
            bool rr = 0, gg = 0, bb = 0;
            if(r==1) rr=1;
            if(g==1) gg=1;
            if(b==1) bb=1;
            if(s.at(j)=='R' && r == 1) continue;
            if(s.at(j)=='G'&& g == 1) continue;
            if(s.at(j)=='B' && b == 1) continue;
            if(s.at(j)=='R') r = 1;
            if(s.at(j)=='G') g = 1;
            if(s.at(j)=='B') b = 1; 
            if(r==0){
                auto it = lower_bound(a.at(0).begin(),a.at(0).end(),(j+1));  
                ans += (int)(a.at(0).size()) - (it - a.at(0).begin());
                if(j+(j-i)<n  && s.at(j+(j-i)) == 'R') ans--;  
            }
            if(g==0){
                auto it = lower_bound(a.at(1).begin(),a.at(1).end(),(j+1));  
                ans += (int)(a.at(1).size()) - (it - a.at(1).begin());
                if(j+(j-i)<n && s.at(j+(j-i)) == 'G') ans--;  
            }
            if(b==0){
                auto it = lower_bound(a.at(2).begin(),a.at(2).end(),(j+1));  
                ans += (int)(a.at(2).size()) - (it - a.at(2).begin());
                if(j+(j-i)<n && s.at(j+(j-i)) == 'B') ans--;  
            }
            r = 0, g = 0, b = 0;
            if(rr==1) r = 1;
            if(gg==1) g = 1;
            if(bb==1) b = 1;
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}

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

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    bool negx = (x < 0);
    if (negx)
        x = -x;
    ll m = x % d;
    bool mind = 1;
    if (-m < (m - d))
        mind = 0;
    if (negx)
        mind = !mind;
    if (x / d > k)
    {
        cout << x - d * k << endl;
    }
    else if ((mind = 1 && (x / d % 2 == k % 2)) || (mind == 0 && (x / d % 2 == k % 2)))
        cout << m << endl;
    else
        cout << d - m << endl;
}


Measured memory_bytes: 3532
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
K = input("")
K = int(K)
SUM = 0
for a in range(K):
    ai = a+1
    for b in range(K):
        bi = b+1
        for c in range(K):
            ci = c+1
            SUM = SUM + gcd(ai, bi, ci)

print(SUM)

Measured memory_bytes: 69824
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
  int i;
  int A, B;

  scanf("%d", &A);
  scanf("%d", &B);

  for(i=0; i<=1000000000; i++){
    if(abs(A-i) == abs(B-i)){
      printf("%d", i);
      break;
    }
    if(i==1000000000){
      printf("IMPOSSIBLE");
    }
  }

  return 0;

}

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

int main(){
	int n,sum = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int j = i,f = 0;
		while(j){
			j /= 10;
			f++;
		}
		if(f % 2 == 1) {
			sum++;
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nab = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            if (nab[1] == 0)
            {
                Console.WriteLine(0);
                return;
            }

            var tmp = nab[1] + nab[2];
            var mod = nab[0] % tmp;
            if (mod > nab[1]) mod = nab[1];
            var div = nab[0] / tmp;
            Console.WriteLine(nab[1] * div + mod);
        }
    }
}


Measured memory_bytes: 13396
#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
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  while(1) {
      int a,b;
      string s;
      cin >> a >> s >> b;
      if(s == "?") break;
      if(s == "+") cout << a + b << "\n";
      if(s == "-") cout << a - b << "\n";
      if(s == "*") cout << a * b << "\n";
      if(s == "/") cout << a / b << "\n";
  }
}


Measured memory_bytes: 3228
a,b = map(int,input().split())
if a == b:
    print(0)
elif a == -b:
    print(1)
elif a == 0:
    if b > 0:
        print(b)
    else:
        print(-b+1)
elif b == 0:
    if a < 0:
        print(-a)
    else:
        print(1+a)
elif a>0 and b>0:
    if a<b:
        print(b-a)
    else:
        print(a-b+2)
elif a<0 and b<0:
    if a<b:
        print(b-a)
    else:
        print(a-b+2)
elif a<0 and b>0:
    if abs(a)<b:
        print(min(b-a,b-abs(a)+1))
    else:
        print(min(b-a,abs(a)-b+1))
else:
    if abs(b)>a:
        print(min(a-b,abs(b)-a+1))
    else:
        print(min(a-b,a-abs(b)+1))





Measured memory_bytes: 38384
s = input()
c = 0
if len(s)%2==0:
  for a,b in zip(s[len(s)//2:],reversed(s[:len(s)//2])):
    if a != b:
      c+=1
else:
  for a,b in zip(s[len(s)//2+1:],reversed(s[:len(s)//2])):
    if a != b:
      c += 1
print(c)

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

import sys
from itertools import permutations

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

N = INT()
P = tuple(LIST())
Q = tuple(LIST())

a = b = 0
for i, perm in enumerate(sorted(permutations(range(1, N+1)))):
    if perm == P:
        a = i + 1
    if perm == Q:
        b = i + 1
print(abs(a - b))


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int count = 0;
    while(1){
        if(count % 2 == 0){
            c = c - b;
            if(c <= 0){
                cout << "Yes" << endl;
                break;
            }
        }else{
            a = a - d;
            if(a <= 0){
                cout << "No" << endl;
                break;
            }
        }
        count++;
    }
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;
    int T, A; cin >> T >> A; T *= 1000; A *= 1000;

    unsigned int diff = 1e+9, index = -1;
    for (int i = 0; i < N; i++) {
        int H; cin >> H;
        if (abs(T-H*6-A) < diff) {
            diff = abs(T-H*6-A);
            index = i;
        }
    } 

    cout << index+1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> A(h + 2, vector<char>(w + 2));
    rep(i, w + 2) {
        A[0][i] = '#';
        A[h + 1][i] = '#';
    }
    rep(i, h + 2) {
        A[i][0] = '#';
        A[i][w + 1] = '#';
    }
    rrep(i, h) {
        rrep(j, w) cin >> A[i][j];
    }
    rep(i, h + 2) {
        rep(j, w + 2) cout << A[i][j];
        cout << endl; 
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
typedef long long lint;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF 1e18




signed main(){
	int T,X;
	cin >> T >> X;

	double ans;
	ans = (double(T) / X);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int w,h,x,y,i,j,k,masu[22][22],checked[22][22],*g,cont;
void check(int xx,int yy){
cont++;
checked[xx][yy]=1;
int m,n;m=1;n=0;
if(checked[xx+m][yy+n]==0 && 
masu[xx+m][yy+n]==0)
check(xx+m,yy+n);
m=0;n=1;
if(checked[xx+m][yy+n]==0 && 
masu[xx+m][yy+n]==0)
check(xx+m,yy+n);
m=-1;n=0;
if(checked[xx+m][yy+n]==0 && 
masu[xx+m][yy+n]==0)
check(xx+m,yy+n);
m=0;n=-1;
if(checked[xx+m][yy+n]==0 && 
masu[xx+m][yy+n]==0)
check(xx+m,yy+n);
}
int main(void){
char a[22];
while(1){
scanf("%d%d",&w,&h);
if(w==0 && h==0)
break;
cont=0;
for(j=0;j<22;j++)
for(i=0;i<22;i++){
masu[i][j]=1;
checked[i][j]=0;
}
for(j=1;j<=h;j++){
scanf("%s",a);
for(i=1;i<=w;i++)
switch(a[i-1]){
case '@':x=i;y=j;
case '.':masu[i][j]=0;break;
}
}
check(x,y);
printf("%d\n",cont);
}
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long N;
    std::cin >> N;
    long long M;
    std::cin >> M;
    std::vector<long long> a(M);
    std::vector<long long> b(M);
    for (int i = 0; i < M; i++) {
        std::cin >> a[i];
        std::cin >> b[i];
    }
    V<pii> p(M);
    rep(i, M) { p[i] = make_pair(b[i], a[i]); }
    sort(all(p));
    int e = 0;
    int ans = 0;
    rep(i, M) {
        if (e <= p[i].second) {
            ans++;
            e = p[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.*;class Main{public static void main(String[]a){Scanner c=new Scanner(System.in);int l=c.nextInt(),n=0,m=0;while(l>=(1<<n++));n--;String s="";for(int b=0;++b<n;s+=b+" "+(b+1)+" "+0+"\n"+b+" "+(b+1)+" "+(1<<(b-1))+"\n",m+=2)if((l&(1<<(b-1)))!=0){s+=b+" "+n+" "+(l>>b<<b)+"\n";m++;}System.out.print(n+" "+m+"\n"+s);}}

Measured memory_bytes: 23636
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N, M;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  // 0-indexed
  int goal = N - 1;
  vector<vector<int>> G(N);
  REP(i, M)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b), G[b].push_back(a);
  }

  int start = 0;
  queue<int> q;
  q.push(start);

  vector<bool> used(N, false);
  vector<int> cost(N, -inf);
  cost[0] = 2;

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    for (auto v : G[u]) {
      if (!used[v]) q.push(v);
      cost[v] = max(cost[v], cost[u] - 1);
    }
  }

  // for (auto c : cost) {
  //   cout << c << " ";
  // }

  // cout << cost[goal] << endl;
  if (cost[goal] >= 0) {
    cout << "POSSIBLE" << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}



Measured memory_bytes: 13168
#include <iostream>
#include <string>

using namespace std;

int main(void){
	int n,m,k,l;
	long sum,cnt;
	string str;
	char s;
	cin >> str;
	cin >> n;
	m = str.length();
	k=m;l=-1;
	sum=0;cnt=0;
	if(str[0]==str[m-1]){
		s = str[m-1];
		for(k=m-2;k>=0;k--){
			if(s!=str[k]){
				k++;
				break;
			}else if((m-1-k)%2==1){
				sum++;
			}
		}
		if(k<0){
			if(m%2==0){
				sum *= n;
				cout << sum << endl;
			}else{
				sum = (sum*2+1)*(n/2)+sum*(n%2);
				cout << sum << endl;
			}
			return 0;
		}
		s = str[0];
		for(l=1;l<m;l++){
			if(s!=str[l]){
				l--;
				break;
			}else if(l%2==1){
				sum++;
			}
		}
	}
	s = str[l+1];
  for(int i=l+2;i<k;i++){
		if(s==str[i]){
			cnt++;
			s = ' ';
		}else{
			s=str[i];
		}
	}
	sum += cnt * n;
	cnt = ((m-k)+l+1)/2;
	sum += cnt*(n-1);
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
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;}
// head
const int mxN = 1e5;
int n, k;
ll a[mxN], dp[mxN];
int main() {
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
	

	cin >> n >> k;
	rep(i, 0, n) cin >> a[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	rep(i, 0, n){
		rep(j, 1, k + 1){
			if(i - j < 0) continue;
			dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
		}
	}
	// rep(i, 0, n) cout << dp[i] << " \n"[i == n-1];
	cout << dp[n-1] << endl;
}




Measured memory_bytes: 1792
//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}

long long search(long long x,long long a[],long long n){
    long long st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

int main(void){
  long long h,w,k;
  long long x,y;
  long long rx[524288]={0},ry[524288]={0};
  long long cx[524288],cy[524288];
  long long mrx=0,mry=0,r;
  long long a[524288];
  scanf("%lld%lld%lld",&h,&w,&k);
  
  for(long long i=0;i<k;i++){
    scanf("%lld%lld",&x,&y);
    x--;y--;
    a[i]=x*w+y;
    rx[x]++;
    ry[y]++;
    mrx=llmax(rx[x],mrx);
    mry=llmax(ry[y],mry);
  }
  r=(mrx+mry-1);
  qsort(a,k,sizeof(long long),llsortfncsj);
  long long c=0,hm=0,wm=0;
  for(long long i=0;i<h;i++){if(rx[i]==mrx){cx[hm]=i;hm++;}}
  for(long long i=0;i<w;i++){if(ry[i]==mry){cy[wm]=i;wm++;}}
  if(hm*wm>k){printf("%lld\n",r+1);return 0;}
  a[k]=-1;
  
  for(long long i=0;i<hm;i++){
    for(long long j=0;j<wm;j++){
      long long key=cx[i]*w+cy[j];
      if(key!=a[search(key,a,k)]){printf("%lld\n",r+1);return 0;}
    }
  }
  
  printf("%lld\n",r);
  return 0;
}


Measured memory_bytes: 16980
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll N, X, Y;
	cin >> N >> X >> Y;
	X -= 1;
	Y -= 1;

	vector<ll> ans(N, 0);

	for (ll x = 0; x < N; ++x)
	{
		for (ll y = x + 1; y < N; ++y)
		{
			ll d1 = abs(x - y);
			ll d2 = 1 + abs(x - X) + abs(y - Y);
			ll d = min(d1, d2);
			ans[d]++;

			//cout << x << " " << y << " " << d1 << " " << d2 << endl;
		}
	}

	for (ll i = 0; i < N - 1; ++i)
	{
		cout << (ans[i + 1]) << endl;
	}
}


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

int main(){
  int n;
  cin>>n;
  int a[n];
  map<int,int>mp;
  vector<int>b;
  for(int i=0;i<n;i++){
      cin>>a[i];
      if(mp.count(a[i])==0)
        b.push_back(a[i]);
      mp[a[i]]++;
  }
      
  int count=0;
  //cout<<b.size()<<endl;
  
  for(int i=0;i<(int)b.size();i++){
    for(int j=(i+1);j<(int)b.size();j++){
      for(int k=(j+1);k<(int)b.size();k++){
        if(b[i]+b[j]>b[k] && b[j]+b[k]>b[i] && b[i]+b[k]>b[j])
           count=count+mp[b[i]]*mp[b[j]]*mp[b[k]];
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3648
N = int(input())
is_matched = False
res = ""

for i in range(1, 10):
    for j in range(1, 10):
        if N == i * j:
            is_matched = True
            res = "Yes"
            break
    if is_matched:
        break
    elif i == j == 9:
        res = "No"
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
pair<int,int> a[maxn];
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;++i) cin>>a[i].first,a[i].second=i;
	sort(a+1,a+1+n);
	cout<<a[1].second;
	for(int i=2;i<=n;++i) {
		cout<<" "<<a[i].second;
	}
	cout<<endl;
}

Measured memory_bytes: 1536
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val limit = (k * 2) - 1
    if (n >= limit) {
        println("YES")
    } else {
        println("NO")
    }
}

Measured memory_bytes: 31380
def main():
    num, k_num = map(int, input().split())

    count_all, count_half = 0, 0
    for i in range(1, num + 1):
        if i % k_num == 0:
            count_all += 1
        elif i % k_num == k_num // 2 and k_num % 2 == 0:
            count_half += 1

    print(int(count_all**3 + count_half**3))



if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let mut K = read!(usize);
    let mut Q = VecDeque::new();
    let lln;

    for d in 1..10_i64 {
        Q.push_back((d, d));
    }

    loop {
        let (x, d) = Q.pop_front().unwrap();

        K -= 1;

        if K == 0 {
            lln = x;
            break;
        }

        for e in max(d - 1, 0)..min(d + 2, 10) {
            let y = x * 10 + e;
            Q.push_back((y, e));
        }
    }

    println!("{}", lln)
}


Measured memory_bytes: 9464
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.split("\n");
  const num = parseInt(input.shift()); // 料理数
  const order = input[0].split(" ").map(c => parseInt(c));
  const point = input[1].split(" ").map(c => parseInt(c));
  const addPoint = input[2].split(" ").map(p => parseInt(p));
  let sum = 0;
  for (let i = 0; i < num; i++) {
    sum += point[order[i] - 1];

    if (order[i + 1] - order[i] === 1) {
      sum += addPoint[order[i] - 1];
    }
  }
  console.log(sum);
}


Measured memory_bytes: 9420
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
bool is_month(int);
int main(){
    string s;
    cin >> s;
    int first,second;
    first = stoi(s.substr(0,2));
    second = stoi(s.substr(2,2));
    if(is_month(first) && is_month(second))
        cout << "AMBIGUOUS" << endl;
    else if(!is_month(first) && !is_month(second))
        cout << "NA" << endl;
    else if(is_month(first))
        cout << "MMYY" << endl;
    else if(is_month(second))
        cout << "YYMM" << endl;
    return 0;
}

bool is_month(int n){
    if(n == 0 || n > 12)
        return false;
    else 
        return true;
}

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

int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;

    long long int x=n/(a+b);
    long long int y=n%(a+b);

    long long int count=0;
    if(y>=a)
        count = x*a+a;
    else
        count=x*a + y;
        
        cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include <map>

using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)


int main(){
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import collections
N, M = map(int, input().split())
KA = [[] for _ in range(N)]
for i in range(N):
    KA[i] = list(map(int, input().split()))
    KA[i].pop(0)

all_ka = []
for ka in KA:
    all_ka.extend(ka)
all_ka = collections.Counter(all_ka)
count = 0
for one in all_ka:
    if all_ka[one] == len(KA):
        count += 1
print(count)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int line1 = sc.nextInt();
		int line2 = sc.nextInt();
		int line3 = sc.nextInt();
		sc.close();
		String number = String.valueOf(line1) + String.valueOf(line2) + String.valueOf(line3);
		int numberIntValue = Integer.valueOf(number);
		if (numberIntValue % 4 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22228
n,x = map(int,input().split())
if n != 1:
  l = list(map(int,input().split()))
  i = 0
  cnt = 0
  ans = 0
  while cnt <= x :
    if i == n:
      print(n+1)
      exit()
    ans += 1
    cnt += l[i]
    i += 1
  print(ans)
else:
  l = int(input())
  if l <= x:
    print(2)
  else:
    print(1)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

int n, m, r;
int dir[8];
int cost[200][200];

int fac(int a){
	if(a == 1){
		return 1;
	}else{
		return a * fac(a-1);
	}
}

int solve(){
	//printf("permutations\n");
	sort(dir, dir+r);
	int ans = 1000000009;
	do{
		/*for(int i = 0; i < r; i++){
			printf("%d ", dir[i]);
		}*/
		int tmp = 0;
		for(int j = 0; j < r-1; j++){
			tmp += cost[dir[j]][dir[j+1]];
		}
		//printf("tmp = %d\n", tmp);
		ans = min(ans, tmp);
	}while(next_permutation(dir, dir+r));
	return ans;
}

int main(){
	scanf("%d%d%d", &n, &m, &r);
	for(int i = 0; i < r; i++){
		scanf("%d", &dir[i]);
		dir[i]--;
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cost[i][j] = 1000000009;
		}
	}
	for(int i = 0; i < n; i++){
		cost[i][i] = 0;
	}
	for(int i = 0; i < m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		scanf("%d", &cost[a-1][b-1]);
		cost[b-1][a-1] = cost[a-1][b-1];
	}
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	/*printf("\n");
	printf("cost\n");
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			printf("%d ", cost[i][j]);
		}
		printf("\n");
	}
	printf("\n");*/
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    string t;
    cin >> t;
    int n=t.length();
    for(int i=0; i<n; i++){
        if(t[i]=='?')t[i]='D';
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int height = sc.nextInt();
        int width = sc.nextInt();
        while (!(height == 0 && width == 0)) {
            for (int h = 0; h < height; h++) {
                StringBuilder sb = new StringBuilder();
                if (h % 2 == 0) {
                    for(int w = 0; w < width; w++){
                        if (w % 2 == 0) sb.append('#');
                        else sb.append('.');
                    }
                } else {
                    for(int w = 0; w < width; w++){
                        if(w % 2 == 0) sb.append('.');
                        else sb.append('#');
                    }
                }
                System.out.println(sb);
            }
            System.out.println();
            height = sc.nextInt();
            width = sc.nextInt();
        }
    }
}



Measured memory_bytes: 28656
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int A,B;
char op;







int main()
{

	cin >> A >> op >> B;

	if(op == '+')
			cout << A + B << endl;
	if(op == '-')
			cout << A - B << endl;






}







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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<long> a(N), b(N);
	long SA=0;
	long SB=0;
	for (int i=0; i<N; i++) {
		cin >>a.at(i);
		SA +=a.at(i);
	}
	for (int i=0; i<N; i++) {
		cin >>b.at(i);
		SB +=b.at(i);
	}
	long S=SB-SA;
	SA=S;
	SB=S;
	for (int i=0; i<N; i++) {
		if ((SA<0)||(SB<0)) {
			cout <<"No" <<endl;
			return 0;
		}
		long d=b.at(i)-a.at(i);
		if (d<0)
			SB +=d;
		else {
			SA -=d/2;
			if (1==d%2) {
				SA--;
				SB--;
			}
		}
	}
	if ((0<=SA)&&(0<=SB)) {
		cout <<"Yes" <<endl;
	} else {
		cout <<"No" <<endl;
	}
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <vector>

const int MOD = (int)1e9 + 9;
const int kN = 250000 + 5;
using LL = long long;
int n;
char s[kN];
const std::vector<int> primes{(int)1e9 + 7, (int)1e8 + 7, 233333, (int)1e6 + 7, 13};
const int kSize = primes.size();
std::vector<int> inv_primes(kSize);


int inv(int x) {
  return x == 1 ? 1 : (MOD - MOD / x) * 1LL * inv(MOD % x) % MOD;
}

std::vector<int> calc(const int *a, const int *b, const int *c) {
  std::vector<int> ret(kSize);
  for (int i = 0; i < kSize; ++ i)
    ret[i] = (a[i] * 1LL * c[i] % MOD + b[i]) % MOD;
  return ret;
}

bool operator < (const std::vector<int>& lhs, const std::vector<int> &rhs) {
  if (lhs.size() != rhs.size())
    return lhs.size() < rhs.size();
  for (int i = 0; i < lhs.size(); ++ i) {
    if (lhs[i] < rhs[i])
      return true;
    else if (lhs[i] > rhs[i])
      return false;
  }
  return false;
}

LL solve() {
  for (int i = 0; i < kSize; ++ i)
    inv_primes[i] = inv(primes[i]);
  LL ret = 0;
  std::map<std::vector<int>, int> map;
  map[std::vector<int>(kSize, 0)] = 1;
  int c[kSize] = {};
  for (int i = n; i >= 1; -- i) {
    char ch = s[i - 1];
    for (int j = 0; j < kSize; ++ j) {
      if (ch == '+')
        c[j] = (c[j] + 1) % MOD;
      else if (ch == '-')
        c[j] = (c[j] + MOD - 1) % MOD;
      else if (ch == '>')
        c[j] = c[j] * 1LL * primes[j] % MOD;
      else
        c[j] = c[j] * 1LL * inv_primes[j] % MOD;
    }
  }
  int a[kSize] = {}, b[kSize] = {};
  for (int i = 0; i < kSize; ++ i)
    a[i] = 1;
  for (int i = n; i >= 1; -- i) {
    char ch = s[i - 1];
    for (int j = 0; j < kSize; ++ j) {
      if (ch == '-')
        b[j] = (b[j] + a[j]) % MOD;
      else if (ch == '+')
        b[j] = (b[j] + MOD - a[j]) % MOD;
      else if (ch == '<')
        a[j] = a[j] * 1LL * primes[j] % MOD;
      else
        a[j] = a[j] * 1LL * inv_primes[j] % MOD;
    }
    auto it = map.find(calc(a, b, c));
    if (it != map.end())
      ret += it->second;
    map[std::vector<int>(b, b + kSize)] ++;
  }
  return ret;
}

int main() {
  srand(time(NULL));
  scanf("%d%s", &n, s);
  printf("%lld\n", solve());
}

Measured memory_bytes: 27776
from math import factorial
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

cases = []
nums = [i for i in range(1,N+1)]
for prm in permutations(nums, N):
    cases.append(prm)
cases.sort()

print(abs(cases.index(P) - cases.index(Q)))

Measured memory_bytes: 8052
/*
[arc077] D - 11
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    static gf mod_inv(int a, int m) {
        int u = 0, v = 1;
        while (a != 0) {
            int t = m / a;
            m -= t * a;
            u -= t * v;
            swap(a, m);
            swap(u, v);
        }
        return u;
    }
    gf() : n(0) {}
    gf(int n) : n(n < 0 ? (n % MOD) + MOD : n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf operator/(gf x) { return *this * x.inv(); }
    gf& operator+=(gf x) { return *this = (*this + x); }
    gf& operator-=(gf x) { return *this = (*this - x); }
    gf& operator*=(gf x) { return *this = (*this * x); }
    gf& operator/=(gf x) { return *this = (*this / x); }
    gf inv() { return mod_inv(n, MOD); }
};

int N;
int a[MAX_N + 1];
int idx[MAX_N + 1];

void solve() {
    fill(idx, idx + N + 1, -1);
    int d;
    for (int i = 0; i < N + 1; i++) {
        if (idx[a[i]] >= 0) {
            d = i - idx[a[i]];
            break;
        }
        idx[a[i]] = i;
    }

    gf t = N + 1;
    gf r = 1;
    for (int k = 1; k <= N + 1; k++) {
        cout << (t - r).n << endl;
        t = t * (N - k + 1) / (k + 1);
        r = r * (N - d - k + 1) / k;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N + 1; i++) {
        cin >> a[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gpu_hash_map<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
array<int, 3> A;
array<int, 3> B;
vector<ttgl> ab;
vector<ttgl> ba;
int n;
int value[mxN];
int main() {
    //freopen("greedy.in", "r", stdin);
    //freopen("greedy.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    cin>>A[0]>>A[1]>>A[2]>>B[0]>>B[1]>>B[2];
    owo(i, 0, 3) {
        ab.senpai({A[i], B[i]});
        ba.senpai({B[i], A[i]});
    }
    vector<ll> kk(n+1, NINF);
    kk[0] = 0;
    for(auto p: ab) {
        owo(i, 0, n-p.first+1) {
            kk[i+p.first] = max(kk[i+p.first], kk[i] + p.second);
        }
    }
    ll most = 0;
    owo(i, 0, n+1) {
        most = max(most, kk[i]-i);
    }
    most+=n;
    kk.resize(most+1);
    owo(i, 0, most+1) {
        kk[i] = NINF;
    }
    kk[0] = 0;
    for(auto p: ba) {
        owo(i, 0, most-p.first+1) {
            kk[i+p.first] = max(kk[i+p.first], kk[i] + p.second);
        }
    }
    ll ans = 0;
    owo(i, 0, most+1) {
        ans = max(ans, (kk[i]-i));
    }
    cout<<(ans+most)<<"\n";
    return 0;
}

Measured memory_bytes: 198456
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

int H, W, K;
bool C[10][10];


bool check(int mask_w, int mask_h)
{
	int cnt = 0;
	for (int y = 0; y < H; y++)
	{
		if ((mask_h & (1LL << y)) == 0)
		{
			for (int x = 0; x < W; x++)
			{
				if ((mask_w & (1LL << x)) == 0)
				{
					if (C[x][y])
					{
						cnt++;
					}
				}
			}
		}
	}
	return cnt == K;
}


signed main()
{
	cin >> H >> W >> K;
	REP(y, H)
	{
		string s;
		cin >> s;
		REP(x, W)
		{
			C[x][y] = s[x] == '#';
		}
	}

	int ww = pow(2, W);
	int hh = pow(2, H);
	int ans = 0;
	for (int w = 0; w < ww; w++)
	{
		for (int h = 0; h < hh; h++)
		{
			if (check(w, h))
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3324
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
s = list(set(A))
b = [True] * (10**6+1)
for x in s:
    t = x * 2
    while t <= 10**6:
        b[t] = False
        t += x
ans = 0
for x in A:
    if c[x] == 1 and b[x]:
        ans += 1
print(ans)


Measured memory_bytes: 44720
import sys
sys.setrecursionlimit(1000000)
import numpy as np
input = sys.stdin.readline

L,A,B,M = map(int, input().split())

C = []
for i in range(19):
  C.append(min(max(0,(10**i - A - 1) //B + 1), L))

def R_mul(A, B, M):
  return np.mod((np.dot(A,B)), M)

def R_pow(R, n, M):
  if n == 1:
    return R
  
  R2 = R_mul(R, R, M)
  R2 = R_pow(R2, n//2, M)
  
  if n % 2 == 0:
    return R2
  else:
    return R_mul(R2, R, M)

                 
ans = 0
R = np.ones((3,3))
s = np.array([0, A%M, 1])

for d in range(1,19):
  r = C[d] - C[d-1]
  if (0 == r):
    continue
  R0 = np.array([[pow(10,d,M),1,0],[0,1,(B%M)],[0,0,1]])
  R = R_pow(R0, r, M)
  s = R_mul(R, s, M)
  #print(d, R, s)
  if (C[d] > L):
    break

print(s[0])


Measured memory_bytes: 12496
program abc131a
  implicit none
  character(len=4, kind=1) :: s
  integer :: i
  logical :: isGood= .True.
  read(*,*) s


  do i = 1, 3
    if ( s(i:i) == s(i+1:i+1) ) then
      isGood = .False.
    endif
  enddo

  if (isGood) then
    print *, 'Good'
  else
    print *, 'Bad'
  endif

end program abc131a


Measured memory_bytes: 256