akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e6+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int h,a;
	cin>>h>>a;
	int ans=h/a;
	h%=a;
	if(h==0)
	{
		cout<<ans;
	}
	else cout<<ans+1;
}
// I never lose. I either win or I learn

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

def main():
	N, M, C = map(int, input().split())
	B = list(map(int, input().split()))
	count = 0
	for _ in range(N):
		X = list(map(int, input().split()))
		AL = 0
		for i in range(M):
			AL += X[i] * B[i]
		AL += C
		if AL > 0:
			count += 1
	print(count)

if __name__ == '__main__':
	main()


Measured memory_bytes: 3060
N = int(input())

def grundy(x, k):
    while x % k != 0:
        p = max(1, (x - x // k * k) // (x // k + 1))
        x = x - (x // k + 1) * p
    return x // k

g = 0

for _ in range(N):
    a, k = map(int, input().split())
    g ^= grundy(a, k)

print('Takahashi' if g != 0 else 'Aoki')

Measured memory_bytes: 73216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   ll n,p;
   cin>>n>>p;
   if(n==1){
      cout<<p<<endl;
      return 0;
   }
   ll ans=0;
   for(int i=1;pow(i,n)<=p;i++){
      if(p%(ll)pow(i,n)==0){
         ans=i;
      }
   }
   cout<<ans<<endl;
}

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

using namespace std;

int main(int argc, char* argv[])
{

	int A,B,C;
	int max;

	cin >> A >> B >> C;

	// A*10+B+C
	// A+B*10+C
	// A+B+C*10

	max = A * 10 + B + C;

	if(max < A + B * 10 + C){
		max = A + B * 10 + C;
	}

	if(max < A + B + C * 10){
		max = A + B + C * 10;
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)

int main(){
  int N,minval,ans=-1e9,num;
  scanf("%d",&N);
  scanf("%d",&minval);
  N--;
  while(N--){
    scanf("%d",&num);
    ans = MAX(ans, num-minval);
    minval = MIN(minval, num);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#define maxi 1000000000
using namespace std;

vector < vector < int > > g, mas, reb;

int getbit(int mask, int num){
	return (mask >> num) & 1;
}
int addbit(int mask, int num){
	return mask | (1 << num);
}

int main(){
	int n,m,a,b,c;
	cin >> n >> m;
	int nn = (1 << n);

	reb.resize(n);
	for(int i=0; i<n; i++)
		reb[i].resize(n);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			reb[i][j] = -1;
		}
	}

	mas.resize(n);
	for(int i=0; i<n; i++)
		mas[i].resize(nn);

	g.resize(n);
	for(int i=0; i<m; i++){
		cin >> a >> b >> c;
		g[a].push_back(b);
		reb[a][b] = c;
	}

	mas[0][1] = 1;
	int nextvert, nextmask;

	for(int mask = 1; mask < nn - 1; mask+=2){
		for(int vert=0; vert<n; vert++){
			if(mas[vert][mask] != 0){
				for(int e=0; e<g[vert].size(); e++){
					nextvert = g[vert][e];
					if(!getbit(mask,nextvert)){
						nextmask = addbit(mask,nextvert);
						if(mas[nextvert][nextmask] == 0 || mas[nextvert][nextmask] > mas[vert][mask] + reb[vert][nextvert]){
							mas[nextvert][nextmask] = mas[vert][mask] + reb[vert][nextvert];
						}
					}
				}
			}
		}
	}

	/*//
	for(int i=0; i<n; i++){
		for(int j=0; j<nn; j++){
			cout << mas[i][j] << " ";
		}
		cout << endl;
	}
	//*/

	int mask = nn - 1; int mi = maxi;
	for(int vert=0; vert<n; vert++){
		if(reb[vert][0] != -1 && mas[vert][mask] != 0 && mi > mas[vert][mask] + reb[vert][0]){
			mi = mas[vert][mask] + reb[vert][0];
		}
	}

	if(mi != maxi){
		cout << mi - 1 << endl;
	}else{
		cout << -1 << endl;
	}
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef map<string, vector<int> > bmap;

int main() {
    string word;
    int page;
    bmap words;
    while (cin >> word >> page) {
        if (words.find(word)==words.end()) {
            vector<int> pages;
            pages.push_back(page);
            words[word] = pages;
        } else {
            words[word].push_back(page);
        }
    }
    bmap::iterator it;
    for (it=words.begin(); it!=words.end(); it++) {
        sort((*it).second.begin(), (*it).second.end());
        cout << (*it).first << endl;
        for (int i=0; i<(*it).second.size()-1; i++) {
            cout << (*it).second[i] << " ";
        }
        cout << (*it).second[(*it).second.size()-1] << endl;
    }
}

Measured memory_bytes: 0
// 課題4_1 AtCoder Beginner Contest 134 B - GoldenApple
// nk777
 
#include<stdio.h>
#include<math.h>
 
int main(void){
    // 林檎の木n_tree本、(監視できる本数)/2-0.5を表すd_watch、結果の格納result
    int n_tree, d_watch, result;
 
    // n_tree, d_watchを受け取る
    scanf("%d %d", &n_tree, &d_watch);
 
    // 監視員が見れる木の本数
    d_watch = d_watch * 2 + 1;
    // 木の本数を監視できる木の本数で割ったものを小数第1位で切り上げたものが監視員の本数
    result = ceil((double)n_tree / (double)d_watch);

    printf("%d\n", result);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define for(i,n) for(int i=0;i<n;i++)
using namespace std;

void solve()
{
     ll n;
     cin >> n;
     n=n%1000;
     if(n)
       cout << 1000-n << endl;
     else
        cout << "0" << endl;
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();

    return 0;
}



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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  float total = 0;
  int count = 0;
  for (int i = 0; i < N; i++) {
    total += A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if ((float)(total/(4.0*M)) <= A.at(i)) {
      count++;
    }
  }

  if (count >= M) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define rep(i,n) for(ll i=0;(i)<(ll)n;(i)++)
const long long INF = 100000000000;

int op(int a, int b){
  return max(a,b);
}
int e(){
  return -1;
}

int target;
bool f(int x){
  return x < target;
}

int main(){
  int n,q; cin >> n >> q;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  segtree<int,op,e> seg(a);
  rep(i,q){
    int t; cin >> t;
    if(t == 1){
      int x,v; cin >> x >> v;
      x--;
      seg.set(x,v);
    }else if(t == 2){
      int l,r; cin >> l >> r;
      l--;
      cout << seg.prod(l,r) << endl;
    }else{
      int x; cin >> x >> target;
      x--;
      cout << seg.max_right<f>(x) + 1 << endl;
    }
  }
  
}


Measured memory_bytes: 6160
#include <bits/stdc++.h>
using namespace std;
long long int a[101];
long long int dp[101][100001];
long long int total[101][100001];
long long int mod=1000000007;
int main(void)
{
	long long int n;
	long long int k;
	cin >> n>>k;
	a[0]=0;
	for (int i = 1; i <=n; ++i)
	{
		cin >> a[i];
	}

	dp[0][0]=1;
	total[0][0]=1;
	for (long long int j = 1; j <=k; ++j)
	{
		dp[0][j]=0;
		total[0][j]=total[0][j-1]+dp[0][j];
	}
	for (long long int i = 1; i <=n; ++i)
	{
		total[i][0]=1;
		for (long long int j = 0; j <=k; ++j)
		{
			if(j-a[i]<=0)
			{
				dp[i][j]=total[i-1][j];
			}
			else
			{
				dp[i][j]=total[i-1][j]-total[i-1][j-a[i]-1];
				if(dp[i][j]<0)
				{
					dp[i][j]+=mod;
				}
			}
			if(j>0)
			{
				total[i][j]=total[i][j-1]+dp[i][j];
			}
			// for (int l = 0; l <=a[i]; ++l)
			// {
			// 	if(j-l>=0)
			// 	{
			// 		dp[i][j]+=dp[i-1][j-l];
			// 	}
			// }
			total[i][j]%=mod;
			dp[i][j]%=mod;
			// printf("%lld ",total[i][j] );
		}
		// printf("\n");
	}
	printf("%lld\n",dp[n][k]%mod );


}

Measured memory_bytes: 158080
#include<stdio.h>
void c(char *s,char *t,int l){for(int i=0;i<6;i++)t[i]=i<l?s[i]:0;}
int J(char *s,char *t){for(int i=0;i<6;i++){if(s[i]<t[i])return 1;if(s[i]>t[i])return 0;}return -1;}
int K(char r[7][6],char *t){for(int i=1;i<6;i++)if(J(t,r[i])==-1)return 0;return 1;}
int main(){
  char s[5001],r[7][6],t[6];
  int i,j,k,n,l;
  scanf("%s%d",s,&k);
  for(i=0;i<42;i++)r[i/6][i%6]='}';
  for(n=0;s[n];n++);
  for(i=0;i<n;i++)for(j=1;j<6&&i+j-1<n;j++){
    c(&s[i],t,j);
    if(K(r,t))for(l=5;l>0;l--)if(J(t,r[l])){c(r[l],r[l+1],6);c(t,r[l],6);}
  }
  printf("%s",r[k]);
}


Measured memory_bytes: 1696
#include<iostream>
using namespace std;
#define rep(i, st, end) for (int i = st; i < end; ++i)
int main() {
    int h, w; cin >> h >> w;
    string b[101];
    rep(y, 0, h) cin >> b[y];
    rep(y, 0, h) rep(x, 0, w) if (b[y][x] == '.') {
        int cnt = 0;
        //近傍の座標を簡単に表すtech
        rep(dx, -1, 2) rep(dy, -1, 2) {
            if (dx == 0 and dy == 0) continue;
            int xx = x + dx;
            int yy = y + dy;
            if (0 <= xx and xx < w and 0 <= yy and yy < h) {
                if (b[yy][xx] == '#') cnt++;
            }
        }
        b[y][x] = '0' + cnt;
    }
    rep(y, 0, h) cout << b[y] << endl;
    return 0;
}


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

using namespace std;

int main(int argc, const char * argv[]) {
    int N = 0;
    cin >> N;

    vector<uint64_t> Hs(N);
    for(int i = 0; i < N; i++) {
        cin >> Hs[i];
    }

    uint64_t last = 0;
    for(int i = 0; i < N; i++) {
        if(last == Hs[i]) {
            continue;
        }

        if(last <= Hs[i]-1) {
            Hs[i]--;
            last = Hs[i];
            continue;
        }

        // Hs[i]-1 < last
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

/**
 cheat sheet

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end());
 => 0 1 2 3 4 5 6 7 8 9

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end(), greater<int>());
 => 9 8 7 6 5 4 3 2 1 0

 struct A { int x, y; };
 bool comp(A i1, A i2) { return (i1.y < i2.y); }
 vector<A> v { { 6, 8 }, { 1, 9 }, { 2, 4 }, { 4, 7 } };
 sort(v.begin(), v.end(), comp);
 => [1, 9] [2, 4] [4, 7] [6, 8]

 */


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var weather string
	fmt.Scanf("%s", &weather)
	if(weather == "Sunny") {
		fmt.Println("Cloudy")
	} else if (weather == "Cloudy") {
		fmt.Println("Rainy")
	} else {
		fmt.Println("Sunny")
	}
}

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

int main(){
    map<string, int> m;
    int q, op, x;
    string s;
    
    cin >> q;
    while(q-- > 0){
        cin >> op;
        if(op == 0){
            cin >> s >> x;
            m[s] = x;
        }else if(op == 1){
            cin >> s;
            if(m.count(s))  cout << m[s] << endl;
            else            cout << 0 << endl;
        }else if(op == 2){
            cin >> s;
            m.erase(s);
        }else if(op == 3){
            string l, r;
            cin >> l >> r;
            auto x = m.lower_bound(l);
            auto y = m.upper_bound(r);
            for(;x != y; x++)   cout << (*x).first << " " << (*x).second << "\n";
        }
    }

    return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(n==1)
	{
		cout<<0;
		return 0;
	}
	
		int p=sum/n;
		//int p1=p+1;
		ll x=0,y=0,z=0;
		//int p2=p-1;
		for(int i=0;i<n;i++)
		{
			x+=((a[i]-p)*(a[i]-p));
			y+=((a[i]-p-1)*(a[i]-p-1));
			//z+=((a[i]-p2)*(a[i]-p2));
		}
		//cout<<min(x,min(z,y));
		cout<<min(x,y);
		
	
	
	
                         
	return 0;
}

Measured memory_bytes: 256
import math

a,b,x=map(int,input().split())

if 2*x<=a*a*b:
    p1=a*b*b
    p2=2*x
else:
    p1=2*(a*a*b-x)
    p2=a*a*a
    
sit=math.atan(p1/p2)
print(math.degrees(sit))


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

int main() {
  std::string s, temp = "";
  std::cin >> s;
  long long k;
  std::cin >> k;
  for (long long i = 0; i < k; i++) {
    if (s[i] != '1') {
      std::cout << s[i] << "\n";
      return 0;
    }
  }
  std::cout << 1 << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[1000],M=-INF,m=INF,cnt=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        M=max(M,a[i]);
        m=min(m,a[i]);
    }
    if(m>=0){
        cout<<n-1<<endl;
        rep(i,n-1){
            cout<<i+1<<" "<<i+2<<endl;
        }
    }
    else if(M<=0){
        cout<<n-1<<endl;
        rep(i,n-1){
            cout<<n-i<<" "<<n-i-1<<endl;
        }
    }
    else{
        if(M>=-m){
            ll num;
            rep(i,n){
                if(a[i]<0)cnt++;
                if(a[i]==M) num=i;
            }
            cout<<n-1+cnt<<endl;
            rep(i,n){
                if(a[i]<0){
                    cout<<num+1<<" "<<i+1<<endl;
                }
            }
            rep(i,n-1){
                cout<<i+1<<" "<<i+2<<endl;
            }
        }
        else{
            ll num;
            rep(i,n){
                if(a[i]>0) cnt++;
                if(a[i]==m) num=i;
            }
            cout<<n-1+cnt<<endl;
            rep(i,n){
                if(a[i]>0){
                    cout<<num+1<<" "<<i+1<<endl;
                }
            }
            rep(i,n-1){
                cout<<n-i<<" "<<n-i-1<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int N = 100010;
int pre[N];
map<int, int> mp;

int main()
{
	int n;
	scanf("%d", &n);
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		mp[x]++;
		sum += x;
	}

	int m;
	scanf("%d", &m);
	while (m--) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (mp.count(x)) {
			sum -= 1LL * mp[x] * x;
			sum += 1LL * mp[x] * y;
			mp[y] += mp[x];
			mp.erase(x);
		} 
		printf("%lld\n", sum);
	}
			
	return 0;
}


Measured memory_bytes: 6212
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())

    for i in range(1, 10):
        if n % i == 0 and 1 <= n // i <= 9:
            print('Yes')
            exit()
    print('No')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk;
  vector<int> ret;

  int n,q;
  vector<int> a;
  vector<int> swap;
  cin >> n;
  
  a.resize(n);
  swap.resize(n);
  for(ii=0;ii<n;ii++){
    cin >> a[ii];
  }

  cin >> q;

  int b,e;

  for(ii=0;ii<q;ii++){

    cin >> b >> e;
    //cout << "b:" << b << "e:" << e << endl;
    for(jj=b;jj<e;jj++){
      swap[jj] = a[b+e-jj-1];
    }
    
    for(jj=b;jj<e;jj++){
      //cout << swap[jj] << " " ;
      a[jj] = swap[jj];
    }
    
    //cout << endl;
    
  }

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



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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x, y, a, b, c;
	cin>>x>>y>>a>>b>>c;
	LL p[a];
	LL q[b];
	LL r[c];
	for(int i=0; i<a; i++)
		cin>>p[i];
	for(int i=0; i<b; i++)
		cin>>q[i];
	for(int i=0; i<c; i++)
		cin>>r[i];
	sort(p, p+a);
	sort(q, q+b);
	sort(r, r+c);
	multiset<LL> S;
	for(int i=a-1; i>=(a-x); i--) {
		S.insert(p[i]);
	}
	for(int i=b-1; i>=(b-y); i--) {
		S.insert(q[i]);
	}
	for(int i=c-1; i>=0; i--) {
		int xx = *(S.begin());
		if(r[i] > xx) {
			S.erase(S.begin());
			S.insert(r[i]);
		}
		else
			break;
	}
	LL w = 0;
	for(auto it = S.begin(); it != S.end(); ++it) {
		w += *(it);
	}
	cout<<w;
}


Measured memory_bytes: 11008
import scala.io.StdIn.readLine

object Dice {
  def rollOnce(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }
}

class Dice(var d:Array[Int]) {

  def roll(dirs:String)  = {
    d = dirs.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => Dice.rollOnce(y).map(x) }.map(d)
  }

  def getTopFace() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = new Dice(faces)
  dice.roll(readLine)

  println(dice.getTopFace())
}

Measured memory_bytes: 44176
#include <algorithm>
#include <iostream>

using namespace std;

int a[100000] = {0};

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

  int N, x;
  cin >> N >> x;

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

  long long ans = 0;
  for (int i = 1; i < N; ++i) {
    if (a[i - 1] > x) {
      ans += a[i - 1] - x;
      a[i - 1] = x;
    }
    if (a[i - 1] + a[i] > x) {
      int y = a[i - 1] + a[i] - x;
      a[i] -= y;
      ans += y;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
def partition(A, p, r):
    x = A[r - 1]
    i = p - 1
    for j in range(p, r - 1):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[-1] = A[-1], A[i + 1]
    return i + 1
        
n = int(input())
A = list(map(int, input().split())) 

tmp = partition(A, 0, n)
for i in range(n - 1):
    if i == tmp:
        print("[" + str(A[tmp]) + "]", end = " ")
    else:
        print(A[i], end = " ")
print(A[-1])








Measured memory_bytes: 16388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool is_OK = true;
        for(int j = 0; j < n; j++){
            if(i>j && h[i]<h[j]){is_OK = false;}
        }
        if(is_OK){ans++;}
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int N = 500000;

int n;
long long res;
int a[N + 1];

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int l = 1;
	int s = a[1];
	for(int i = 2; i <= n + 1; i++) {
		while(s & a[i]) {
			res += i - l;
			s ^= a[l];
			l++;
		}
		s |= a[i];
	}
	cout << (res + 1LL * (n - l + 1) * (n - l + 2) / 2) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
 string a;
 cin>>a;
 if(a=="+-++")
 cout<<2;
 else if(a=="++++")
 cout<<4;

 
 else if(a=="-+++")
 cout<<2;
 else if(a=="++-+")
 cout<<2;
 else if(a=="+++-")
 cout<<2;
 
 else if(a=="----")
 cout<<-4;
 else if(a=="-+--")
 cout<<-2;
 else if(a=="--+-")
 cout<<-2;
 else if(a=="+---")
 cout<<-2;
 else if(a=="---+")
 cout<<-2;
 
 else if(a=="-+-+")
 cout<<0;
 else if(a=="+-+-")
 cout<<0;
  else if(a=="++--")
 cout<<0;
  else if(a=="--++")
 cout<<0;
  else if(a=="-++-")
 cout<<0;
  else if(a=="+--+")
 cout<<0;


    return 0;
}

Measured memory_bytes: 256
def Step():
    
    num = int(input())

    data = list(map(int,input().split()))
    
    count = 0
    
    fn = 0
    
    for i in range(len(data)-1):
        if (data[i+1] - (data[i] + fn)) < 0:
            count = count + abs(data[i+1] - (data[i] + fn))
            fn = abs(data[i+1] - (data[i] + fn))
    
        else:
            fn = 0
    
    print(count)
    
if __name__ == '__main__':
    Step()



Measured memory_bytes: 32352
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val n = input.toInt
    val list = for(i <- 1 to 9; j <- 1 to 9) yield i * j
    if (list contains n) "Yes" else "No"
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """10""".stripMargin -> """Yes
                              |
                                   |""".stripMargin,
    """50""".stripMargin -> """No
                              |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 25548
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;


int main() {
	//cout << fixed << setprecision(10);
	long long int a, b, c, d, e,k;
	cin >> a >> b >> c >> d >> e >> k;
	if ( e - a<= k) {
		cout << "Yay!";
	}
	else {
		cout << ":(";
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
    boost();
    ll n;
    cin >> n;
    ll arr[n],i;
    for(i=0;i<n;i++)
    cin >> arr[i];
    ll sum[n];
    sum[0]=arr[0];
    for(i=1;i<n;i++)
    sum[i]=arr[i]+sum[i-1];
    
    ll ans=0;
    for(i=1;i<n;i++){
        sum[i-1]%=mod;
        arr[i]%=mod;
        ans+=arr[i]*sum[i-1];
        ans=ans%mod;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 6780
s=list(input())
n=len(s)
ans1=0
for i in range(n):
    if i%2==0 and s[i]=='0':
        ans1+=1
    elif i%2 == 1 and s[i]=='1':
        ans1+=1
ans2=0
for i in range(n):
    if i%2==0 and s[i]=='1':
        ans2+=1
    elif i%2 ==1 and s[i]=='0':
        ans2+=1
print(min(ans1,ans2))

Measured memory_bytes: 3956
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    P=list(map(int,input().split()))
    ans=0
    minnum=INF
    for p in P:
        if minnum>=p:
            ans+=1
        minnum=min(minnum,p)
    print(ans)
        
        

if __name__ == '__main__':
    main()


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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

void dfs(int i, int n, int sum, int s, int pre_number, int &count){
	if(i == n){
		if(sum == s){
			count++;
		}
		return;
	}
	
	for(int j = pre_number + 1; j < 10; j++){
		if(sum + j <= s){
			dfs(i + 1, n, sum + j, s, j, count);
		}
	}
	return;
}

int main(int argc, char **argv){
	int n, s;
	int count = 0;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	while(ifs >> n >> s){
#else
	while(std::cin >> n >> s){
#endif
		if(n == 0 && s == 0){
			break;
		}
	
		count = 0;
		dfs(0, n, 0, s, -1, count);

		std::cout << count << std::endl;
	}


	return 0;
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll ans = 0;
    for (auto p : mp) {
        if (p.second >= 2) {
            ans += (p.second * (p.second - 1)) / 2;
        }
    }
    for (ll i = 0; i < n; i++) {
        ll k = mp[a[i]];
        ll cur = ans;
        if (k >= 2) {
            cur -= (k * (k - 1)) / 2;
            cur += ((k - 1) * (k - 2)) / 2;
        }
        cout << cur << "\n";
    }
    return 0;
}


Measured memory_bytes: 11008
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<complex>
const int mod=998244353,g=3,invg=998244354/3;
using namespace std;
int main() {
	int n;
	cin>>n;
	while(n--)cout<<"ACL";
	return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,k;cin >> n >> m >> k;
	rep(i,n+1){
		rep(j,m+1){
			if(i*m+j*n-i*j*2==k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
s1 = input()
s2 = input()
p = 0
n = 0
ans = 1
while n < N:
    if p == 1:
        if s1[n] == s2[n]:
            ans *= 2
            n += 1
        else:
            ans *= 2
            n += 2
            p = 2
    elif p == 2:
        if s1[n] == s2[n]:
            # ans *= 1
            n += 1
            p = 1
        else:
            ans *= 3
            n += 2
    else:
        if s1[n] == s2[n]:
            ans *= 3
            n += 1
            p = 1
        else:
            ans *= 6
            n += 2
            p = 2
    ans %= 1000000007
    # print(n, ans)
print(ans)


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

int main(){
    int L, R, d;
    cin >> L >> R >> d;
    int c = 0;
  
    for (int i = L; i <= R; i++) {
		if (i%d==0){
          c++;
        }
	}
   cout << c << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  cout << (n ^ 1) << endl;
  return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<queue>
#include<algorithm>
#define rep(i,b,e) for ( int i = b; i <= e; i++ )
using namespace std;

#define MAX 1000
#define INFTY (1<<21)
int n, C[MAX+1][MAX+1], T[MAX+1][MAX+1];

class State{
    public:
    int p, e;
    State( int p = 0, int e = 0 ): p(p), e(e){}
    bool operator < ( const State &s ) const{
	return e > s.e;
    }
};

int dijkstra( int s, int t, int type ){
    priority_queue<State> PQ;
    bool visited[MAX+1];
    int d[MAX+1];
    rep(i,1,n){
	visited[i] = false;
	d[i] = INFTY;
    }
    PQ.push(State(s, 0));
    d[s] = 0;
    State u;
    while( !PQ.empty() ){
	u = PQ.top(); PQ.pop();
	if ( u.p == t ) return u.e;
	visited[u.p] = true;
	rep(v,1,n){
	    if ( C[u.p][v] == INFTY || visited[v] ) continue;
	    if ( type == 0 ){
		if ( d[v] > d[u.p] + C[u.p][v] ){
		    d[v] = d[u.p] + C[u.p][v];
		    PQ.push(State(v, d[v]));
		} 
	    } else {
		if ( d[v] > d[u.p] + T[u.p][v] ){
		    d[v] = d[u.p] + T[u.p][v];
		    PQ.push(State(v, d[v]));
		} 
	    }
	}
    }
    return -1;
}

main(){
    int k, s, t, cost, tm, q, r;
    while(1){
	scanf("%d %d", &k, &n);
	if ( n == 0 && k == 0 ) break;
	rep(i,1,n) rep(j,1,n) { C[i][j] = T[i][j] = INFTY; }
	rep(i,1,k){
	    scanf("%d %d %d %d", &s, &t, &cost, &tm);
	    C[s][t] = C[t][s] = cost;
	    T[s][t] = T[t][s] = tm;
	}
	scanf("%d", &q);
	rep(i,1,q){
	    scanf("%d %d %d", &s, &t, &r);
	    cout << dijkstra(s, t, r) << endl;
	}
    }
}

Measured memory_bytes: 1732
n = gets.to_s.to_i

if n == 0
  puts 0
  exit
end

k = -2

ans = ""
while n != 0
  
  if n.odd?
    ans += "1"
  else
    ans += "0"
  end
  r = n % k
  n -= r.abs
  n /= k
end

puts ans.reverse

Measured memory_bytes: 1788
from queue import deque


def paint(s, d, c):
    queue = deque([(d, s)])
    while queue:
        remains, v = queue.popleft()
        if painted[v] >= remains:
            continue
        if colors[v] == 0:
            colors[v] = c
        painted[v] = remains
        if remains:
            queue.extend((remains - 1, u) for u in links[v])


n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

q = int(input())
queries = [map(int, input().split()) for _ in range(q)]
colors = [0] * (n + 1)
painted = [-1] * (n + 1)
while queries:
    paint(*queries.pop())

for c in colors[1:]:
    print(c)


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2!=0){
		cout<<"No"<<endl;
	}else{
		string temp= s.substr(0, n/2);
		string ans= s.substr(n/2, n);
		if(temp==ans){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>

using namespace std;

using intll_t = long long;

int main() {
    int N;
    scanf("%d", &N);
    vector<int> AIS;
    AIS.reserve(N);
    for (int i = 0; i < N; i++) {
        int AI;
        scanf("%d", &AI);
        AIS.push_back(AI);
    }
    vector<int> c(10001, 0);
    for (int number : AIS) {
        c[number]++;
    }
    for (int i = 1; i < c.size(); i++) {
        c[i] += c[i-1];
    }
    vector<int> out(N, 0);
    for (int j = N - 1; j >= 0; j--) {
        int number = AIS[j];
        int& cntAtMostNumber = c[number];
        out[cntAtMostNumber - 1] = number;
        cntAtMostNumber--;
    }
    auto outIt = out.begin();
    while (true) {
        printf("%d", *outIt);
        ++outIt;
        if (outIt == out.end()) {
            break;
        } else {
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}


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

vector<int> v[202020];
bool used[202020];
vector<int> ans;

void dfs(int x){
    used[x]=true;
    for(auto nx:v[x]){
        if(!used[nx]){
            ans.push_back(nx);
            dfs(nx);
            break;
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1);
    reverse(ans.begin(),ans.end());
    ans.push_back(1);
    dfs(1);
    cout<<ans.size()<<endl;
    for(auto e:ans)cout<<e<<" ";
    return 0;
}

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

int main(){
  int64_t N;
  cin >> N;
  int64_t ans = N+1;
  for(int64_t i=1; i*i<=N; i++){
    if(N %i == 0){
      ans = min(ans,(i-1) + (N/i)-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int n; cin>>n;
  ll mo = 1000;
  ll ka = 0;
  vector<int> a(n);
  for(auto &i:a) cin>>i;
  for(int i=0; i<n-1; i++){
    if(a.at(i)<=a.at(i+1)){
      ka += mo/a.at(i);
      mo %= a.at(i);
    }
    else{
      mo += ka * a.at(i);
      ka = 0;
    }
  }
  mo += ka * a.at(n-1);
  cout<<mo<<endl;
  
}


Measured memory_bytes: 3616
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n = inp()
    a = inlt() + [0]
    q = 0
    w = 1000
    for i in range(len(a) - 1):
        if a[i + 1] >= a[i]:
            q = q + (w // a[i])
            w = w - ((w // a[i]) * a[i])
        else:
            w = w + (q * a[i])
            q = 0
    print(w)
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll K) {
  ll x = 7;

  int cnt = 1;

  while (true) {
    if (cnt >= 1e6 + 1) {
      cnt = -1;
      break;
    }
    if (x % K == 0) break;
    x = (x * 10) % K;
    x = (x + 7) % K;
    cnt++;
  }

  cout << cnt << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll K;
  scanf("%lld", &K);
  solve(K);
  return 0;
}


Measured memory_bytes: 3712
import numpy as np


def add(x):
    if x == 1:
        return 300000
    elif x == 2:
        return 200000
    elif x == 3:
        return 100000
    else:
        return 0


n, m = map(int, input().split())

ans = 0
ans += add(n) + add(m)
if n == 1 and m == 1:
    ans += 400000
print(ans)


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


mint dp[105][65];

bool is_ok(string s) {
    // cout << s << endl;

    // sには4文字入ってくる。
    // その並びがOKかどうかを確かめる。
    if (s.substr(0, 3) == "AGC" || s.substr(0, 3) == "GAC" || s.substr(0, 3) == "ACG") return false;
    if (s.substr(1, 3) == "AGC" || s.substr(1, 3) == "GAC" || s.substr(1, 3) == "ACG") return false;
    if (s[0] == 'A' && s[2] == 'G' && s[3] == 'C') return false;
    if (s[0] == 'A' && s[1] == 'G' && s[3] == 'C') return false;
    return true;
}

char chars[4] = {'A', 'C', 'G', 'T'};

int encode(string s) {
    int res = 0;
    int digit = 1;
    rep(i, 3) {
        int x;
        if (s[i] == 'A') x = 0;
        else if (s[i] == 'C') x = 1;
        else if (s[i] == 'G') x = 2;
        else x = 3;
        res += digit * x;
        digit *= 4;
    }
    return res;
}

string decode(int index) {
    string res;
    int digit = 3;
    while (digit--) {
        int i = index % 4;
        res.push_back(chars[i]);
        index /= 4;
    }
    // cout << res << endl;
    return res;
}

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

    mint ans = mint(4).pow(N);  // 全組み合わせ

    rep(i, N + 1) rep(j, 65) dp[i][j] = 0;
    rep(j, 64) {
        string s = decode(j);
        if (s == "AGC" || s == "ACG" || s == "GAC") dp[3][j] = 0;
        else dp[3][j] = 1;
    }

    for (int i = 3; i < N; i++) {
        rep(j, 64) {
            rep(k, 4) {
                string s = decode(j);
                s.push_back(chars[k]);
                // cout << s << endl;
                if (is_ok(s)) dp[i+1][encode(s.substr(1, 3))] += dp[i][j];
            }
        }
    }
    
    mint res = 0;
    rep(j, 64) {
        res += dp[N][j];
    }

    cout << res.x << endl;
    return 0;
}

Measured memory_bytes: 3696
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int h, w;
int s[52][52];

void output() {
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (s[i][j] >= 100) {
        cout << "#";
      } else {
        cout << s[i][j];
      }
    }
    cout << endl;
  }
}

int main() {
  cin >> h >> w;

  for (int i = 0; i < h+2; i++) {
    for (int j = 0; j < w+2; j++) {
      s[i][j] = 0;
    }
  }

  for (int i = 1; i < h + 1; i++) {
    string tmp;
    cin >> tmp;

    for (int j = 1; j < w + 1; j++) {
      if (tmp[j - 1] == '#') {  // s[i+1][j+1]
        s[i][j] = 100;
        s[i - 1][j - 1]++;
        s[i - 1][j]++;
        s[i - 1][j + 1]++;
        s[i][j - 1]++;
        s[i][j + 1]++;
        s[i + 1][j - 1]++;
        s[i + 1][j]++;
        s[i + 1][j + 1]++;
        //output();
      }
    }
  }
  output();

  return 0;
}


Measured memory_bytes: 256
A = input()
A, B, M = A.split(' ')

a = input()
a = a.split(' ')
b = input()
b = b.split(' ')

x = []
y = []
c = []

for i in list(range(int(M))):
    tmp = input()
    tmp = tmp.split(' ')

    x.append(int(tmp[0]))
    y.append(int(tmp[1]))
    c.append(int(tmp[2]))

ans = []
tmp = int(min(a)) + int(min(b))
ans.append(tmp)

for i in list(range(int(M))):
    tmp = int(a[x[i]-1]) + int(b[y[i]-1]) - c[i]
    ans.append(tmp)

ans.sort()
print(ans[0])


Measured memory_bytes: 36388
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0l);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
void chmin(T &x, T y) {
    x = min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
    x = max(x, y);
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}


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



int main() {
    srand(time(NULL));

    retry:
#ifdef LOCAL
    //gen();
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("lock.in", "r", stdin);
    //freopen("lock.out", "w", stdout);
#endif

    ll a, b;
    cin >> a >> b;

    if (a <= 0 && 0 <= b) {
        cout << "Zero" << endl;
    } else {
        if (0 < a) {
            cout << "Positive" << endl;
        } else {
            if ((b - a) & 1) {
                cout << "Positive" << endl;
            } else {
                cout << "Negative" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, M;
    intmax_t ans = 0;

    scanf("%jd%jd", &N, &M);

    if (N >= 2) {
        ans += N * (N - 1) / 2;
    }
    if (M >= 2) {
        ans += M * (M - 1) / 2;
    }

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

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


Measured memory_bytes: 7072
S =str(input())

import collections
S= collections.Counter(S)

if len(S)==1:
    print(0)
    exit()

#print(S.items())
#print(min(S.items(),key=lambda x:x[1]))

aaa =min(S.items(),key=lambda x:x[1])

print(2*aaa[1])


# 0
# 0010110010101
# 0000000111111

Measured memory_bytes: 3444