akhauriyash/Code-Regression huggingface dataset:
import numpy as np

n,m = map(int,input().split())
arr = np.array([list(map(int,input().split())) for i in range(m)])
arr = arr[ arr[:,1].argsort(), :] #各行の1列目だけみて、行インデックスをソート


ans = 0
start,end = 0,0
for ab in arr:
    a,b = ab[0],ab[1]
    if a < end: continue
    start,end = a,b
    ans += 1

print(ans)




Measured memory_bytes: 37908
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	string S;
	cin >> S;
	int ans = 0;
	rep(i, S.size() - 1)
	{
		if (S[i + 1] != S[i]) ans++;
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

int N, K;
int D[10];
bool exists[10];

bool ok(int v) {
    string str = to_string(v);
    rep(i, str.size()) {
        if (exists[str[i] - '0']) return false;
    }
    return true;
}

void solve() {
    cin >> N >> K;
    rep(i, K) {
        cin >> D[i];
        exists[D[i]] = true;
    }  
    rep2(i, N, 100000) {
        if (ok(i)) {
            cout << i << endl;
            return;
        }
    }
    return;
}


Measured memory_bytes: 256
// 解答不能.
// scott_wu氏.
// https://atcoder.jp/contests/abc155/submissions/10170571
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAXN = 1010101;
int dig[MAXN];
int dp[MAXN][2];

int main(){
    char c[MAXN];
    scanf("%s", c);
    string s(c);
    int N = s.size();
    rep(i, N) dig[i + 1] = s[i] - '0';
    dig[0] = 0;
    N++;
    dp[N - 1][0] = dig[N - 1];
    dp[N - 1][1] = 10 - dig[N - 1];
    repr(i, N - 2, 0){
        dp[i][0] = min(dig[i] + dp[i + 1][0], dig[i] + 1 + dp[i + 1][1]);
        dp[i][1] = min(9 - dig[i] + dp[i + 1][1], 10 - dig[i] + dp[i + 1][0]);
    }
    printf("%d\n", dp[0][0]);
    return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  int N, K;
  cin >> N >> K;
  int D[K];

  for (int i = 0; i < K; i++)
    cin >> D[i];

  int ans = N;
  int tmp;
  bool judge;

  while (ans <= 100000)
  {
    tmp = ans;
    judge = true;
    while (tmp != 0)
    {
      for (int i = 0; i < K; i++)
      {
        if ((tmp % 10) == D[i])
        {
          judge = false;
          break;
        }
      }

      if (!judge)
        break;

      tmp /= 10;
    }

    if (judge)
      break;
    else
      ans++;
  }

  cout << ans << endl;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x ,int y){return (x%mod + y%mod)%mod;}
inline int submod(int x ,int y){return (x%mod - y%mod + mod)%mod;}
inline int mulmod(int x ,int y){return (x%mod *1LL* y%mod)%mod;}
inline int nextSubMask(int i , int mask) {return (i-1)&mask;} /// returns next  submask

template<typename T>
void we_r_done(T mssg){cout<<mssg; exit(0);}


int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n;
    string s;
    cin>>n>>s;
    deque<char>dq;
    int op = 0;
    for(int i=0; i<s.size(); i++){

        if(s[i] == '('){
            op++;
            dq.pb('(');
        }
        else if(op){
            op--;
            dq.pb(')');
        }
        else{
            dq.pb(')');
            dq.push_front('(');
        }
    }
    while(op--)dq.pb(')');

    while(dq.size()){
        cout<<dq.front();
        dq.pop_front();
    }

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


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

def func(x):
  res = []
  for i in range(n):
    res.append(x%2)
    x //= 2
  return res

test = {}
for i in range(n):
  A = int(input())
  test[i+1] = []
  for a in range(A):
    x,y = map(int,input().split())
    test[i+1].append((x,y))

ans = 0
for i in range(2**n):
  people = func(i)
  for i in range(n):
    if people[i]:
      for x,y in test[i+1]:
        if people[x-1] == y:
          continue
        else:
          break
      else:
        continue
      break
  else:
    ans = max(sum(people),ans)
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, m;
  int a, b;
  //  int ans;
  int tmp; 
  int xmax, ymin; 
  
  //  cin >> N;
  cin >> n >> m;
  cin >> a >> b;

  xmax = -100; ymin = 100;
  for(int i; i<n; i++){    
    cin >> tmp;
    if(tmp > xmax){
      xmax = tmp;
    }
  }
  for(int i; i<m; i++){    
    cin >> tmp;
    if(tmp < ymin){
      ymin = tmp;
    }
  }
  
  if(xmax >= ymin){
    cout << "War" <<endl;
    return 0; 
  }


  if(xmax <= a && b <= ymin){
    cout << "No War" <<endl;
    return 0;
  }else if(b > ymin){
    if(a<ymin){
      cout << "No War" <<endl;
      return 0;
    }else{
      cout << "War" <<endl;
      return 0; 
    }
  }else if(xmax <b){
          cout << "No War" <<endl;
      return 0;
    }else{
      cout << "War" <<endl;
      return 0; 
    }
}
  


Measured memory_bytes: 256
# coding: utf-8

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]


def solve(N, W, v, w):
    # dp[i][k]: 0~i?????????item????????????????????????k??\?????¨??????????????????????????´??????max value
    # return: dp[N-1][W]
    # dp[i][k] = max(dp[i-1][k], dp[i-1][k-w[i]] + v[i])
    # dp[i][0] = 0, dp[0][k] = 0(k<w[0]), v[0](otherwise)
    dp = array2d(N, W + 1)
    for k in range(0, W + 1):
        dp[0][k] = 0 if k < w[0] else v[0]
    for i in range(1, N):
        for k in range(0, W + 1):
            dp[i][k] = dp[i-1][k]
            if k - w[i] >= 0:
                dp[i][k] = max(dp[i][k], dp[i-1][k-w[i]] + v[i])
    return dp[N-1][W]



def main():
    N, W = map(int, input().split())
    v = [None] * N
    w = [None] * N
    for i in range(N):
        v[i], w[i] = map(int, input().split())
    print(solve(N, W, v, w))

main()

Measured memory_bytes: 27552
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<vector>

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

typedef long long ll;
typedef vector<int> vi;

map<string,int> id;
ll n,s[100],t,num[100],maxlen;
ll dp[10001];
string w[100],g[4];
bool vis[4][4];
int deq[10001], deqv[10001];
const int dy[] = {-1,-1,0,1,1,1,0,-1}, dx[] = {0,1,1,1,0,-1,-1,-1};

void dfs(int y,int x,string txt){
  txt += g[y][x];
  if(txt.size()>maxlen)return;
  if(id.find(txt) != id.end())num[id[txt]]++;

  rep(i,8){
    int ny = y+dy[i], nx = x+dx[i];
    if(ny<0 || nx<0 || ny>=4 || nx>=4)continue;
    if(vis[ny][nx])continue;
    vis[ny][nx] = true;
    dfs(ny,nx,txt);
    vis[ny][nx] = false;
  }
}

int main(){
  cin >> n;
  maxlen = 0;
  rep(i,n){
    cin >> w[i] >> s[i];
    id[w[i]] = i;
    maxlen = max(maxlen,(ll)w[i].size());
  }

  rep(i,4)cin >> g[i];
  cin >> t;
  memset(vis,0,sizeof(vis));


  rep(i,4){
    rep(j,4){
      vis[i][j] = true;
      dfs(i,j,"");
      vis[i][j] = false;
    }
  }

  memset(dp,0,sizeof(dp));

  rep(i,n){
    rep(a,w[i].size()){
      int st = 0, en = 0;
      for(int j=0;j*w[i].size() + a <= t;j++){
	int val = dp[j*w[i].size() + a] - j * s[i];
	while(st<en && deqv[en-1] <= val)en--;
	deq[en] = j;
	deqv[en++] = val;
	dp[j*w[i].size() + a] = deqv[st] + j * s[i];
	if(deq[st] == j - num[i])st++;
      }
    }
  }
  cout << dp[t] << endl;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    //>>>>> <<<< >>>>>>>>> <<
    //     0    (?)       0
    //<<<<がk個,そのあと>>>>がm個→k(k-1)/2+max(k,m)+m(m-1)/2
    //<<<<>>>>>が途切れた段階でcntしてやれば良い
    ll ans=0;
    ll left=0;ll right=0;
    string s;cin >> s;
    int n=(int)s.size()+1;
    rep(i,n-1){
        if(i==n-2){
            if(s[i]=='>'){
                right++;
                ans+=left*(left-1)/2+max(right,left)+right*(right-1)/2;
            }else{
                left++;
                ans+=left*(left+1)/2;
            }
            continue;
        }
        if(s[i]=='>'&&s[i+1]=='<'){
            right++;
            ans+=left*(left-1)/2+max(left,right)+right*(right-1)/2;
            left=0;right=0;
        }else if(s[i]=='>'&&s[i+1]=='>')right++;
        else if(s[i]=='<')left++;
    }
    cout << ans << '\n';
}

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

long long n, x, y, lst, ans, tmp=0;
pair <long long, long long> arr[100001];

int main(){
	cin>>n;
	
	for(long long i=0; i<n; i++){
		cin>>x>>y;
		arr[i].first=x+y;
		arr[i].second=x-y;
	}
	sort(arr, arr+n);
	
	for(long long i=0; i<n; i++){
		if(i==0||arr[i].second>=lst){
			lst=arr[i].first;
			ans++;
		}
	}
	
	cout<<ans<<endl;
}


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

const int inf = 1e9;
const ll linf = 1e18;

int main()
{
    int n; cin >> n;
    map<char, ll> mp;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        char c = s.front();
        if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
            mp[c]++;
        }
    }
    ll ans = 0;
    for (auto &e1: mp) for (auto &e2: mp) for (auto &e3: mp) {
        if (e1 != e2 && e2 != e3 && e3 != e1) {
            ans += e1.second * e2.second * e3.second;
        }
    }
    ans /= 6;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, k, p[10000], a, b=0, i, j;
    
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++) scanf("%d",&p[i]);
    
    for(i=1;i<n;i++){
        for(j=0;j<i;j++){
            if(p[i-j]<p[i-j-1]){
                a=p[i-j];
                p[i-j]=p[i-j-1];
                p[i-j-1]=a;
            }
        }
    }
    for(i=0;i<k;i++) b+=p[i];
    printf("%d\n",b);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans=0;
  for(int i=1;i<n;i++){
    int cnt=0;
    for(char c='a';c<='z';c++){
      bool l=false,r=false;
      for(int j=0;j<i;j++){
        if(s[j]==c){
          l=true;
        }
      }
      for(int j=i;j<n;j++){
        if(s[j]==c){
          r=true;
        }
      }
      if(l&&r){
        cnt++;
      }
    }
    if(ans<cnt){
      ans=cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)
#define mp make_pair
#define fi first
#define sc second
ll n,acx[300000],acp[300000];
int main(){
	cin >> n;
	REP(i,n){
		cin >> acx[i + 1];
		acp[i + 1] = acx[i + 1];
	}

	acx[0] = acp[0] = 0;
	REP(i,n) {
		acp[i + 1] += acp[i];
		acx[i + 1] ^= acx[i];
	}

	ll l = 0,r = 0;

	ll ans = 0;
	while(r < n) {
		if(acp[r + 1] - acp[l] == (acx[r + 1] ^ acx[l])) {
			r++;
		}else {
			ans += r - l;
			l++;
			if(l > r) r++;
		}
	}
	ans += (r - l) * (r - l + 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,k;
  cin >> a >> b >> k;
  for(int i=0;i<k;i++){
    if(i%2==0){
      if(a%2==1){
        a--;
      }
      b+=a/2;
      a/=2;
    }else{
      if(b%2==1){
        b--;
      }
      a+=b/2;
      b/=2;
    }
  }
  cout << a << ' ' << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int w,h,mp[101][101];
int dy[6]={-1,-1,0,0,1,1};
int dx[2][6]={
  {0,1,-1,1,0,1},
  {-1,0,-1,1,-1,0}
};
 
 
int used[101][101];
int mark(int y,int x){
  if(x<0||y<0||x>=w||y>=h)return 0;
  if(mp[y][x]||used[y][x]++)return 1;
 
  int res=1;
  for(int i=0;i<6&&res;i++){
    int nx=x+dx[y%2][i],ny=y+dy[i];    
    res*=mark(ny,nx);
  }
  return res;
}
 
int main(){
  cin>>w>>h;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)cin>>mp[i][j];
   
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      memset(used,0,sizeof(used));
      if(!mp[i][j])mp[i][j]=mark(i,j);
    } 
 
  int ans=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      int cnt=6;
      if(!mp[i][j])continue;
      for(int k=0;k<6;k++){
    int nx=j+dx[i%2][k],ny=i+dy[k];
    if(nx<0||ny<0||nx>=w||ny>=h) continue;
    cnt-=mp[ny][nx];
      }
      ans+=cnt;
    }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1468
#include <stdio.h>
int main ()
{
    long int number[10000],i,j,a; 
    for(i=0;i<10;i++)
    scanf("%d",&number[i]);
    for (i=0;i<10;i++)
     {
          for (j=i+1;j<10;j++)
          {
               if(number[i]<number[j])
               {
                    a=number[i];
                    number[i]=number[j];
                    number[j]=a;

            }

        }

    }
    for(i=0;i<3;i++)
     {
          printf("%d\n",number[i]);
    }
 return 0;
}

Measured memory_bytes: 608
#include<stdio.h>
int main()
{
	int x,y;
	int i,f1=0,f2=0,flg=0;
	int a[7]={1,3,5,7,8,10,12},b[4]={4,6,9,11};
	scanf("%d %d",&x,&y);
	if(x==2&&y==2) flg=1;
	for(i=0;i<7;i++){
		if(x==a[i]) f1=1;
		if(y==a[i]) f2=1;
	}
	if(f1==1&&f2==1) flg=1;
	f1=0;f2=0;
	for(i=0;i<4;i++){
		if(x==b[i]) f1=1;
		if(y==b[i]) f2=1;
	}
	if(f1==1&&f2==1) flg=1;
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>

using namespace std;

int main(void)
{
  unsigned long m, n;
  cin >> n >> m;
  if(m >= 2*n){
    cout << n + (m - 2*n) / 4 << endl;
  }else{
    cout << m / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(input().split())
A_copy = A[:]

def bubble_sort(N, A):
  flag = 1
  sorted_index = 0
  while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1

def selection_sort(N, A):
  for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp

bubble_sort(N, A)
selection_sort(N,A_copy)
print(' '.join(map(str, A)))
print('Stable')
print(' '.join(map(str, A_copy)))
if A == A_copy:
  print('Stable')
else:
  print('Not stable')



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

// debug methods
// usage: debug(x,y);
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {rep(i, sz(vec)) os << vec[i] << (i+1==sz(vec)? "" : ", "); return os; }
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

int main() {
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	
	map<ll, ll> mp;
	rep(i, n) mp[a[i]]++;

	ll total = accumulate(all(a), 0ll);
	// cout << total << endl;
	int q; cin >> q;
	rep(i, q) {
		ll fr, to; cin >> fr >> to;
		total -= fr * mp[fr];
		mp[to] += mp[fr];
		total += to * mp[fr];
		mp[fr] = 0ll;
		cout << total << endl;
	}
}

Measured memory_bytes: 9892
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int HP = sc.nextInt();
    int AT = sc.nextInt();
    int X = HP/AT;
    
    if(HP%AT != 0){
      X++;
    }
    System.out.println(X);
  }
}

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

void dump(vector<int> &data, string name) {
  cout << name << "= { ";
  for(int i = 0; i<data.size(); i++)
    cout << data[i] << " ";
  cout << "} " << endl;
}

bool isn(vector<int> &a, vector<int> &b, int d){
  vector<int> diff(d);
  rep(i,d) diff[i] = (a[i] - b[i]) * (a[i] - b[i]);
  int sum = 0;
  rep(i,d) sum += diff[i];
  int cand = (int)pow(sum, 0.5);
  if(cand*cand == sum)
    return true;
  else
    return false;
}

int main() {
  int n, d;
  cin >> n >> d;
  vector <vector <int> > v(n);
  int ans = 0;
  for(int i = 0; i<n; i++){
    for(int j = 0; j<d; j++){
      int a;
      cin >> a;
      v[i].push_back(a);
    }
  }
  for(int i = 0; i<n-1; i++){
    for(int j = i+1; j<n; j++){
      if(isn(v[i],v[j], d))
	ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int isprime(int);

int main(){
  int i,n,a,b,cnt=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    b=isprime(a);
    if(b==1)cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}

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



Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
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 int INF=1e18;
const int MOD=1e9+7;

bool hantei(string S){
    if(S.size()%2==1)return false;
    REP(i,S.size()/2){
        if(S[i]!=S[i+S.size()/2])return false;
    }
    return true;
}

signed main(){
    string S;cin>>S;
    S=S.substr(0,S.size()-1);
    while(!hantei(S)){
        S=S.substr(0,S.size()-1);
    }
    cout<<S.size()<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
    int main()
    {
        int A,B,x,y,z;
        scanf("%d %d",&A,&B);
        x=A+B;
        y=A-B;
        z=A*B;
        if(x>=y&&x>=z)
           {
               printf("%d\n",x);
           }
        else if(y>=x&&y>=z)
           {
               printf("%d\n",y);
           }
        else
           {
               printf("%d\n",z);
           }
           return 0;
    }

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll d = 0;
  cin >> d;
  vector<ll> c(26);
  ll min = 0;
  min = pow(10,18);
  ll mini = 0;
  for(int i = 0;i < 26;i++){
    cin >> c[i];
    if(min > c[i])min = c[i],mini = i;
  }
  /*vector<vector<ll>> s(d,vector<ll>(26));
  for(int i = 0;i < d;i++){
    ll now = 0;
    ll nowi = 0;
    for(int j = 0;j < 26;j++){
      cin >> s[i][j];
      s[i][j] += c[j];
      if(now < s[i][j]){
        now = s[i][j];
        nowi = j;
      }
    }
    cout << nowi + 1 << endl;
  }*/
  for(int i = 0;i < 365;i++)cout << mini + 1 << endl;
}

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

int main()
{              //coded by shoaib ////

    long long int n;
    cin>>n;
    long long int i;
    vector<long long int >v(n),c(n),z;
    for(i=0; i<n; i++)
        cin>>v[i];
    for(i=0; i<n; i++)
        cin>>c[i];
    for(i=0; i<n; i++)
    {
        z.push_back(v[i]-c[i]);
    }
    sort(z.begin(),z.end());
    long long int ans=0;
    for(long long int i=n-1; i>=0; i--)
    {
        if(z[i]<0)
            break;
        ans+=z[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int fre[26];

// -----------------------------------------------------------------------

void solve(){
	int a,b;
  cin>>a;
  char t;
  cin>>t;
  cin>>b;
  if(t=='-') cout<<a-b;
  else cout<<a+b;
  
}


// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
//	cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>

#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 all(x)  (x).begin(), (x).end()
#define MAX 100000
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  int ans = 1;
  for(int A = 1; A * A <= M; A++){

    if(M % A != 0)  continue;
    int B = M / A;

    if((long)A * N <= M)  ans = max(ans, A);
    if((long)B * N <= M)  ans = max(ans, B);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll z[100009];
void solve()
{
    ll x,y,a,b,c;
    multiset<ll> r,g;
    cin>>x>>y>>a>>b>>c;
    for(ll i=0;i<a;i++)
        cin>>z[i];
    sort(z,z+a,greater<ll>());
    for(ll i=0;i<x;i++)
        r.insert(z[i]);
    for(ll i=0;i<b;i++)
        cin>>z[i];
    sort(z,z+b,greater<ll>());
    for(ll i=0;i<y;i++)
        g.insert(z[i]);
    for(ll i=0;i<c;i++)
        cin>>z[i];
    sort(z,z+c);
    for(ll i=0;i<c;i++)
    {
        ll q=*r.begin();
        ll w=*g.begin();
        if(q<w)
        {
            if(z[i]>q)
            {
                r.erase(r.begin());
                r.insert(z[i]);
            }
        }
        else
        {
            if(z[i]>w)
            {
                g.erase(g.begin());
                g.insert(z[i]);
            }
        }
    }
    ll sum=0;
    for(auto i:r)
        sum+=i;
    for(auto i:g)
        sum+=i;
    cout<<sum;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 9472
unittest
{
	assert( [ "3 8", "3 30", "4 50", "5 60" ].parse.expand.solve == 90 );
	assert( [ "1 1000000000", "1000000000 10" ].parse.expand.solve == 10 );
	assert( [ "6 15", "6 5", "5 6", "6 4", "6 6", "3 5", "7 2" ].parse.expand.solve == 17 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nw = input.front.split.to!( long[] );
	auto wvs = new long[][]( nw[ 0 ], 2 );
	foreach( ref wv; wvs )
	{
		input.popFront;
		wv = input.front.split.to!( long[] );
	}
	return tuple( nw[ 1 ], wvs );
}

auto solve( long t, long[][] wvs )
{
	// 価値と重量の上限を計算
	auto vm = reduce!( ( a, wv ) => a + wv[ 1 ] )( 0L, wvs ) + 1;
	auto wm = t + 1;
	
	// dp[ wvi ][ vi ]＝「価値がvi以上になる最小の重量」を計算（条件を満たせない場合はwmを入れる）
	auto dp = new long[][]( 1 + wvs.length, 1 + vm );
	
	dp[ 0 ][ 1 .. $ ] = wm;		// 何も入れない場合は価値を1以上にできない
	for( auto wvi = 1L; wvi < dp.length; wvi++ )
	{
		auto w = wvs[ wvi - 1 ][ 0 ];
		auto v = wvs[ wvi - 1 ][ 1 ];
		for( auto vi = 1L; vi < dp[ wvi ].length; vi++ )
		{
			// wvs[ wvi ]の品物を入れない場合（wvs[ 0 .. wvi - 1 ]の選択結果そのまま）
			auto dp_p1 = dp[ wvi - 1 ][ vi ];
			
			// wvs[ wvi ]の品物を入れる場合（wvs[ 0 .. wvi - 1 ]の選択結果 ＋ wvs[ wvi - 1 ]の重量）
			auto dp_p2_vi = vi - v;
			auto dp_p2    = ( 0 <= dp_p2_vi ) ? dp[ wvi - 1 ][ dp_p2_vi ] + w : w;
			
			// 軽いほうを取る
			dp[ wvi ][ vi ] = min( dp_p1, dp_p2 );
		}
	}
	
	// 重量が上限未満での最大価値が答え
	return dp[ $ - 1 ].assumeSorted.countUntil( wm ) - 1;
}


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

using namespace std;

int main(){
	vector<int> x;
	vector<char> op;
	while(1){
		int a,b;
		char o;
		cin>>a;
		cin>>o;
		cin>>b;
		if (o=='?') break;
		x.push_back(a);
		op.push_back(o);
		x.push_back(b);
	}
	for (vector<char>::size_type k=0;k<op.size();k++){
		int ans;
		switch (op[k]){
			case '+':
				ans=x[k*2]+x[k*2+1];
				break;
			case '-':
				ans=x[k*2]-x[k*2+1];
				break;
			case '*':
				ans=x[k*2]*x[k*2+1];
				break;
			case '/':
				ans=x[k*2]/x[k*2+1];
				break;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
	string s;
	cin >> s;
	if (s[2] == s[3]) {
		if (s[4] == s[5]) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  char str[16]={};
  int n;
  int i;
  int score=0;
  int base=0;
  int out=0;

  scanf("%d", &n);

  for(i=0;i<n;i++)
    {
      score=0;
      base=0;
      out=0;
      while(1)
        {
          scanf("%s", str);
          if(str[1]=='I')
            if(base==3)
              score++;
            else
              base++;
          else if(str[1]=='U')
            if(out==2)
              break;
            else
              out++;
          else if(str[1]=='O')
            {
              score+=(base+1);
              base=0;
            }
        }
      printf("%d\n", score);
    }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	int n, m,money=0;
	ll minmoney = 100100100100100;
	bool reg = true;
	ll a, b, c,x;
	ll sum = 0;
	cin >> n >> m >> x;
	vii alg(n);
	vi vsum(m + 1);
	vi vtmp;
	rep(i, n) {
		cin >>money;
		vsum[0] += money;
		alg[i].push_back(money);
		rep(j, m) {
			cin >> a;
			alg[i].push_back(a);
			vsum[j + 1] += a;
		}
	}

	for (int bit = 0; bit < (1 << n); bit++) {
		vtmp = vsum;
		reg = true;
		rep(k, n) {
			if (bit & (1 << k)) {
				vtmp[0] -= alg[k][0];
				rep(s, m) {
					vtmp[s + 1] -= alg[k][s + 1];
				}
			}
		}
		rep(s, m) {
			if (vtmp[s + 1] < x) reg = false;
		}
		if (reg) {
			if (vtmp[0] < minmoney) minmoney = vtmp[0];
		}
	}
	if (minmoney != 100100100100100) {
		cout << minmoney << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>

using vi = std::vector<int>;
using vvi = std::vector<vi>;

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

    int w, h; std::cin >> h >> w;

    vvi grid(h, vi(w));

    int n; std::cin >> n;
    vi a(n + 1);

    int x = 0, y = 0;
    for (int i = 1; i <= n; i++) {
        int a; std::cin >> a;
        for (int j = 0; j < a; j++) {
            grid[y][x] = i;
            x++;
            if (x >= w) {
                x = 0;
                y++;
            }
        }
    }
    for (int i = 1; i < h; i += 2) {
        std::reverse(grid[i].begin(), grid[i].end());
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cout << grid[i][j] << " ";
        }
        std::cout << std::endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,A;

    cin >> N >> A;

    if(N<=A){
        cout << "Yes" << endl;
    }
    else{
        int a,b;
        a = N/500;
        b = a*500;
        if(N - b <= A){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int now = 0;
        int ans = 0;
        for(char c : s){
            if(c == 'I'){
                now++;
                ans = Math.max(ans,now);
            }else{
                now--;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const double EPS = 1e-12;
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

bool orthogonal(const L &l1, const L &l2){
  return (dot(l1[0]-l1[1], l2[0]-l2[1]) <= EPS && dot(l1[0]-l1[1], l2[0]-l2[1]) >= -EPS);
}

int main() {
  double xa, ya, xb, yb, xc, yc, xd, yd;
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF) cout <<(orthogonal(L(P(xa, ya), P(xb, yb)), L(P(xc, yc), P(xd, yd))) ? "YES" : "NO") <<endl;
  return 0;
}

Measured memory_bytes: 1236
n = gets.to_i
a = gets.split.map(&:to_i)

a.unshift(0)
a.push(0)

total = 0

a.each_cons(2) do |a,b|
  total+=(a-b).abs
end

1.upto(n) do |i|
   cost = total
   cost -= (a[i-1]-a[i]).abs
   cost -= (a[i]-a[i+1]).abs
   cost += (a[i-1]-a[i+1]).abs
   p cost
end


Measured memory_bytes: 16644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		String s = sc1.next();
		int k = sc1.nextInt();

		char x = s.charAt(k-1);

		for ( int i = 0 ; i < n ; i++) {
			if ( s.charAt(i) != x && s.charAt(i) != '*' ) {
				s = s.replace(s.charAt(i), '*');
			}
		}

		System.out.println(s);

		sc1.close();

	}

}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		while(scan.hasNext()){
			System.out.println(scan.nextInt()+scan.nextInt());
		}
	}

}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;


void solve(){
    int k;
    cin >> k;
    if(k==1 || k==7) {
            cout << 1;
        return;
    }
    if(k%5==0 || k%2==0) {
            cout << -1;
            return ;
    }

    if(k%7==0){
        k = floor(k/7);
    }

    int m = 9*k;
    int i = 1;
    ll ans = 10;
    while(ans!=1) {

        ans = (ans*10)%m;
        i+=1;

    }
    cout << i;
    line
    return;
}
int main(){
	fast
	int t=1;
	//cin >> t;
	while(t--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String x=gs();
	   
	    //System.out.print(P[1]+P[0]);

        if ((x.charAt(0)==x.charAt(1) && x.charAt(2)==x.charAt(3) && x.charAt(0)!=x.charAt(2))
        || (x.charAt(0)==x.charAt(2) && x.charAt(1)==x.charAt(3) && x.charAt(0)!=x.charAt(1))
        || (x.charAt(0)==x.charAt(3) && x.charAt(2)==x.charAt(1) && x.charAt(0)!=x.charAt(2))) {
        	System.out.print("Yes");
        }else {
        	System.out.print("No");
        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

ll p[123456],q[123456];

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll inv(ll x){
	ll a = MOD-2,ans=1ll;
	while(a > 0){
		if((a&1)>0){
			mul_mod(ans,x);
		}
		a /= 2;
		mul_mod(x,x);
	}
	return ans;
}

ll comb(int x, int y){
	ll ans=1ll;
	if(x <= 0 || y < 0 || (x-y) < 0){
		return 0ll;
	}
	mul_mod(ans,p[x]);
	mul_mod(ans,q[y]);
	mul_mod(ans,q[x-y]);
	return ans;
}


int main(void){
	int a,b;
	cin >> a >> b;
	cout << ((a%3 && b%3 && (a+b)%3)?"Imp":"P") << "ossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int ans[100000];
int a[100000];
int b[100000];
vector <int> v[100000];

void dfs(int x, int y, int l, int r) {
    int i;
    
    if (ans[x] != 1e9) {
        if (ans[x] < l || ans[x] > r || (r - ans[x]) % 2 == 1) {
            puts("No");
            
            exit(0);
        }
        
        a[x] = b[x] = ans[x];
        
        for (i = 0; i < v[x].size(); i++) {
            if (v[x][i] == y) continue;
            
            dfs(v[x][i], x, ans[x] - 1, ans[x] + 1);
        }
    } else {
        a[x] = l;
        b[x] = r;
        
        for (i = 0; i < v[x].size(); i++) {
            if (v[x][i] == y) continue;
            
            dfs(v[x][i], x, l - 1, r + 1);
        }
    }
}

pair <int, int> dfs2(int x, int y) {
    int i;
    
    for (i = 0; i < v[x].size(); i++) {
        pair <int, int> p;
        
        if (v[x][i] == y) continue;
        
        p = dfs2(v[x][i], x);
        
        a[x] = max(a[x], p.first);
        b[x] = min(b[x], p.second);
    }
    
    if (a[x] > b[x]) {
        puts("No");
        
        exit(0);
    }
    
    return make_pair(a[x] - 1, b[x] + 1);
}

void dfs3(int x, int y, int z) {
    int i;
    
    if (a[x] <= z - 1 && b[x] >= z - 1) {
        ans[x] = z - 1;
    } else {
        ans[x] = z + 1;
    }
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        
        dfs3(v[x][i], x, ans[x]);
    }
}

int main() {
    int n, k, c, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    for (i = 0; i < n; i++) ans[i] = 1e9;
    
    scanf("%d", &k);
    
    for (i = 0; i < k; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        c = x;
        
        ans[x] = y;
    }
    
    dfs(c, -1, ans[c], ans[c]);
    dfs2(c, -1);
    dfs3(c, -1, ans[c] - 1);
    
    puts("Yes");
    for (i = 0; i < n; i++) printf("%d\n", ans[i]);
    
    return 0;
}


Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
//	freopen("SNOOKER.inp","r",stdin);
//	freopen("SNOOKER.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
/*----------------------------------------------------------------------
 
-----------------------------------------------------------------------*/
using ll =  long long;
#define endl "\n"
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define what_is(x)  cerr << #x << " is :" << (x) << endl
const int MOD =  1e9+7;
const ll inf = LLONG_MAX;
const int MAX_N = 1e5 + 7;
 
int n;
 
ll a[MAX_N], dp[MAX_N];
void solve()
{
	cin >> n;
	for(int i = 1; i <= n ; i++)
	{
		cin >> a[i];
	}
	
	dp[0] = dp[1] = 0;
  dp[2] = abs(a[2] -a[1]);
	for(int i = 3; i <= n; i ++)
	{
		dp[i] = min(	abs(a[i]-a[i-1] )+ dp[i-1], 
						abs(a[i]-a[i-2] )+ dp[i-2]
				);
	}
	//for(int i = 1; i <= cur_lenght; i++) cout << tail[i] << endl;
	cout << dp[n] ;
}

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

string to_string(const string& s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) res += ", ";
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 998244353, nn = 3003;

int n, s;
int a[nn], dp[nn][nn];

int expo(int a, int n) {
    int res = 1;
    while(n) {
        if(n & 1) res = res * a % mod;
        n >>= 1;
        a = a * a % mod;
    }
    return res;
}

int fun(int ind, int sum) {
    if(sum == 0) {
        return expo(2, n - (ind - 1));
    }
    if(ind > n || sum < 0) return 0;

    int& ans = dp[ind][sum];
    if(ans != -1) return ans;
    return ans = (2 * fun(ind+1, sum) + fun(ind+1, sum - a[ind])) % mod;
}

void solve(){
    cin >> n >> s;
    for(int i = 1; i <= n; i++) cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << fun(1, s) << '\n';
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 74288
from collections import Counter
N = int(input())

def change_to_num(ls):
    ls = list(map(str, ls))
    strnum = ''.join(ls)
    return int(strnum)
def dfs(num_ls):
    '''
    引数のnum_ls以降の753numの総数を返す
    '''
    if change_to_num(num_ls) > N:
        return 0
    
    tmp = 0
    # 引数のnum_lsは753か？
    c = Counter(num_ls)
    is753 = True
    for num in [7,5,3]:
        if c[num] == 0:
            is753 = False
    if is753:
        tmp += 1
    
    # 次の状態の753総数を足す
    for num in [7,5,3]:
        num_ls.append(num)
        tmp += dfs(num_ls)
        num_ls.pop()
    return tmp
print(dfs([0]))


    

Measured memory_bytes: 3316