akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int n = nextInt();
			if (n == 0) {
				break;
			}

			int[][] jewels = new int[21][21];
			for (int i = 0; i < n; i++) {
				int px = nextInt();
				int py = nextInt();
				jewels[px][py] = 1;
			}

			int x = 10;
			int y = 10;

			int ope = nextInt();
			int obtained = 0;
			for (int i = 0; i < ope; i++) {
				char direction = nextChar();
				int length = nextInt();

				int dx = x;
				int dy = y;
				if (direction == 'N') {
					dy += length;
				} else if (direction == 'S') {
					dy -= length;
				} else if (direction == 'W') {
					dx -= length;
				} else if (direction == 'E') {
					dx += length;
				}

				if (dx == x) {
					int max = Math.max(y, dy);
					int min = Math.min(y, dy);
					for (int py = min; py <= max; py++) {
						if (jewels[x][py] != 0) {
							jewels[x][py] = 0;
							obtained++;
						}
					}

				} else {
					int max = Math.max(x, dx);
					int min = Math.min(x, dx);
					for (int px = min; px <= max; px++) {
						if (jewels[px][y] != 0) {
							jewels[px][y] = 0;
							obtained++;
						}
					}

				}

				x = dx;
				y = dy;

			}

			if (obtained == n) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

	static char nextChar() {
		try {
			int b = System.in.read();
			while (b != -1 && (b == ' ' || b == '\r' || b == '\n'))
				;
			if (b == -1)
				return 0;
			return (char) b;
		} catch (IOException e) {
		}
		return 0;
	}

}

Measured memory_bytes: 21108
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    vector<int>v;
    
    cin>>n;
    vector<int>cost(n);
    for(int i=0;i<n;i++)
        {
            cin>>a;
            v.push_back(a);
        }
    cost[0]=0;
    cost[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++)
        {cost[i]=min((cost[i-1]+abs(v[i]-v[i-1])),(cost[i-2]+abs(v[i]-v[i-2])));
        }//cout<<cost[i]<<"\n";}
    cout<<cost[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 4200
#!/usr/bin/env python3
import sys
import numpy as np

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = np.zeros((N,M+1))
    for i in range(N):
        A[i] = [int(next(tokens)) for _ in range(M+1)]
    
    min_c = [10000000]

    def dfs(k, dep):
        if dep == N-1:
            if (k[1:]>=X).all():
                min_c[0] = min(min_c[0], k[0])
            elif ((k+A[dep])[1:]>=X).all():
                min_c[0] = min(min_c[0], k[0]+A[dep][0])
        else:
            dfs(k+A[dep],dep+1)
            dfs(k,dep+1)
    
    dfs(np.zeros(M+1), 0)
    
    if min_c[0] != 10000000:
        print(int(min_c[0]))
    else:
        print(-1)




if __name__ == '__main__':
    main()


Measured memory_bytes: 27248
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    string s;
    cin>>s;
    cout<<"2018"<<s.substr(4)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

// 各ノードの座標と深さを保持するための構造体
//struct Node{
//    int y;
//    int x;
//    int depth;
//};

int main() {
    long long N, M;
    cin >> N >> M;
    long long mod =1000000007;
    
    long long ans = 1;
    if (abs(N-M)>=2) {
        ans=0;
    }
    else{
        for (long long i=0; i<N; i++) {
            ans=ans*(N-i);
            ans=ans%mod;
        }
        for (long long j=0; j<M; j++) {
            ans=ans*(M-j);
            ans=ans%mod;
        }
        if (N==M) {
            ans=ans*2;
            ans=ans%mod;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int n,a,i=0,c=0;
 cin>>n;
 a=100;
 while(a<n)
 {
     a+=(a*1/100);
     c++;
     i++;
 }
 cout<<c;
    return 0;
}


Measured memory_bytes: 3592
n, x, m = map(int, input().split())
result = [x]
for i in range(m):
    y = (result[-1] * result[-1]) % m
    if y in result:
        start = result.index(y)
        end = i
        break
    result.append(y)

loop = result[start:]
a = start
b = (n - a) // len(loop)
c = (n - a) % len(loop)
ans = sum(result[:a]) + (sum(loop) * b) + sum(loop[:c])
print(ans)

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int i##_to_ = (t), i = (f); i <= i##_to_; i++)
#define uptil(f, t, i)   for(int i##_to_ = (t), i = (f); i <  i##_to_; i++)
#define downto(f, t, i)  for(int i##_to_ = (t), i = (f); i >= i##_to_; i--)
#define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i >  i##_to_; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

//constexpr long MOD = 1000000007;

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N; scanf("%d", &N);
    vector<int> D(N + 1);
    times(N, i) scanf("%d", &D[i]);
    D[N] = 0;
    ++N;
    int cnt[13] = {};
    times(N, i) ++cnt[D[i]];

    int ans_b = 24;
    times(13, j) {
        if(cnt[j] >= 3) { cout << 0 ln; return 0; }
        if(cnt[j] == 2) ans_b = min({ans_b, j * 2, 24 - j * 2});
    }

    int ans = 0;
    times((2 << 11), p) {
        int s = 24;
        times(13, x) times(13, y) if(x != y && cnt[x] && cnt[y]) {
            if(cnt[x] >= 2 || cnt[y] >= 2)
                s = min(s, abs(x - y));
            else if(((p >> (x - 1)) & 1) == ((p >> (y - 1)) & 1))
                s = min(s, abs(x - y));
            else
                s = min({s, x + y, 24 - x - y});
        }
        ans = max(ans, s);
    }
    cout << min(ans, ans_b) ln;

    return 0;
}


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


int main()
{
    int w,h,n;
    std::cin >> w >> h >> n;
    std::pair<int,int> r_w = {0,w}, r_h = {0,h};
    
    for(int i = 0; i < n; i++){
        int x,y,a;
        std::cin >> x >> y >> a;
        if(a == 1)  r_w.first  = std::max(r_w.first,x);  //右
        if(a == 2)  r_w.second = std::min(r_w.second,x); //左
        if(a == 3)  r_h.first  = std::max(r_h.first,y);  //上
        if(a == 4)  r_h.second = std::min(r_h.second,y); //下
        //std::cout << r_w.first <<" : " << r_w.second << " : " << r_h.first << " : " << r_h.second << std::endl;
    }
    std::cout << std::max(0, std::max(0,(r_w.second - r_w.first)) * std::max(0,(r_h.second - r_h.first))) << std::endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define ull unsigned ll
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)

ll a[2010];
ull s[40010];
ll sum;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n){
		scanf("%lld",a+i);
		sum+=a[i];
	}
	//sum/2以上で最も小さいもの⇔sum-(sum/2以下で最も大きいもの)

	//iが作れる⇔bit(s[i/64],i%64)が1
	s[0]=1;
	rep(i,0,n){
		for(int j=34000-a[i]/64;j>=0;j--){
			if(a[i]%64)s[j+a[i]/64+1]|=s[j]>>(64-a[i]%64);
			s[j+a[i]/64]|=s[j]<<(a[i]%64);
		}
	}
	for(ll ans=sum/2;;ans--)if(bit(s[ans/64],ans%64)){
		printf("%lld",sum-ans);
		return 0;
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
inline int sqr(int x){return x*x%mod;}
int pow(int a,int n){return n?sqr(pow(a,n/2))*(n&1?a:1)%mod:1;}
int n,x,h[200001];
main()
{
	cin>>n;
	for(int i=1;i<=n;i++)h[i]=(h[i-1]+pow(i,mod-2))%mod;
	int ans=0,r=1;
	for(int i=1;i<=n;i++)cin>>x,ans+=x*(h[i]+h[n-i+1]-1+mod)%mod,r=r*i%mod;
	cout<<ans%mod*r%mod<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int x=0,y=0,cnt;
int main() {
	cin>>a;
	for (int i=0; i<sizeof(a); i++)
		if (x==y) {
			x++;
			if(a[i]=='p') cnt--;
		} else {
			y++;
			if(a[i]=='g') cnt++;
		}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		if(a<b&&b<c){
		System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26168
import sys
N, K = map(int, input().split())
x, y, c = [0] * N, [0] * N, [0] * N
board = [[0] * (2 * K + 1) for i in range(2 * K + 1)]
MOD = 2 * K + 1
for i in range(N):
    x[i], y[i], c[i] = input().split()
    x[i], y[i] = int(x[i]), int(y[i])
    if c[i] == 'W':
        x[i] += K
        c[i] = 'B'
    x[i] %= 2 * K
    y[i] %= 2 * K
    board[y[i]+1][x[i]+1] += 1

# for i in range(2*K+1):
#     print(' '.join(map(str, board[i])))
# print('================')
for i in range(2*K+1):
    for j in range(2*K):
        board[i][j+1] += board[i][j]
for j in range(2*K+1):
    for i in range(2*K):
        board[i+1][j] += board[i][j]

# for i in range(2*K+1):
#     print(' '.join(map(str, board[i])))
ans = 0
def c(x1, y1):
    global K, board
    x1 = x1 % MOD + x1 // MOD
    y1 = y1 % MOD + y1 // MOD
    x2 = (x1 + K) % MOD + (x1 + K) // MOD
    y2 = (y1 + K) % MOD + (y1 + K) // MOD
    if x1 < x2:
        x11, x12, x21, x22 = x1, x2, 0, 0
    else:
        x11, x12, x21, x22 = x1, -1, 0, x2
    if y1 < y2:
        y11, y12, y21, y22 = y1, y2, 0, 0
    else:
        y11, y12, y21, y22 = y1, -1, 0, y2
    f = lambda a, b, c, d: board[a][b] + board[c][d]\
            - board[a][d] - board[c][b]
    # print("x11: %d, x12: %d" % (x11, x12))
    # print("x21: %d, x22: %d" % (x21, x22))
    # print("y11: %d, y12: %d" % (y11, y12))
    # print("y21: %d, y22: %d" % (y21, y22))
    # print("a1: %d" % f(y12, x12, y11, x11))
    # print("a2: %d" % f(y22, x22, y21, x21))
    # print("a3: %d" % f(y12, x22, y11, 0))
    # print("a4: %d" % f(y22, x12, 0, x11))
    ret = 0
    ret += f(y12, x12, y11, x11)
    ret += f(y22, x22, y21, x21)
    ret += f(y12, x22, y11, x21)
    ret += f(y22, x12, y21, x11)
    return ret


for i in range(2*K+1):
    for j in range(K+1):
        # print('i: %d, j: %d' % (i, j))
        # print('c(i, j): %d' % c(i, j))
        # print('c(i+K, j+K): %d' % c(i+K, j+K))
        # print('')
        ans = max((ans, c(i, j) + c(i+K, j+K)))

print(ans)


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

int main(){
	int a, b;
	cin >> a >> b;
	if(a < b) cout << "a < b" << endl;
	if(a > b) cout << "a > b" << endl;
	if(a == b) cout << "a == b" << endl;
	return 0;
}



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

using namespace std;
using ll = long long;
const ll INF = 1e18;

ll pow(int x, int n){
    if(n==0)return 1;
    else return x * pow(x, n-1);
}

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

    vector<ll> dp(N+1, INF);
    dp.at(0) = 0;

    for(int i=0; i<N; i++){
        dp.at(i+1) = min(dp.at(i+1), dp.at(i)+1);
        for(int j=1; i+pow(6,j)<=N; j++)
            dp.at(i+pow(6,j)) = min(dp.at(i+pow(6,j)), dp.at(i)+1);
        for(int k=1; i+pow(9,k)<=N; k++)
            dp.at(i+pow(9,k)) = min(dp.at(i+pow(9,k)), dp.at(i)+1);
    }

    cout << dp.at(N) << endl;
}

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

ll val[101], wt[101], dp[110][(int)1e5+10];


ll solve(int ith, int cwt, int n) {

    if(ith == n) return 0;

    if(dp[ith][cwt] != 0) return dp[ith][cwt];

    ll sml = 0;

    if(cwt - wt[ith] >= 0)
        sml = solve(ith + 1, cwt - wt[ith], n) + val[ith];

    ll sml1 = solve(ith + 1, cwt, n);

    return dp[ith][cwt] = max(sml, sml1);
}



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

    for(int i=0; i<n; ++i) {
        cin >> wt[i] >> val[i];
    }

    cout << solve(0, w, n);

    return 0;
}

Measured memory_bytes: 78080
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int main() {
	ll N, W;
	cin >> N >> W;
	ll w0, v0;
	cin >> w0 >> v0;

	vector<vector<ll>> v(4);
	v[0].pb(v0);

	for (int i = 1; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		v[a-w0].pb(b);
	}

	for (int i = 0; i < 4; i++) sort(RALL(v[i]));

	vector<vector<ll>> sum(4);
	for (int i = 0; i < 4; i++) {
		sum[i].pb(0);
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < (int)v[i].size(); j++) {
			sum[i].pb(sum[i][j] + v[i][j]);
		}
	}

	ll ans = 0;
	for (int i = 0; i <= (int)v[0].size(); i++) {
		for (int j = 0; j <= (int)v[1].size(); j++) {
			for (int k = 0; k <= (int)v[2].size(); k++) {
				for (int l = 0; l <= (int)v[3].size(); l++) {
					ll tmp_w = w0*i + (w0+1)*j + (w0+2)*k + (w0+3)*l;
					if (tmp_w <= W) ans = max(ans, sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]);
				}
			}
		}
	}

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


Measured memory_bytes: 256
import math
import collections

def main():
    K = int(input())
    A, B = map(int, input().split())

    count = K
    while True:
        if (count >= A) and (count <= B):
            print("OK")
            break
        elif count > B:
            print("NG")
            break
        count += K

    return 0

if __name__ == '__main__':
    main()

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

k, n = map(int, input().split())
a = list(map(int, input().split()))
gap = a[0] + k - a[n - 1]
for i in range(n - 1):
    gap = max(gap, a[i + 1] - a[i])
print(k - gap)

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

long gcd(long i,long j){

  long counter;

  if(i == 0)counter = j;
  if(j == 0)counter = i;
  if(i != 0 && j != 0){

    if(i > j)swap(i,j);

    long r = j % i;
 
    while(r != 0){
        j = i;
        i = r;
        r = j % i;  
    }
    counter = i;    
  }
    return counter;
}

int main(){
  int N;
  cin >> N;
  vector<long> A(N);
  vector<long> begin(N);
  vector<long> end(N + 1);

  long counter;
  long counter_max = 0;

  begin[0] = 0;
  end[N] = 0;
 
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }

  for(int i = 1;i < N;i++){
    begin[i] = gcd(begin[i - 1],A[i - 1]);
  }
 
  for(int i = N - 1;i > 0;i--){
    end[i] = gcd(end[i + 1],A[i]);
  }

  for(int i = 0;i < N;i++){
    counter_max = max(counter_max,gcd(begin[i],end[i + 1]));
  }

  cout << counter_max << endl;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

class Point{
public:
  int n,x;
  Point (int n=0,int x=0): n(n),x(x){}
  bool operator < (const Point &p)const{
    if(x == p.x) return n < p.n;
    else return x > p.x;}
}; 

int main(){
  int i,j,n,m,a[1000][100];
  Point b[100];
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	cin >> a[i][j];
      }
    }

    for(j=0;j<m;j++){
      b[j].x = 0;
      b[j].n = j + 1;
      for(i=0;i<n;i++){
	if(a[i][j]) b[j].x++;
      }
    }
    sort(b,b+m);
    cout << b[0].n;
    for(i=1;i<m;i++) cout << " " << b[i].n;
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int Q = scanner.nextInt();
		long [] A = new long[Q];
		long [] B = new long[Q];
		for(int i = 0; i < Q; i++) {
			A[i] = scanner.nextLong();
			B[i] = scanner.nextLong();
		}
		scanner.close();
		double score;
		for(int i = 0; i < Q; i++) {
			score = A[i] * B[i];
			if(A[i] > B[i]) {
				long t = A[i];
				A[i] = B[i];
				B[i] = t;
			}
			double C0 = Math.sqrt(score);
			long C = (long)Math.sqrt(score);
			if(C0 == C) {
				C = C -1;
			}
			if(A[i] == B[i] || A[i] + 1 == B[i]) {
				System.out.println(2 * A[i] - 2);
			}else if(C * (C + 1) >= score) {
				System.out.println(2* C - 2);
			}else {
				System.out.println(2* C - 1);
			}
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
int main()
{
    int t, tt;
    scanf("%d %d", &t,&tt);

    if (t>tt){
        printf("%d\n",t + t - 1);
    }
    else if(tt > t){
        printf("%d\n",tt + tt - 1);
    }
    else if(tt == t)
    {
        printf("%d\n",tt + t);
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
s = input()
dp = [[0]*(n) for _ in range(n)]

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        if i == (n-1):
            if s[i] == s[j]:
                dp[i][j] += 1
            continue

        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1        

ans = 0
for i in range(n-1, -1, -1):
    for j in range(i, -1, -1):
        ans = max(ans, min(abs(j-i), dp[i][j]))
print(ans)

Measured memory_bytes: 270412
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
using ll = long long;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> w(n);
    vector<ll> ans(n);
    REP(i, n) cin >> w[i];
    int sign = 1;
    ll sm = 0;
    REP(i, n) {
        sm += w[i] * sign;
        sign *= -1;
    }
    ans[0] = sm;
    for (int i = 1; i < n; ++i) {
        ans[i] = (w[i - 1] - ans[i - 1] / 2) * 2;
    }
    cout << ans[0];
    REP(i, n - 1) cout << " " << ans[i + 1];
    cout << endl;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
    return 0;
}


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

class MyClass
{
    public static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var str = Console.ReadLine();
        var count = 0;
        var phase = 0;
        char prev = ' ';
        foreach (var c in str)
        {
           if (c != prev && phase == 1)
            {
                count++;
                phase = 0;
            }
            else if (phase == 0)
            {
                phase = 1;
            }
            prev = c;
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 17960
#include <cstdio>
#include <map>
#include <vector>

#define MAXN 100003

std::map <int, int> mp;
std::vector <int> g[MAXN];

int ans, k, n;
bool viz[MAXN];
int t[MAXN];
int a[MAXN], b[MAXN];
int v[MAXN];
int ind[MAXN], per[MAXN];

int sef(int x) {
    if (x == t[x]) return x;
    else return t[x] = sef(t[x]);
}

inline void baga(int i) {
    if (a[i] == b[i] && i != n + 1)
        return ;
    int &u = mp[b[i]];
    if (u == 0)
        u = ++k;
    g[u].push_back(i);
}

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

    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        a[n + 1] ^= a[i];
    }

    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
        b[n + 1] ^= b[i];
        baga(i);
    }
    baga(n + 1);

    int poz = 1;
    bool sol = 1;
    while(poz <= n + 1 && sol) {
        if (a[poz] != b[poz] || poz == n + 1) {
            int &u = mp[a[poz]];
            if (ind[u] < (int)g[u].size()) {
                v[poz] = g[u][ind[u]];
                per[g[u][ind[u]]] = poz;
                ind[u]++;
            }
            else sol = 0;
        }
        poz++;
    }

    for (int i = 1; i <= n; i++)
        ans += (a[i] != b[i]);

    if(sol == 0) {
        printf("-1\n");
        return 0;
    }

    for (int i = 1; i <= n + 1; i++) {
        if (viz[i] == 0 && v[i]) {
            int x = i;
            t[x] = i;
            ans++;
            viz[x] = 1;
            x = v[x];
            while (viz[x] == 0) {
                viz[x] = 1;
                t[x] = i;
                x = v[x];
            }
        }
    }

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j < (int)g[i].size(); j++) {
            int x = sef(per[g[i][j - 1]]), y = sef(per[g[i][j]]);
            if (x != y) {
                ans--;
                t[x] = y;
            }
        }
    }
    ans--;

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

    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, k; cin >> n >> k;
    int cnt = 0;
    while(n != 0){
        n/=k;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3604
import sys
N = int(input())
x, y, z = 0, 0, 0
for i, e in enumerate(sys.stdin):
    a, b, c = map(int, e.split())
    nx = max(y, z) + a
    ny = max(x, z) + b
    nz = max(x, y) + c
    x, y, z = nx, ny, nz
print(max(x, y, z))

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AServalVsMonster solver = new AServalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class AServalVsMonster {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int a = in.nextInt();

            if (h % a == 0)
                out.println((h / a));
            else
                out.println((h / a) + 1);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main()
{
    long long int n, s = 0;


        cin >> n;

       for (int i = 1 ; i <= n ; i++)
        {
            if ( i%3!=0 && i%5!=0)

            s = s + i;

        }

        cout<<s<<endl; 
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int N, T, A; cin >> N >> T >> A;
	T--; A--;
	vector<vector<int>> edg(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		edg[a].push_back(b);
		edg[b].push_back(a);
	}
	vector<int> da(N, 1e9), dt(N, 1e9);
	deque<int> que;
	que.push_back(A);
	da[A] = 0;
	while (!que.empty()) {
		int pos = que.front();
		que.pop_front();
		for (int to : edg[pos]) {
			if (da[to] <= da[pos]) continue;
			da[to] = da[pos] + 1;
			que.push_back(to);
		}
	}

	que.push_back(T);
	dt[T] = 0;
	while (!que.empty()) {
		int pos = que.front();
		que.pop_front();
		for (int to : edg[pos]) {
			if (dt[to] <= dt[pos]) continue;
			dt[to] = dt[pos] + 1;
			que.push_back(to);
		}
	}

	int gl = 0, m = 0;
	for (int i = 0; i < N; i++) {
		if (dt[i] >= da[i]) continue;
		if (da[i] > m) {
			m = da[i];
			gl = i;
		}
	}
	int ans = da[gl] - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3F3F3F3F;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    ll a, b, c;
    cin >> a >> b >> c;
    ll go = b * c;
    cout << (go >= a ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

namespace temp {
#define Int register int
#define Type template<typename Tp>
#ifdef __DEBUG
#define __disp( x )	printf ( "#disp: %s = %.2f ( at %dL )\n", #x, ( double ) x, __LINE__ )
#endif
typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef unsigned long long uLL;
Type inline Tp rintt () {
	register Tp x = 0; register int f = 1; register char s = getchar ();
	for ( ; s < '0' || '9' < s; s = getchar () ) f = s == '-' ? -f : f;
	for ( ; '0' <= s && s <= '9'; s = getchar () ) x = ( x << 3 ) + ( x << 1 ) + ( s ^ '0' );
	return x * f;
}
#define rll rintt<LL>
#define rint rintt<int>
Type inline void wint ( Tp x ) {
	if ( x < 0 ) putchar ( '-' ), x = ~ x + 1;
	if ( 9 < x ) wint ( x / 10 );
	putchar ( x % 10 ^ '0' );
}
Type inline void wintsp ( Tp x ) { wint ( x ), putchar ( ' ' ); }
Type inline void wintln ( Tp x ) { wint ( x ), putchar ( '\n' ); }
Type inline Tp Abs ( const Tp x ) { return x < 0 ? -x : x; }
Type inline void Swap ( Tp& a, Tp& b ) { Tp t = a; a = b, b = t; }
Type inline Tp Min ( const Tp a, const Tp b ) { return a < b ? a : b; }
Type inline Tp Max ( const Tp a, const Tp b ) { return b < a ? a : b; }
#undef Type
} using namespace temp;

typedef pair<int, int> pii;

const int MAXN = 100, MOVE[2][2] = { { 1, 0 }, { 0, 1 } };
int H, W, Dist[MAXN + 5][MAXN + 5];
char Col[MAXN + 5][MAXN + 5];
bool Vis[MAXN + 5][MAXN + 5];
priority_queue<pii, vector<pii>, greater<pii> > Q;

inline bool Inside ( const int x, const int y ) { return 1 <= x && x <= H && 1 <= y && y <= W; }

inline void Dijkstra () {
	memset ( Dist, 0x3f, sizeof Dist );
	Dist[1][1] = Col[1][1] == '#';
	Q.push ( { Col[1][1] == '#', 1 } );
	while ( ! Q.empty () ) {
		pii p = Q.top (); Q.pop ();
		int x = ( p.second - 1 ) / W + 1, y = ( p.second - 1 ) % W + 1;
		if ( Vis[x][y] ) continue;
		Vis[x][y] = true;
		for ( Int i = 0, tx, ty; i ^ 4; ++ i ) {
			if ( Inside ( tx = x + MOVE[i][0], ty = y + MOVE[i][1] ) && ! Vis[tx][ty] && Dist[tx][ty] > p.first + ( Col[tx][ty] != Col[x][y] ) ) {
				Q.push ( { Dist[tx][ty] = p.first + ( Col[tx][ty] != Col[x][y] ), ( tx - 1 ) * W + ty } );
			}
		}
	}
}

inline void Work () {
	H = rint (), W = rint ();
	for ( Int i = 1; i <= H; ++ i ) scanf ( "%s", Col[i] + 1 );
	Dijkstra ();
	printf ( "%d\n", Dist[H][W] + 1 >> 1 );
}

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


Measured memory_bytes: 256
def serch_1(b,x):
    i=1
    an=0
    while 1:
        if b.count(x+i)==0:
            an=x+i
            break
        else:
            i=i+1
    return an

def serch_2(b,x):
    i=1
    an=0
    while 1:
	    if b.count(x-i)==0:
		    an=x-i
		    break
	    else:
		    i=i+1
    return an
def hikaku(a,b,x):
    if abs(a-x)>=abs(b-x):
    	return b
    else:
        return a
s = list(map(int,input().split()))
# n = int(input())
a = list(map(int,input().split()))
# print(serch_1(a,x),serch_2(a,x))
x=s[0]
n=s[1]
if a.count(x)==0:
	print(x)
else:
	print(hikaku(serch_1(a,x),serch_2(a,x),x))

    

Measured memory_bytes: 9216
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        Map<Integer, Integer> mMap = new HashMap<Integer, Integer>(N);
        long allsum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (mMap.containsKey(A[i])) {
                allsum += mMap.get(A[i]);
                mMap.put(A[i], mMap.get(A[i])+1);
            }
            else {
                mMap.put(A[i], 1);
            }
        }
        sc.close();

        for (int i = 0; i < N; i++) {
            int num = mMap.get(A[i]);
            System.out.println(allsum - (num - 1));
        }
    }
}


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

int main(){
  ll N;
  cin>>N;
  for(ll h=1;h<=3500;h++){
    for(ll n=1;n<=3500;n++){
      ll b=N*h*n;
      ll a=4*h*n-N*n-N*h;
      if(a>0&&b%a==0){
	printf("%d %d %d\n",h,n,b/a);
	return 0;
      }
    }
  }
  return 0;
}

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

int main(){
  int n,d,cnt=0;
  cin >> n >> d;
  int a[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int ans =0;
      for(int k=0;k<d;k++){
       	ans += pow((a[i][k]-a[j][k]),2);
      }
      if(pow(int(sqrt(ans)),2)==ans)
        cnt++;
    }
  }
  cout << cnt << endl;
}


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

using namespace std;
using int64 = long long;

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

    int64 x = b-1;
    if (x > n) x = n;

    cout << (a*x)/b << endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, m;
vector<int> edge[100005];
int dp[100005];

int dfs(int v) {
    if(dp[v])
        return dp[v];
    for(auto&&u:edge[v]) {
        chmax(dp[v],dfs(u)+1);        
    }

    return dp[v];
}

inline void solve(){

    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >>x >> y;

        x--,y--;
        edge[x].bash(y);
    }
    int maxi = 0;
    for(int i = 0; i < n; i++) {
        chmax(maxi,dfs(i));
    }

    cout << maxi << endl;
    
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 7552
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

cnt = 0
for i in range(n-1, -1, -1):
    cnt += min(b[i], a[i]+a[i+1])
    diff = b[i] - a[i+1]
    if diff > 0:
        a[i] = max(0, a[i]-diff)

print(cnt)

Measured memory_bytes: 24128
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
bool A[3005];
bool B[3005];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    for (int x = 0; x * a * 100 <= f; x++) {
        for (int y = 0; x * a * 100 + y * b * 100 <= f; y++) {
            int t = 100 * (x * a + y * b);
            A[t] = true;
        }
    }
    for (int x = 0; x * c <= f; x++) {
        for (int y = 0; y * d + x * c <= f; y++) {
            B[x * c + y * d] = true;
        }
    }
    int c1 = -1;
    int c2 = -1;
    for (int i = 0; i <= f; i++) {
        for (int j = 0; i + j <= f; j++) {
            if (i == 0 && j == 0) continue;
            if (A[i] && B[j] && i * e >= j * 100) {
                if (c1 == -1 || ((100 * j) * (c1 + c2) >= (100 * c2) * (i + j))) {
                    c1 = i;
                    c2 = j;
                }
            }
        }
    }
    cout << c1 + c2 << " " << c2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void)
{
	int input1,input2;
	
	scanf("%d %d",&input1,&input2);
	if(input1 > input2)
	{
		printf("a > b\n");
	}
	else if(input1 < input2)
	{
		printf("a < b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	
	char c[4] = { 'S' , 'N' , 'E' , 'W' };
	bool used[4];
	rep(i,4)used[i] = false;
	
	rep(i,s.size()){
		rep(j,4){
			if(s[i] == c[j]){
				used[j] = true;
			}
		}
	}
	
	int cnt[2] = {};
	rep(i,4)if(used[i])cnt[i/2] ++;
	rep(i,2){
		if(cnt[i] == 1){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define int long long
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
signed main(void){
    int N,K;
    int count =0;
    int ans=0;
    int a[114514],b[114514],E[114514]={};
    cin >> N >> K;
    REP(i,N){cin >> a[i] >> b[i];}
    REP(i,N){
        E[a[i]]+=b[i];
    }
    for(int i=1;count<K;i++){count+=E[i];ans++;}
    cout << ans;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

int N, K;

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

    std::cin >> N >> K;

    double probs = 0;
    for(int i = 1; i <= N; i++) {
        int pow_n = 0;
        while(i * pow(2, pow_n) < K) {
            pow_n++;
        }
        probs += (1.0 / N) * pow(0.5, pow_n);
    }

    std::cout << std::setprecision(20) << probs << std::endl;

    return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
flag = 1 
for x in range(N + 1): 
        if 10000 * x > Y or flag == 0:
                break
        for y in range(N + 1): 
                if 10000*x + 5000*y > Y:
                        break
                if 10000*x + 5000*y + 1000*(N - x - y) == Y:
                        print(str(x) + " " + str(y) + " " + str(N - x - y)) 
                        flag = 0 
                        break
if flag:
        print("-1 -1 -1")

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"strings"
)

func main() {

	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	var S string
	fmt.Scanf("%s", &S)

	fmt.Printf("%s%s%s\n", S[0:K-1], strings.ToLower(S[K-1:K]), S[K:N])
}


Measured memory_bytes: 1844
using System;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int A = int.Parse(input[1]);
            int B = int.Parse(input[2]);

            int result = 0;
            int value = 0;
            int sum = 0;

            for (int i = 1; i <= N; i++)
            {
                value = i;

                while(value > 0)
                {
                    sum += value % 10;
                    value = value/10;
                }

                if (A <= sum && sum <= B)
                {
                    result += i;
                }

                sum = 0;
            }
            Console.WriteLine(result);

        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[n + 1];
		for(int i = 1; i <= n; i++) {
			dp[i] = dp[i - 1] + 1;
		}
		for(int i = 1; i <= n; i++) {
			int j = 1;
			while(true) {
				if(i - Math.pow(6, j) >= 0) {
					dp[i] = Math.min(dp[(int) (i - (Math.pow(6, j)))] + 1, dp[i]);
					j++;
				}else {
					break;
				}
			}
		}
		for(int i = 1; i <= n; i++) {
			int j = 1;
			while(true) {
				if(i - Math.pow(9, j) >= 0) {
					dp[i] = Math.min(dp[(int) (i - (Math.pow(9, j)))] + 1, dp[i]);
					j++;
				}else {
					break;
				}
			}
		}
		System.out.println(dp[n]);
	}

}


Measured memory_bytes: 23888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

string s,t;
ll solve(){
   ll ans=0;
   

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

    cin>>s>>t;
    int n=s.size();
    int m=t.size();
    rep(i,n){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(m-n!=1){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    //cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3640
from collections import defaultdict

n = int(input())
arr = list(map(int, input().split()))

d = defaultdict(int)

for x in arr:
    d[x] += 1
    d[x - 1] += 1
    d[x + 1] += 1

result = [y for x, y in d.items()]

print(max(result))

Measured memory_bytes: 23600
using System;

namespace abc081{
    public class A
    {
        static void Main(string[] args)
        {
            char[] s = Console.ReadLine().ToCharArray();
            int ans = 0;
            for(int i = 0; i < 3; i++)
            {
                if (s[i] == '1')
                    ans++;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void){
	int n;
	int count = 0;
	bool flag = true;
	int t[100001], x[100001], y[100001];
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	cin >> n;
	FOR(i, 1, n) {
		cin >> t[i] >> x[i] >> y[i];
	}
	FOR(i, 1, n) {
		count = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		if (t[i] - t[i - 1] - count >= 0 && (t[i] - t[i - 1] - count) % 2 == 0) {
			continue;
		}
		else {
			flag = false;
			break;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + 1 < c)
    {
        cout << a + b * 2 + 1 << endl;
    }
    else
    {
        cout << b + c << endl;
    }
}

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

#define scd second
#define fst first
#define mkp make_pair
#define pb push_back
#define pf push_front

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;

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

    int n;
    cin>>n;
    unordered_set<string> ss;
    for(int i=0; i<n; i++){
        string s;
        cin>>s;
        ss.insert(s);
    }
    cout<<ss.size()<<endl;
}

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

int N;
string S;

int main() {
  cin >> N >> S;
  
  int x = 0;
  for (int i = 0; i < N; i++) {
    if(S[i] == '.') x++;
  }

  int min = x;
  for (int i = 0; i < N; i++) {
    if (S[i] == '.') {
      x--;
      if (min > x) min = x;
    }
    else x++;
  }
  cout << min << endl;
}


Measured memory_bytes: 640
while True:
  n = int(input())
  if n == 0:
    break
  tlst = []
  qlst = []
  for _ in range(n):
    m, a, b = map(int, input().split())
    qlst.append((m, a, b))
    tlst.append(a)
    tlst.append(b)
  tlst = sorted(list(set(tlst)))
  tlst.sort()
  tdic = {}
  for i, t in enumerate(tlst):
    tdic[t] = i
  lent = len(tlst)
  mp = [0] * lent
  for m, a, b in qlst:
    a, b = tdic[a], tdic[b]
    mp[a] += m
    mp[b] -= m
  
  acc = 0
  for i in range(lent):
    acc += mp[i]
    if acc > 150:
      print("NG")
      break
  else:
    print("OK")



Measured memory_bytes: 5624
import java.util.Scanner;

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

        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            int digits = Integer.toString(a + b).length();

            System.out.println(digits);
        }
    }
}

Measured memory_bytes: 26140
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#include <cmath>
using namespace std;
typedef long long ll;

int main(void){
  ll N,D;
  ll ans=0;
  cin >>N>>D;
  vector<ll> X(N);
  vector<ll> Y(N);
  //入力
  for(ll i=0LL;i<N;i++){
    cin >> X.at(i)>>Y.at(i);
  }
  for(ll i=0LL;i<N;i++){
    if((X.at(i)*X.at(i)+Y.at(i)*Y.at(i)) <=D*D){
      ans++;
    }
  }
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 6424
def bbreak(n, s):
    ans = 0
    pnt = 1
    for b in s:
        if b == pnt:
            pnt += 1
        else:
            ans += 1
    if pnt == 1:
        print('-1')
    else:
        print(ans)

if __name__ == "__main__":
    import sys
    in_str = []
    for line in sys.stdin:
        in_str.append(line)
    bbreak(int(in_str[0]), [int(_) for _ in in_str[1].split()])

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

int main() {
  int n, d = 100000;
  cin >> n;
  while (n--) {
    d = (int)ceil(d * 1.05 / 1000) * 1000;
  }
  cout << d << endl;
  return 0;
}


Measured memory_bytes: 3052
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

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

int main(void) {
    string c;
    cin >> c;
    cout << ++c[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>a>>b>>c;
	if(c<=a&&c>=b||c<=b&&c>=a)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256