akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt

    var n = N
    var m = 0
    while (n > 0) {
      m += (n % 10)
      n /= 10
    }
    if (N % m == 0) "Yes" else "No"
  }
}


Measured memory_bytes: 25532
N = int(input())
S = list(input())
c2i = lambda c: ord(c) - ord('A')
i2c = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

for i, s in enumerate(S):
    index = c2i(s)
    index += N
    if index >= 26:
        index -= 26
    S[i] = i2c[index]

print(''.join(S))

Measured memory_bytes: 39280
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n;
    cin>>n;

    vi v(n);
    for(int i=0;i<n;++i)
        cin>>v[i];

    vi w=v;
    sort(all(w));

    mii mp;
    for(int i=0;i<n;++i)
        mp[w[i]]=i;

    int ans=0;
    for(int i=0;i<n;++i)
        ans+=abs(i-mp[v[i]])%2;
    ans/=2;
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 8064
N, M, C = map(int, input().split())
B = []
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

count = 0
for i in range(N):
    S = 0
    for j in range(M):
        S += A[i][j] * B[j]
    if S + C > 0:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll m;
    cin >> m;
    ll vsum = 0, fsum = 0;
    rep(i, m) {
        ll d, c;
        cin >> d >> c;
        vsum += d * c;
        fsum += c;
    }
    cout << ((fsum - 1) + ((vsum - 1) / 9)) << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
bubble=input().split()
select=bubble[:]
for i in range(n):
    for j in range(n-1,i,-1):
        if int(bubble[j][1])<int(bubble[j-1][1]):
            bubble[j],bubble[j-1]=bubble[j-1],bubble[j]

for i in range(n-1):
    minj=i
    for j in range(i+1,n):
        if int(select[j][1])<int(select[minj][1]):
            minj=j
    select[i],select[minj]=select[minj],select[i]

for i in range(n-1):
    print(bubble[i],end=" ")
print(bubble[n-1])
print("Stable")
for i in range(n-1):
    print(select[i],end=" ")
print(select[n-1])
if bubble==select:
    print("Stable")
else:
    print("Not stable")




Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+10;
typedef long long ll;
ll fac[maxn],inv[maxn],f[5010][5010],a[2*maxn],b[2*maxn];
inline ll Pow_mod(ll a,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
inline ll C(ll n,ll m)
{
    return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
    //freopen("in.txt","r",stdin);
    fac[1]=1;
    for (ll i=2; i<=8002; i++)  
        fac[i]=1ll*fac[i-1]*i%mod;
    inv[8002]=Pow_mod(fac[8002],mod-2)%mod;
    for (ll i=8001; i>=0; i--) 
        inv[i]=1ll*inv[i+1]*(i+1)%mod;
    int n;
    ll ans=0;
    scanf("%d",&n);
    for (int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]),f[2001-a[i]][2001-b[i]]++;
    for (int i=1; i<4002; i++)
    for (int j=1; j<4002; j++)
        f[i][j]=(f[i][j]+f[i][j-1]+f[i-1][j])%mod;
    for (int i=1; i<=n; i++)
        ans=(ans+f[2001+a[i]][2001+b[i]])%mod;
    for (int i=1; i<=n; i++)
        ans=((ans-C((a[i]+b[i])<<1,b[i]<<1))%mod+mod)%mod;
    ans=(500000004ll*ans)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 161792
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            while(true){
                int n = sc.nextInt();
                int r = sc.nextInt();

                if(n==0){
                    break;
                }
                int[] card = new int[n];
                for(int i=0;i<n;i++){
                    card[i] = n-i;
                }

                for(int i=0;i<r;i++){
                    int p = sc.nextInt();
                    int c = sc.nextInt();

                    int[] shuffleC = new int[c];
                    int[] shuffleP = new int[p];

                    for(int j=0;j<p-1;j++){
                        shuffleP[j] = card[j];
                    }
                    for(int j=0;j<c;j++){
                        shuffleC[j] = card[p-1+j];
                    }

                    for(int j=0;j<c;j++){
                        card[j] = shuffleC[j];
                    }
                    for(int j=0;j<p-1;j++){
                        card[j+c] = shuffleP[j];
                    }

                    shuffleC = null;
                    shuffleP = null;

                }
                
                System.out.println(card[0]);
                
                card =null;
            }
        }  
    }
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string t; cin>>t;
  
  ll n=t.size();
  rep(i,n){
    if(t[i]=='?') t[i]='D';
  }
  cout<<t<<endl;
}

Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main()
{
    int n, f[110][11], p[110][11];

    cin >> n;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < 10; j++)
            cin >> f[i][j];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < 11; j++)
            cin >> p[i][j];

    long long res = -LLONG_MAX;

    for (int i = 1; i < (1 << 10); i++)
    {
        long long sum = 0;

        for (int j = 0; j < n; j++)
        {
            int cnt = 0;
            for (int k = 0; k < 10; k++)
            {
                if ((i & (1 << k)) && f[j][k])
                    cnt++;
            }

            sum += p[j][cnt];
        }

        res = max(res, sum);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
*/

f(0, _, 0).
f(N, [X|Xs], Z) :- N2 is N - 1, f(N2, Xs, Z2), Z is Z2 + X.

main :-
    get_number(N, K),
    get_numbers(N, Xs),
    sort(0, =<, Xs, Ys),
    f(K, Ys, Z),
    writeln(Z).


Measured memory_bytes: 8328
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
     int n;
     cin >> n;
     
     int v[n];
     forn(i, 0, n) {
         cin >> v[i];
     }
     sort(v, v+n, greater<int>());
     
     int cnt[2] = {};
     forn(i, 0, n) {
         cnt[i&1] += v[i];
     }
     
     cout << cnt[0]-cnt[1] << endl;
}


Measured memory_bytes: 3652
package main

import "fmt"

func main() {

	mainA()

}

func mainA() {
	var a, b, res int64
	fmt.Scan(&a, &b)
	res = solveA(a, b)
	fmt.Println(res)
}

func solveA(a int64, b int64) int64 {
	var res int64
	if b%a == 0 {
		res = a + b
	} else {
		res = b - a
	}

	return res
}


Measured memory_bytes: 512
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  int n,k,p,q;
  cin >> n >> k;
  long long ans = 0;
  for(int b=k+1;b<=n;b++){
    p = n/b;
    q = n%b;
    ans += max(q-k+1,0);
    ans += p*(b-k);
  }
  if(k == 0) ans -= n;
  cout << ans << endl;

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    if (n % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    string s;
    cin >> s;
    for (int i = 0; i < n / 2; i++) {
        if (s.at(i) != s.at(n / 2 + i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
            var sorted = a.OrderBy(x => x).ToList();
            var result = 0;
            for (int i = 1; i < sorted.Count(); i++)
            {
                result += sorted[i] - sorted[i - 1];
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
struct UnionFind {
    vector<ll> par, rank, cnt;

    UnionFind(ll N) : par(N), rank(N), cnt(N) {
        rep(i, N) par[i] = i, rank[i] = 0, cnt[i] = 1;
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        ll cntx = cnt[rx], cnty = cnt[ry];
        if (rx == ry) return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
        }
        else {
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
        cnt[rx] += cnty; cnt[ry] += cntx;
    }

    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll getCnt(ll x) {
        return cnt[root(x)];
    }
};

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    UnionFind tree(N);

    ll ans = N * (N - 1);
    ans /= 2;

    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    vector<ll> res(M);
    res[M - 1] = ans;

    for (ll i = M - 1; i >= 1; i--) {
        if (tree.same(A[i], B[i])) {
            res[i - 1] = res[i];
            continue;
        }
        ll size_b1 = tree.getCnt(A[i]);
        ll size_b2 = tree.getCnt(B[i]);
        // cout << i << " " << size_b1 << " " << size_b2 << endl;
        tree.unite(A[i], B[i]);
        ll size_a = tree.getCnt(A[i]);
        size_b1 = (size_b1 * (size_b1 - 1)) / 2;
        size_b2 = (size_b2 * (size_b2 - 1)) / 2;
        size_a = (size_a * (size_a - 1)) / 2;
        ans -= size_a - size_b1 - size_b2;
        res[i - 1] = max(0LL, ans);
    }

    rep(i, M) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair 
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 2e2+7;
const ll inf = 1e18+7;


int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<max(b*c,max(b*d,max(a*c,d*a)))<<"\n";
return 0; 

}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  vector<char> vec(n);
  int ab = a + b;
  
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
    if(vec.at(i) == 'a' && ab > 0){ab --;cout << "Yes" << endl;}
    else if(vec.at(i) == 'b' && ab > 0 && b > 0){ab --;b --;cout << "Yes" << endl;}
    else cout << "No" << endl;
  }
}

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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    ll a,b,k;
    cin >> a >> b >> k;
    if(a > k){
        cout << a - k << ' ' << b;
    }else if(a + b - k >= 0){
        cout << 0 << ' ' << a + b - k;
    }else{
        cout << 0 << ' ' << 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define sf scanf
#define pf printf
#define MAX 200002
#define INF 1000000
#define EXP 1e-6
#define endl '\n'
#define all(v) v.begin(), v.end()
#define FOR(i, a, b, c) for( int i = a; i < b; i+=c )
#define rep(i, a) for( int i = 0; i < a; i++ )
#define fastio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
const int maxn = 1e6 + 5;
const ll MOD = 1e9 + 7;

using namespace std;

typedef pair <int, int> ii;
typedef pair <int, ii> trie;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <trie> vtrie;
typedef bitset <maxn> bs;

int arr[maxn], n;
int dp[maxn];

int cost( int pos )
{
	int &ret = dp[pos];
	if( pos == (n-1) ) return 0;
	if( pos == (n-2) ) return abs(arr[pos + 1] - arr[pos]);
	if( ret != -1 ) return ret;
	int fst_place = 0, snd_place = 0;

	fst_place = cost( pos + 1 ) + abs(arr[pos + 1] - arr[pos]);
	snd_place = cost( pos + 2 ) + abs(arr[pos + 2] - arr[pos]);

	return ret = min( fst_place, snd_place );
}

int main()
{
	fastio

    cin >> n;
    for( int i = 0; i < n; i++ )
    	cin >> arr[i];

    memset( dp, -1, sizeof(dp) );

    int min_cost = cost( 0 );
    cout << min_cost << endl;

	return 0;

}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define LL long long
using namespace std;
 
const int maxn = 20;
int n, m, swaped[maxn];
bool used[maxn], ans;
 
string s[20];
 
bool check()
{
    memset(used, false, sizeof(used));
    for(int i = 0; i < m; i ++) {
        if(used[i])
            continue;
        for(int j = 0; j < m; j ++) {
            bool cur = true;
            if(i == j || used[j])
                continue;
            for(int k = 0; k < n; k ++) {
                if(s[swaped[k]][i] != s[swaped[n - 1 - k]][j]) {
                    cur = false;
                    break;
                }
            }
            if(cur) {
                used[i] = used[j] = true;
                break;
            }
        }
    }
 
    int cnt = 0, noused = -1;
    for(int i = 0; i < m; i ++)
        if(!used[i])
            cnt ++, noused = i;
    if((cnt >= 2 ) || (cnt && (m % 2 == 0)))
        return false;
    for(int i = 0; i < n; i ++)
        if(s[swaped[i]][noused] != s[swaped[n - 1 - i]][noused])
            return false;
    return true;
}
 
void dfs(int u, int flag)
{
    if(u == (n + 1) / 2) {
        if(check())
            ans = true;
        return;
    }
 
    for(int i = u; i < n; i ++) {
        if(swaped[i] == -1) {
            for(int j = i + 1; j < n; j ++) {
                if(swaped[j] >= 0)
                    continue;
                swaped[i] = i;
                swaped[j] = j;
                dfs(u + 1, flag);
 
                swaped[i] = j;
                swaped[j] = i;
                dfs(u + 1, flag);
                swaped[i] = swaped[j] = -1;
            }
            if(flag) {
                swaped[i] = i;
                dfs(u + 1, false);
                swaped[i] = -1; 
            }
            break;
        }
    }
}
 
int main()
{
    scanf("%d%d", &n, &m);
    memset(swaped, -1, sizeof(swaped));
    for(int i = 0; i < n; i ++)
        cin >> s[i];
 
    if(n & 1)
        dfs(0, true);
    else
        dfs(0, false);
    printf(ans ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

ll comeca[15][15], termina[15][15];

int main(){
	fastio;
	// cnt[i][j] = comeca com i e termina com j
	int n;
	cin >> n;
	vector<pii> v(n+1);
	for(int i = 1; i <= n; i++){
		v[i].sc = i%10;
		int aux = i;
		while(aux/10) aux/=10;
		v[i].fs = aux;
		comeca[v[i].fs][v[i].sc]++;
		termina[v[i].sc][v[i].fs]++;
	}
	ll ans = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			ans += comeca[i][j]*termina[i][j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int A = 26;

struct node {
	bool word = false;
	node* child[A];
	node() {
		for (int i = 0; i < A; ++i) {
			child[i] = NULL;
		}
	}
};
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	vector<string> v(n);
	for (string &s : v) {
		cin >> s;
	}
	sort(v.begin(), v.end(), [&](string &a, string &b) {
		return (int)a.size() < (int)b.size();
	});
	node *root = new node;
	int ans = 0;
	for (string &s : v) {
		int n = s.size();
		int cnt[A] = {0};
		for (char &c : s) ++cnt[c - 'a'];
		node *cur = root;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < A; ++j) {
				if (cnt[j] and cur->child[j] != NULL and (cur->child[j])->word == true) {
					++ans;
				}
			}
			int now = s[n - i - 1] - 'a';
			--cnt[now];
			if (cur->child[now] == NULL) {
				cur->child[now] = new node;
			}
			cur = cur->child[now];
		}
		cur->word = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 222948
import java.util.*;
 
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = Integer.parseInt(sc.next());
        } 
        sc.close();

        int min = Integer.MAX_VALUE, ans = 0;
        
        for(int i = 0; i < N; i++){
            min = Math.min(min, a[i]);
            if(a[i] <= min) ans++;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 50836
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

i64 rec(i64 i, bool flag, i64 k, vector<vector<i64>> dp, vector<vector<i64>> b) {
    // i番目以降の最大値
    if(dp[flag][i] != -1){
        return dp[flag][i];
    }else if (i == 0) {
        if (flag || (k & 1) == 1){
            return dp[flag][i] = max(b[0][0], b[1][0]);
        }
        else {
            return dp[flag][i] = b[0][0];
        }
    }else if (flag) {
        return dp[flag][i] = max(b[0][i], b[1][i]) + rec(i - 1, true, k, dp, b);
    }else if (k & 1LL << i) {
        return dp[flag][i] = max(b[0][i] + rec(i - 1, true, k, dp, b), b[1][i] + rec(i - 1, false, k, dp, b));
    }else {
        return dp[flag][i] = b[0][i] + rec(i - 1, false, k, dp, b);
    }
}

int main() {
    i64 ans = 0;
    i64 n, ma = -1;
    i64 k;
    vector<vector<i64>> b(2, vector<i64>(41, 0)), dp(2, vector<i64>(41, -1));
    cin >> n >> k;
    vector<i64> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i){
        ma = max(ma, a[i]);
        for(i64 j = 0; j < 41; ++j){
            if(1LL<<j > a[i] && 1LL<<j > k) break;
            if(a[i] & 1LL<<j){
                b[0][j] += 1LL<<j;
            }else{
                b[1][j] += 1LL<<j;
            }
        }
    }
    for (int i = 41; i >= 0; --i) {
        if (k & 1LL << i || ma & 1LL<<i) {
            cout << rec(i, false, k, dp, b) << endl;
            return 0;
        }
    }
    cout << rec(0, false, k, dp, b) << endl;
}


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

typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pi           acos(-1)ll m=998244353;
ll t;


string s;
ll one(ll a,ll b)
{
    ll c,d,e,f,i,j;
    a=a*9;
    a+=b;
    //cout<<a<<endl;
    return a;
}
ll two(ll a,ll k)
{
    ll b,c,d,e,f=0,g,i,j;
    //cout<<a<<' '<<k<<endl;
    e=s.size();
    for(i=k; i<e; i++)
    {
        b=s[i]-'0';
        if(b!=0)
            break;
    }
    //cout<<b<<endl;
    f+=one(e-i-1,b);
    if(i==e)f=0;
    //dbgg(f);
    d=a-1;
    d=d*(d-1);
    d/=2;
    //dbgg(d);
    f+=(d*81);
    //dbgg(f);
    a--;
    c=s[k-1]-'0';
    //cout<<c<<endl;
    c--;
    f+=(c*9*a);
    //dbgg(f);
    return f;
}


vector<ll>v;
int main()
{
    ll a,b,c,d,e,f,g,i,j;
    cin>>s>>a;
    f=0;
    b=s.size();
    if(b<a)
        cout<<'0'<<endl;
    else if(a==1)
    {
        b--;
        f=s[0]-'0';
        cout<<one(b,f)<<endl;
    }
    else if(a==2)
    {
        cout<<two(b,1)<<endl;
    }
    else
    {
        f=0;
        for(i=1; i<b; i++)
        {
            d=s[i]-'0';
            if(d!=0)
                break;
        }
        if(i!=b)
        {
            f+=two(b-i,i+1);
            //cout<<a-i<<' '<<i+1<<endl;
        }
        //cout<<f<<endl;
        c=s[0]-'0';
        c--;
        for(i=0;i<b-2;i++)
        {
            for(j=i+1;j<b-1;j++)
            {
                for(ll k=j+1;k<b;k++)
                {
                    if(k!=b-1)f+=729;
                    else f+=(81*c);
                }
            }
        }
        cout<<f<<endl;
}
return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    int x = i;
    
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    
    while (x > 0) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
    
  }
  cout << endl;
  
  return 0;
}


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

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()

    cnt_ac = 0
    arr_ac = [0] * (N)
    for x in range(0, N-1):
        if S[x:x+2] == 'AC':
            cnt_ac += 1
        arr_ac[x+1] = cnt_ac

    for i in range(Q):
        L, R = map(int, input().split())
        print(arr_ac[R-1] - arr_ac[L-1])


main()

Measured memory_bytes: 6484
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M
import Data.Maybe
import Data.List

main :: IO ()
main = do
  n <- readB <$> B.getLine
  as <- map readB . B.words <$> B.getLine
  bs <- map readB . B.words <$> B.getLine
  print $ snd . solve $ zip as bs

readB :: B.ByteString -> Int
readB = fst . fromJust . B.readInt

solve :: [(Int, Int)] -> (Int, Int)
solve = foldl' op (0, 0)

op :: (Int, Int) -> (Int, Int) -> (Int, Int)
op (a, b) (c, d) = (x, y)
  where
    x = a + c
    y = d + max b x

Measured memory_bytes: 508
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

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

  vector<int> NWSE(4,-1);
  for(int i=0;i<S.size();++i){
    if(S.at(i)=='N') NWSE.at(0)=1;
    if(S.at(i)=='W') NWSE.at(1)=1;
    if(S.at(i)=='S') NWSE.at(2)=1;
    if(S.at(i)=='E') NWSE.at(3)=1;
  }

  string ans="Yes";
  for(int i=0;i<2;++i){
    if(NWSE.at(i)*NWSE.at(i+2)<0) ans="No";
  }

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


Measured memory_bytes: 3612
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

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

    if(a <= b*2){
        cout << 0 << endl;
    }else{
        cout << a - (b*2) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  int result = 0;
  for(int x=1; x<=N; x+=2) {
    int yaku = 0;
    for(int i=1; i<=x; i++) if (x%i==0) yaku++;
    if (yaku==8) result++;
  }
  cout << result << endl;
  return 0;
}

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

int n,k,v[101],dp[103][3][3];

int calc(int i,int back1,int back2){
	if(i==n)return 1;
	if(dp[i][back1][back2]!=0)return dp[i][back1][back2];
	if(v[i]!=0){
		if(back1==v[i]&&v[i]==back2)return 0;
		else return calc(i+1,v[i],back1);
	}else{
		int ans=0;
		for(int k=1;k<=3;k++){
			if(k!=back1||k!=back2)ans+=calc(i+1,k,back1);
			ans%=10000;
		}
		return dp[i][back1][back2]=ans;
	}
}

int main(){
	std::cin>>n>>k;
	for(int i=0,a,b;i<k;i++){
		std::cin>>a>>b;
		v[a-1]=b;
	}
	std::cout<<calc(0,0,0)<<std::endl;
	return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  string ans="Yes";
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      ans="No";
    }
  }
  if(s.size()+1!=t.size())
    ans="No";
  cout << ans << endl;
}

Measured memory_bytes: 3508
class Node
  attr_accessor :post, :visited, :child, :parent, :group
  def initialize
    @post = nil
    @visited = false
    @child = []
    @parent = []
    @group = nil
  end
end

def dfs(g)
  arr = []
  v = g.size
  t = 1
  v.times{|i|
    next if g[i].visited
    stack = []
    g[i].visited = true

    stack << i
    while stack.size > 0
      u = stack[-1]
      flag = true
      g[u].child.each{|x|
        if g[x].visited == false
          g[x].visited = true
          stack << x
          flag = false
          break
        end
      }
      if flag == true
        g[u].post = t
        arr.unshift(u)
        t += 1
        stack.pop
      end
    end
  }
  return arr
end

def scc_decomposition(arr, g)
  arr.each{|i|
    next if g[i].group != nil
    stack = []
    g[i].group = i
    stack << i
    while stack.size > 0
      u = stack[-1]
      flag = true
      g[u].parent.each{|x|
        if g[x].group == nil
          g[x].group = i
          stack << x
          flag = false
          break
        end
      }
      if flag == true
        stack.pop
      end
    end
  }
end

v, e = gets.split.map(&:to_i)
graph = Array.new(v){Node.new}
e.times{
  s, t = gets.split.map(&:to_i)
  graph[s].child << t
  graph[t].parent << s
}

arr = dfs(graph)
scc_decomposition(arr, graph)

# v.times{|i|
#   p graph[i]
# }

q = gets.to_i
q.times{
  u, v = gets.split.map(&:to_i)
  if graph[u].group == graph[v].group
    puts 1
  else
    puts 0
  end
}

Measured memory_bytes: 10324
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    int k;
    scan(k);
    print(a[k-1]);
    
    
    return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 159D.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1400000).
*>
WORKING-STORAGE SECTION.
01 N          PIC  9(6).
01 IN-TBL.
   03 A       PIC  9(6) OCCURS 200000.
01 CNT-TBL.
   03 C       PIC  9(6) OCCURS 200000.
01 SORT-TBL.
   03 C1      PIC  9(6) OCCURS 200000 DEPENDING ON N.
01 P1         PIC  9(7).
01 P2         PIC  9(7).
01 I          PIC  9(6).
01 CNT        PIC  9(11).
01 OUT        PIC  Z(10)9.
*> 
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT N.
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    MOVE 0   TO C(I)
  END-PERFORM.
*>
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I)
    ADD  1               TO C(A(I))
*>
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  MOVE CNT-TBL TO SORT-TBL.
  SORT C1 DESCENDING KEY C1.
*>  
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 
    UNTIL I > N OR C1(I) < 2 
    COMPUTE CNT = CNT + C1(I) * (C1(I) - 1) / 2   
  END-PERFORM.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (C(A(I)) > 1)
      COMPUTE OUT = CNT - (C(A(I)) - 1)
    ELSE
      MOVE CNT TO OUT
    END-IF
*>
    DISPLAY FUNCTION TRIM(OUT)
  END-PERFORM.
*>
  STOP RUN.


Measured memory_bytes: 7600
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String O = sc.next();
        String E = sc.next();
        for (int i = 0; i < E.length(); i++) {
            System.out.print(O.charAt(i) + "" + E.charAt(i));
        }
        if (O.length() != E.length()) {
            System.out.print(O.charAt(O.length() - 1));
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 int H,W;
 int h,w;

 cin>>H>>W;
 cin>>h>>w;

 cout<<H*W-(W*h+(H-h)*w)<<endl;
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000

const ll MOD=998244353;

main(){
    int n=in();
    int cnt=0;
    rep(i,n){
        int a=in();
        cnt+=a%2;
    }
    cnt%=2;
    cout<<(cnt?"NO":"YES");
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, M):
    ans = (N*(N-1) + M*(M-1)) // 2
    return ans


if __name__ == "__main__":

    N, M = map(int, input().split())
    ans = solv(N, M)

    print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, k;
double ans;
int main() {
	cin >> n >> k;
	REPO(i, n) {
		ll now = 0, ii = i;
		while (ii < k) {
			now++;
			ii *= 2;
		}
		double nn = (double)((double)1 / n) * ((double)1 / pow(2, now));
		ans += nn;
	}
	cout << fixed << setprecision(20) << ans << endl;
}

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

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
          int n;
          cin>>n;
          if(n%2==0)cout<<-1<<endl;
          else{
            int d=0;
            int x=n;
            while(x>0){
              x/=10;
              d++;
            }
            ll ans=d;
            map<int,int>M;
            ll num=0;
            ll c=d;
            while(d>0){
              num+=7;
              d--;
              if(d>0)num*=10;
            }
            bool ok=true;
            while(true){
              int r=num%n;
              if(r==0)break;
              num=r*10+7;
              ans++;
              M[r]++;
              if(M[r]>1){
                ok=false;
                break;
              }
            }
            if(!ok)cout<<-1<<endl;
            else cout<<ans<<endl;
          }

   }
   }
















Measured memory_bytes: 50424
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int A, B; cin >> A >> B;
  if (A >= 13) cout << B << endl;
  else if (A >= 6 && A <= 12) cout << B / 2 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int x = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++){
      a[i] = sc.nextInt();
    }

    int cho = 0;
    for(int i = 0;i<n;i++){
      for(int j = 1;j<=d;j+=a[i]){
        cho++;
      }
    }
    cho += x;
    System.out.println(cho);
  }
}


Measured memory_bytes: 23764
/*input
7
1 2 3 4 5 6
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll x;
	ll a[n]={0};
	rep(i,0,n-1)cin>>x,--x,a[x]++;
	rep(i,0,n)cout<<a[i]<<endl;
	return 0;
}




Measured memory_bytes: 5208
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

typedef tuple<int, int> point; // score, num

int R, C, N;

bool onedge(int x, int y) {
  return (x == 0 || x == R || y == 0 || y == C);
}

int score(int x, int y) {
  assert(onedge(x, y));
  if (y == 0) {
    return x;
  }
  if (x == R) {
    return R + y;
  }
  if (y == C) {
    return R + C + (R - x);
  }
  // x == 0
  return R + C + R + (C - y);
}

int main () {
  cin >> R >> C >> N;
  vector<point> V;
  for (auto i = 0; i < N; ++i) {
    int X0, Y0, X1, Y1;
    cin >> X0 >> Y0 >> X1 >> Y1;
    if (onedge(X0, Y0) && onedge(X1, Y1)) {
      V.push_back(point(score(X0, Y0), i));
      V.push_back(point(score(X1, Y1), i));      
    }
  }
  int visited[100010];
  fill(visited, visited+100010, 0);
  sort(V.begin(), V.end());
  stack<int> S;
  for (auto it = V.begin(); it != V.end(); ++it) {
    int num = get<1>(*it);
    // cerr << "score = " << get<0>(*it) << ", num = " << get<1>(*it) << endl;
    if (visited[num] == 0) {
      visited[num]++;
      S.push(num);
    } else {
      assert(visited[num] == 1);
      int t = S.top();
      S.pop();
      if (num != t) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;
const int MAXN = 1050000;

int trie[MAXN][26], cnt[MAXN];
char buf[MAXN];
int piv;

int main(){
	int n; scanf("%d",&n);
	vector<string> v;
	for(int i=0; i<n; i++){
		scanf("%s", buf);
		int l = strlen(buf);
		reverse(buf, buf + l);
		int p = 0;
		for(int i=0; i<l; i++){
			if(!trie[p][buf[i] - 'a']){
				trie[p][buf[i] - 'a'] = ++piv;
			}
			p = trie[p][buf[i] - 'a'];
		}
		cnt[p] = 1;
		v.emplace_back(buf);
	}
	lint ret = 0;
	for(auto &i : v){
		int p = 0;
		int foo[26] = {};
		for(auto &j : i){
			foo[j - 'a']++;
		}
		for(auto &j : i){
			for(int k = 0; k < 26; k++){
				if(!foo[k]) continue;
				if(trie[p][k]) ret += cnt[trie[p][k]];
			}
			foo[j - 'a']--;
			p = trie[p][j - 'a'];
		}
	}
	cout << ret - n << endl;
}


Measured memory_bytes: 109144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

ll modpow(ll x,ll y){
  long long ans=1;
  while(y>0){
    if(y&1){
      ans*=x%MOD;
    }
    x*=x%MOD;
    x%=MOD;
    ans%=MOD;
    y>>=1;
  }
  return ans;
}

int main() {
  ll N;
  cin>>N;
  ll ans=1;
  ans*=modpow(10,N);
  ans%=MOD;
  ans-=2*modpow(9,N);
  ans+=modpow(8,N);
  while(ans<0){
    ans+=MOD;
  }
  cout<<ans;
}



Measured memory_bytes: 3592