akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n; cin >> n;

    cout << n * n * n;

    return 0;

}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val list = List.fill(n)(sc.nextInt)
  val ans = list.
    zipWithIndex.
    map { case (t1, t2) =>
      if (t1 > t2 + 1)
        (t2 + 1, t1)
      else
        (t1, t2 + 1)
    }.
    groupBy(identity).
    values.
    count(p => p.size == 2)
  println(ans)
}

Measured memory_bytes: 95568
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  FOR(p,1,n-1){
    string s1 = s.substr(0,p);
    string s2 = s.substr(p);
    int kinds = 0;
    for(char c='a'; c<='z'; c++){
      if(s1.find(c) != string::npos && s2.find(c) != string::npos) kinds++;
    }
    ans = max(ans, kinds);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s;
	cin>>t;
	int sl=s.length();
	int tl=t.length();
	assert(sl>=1 && sl<=100 && tl>=1 && tl<=100);
	cout<<t.append(s)<<endl;
	return 0;	
}


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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<pii> v;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(pii(a, b));
    }
    sort(v.begin(), v.end());
    ll pos = 0;
    for (int i = 0; i < v.size(); i++) {
        pos += v[i].second;
        if (k <= pos) {
            cout << v[i].first << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;  //このネームスペースを使う

int main(){
  int N ;
  int i,j;
  int max;
  int max2;

  cin >> N ;
 
  int A[N];
  int comp;

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

  max=0;
  for(i=0;i<N;i++){
    if(max < A[i]){
      max  = A[i];
    }
  }

  max2=0;
  j=0;
  for(i=0;i<N;i++){
    if(max == A[i]){
      j++;
    }

    if(max2 < A[i] && max != A[i]){
      max2 =A[i];
    }
  }

  if(j >= 2){
    max2 = max;
  }

  if(max == max2){
    for(i=0;i<N;i++){
      cout << max << endl;
    }
  }
  else{
    for(i=0;i<N;i++){
      if(A[i]==max){
        cout << max2 << endl;
      }
      else{
        cout << max << endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

ll dp[3001][3001];
vector<int> a;

// ll fun(int l,int r,int c){
// 	if(r<l)
// 		return 0;
// 	ll &ans = dp[l][r][c];
// 	if(dp[l][r][c]!=1e17)
// 		return dp[l][r][c];

// 	if(!c)
// 		ans = max(a[l]+fun(l+1,r,!c),a[r]+fun(l,r-1,!c));
// 	else
// 		ans = min(-a[l]+fun(l+1,r,!c),-a[r]+fun(l,r-1,!c));

// 	return ans;
// }

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	a.resize(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		dp[i][i] = a[i];
	}

	for(int d=1;d<=n;++d){
		for(int l=0;l<n-d;++l){
			int r = l+d;
			dp[l][r] = max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
		}
	}

	cout<<dp[0][n-1];

	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

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

void solve() 
{
    int n;cin>>n;
    int cnt=0;
    while(n--){
        int a,b;cin>>a>>b;
        if(a==b)cnt++;
        else cnt=0;
        if(cnt==3){
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
}

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

Measured memory_bytes: 3652
# https://atcoder.jp/contests/abc143/tasks/abc143_d

import bisect

N = int(input())
L_list = list(map(int, input().split()))
L_list = sorted(L_list)
count = 0

for a in range(N-2):
    for b in range(a + 1, N-1):
        c_min = L_list[b + 1]
        c_max = L_list[a] + L_list[b]
        c_max_idx = bisect.bisect_left(L_list, c_max)
        c_count = c_max_idx - (b + 1)
        count += c_count

print(count)

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

int main(void){
  char buf[16] = { 0 };
  int num[4];
  char numstr;
  int calc[8][3] = {{1,1,1}, {1,1,-1}, {1,-1,1}, {-1,1,1}, 
                        {1,-1,-1}, {-1,1,-1}, {-1,-1,1},{-1,-1,-1}};
  
  fgets(buf, sizeof(buf), stdin);
  for(int i = 0; i < 4; i++){
    numstr = buf[i];
    num[i] = atoi(&numstr);
  }
  
  int i;
  int ans = 0;
  for(i = 0; i < 8; i++){
    ans = num[0] + calc[i][0]*num[1] + calc[i][1]*num[2] + calc[i][2]*num[3];
    if(ans == 7) break;
  }
  
  if( ans != 7 ) return 0; 
  printf("%d", num[0]);
  for(int j = 0; j < 3; j++){
    if(calc[i][j] > 0) printf("+");
    else printf("-");
    printf("%d", num[j+1]);
  }
  printf("=7\n");
  
  return 0;
}

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

int main() {
  int a,b,x;
  cin>>a>>b>>x;
  double pi=2.0 * asin(1.0); 
  if (x>a*a*b/2){
    double c=(double)b/a-(double)(2*x-a*a*b)/(a*a*a);
    double d=atan(c);
    cout << fixed << setprecision(10);
    cout<<d*180/pi<<endl;
  }
  if (x<=a*a*b/2){
    double e=(double)2*x/a/b/b;
    double f=atan(e);
    cout << fixed << setprecision(10);
    cout<<90-f*180/pi<<endl;
  }
}

Measured memory_bytes: 256
#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>;

const int INF = 1001001001;

int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> dp(n+1, INF);
    dp[n] = 0;
    queue<int> q;
    q.push(0);
    for (int i = n-1; i >= 0; i--) {
        while (1) {
            if (q.size() == 0) {
                cout << -1 << endl;
                return 0;
            }
            if (q.front() != INF && q.size() <= m) break;
            q.pop();
        }
        if (s[i] == '0') dp[i] = q.front()+1;
        q.push(dp[i]);
    } 
    vector<int> ans;
    int x;
    int rest = dp[0];
    while (x < n) {
        rest--;
        int i = 1;
        while (dp[x+i] != rest) i++;
        ans.push_back(i);
        x += i;
    }
    rep(i,ans.size()) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4452
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
#define MAX_M 200005
#define INF (1e8)
int N,M,q;
set<int> G[MAX_N];
vector<int> g[MAX_N];
int ea[MAX_M],eb[MAX_M];
int d[MAX_N];
int C[MAX_N];
bool flg[MAX_N];

int ans;

void bfs(int si){

  queue<int> Q;
  Q.push(si);
  while(!Q.empty()){
    int pos=Q.front();Q.pop();

    if(!flg[pos]){
      ans++;
      flg[pos]=true;
    }

    while(G[pos].size()>0){
      int to=*G[pos].begin();
      G[pos].erase( G[pos].begin() );
      C[to]--;
      if(C[to]==0)Q.push(to);
    }
  }
}

void solve(){
  while(q--){
    int id;
    scanf("%d",&id);
    int a=ea[id],b=eb[id];
    if(d[a]-1==d[b]){
      // a -> b
      if(G[b].count(a)>0){
        G[b].erase(a);
        C[a]--;
        if(C[a]==0)bfs(a);
      }
    }
    if(d[b]-1==d[a]){
      if(G[a].count(b)>0){
        G[a].erase(b);
        C[b]--;
        if(C[b]==0)bfs(b);
      }
    }
    printf("%d\n",ans);
  }
}

int main(){
  scanf("%d %d %d",&N,&M,&q);
  for(int i=1;i<=M;i++){
    scanf("%d %d",&ea[i],&eb[i]);
    g[ea[i]].push_back(eb[i]);
    g[eb[i]].push_back(ea[i]);    
  }

  for(int i=0;i<MAX_N;i++)d[i]=INF;
  queue<int> Q;
  Q.push(1);
  d[1]=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    for(int i=0;i<(int)g[pos].size();i++){
      int to=g[pos][i];
      if(d[to]==INF){
        d[to]=d[pos]+1;
        Q.push(to);
      }
    }
  }
  for(int i=1;i<=M;i++){
    int a=ea[i],b=eb[i];
    if(d[a]-1==d[b]){
      G[b].insert(a);
      C[a]++;
    }
    if(d[b]-1==d[a]){
      G[a].insert(b);
      C[b]++;
    }
  }
  C[1]=INF;
  solve();
  return 0;
}

Measured memory_bytes: 23164
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String args[]){
		int in[]=new int[10];
		for(int i=0;i<10;i++)
			in[i]=s.nextInt();
		Arrays.sort(in);
		System.out.println(in[9]);
		System.out.println(in[8]);
		System.out.println(in[7]);
	}
}

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

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    
    G = [[] for i in range(N)]
    ans = [None] * (N-1)
    
    for i in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        
        G[a].append((b, i))
        G[b].append((a, i))
        
    q = [(0, -1)]
    
    visited = [False] * N
    cur = 0
    
    while q and cur < N:
        v, c = q.pop(0)
    
        if visited[v]: continue
        visited[v] = True
        cur += 1
        
        k = 0
        for u, idx in G[v]:
            if visited[u]: continue
            if c == k: k += 1
            
            ans[idx] = k
            q.append((u, k))
            k += 1
            
    print(max(ans)+1)
    for a in ans: print(a+1)
     
if __name__ == '__main__':
    main()        


Measured memory_bytes: 40512
import sys
sys.setrecursionlimit(10**6)

N = int(input())

ki = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    ki[a-1].append([b-1,i])
    ki[b-1].append([a-1,i])

result = [0]*(N-1)
def search(par, ans, own, par_num):
    ans =  max(ans, len(ki[own]))
    i = 1
    for child in ki[own]:
        if child[0] == par:
            continue
        else:
            if i == par_num:
                i += 1
            result[child[1]] = i
            ans = max(search(own, ans, child[0], i),ans)
            i += 1
    return ans

print(search(-1, 0, 0, -1))
for i in result:
    print(i)

Measured memory_bytes: 112412
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n;

int main()
{Tie
	cin>>n;
	ll l=1,r=n,m;
	while(l!=r)
	{
		m=l+r>>1;
		if(m*m<n)
			l=m+1;
		else
			r=m;
	}
	for(int i=sqrt(n);i>0;i--)
		if(n%i==0)
			return cout << to_string(n/i).size()<<'\n',0;
}

Measured memory_bytes: 256
S = input()
N = len(S)+1
l = [0]*N
r = [0]*N
for i in range(N-1):
    if S[i] == '<': l[i+1] = l[i]+1
    if S[N-2-i] == '>': r[N-2-i] = r[N-1-i]+1
ans = 0
for i in range(N): ans += max(l[i],r[i])
print(ans)

Measured memory_bytes: 27324
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    
    int ans = k * (int)Math.pow(k-1,n-1);
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}
	
	public static String solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		return N > M ? "No" : "Yes";
	}
}


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

signed main(){
	int L, R, i, j, ans = 2019;
	scanf("%lld%lld", &L, &R);
	if(R - L <= 2019){
		for(i = L; i <= R; i++){
			for(j = i + 1; j <= R; j++){
				ans = min(ans, (i * j) % 2019);
			}
		}
	}
	else{
		ans = 0;
	}
	printf("%lld\n", ans);
	return 0;
}

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

char a;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string bet   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  cin >> a;
  for(int i=0;i<alpha.size();i++) {
    if(a == alpha.at(i)) {
      cout << 'a' << endl;
    } else if(a == bet.at(i)) {
      cout << 'A' << endl;
    }
  } 
}


Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
struct Scanner {
  std::string pp(const char ch) {
    switch (ch) {
    case ' ':
      return "Space";
    case '\n':
      return "Newline";
    case EOF:
      return "EOF";
    default:
      return std::string(1, ch);
    }
  }
  void readSpace() {
    auto ch = getchar();
    if (ch != ' ') {
      throw std::runtime_error(std::string("want: Space, got: ") + pp(ch));
    }
  }
  void readNewline() {
    auto ch = getchar();
    if (ch != '\n') {
      throw std::runtime_error(std::string("want: Newline, got: ") + pp(ch));
    }
  }
  void readEof() {
    auto ch = getchar();
    if (ch != EOF) {
      throw std::runtime_error(std::string("want: EOF, got: ") + pp(ch));
    }
  }
  std::string readString(size_t minLength, size_t maxLength) {
    std::string ret;
    char ch;
    while (ch = getchar(), ch != ' ' and ch != '\n' and ch != EOF) {
      ret += ch;
    }
    ungetc(ch, stdin);
    if (not(minLength <= ret.size() and ret.size() <= maxLength)) {
      std::ostringstream os;
      os << "length of " << ret << " is not in [" << minLength << ", "
         << maxLength << "]";
      throw std::runtime_error(os.str());
    }
    return ret;
  }
  template <typename T>
  T readInt(const T lb, const T ub) {
    auto ch = getchar();
    if ((not isdigit(ch)) and (ch != '-')) {
      ungetc(ch, stdin);
      throw std::runtime_error(std::string("want: [0-9\\-]+, got: ") + pp(ch));
    }
    T ret = ch == '-' ? 0 : ch - '0';
    int sgn = ch == '-' ? -1 : +1;
    while (isdigit(ch = getchar())) {
      ret = ret * 10 + (ch - '0');
    }
    ungetc(ch, stdin);
    ret *= sgn;
    if (not(lb <= ret and ret <= ub)) {
      std::ostringstream os;
      os << ret << " is not in [" << lb << ", " << ub << "]";
      throw std::runtime_error(os.str());
    }
    return ret;
  }
};

using namespace std;
int main() {
  Scanner sc;
  auto a = sc.readInt<int>(1, 20);
  sc.readSpace();
  auto b = sc.readInt<int>(1, a);
  sc.readSpace();
  auto c = sc.readInt<int>(1, 20);
  sc.readNewline();
  sc.readEof();
  cout << max(0, c - (a - b)) << endl;
  return 0;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int a[30];

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

    int n;
    cin >> n;

    f0(i,n){
        cin >> a[i];
    }

    int ans=0;
    for(int i=1 ; i<n-1 ; i++){
        int pre=a[i-1];
        int val=a[i];
        int nxt=a[i+1];
        if(val<nxt && val>pre){
            ans++;
        }else if(val<pre && val>nxt){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
using P = pair<int,int>;
int n,m,k;
P ord[M];
char in[M];
int main()
{
    while (~scanf("%d %d",&n,&k)) {
        m = 0;
        scanf("%s", in+1);
        REP(i,1,n) {
            int j=i;
            while (j+1<=n && in[j+1]==in[j]) j++;
            ord[++m] = make_pair(in[i]-48, j-i+1);
            i = j;
        }

        int r=0, c0=0, sum=0, ans=0;
        int l=1;
        while (l<=m) {
            r = max(l-1, r);
            while (r+1<=m && c0+(ord[r+1].first==0 ? 1 : 0)<=k) {
                sum += ord[r+1].second;
                c0 += (ord[r+1].first == 0 ? 1 : 0);
                r++;
            }

            ans = max(ans, sum);

            sum -= ord[l].second;
            c0 -= (ord[l].first == 0 ? 1 : 0);
            l++;
        }
        printf("%d\n", ans);

    }
    
    return 0;
}



Measured memory_bytes: 1152
#include<stdio.h>

int max(int,int);

int main(void){
  int dp[1001][1001],W,i,j,n,w[1001],v[1001],t=1,ansv,answ;

  while(scanf("%d",&W),W){
    scanf("%d",&n);
    for(i=0;i<n;i++)
      scanf("%d,%d",&v[i],&w[i]);

    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	dp[i][j]=0;

    for(i=0;i<=n;i++){
      for(j=0;j<=W;j++){
	if(j>=w[i])dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
	else dp[i+1][j]=dp[i][j];
      }
    }
    ansv=0;
    for(i=0;i<=W;i++){
	if(ansv<dp[n][i]){
	  ansv=dp[n][i];
	  answ=i;
	}
    }

    printf("Case %d:\n%d\n%d\n",t++,ansv,answ);
  }
  return 0;
}

int max(int x,int y){
  return x>y?x:y;
}

Measured memory_bytes: 0
N = int(input())
S = input()
moji = {'R', 'G', 'B'}

count = 0
for j in range(1, N-1):
    sj = S[j]
    diff_m = moji - {sj}
    rem_moji = list(diff_m)
    for mi, mj in zip(rem_moji, rem_moji[::-1]):
        ci = S.count(mi, 0, j)
        ck = S.count(mj, j+1, N)
        count += ci * ck

    l = min([j+1, N - j])
    for d in range(1, l):
        si = S[j-d]
        sk = S[j+d]
        if si != sj and sj != sk and sk != si:
            count -= 1

print(count)

Measured memory_bytes: 9228
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanNAndIntSlice(s *bufio.Scanner) (int, []int) {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n, scanIntSlice(s, n)
}

func scanIntSlice(s *bufio.Scanner, n int) []int {
	vals := make([]int, n)
	for i := range vals {
		s.Scan()
		m, _ := strconv.Atoi(s.Text())
		vals[i] = m
	}
	return vals
}

func main() {
	s := wordScanner(100)
	_, h := scanNAndIntSlice(s)

	cur, mv, ans := 0, 0, 0
	for _, hi := range h {
		if hi <= cur {
			mv++
		} else {
			mv = 0
		}
		if mv > ans {
			ans = mv
		}
		cur = hi
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  ll n,d;
  cin >> n >> d;
  int cnt=0;
  REP(i,n) {
    ll x,y;
    cin >> x >> y;
    ll r=x*x+y*y;
    if(r<=d*d) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  int a, ans = 0;
  for(int i = 0; i < N; i++){
    cin >> a;
    if(a >= K)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int K;
  cin >> K;
  int A, B;
  cin >> A >> B;
  int count = 0;
  
  for (int i = A / K; i < (B / K + 1); i++) {
    if (K * i >= A and K * i <= B) {
      cout << "OK";
      count += 1;
      break;
    }
  }
  if (count == 0) {
    cout << "NG";
  }
}

Measured memory_bytes: 3620
#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>
#include <assert.h>
#include <numeric>

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)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();
    ll n, k;
    cin >> n >> k;
    ll res = 0;
    for (ll i = 0; i <= min(n, k); i++)
    {
        res += COM(n, i) * COM(n - 1, n - i - 1) % mod;
        res %= mod;
    }

    cout << res << endl;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[105];
 
int32_t main()
{
    fast;
    int n; cin >> n;
    For(i, 0, n) cin >> a[i];
    sort(a, a+n, greater<int>());
    int res = 0;
    For(i, 0, n) {
        if(i % 2 == 0) res += a[i];
        else res -= a[i];
    }

    cout << res;

    
    
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> Vec;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
static const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    ll len=v.size();
    for(ll i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    ll len=vv.size();
    for(ll i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    ll ans=0;
    cin>>n>>k;
    Vec v(n);
    rep(i,n){
        cin>>v[i];
    }
    rep(i,n){
        REP(j,i,n){
            if(v[i]>v[j]){
                ans += k;
                ans %= MOD;
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(v[i]>v[j]){
                ans += k*(k-1)/2;
                ans %= MOD;
            }
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n,m;
vector< pair<ll,ll> > p;

/* add your algorithm here */

int main() {
  cin >> n >> m;
  rep(i,m) {
    pair<ll, ll> pp;
    cin >> pp.first >> pp.second;
    p.pb(pp);
  }

  sort(
    p.begin(),
    p.end(),
    [](const pair<ll, ll>& x, const pair<ll, ll>& y){return x.second < y.second;}
  );

  ll ans = 0;
  ll x = -1;
  rep(i,m) {
    if (p[i].first >= x) {
      ans++;
      x = p[i].second;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int N, M, K, p[20][1010],res=1010;
string s;
int sum(int L1,int R1,int L2,int R2){
    return  p[L2][R2] + p[L1 - 1][R1 - 1] - p[L1 - 1][R2] - p[L2][R1 - 1] ;
}
void solve(){
	cin>>N>>M>>K;
	rep(i,0,N){
		cin>>s;
		rep(j,0,M)if(s[j]=='1')p[i+1][j+1] = 1;
	}
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i][j - 1]; }
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i - 1][j]; }
	for(int bits = 0 ;bits<(1<<(N-1));bits++){
		if(__builtin_popcount(bits)>=res)continue;//剪枝 7ms ~ 3ms 
		VI cut;for(int i=0;i<N-1;i++)if((bits>>i)&1)cut.pb(i+1);cut.pb(N);	
		int  pcol = 1,ans=sz(cut)-1,ok = 1;
		for(int i=1;i<=M;i++){
			int f=1,prow=1;
			for(int j=0;j<sz(cut);j++){
				if(sum(prow,pcol,cut[j],i)>K){
					f = 0;
					break;
				}
				prow = cut[j]+1;
			}
			if(!f){
				ans++;
				if(ans>=res||pcol==i){//剪枝 3ms ~ 2ms 
					ok = 0;
					break;
				}
				pcol = i;
			}
		}
		if(ok)res = min(res,ans);
	}
	cout<<res;
}
int main() {
	solve();
  	return 0;
}

Measured memory_bytes: 256
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n:u32 = sc.read();
    for i in 1..n+1 {
        if i % 3 == 0 {
            print!(" {}", i);
            continue;
        };
        let mut temp = i;
        while temp > 0 {
            if temp % 10 == 3 {
                print!(" {}", i);
                break
            }
            temp /= 10;
        }
    }
    println!("")
}

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
 
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


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

struct Tree {
  Tree *left;
  Tree *right;
public:
  Tree() : left(0), right(0) {}
};

Tree *ana(string s) {
  int k=0;
  Tree *node = new Tree();
  int i;
  if (s[1] != ',') {
    for (i=1; i<s.length(); i++) {
      if (s[i] == '(') k++;
      if (s[i] == ')') k--;
      if (k == 0) {
        //    cout << s.substr(1,i) << endl;
        node->left = ana(s.substr(1,i));
        break;
      }
    }
  } else
    i=0;
  if (s.length()-i-3) {
    // cout << " " << s.substr(i+2, s.length()-i-3) << endl;
    node->right = ana(s.substr(i+2, s.length()-i-3));
  }
  return node;
}

Tree *inter(Tree *t1, Tree *t2) {
  Tree *node = new Tree();
  if (t1->left && t2->left) {
    node->left = inter(t1->left, t2->left);
  }
  if (t1->right && t2->right) {
    node->right = inter(t1->right, t2->right);
  }
  return node;
}

Tree *unit(Tree *t1, Tree *t2) {
  Tree *node = new Tree();
  if (t1 && t2) {
    if (t1->left || t2->left) {
      node->left = unit(t1->left, t2->left);
    }
    if (t1->right || t2->right) {
      node->right = unit(t1->right, t2->right);
    }
  }
  if (t1 == NULL && t2) {
    if (t2->left)
      node->left = unit(NULL, t2->left);
    if (t2->right)
      node->right = unit(NULL, t2->right);
  }
  if (t1 && t2 == NULL) {
    if (t1->left)
      node->left = unit(t1->left, NULL);
    if (t1->right)
      node->right = unit(t1->right, NULL);
  }
  return node;
}

string strTree(Tree *node) {
  string s = "(";
  if (node->left)
    s += strTree(node->left);
  s += ",";
  if (node->right)
    s += strTree(node->right);
  s+= ")";
  return s;
}

int main() {
  char c;
  while(cin >> c) {
    string a, b;
    cin >> a >> b;

    Tree *root1 = ana(a);
    Tree *root2 = ana(b);
    if (c == 'i') {
      cout << strTree(inter(root1,root2)) << endl;
    } else {
      cout << strTree(unit(root1,root2)) << endl;
    }

  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
    int R[MAX],n;

    cin>>n;
    for (int i=0;i<n;i++){
        cin>>R[i];
    } 
    int maxv=-2000000000;
    int minv=R[0];

    for (int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout<<maxv<<endl;

    return 0;
}


Measured memory_bytes: 3860
(defun compute(c k lst)
  (labels ((rec (tt cc lst acc)
                (cond ((null lst) acc)
                      ((zerop cc) (rec (car lst) (1- c) (cdr lst) (1+ acc)))
                      ((<= tt (+ k (car lst))) (rec tt (1- cc) (cdr lst) acc))
                      (t (rec (car lst) (1- c) (cdr lst) (1+ acc))))))
    (rec (car lst) (1- c) (cdr lst) 1)))
(defun test()
  (format t "~A~%" (compute 2 5 (sort '(1 2 3 7 7 7 7 7 7 7 7 7 7 12) #'>)))
  (format t "~A~%" (compute 3 5 (sort '(1 2 3 7 7 7 7 7 7 7 7 7 7 12) #'>)))
  (format t "~A~%" (compute 3 5 (sort '(1 2 3 6 6 6 6 6 6 6 6 6 6 12) #'>)))
  (format t "~A~%" (compute 3 5 (sort '(1 2 3 6 6 6 6 6 6 12) #'>)))
  (format t "~A~%" (compute 3 5 (sort '(1 2 3 6 12) #'>)))
  (format t "~A~%" (compute 3 3 (sort '(7 6 2 8 10 6) #'>))))
;(test)

(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(cons line acc)))))
	(rec line nil)))
(defun readline (callback)
  (labels ((rec (i)
				(let ((line (read-line nil nil)))
				  (when (not (zerop (length line)))
					(funcall callback line i)
					(rec (1+ i))
					)
				  )
				))
	(rec 0)))

(let ((n 0)
      (c 0)
      (k 0)
      (lst nil))
  (defun start()
    (readline (lambda(line i)
                (cond ((zerop i) (let ((r (splitat #\space line)))
                                   (setf n (parse-integer (nth 2 r)))
                                   (setf c (parse-integer (nth 1 r)))
                                   (setf k (parse-integer (nth 0 r)))))
                      (t (setf lst (cons (parse-integer line) lst))))))
    (format t "~A~%" (compute c k (sort lst #'>)))))
(start)

Measured memory_bytes: 43368
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<int> a(N);rep(i,N)cin >> a[i];
    int xo = 0;
    rep(i,N)xo = xo ^ a[i];
    vector<int> ans(N);

    rep(i,N)ans[i] = xo ^ a[i];

    rep(i,N)cout << ans[i] << endl;  
}

Measured memory_bytes: 4624
num = int(input())
n = num
num -= 1
result = 1
for i in range(2, int(pow(num, 0.5))+1):
    c = 0
    while num%i==0:
        num //= i
        c += 1
    if c>0:
        result *= c+1

if num > 1:
    result *= 2
result -= 1

r = set()
for i in range(2, int(pow(n, 0.5))+1):
    num = n
    if num%i==0:
        r.add(i)
        r.add(n//i)
r.add(n)
for i in r:
    num = n
    while num%i==0:
        num //= i
    if num%i == 1:
        result += 1

print(result)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s)
        a--;
    else
        b--;
    cout << a << " " << b << endl;

    return 0;
}


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

using namespace std;



int main(){
  int N; cin >> N;
  vector<vector<int>> to(N); vector<vector<int>> cost(N);
  
  for(int i = 1; i < N; i++){
    int a,b,w; cin >> a >> b >> w; a--; b--;
    to[a].push_back(b); cost[a].push_back(w);
    to[b].push_back(a); cost[b].push_back(w);}
  
  vector<int> ans(N,-1); queue<int> q;
  
  ans[0] = 0;
  q.push(0);
  
  while(!q.empty()){
    int v = q.front(); q.pop();
    
    for(int i = 0; i < to[v].size(); i++){
      int u = to[v][i];
      int x = cost[v][i];
      if(ans[u] != -1){ continue;}
      ans[u] = ( ans[v] + x ) % 2;
      q.push(u);} }
  
  for(int i = 0; i < ans.size(); i++){ cout << ans[i] << endl;}
  
  return 0;}

Measured memory_bytes: 11904
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

static int count = 0;

class Vtx {
public:
	int id;
	int c = 0;
	int v = 0;
	vector<int> vtxs;
};

int getNext(int id,Vtx vtxs[]){
	vector<int> v=vtxs[id].vtxs;
	for(int i=0;i<v.size();i++){
		if(vtxs[v[i]-1].v == 0){
			return v[i];
		}
	}
	return -1;
}

void dfs_(int id,Vtx vtxs[]){
	
	stack<int> stack;
	stack.push(vtxs[id].id);
	int i=0;
	while(!stack.empty()){
		id=stack.top();
		id--;
		if(vtxs[id].v==0){
			vtxs[id].v=++count;
		}
		int nId=getNext(id,vtxs);
		if(nId==-1){
			vtxs[id].c=++count;
			stack.pop();
		}else{
			stack.push(nId);
		}
	}
}

void dfs(int n, Vtx vtxs[]){
	for(int i=0;i<n;i++){
		if(vtxs[i].v==0){
			dfs_(i,vtxs);
		}
	}
}

int main(){
	int n;
	cin >> n;
	Vtx vtxs[n];
	for (int i=0;i<n;i++){
		int id, k;
		cin >> id >> k;
		vtxs[i].id = id;
		for(int j=0;j<k;j++){
			int v;
			cin >> v;
			vtxs[i].vtxs.push_back(v);
		}
	}
	
	dfs(n,vtxs);
	
	for(int i=0;i<n;i++){
		Vtx v = vtxs[i];
		cout << v.id << " " << v.v;
		cout << " " << v.c << endl;
	}
	return 0;
}



Measured memory_bytes: 3156
//Have a nice day
#include<bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;

const int inf=2147483647;
const LL INF=1e18;

template <typename T> inline T read()
{
	T sum=0, fl=1; char ch=getchar();
	for(; !isdigit(ch); ch=getchar()) if(ch=='-') fl=-1;
	for(; isdigit(ch); ch=getchar()) sum=(sum<<3)+(sum<<1)+ch-'0';
	return sum*fl;
}

const int maxn=1e5+5;
int k; deque<int>Q;
int dis[maxn];

inline int get_sum(int x, int ans=0)
{
	while(x) ans+=x%10, x/=10;
	return ans;
}

void Solve()
{
	k=read<int>();
	for(int i=1; i<k; ++i) dis[i]=get_sum(i), Q.push_front(i);	
	dis[0]=get_sum(k); Q.push_front(0);
	while(!Q.empty())
	{
		int p=Q.front(); Q.pop_front();
		if(dis[(p+1)%k] > dis[p]+1) 
		{
			dis[(p+1)%k]=dis[p]+1;
			Q.push_back((p+1)%k);
		}
		if(dis[(p*10)%k] > dis[p])
		{
			dis[(p*10)%k]=dis[p];
			Q.push_front((p*10)%k);
		}
	}
	printf("%d\n", dis[0]);
}

int main()
{

    Solve();

    return 0;
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int a, b, c; cin >> a >> b >> c;
    if(a == b && b == c) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

int main() {
  int n;
  cin >>n;
  string s;
  cin>>s;
  int x=0;
  int saidai=0;
  for(int i=0;i<n;i++){
    if(s[i]=='I')x++;
    else x--;
    saidai=max(saidai,x);
  }
  cout<<saidai<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
int a[101010];
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i)
		scanf("%d",&a[i]);
	for (int i=2;i<m;++i)
	if (a[i]%2==1)
	{
		if (a[1]%2==0)
			swap(a[1],a[i]);
		else if (a[m]%2==0)
			swap(a[i],a[m]);
		else
		{
			printf("Impossible\n");
			return 0;
		}
	}
	printf("%d",a[1]);
	for (int i=2;i<=m;++i)
		printf(" %d",a[i]);
	printf("\n");
	if (m==1)
	{
		if (a[1]==1)
		{
			printf("1\n1\n");
			return 0;
		}
		printf("2\n");
		printf("%d %d\n",1,a[1]-1);
		return 0;
	}
	if (a[m]==1 && m!=1) printf("%d\n",m-1);
	else printf("%d\n",m);
	
	if (m!=1) printf("%d",a[1]+1);
	else printf("%d",a[1]);
	for (int i=2;i<m;++i)
		printf(" %d",a[i]);
	if (m!=1 && a[m]!=1) printf(" %d\n",a[m]-1);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IL inline
#define _ 1524288
#define ll long long
using namespace std;

IL ll gi(){
	ll data=0,fu=1; char ch=0; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')fu=-1,ch=getchar();
	while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar(); return data*fu;
}

int n,H,D,f[_],pre[_],g[_],Ans;
#define mod 1000000007
IL int Pow(int ts,int js){
	int al=1;
	while(js){
		if(js&1)al=1ll*al*ts%mod;
		ts=1ll*ts*ts%mod;
		js>>=1;
	}return al;
}

int main(){
	n=gi(); H=gi(); D=gi();
	int ret=0,fc=1;
	for(int i=1;i<=n;++i){
		fc=1ll*i*fc%mod;
		ret=(ret+fc)%mod; 
	}
	f[0]=fc; pre[0]=f[0];
	for(int i=1;i<=H;++i){
		f[i]=(pre[i-1]-((i-D-1>=0)?pre[i-D-1]:0)+mod)%mod;
		f[i]=1ll*ret*f[i]%mod;
		pre[i]=(pre[i-1]+f[i])%mod;
	}
	cout<<1ll*f[H]*Pow(ret,mod-2)%mod<<endl;
	return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int n, m, k;
vector<int> g[100000];
int f[100000];
int fb[100000];
int color[100000];
int group[100000];

void dfs(int i, int col) {
    color[i] = col;
    for (auto t : g[i]) {
        if (color[t] == 0) {
            dfs(t, col);
        }
    }
}

int main() {
    int a, b;
    cin >> n >> m >> k;
    while (m--) {
        cin >> a >> b;
        a--; b--;
        f[a]++;
        f[b]++;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i = 0; i < n; ++i) {
        sort(g[i].begin(), g[i].end());
    }
    int col = 1;
    for (int i = 0; i < n; ++i) {
        if (color[i] == 0) {
            dfs(i, col++);
        }
    }
    while (k--) {
        cin >> a >> b;
        a--; b--;
        if (color[a] == color[b] && binary_search(g[a].begin(), g[a].end(), b) == false) {
            fb[a]++;
            fb[b]++;
        }
    }
    for (int i = 0; i < n; ++i) {
        group[color[i] - 1]++;
    }
    for (int i = 0; i < n; ++i) {
        cout << max(0, group[color[i] - 1] - f[i] - fb[i] - 1);
        if (i < n - 1)
            cout << " ";
        // cout << group[color[i] - 1] << " " << f[i] << " " << fb[i] << endl;
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 7936
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 998244353;

int main() {
	int n;
	cin >> n;
	vi d(n);
	vi s(n);
	int m = -1;
	rep(i, n) {
		cin >> d[i];
		s[d[i]]++;
		s[d[i]] %= MOD;
		if (d[i] > m) m = d[i];
	}
	ll ans = (d[0] == 0 && s[0] == 1) ? 1 : 0;
	for (int i = 1; i <= m; i++) {
		ll p = 1;
		rep(j, s[i]) {
			p *= s[i - 1] % MOD;
			p %= MOD;
		}
		ans *= p % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	/*rep(i, m + 1) cout << s[i] << " ";*/
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int i,j,k,time[2][3],work[3];
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			for(k=0;k<3;k++){
				work[k]=0;
				scanf("%d",&time[j][k]);
			}
		}
		for(j=0;j<3;j++){
		work[2-j]+=time[1][2-j]-time[0][2-j];
		if(work[2-j]<0){
			work[2-j]+=60;
			work[1-j]-=1;
		}
		}
		printf("%d %d %d\n",work[0],work[1],work[2]);
	}
	return 0;
}

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

typedef long long LL;
const int maxn = 100010;
const LL INF = 100000000000000LL;
const LL mod = 998244353;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define For(i,a,b) for(int i=a;i<=b;++i)

int n;
int a[maxn];

void solve() {
    for(int i = 1;i <= n;i++) {
        scanf("%d", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    cout << a[n] - a[1] << endl;
}

int main() {
	int t = 1;
    while(~scanf("%d", &n)) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,j,k,n,f1,f2,f3,h1,h2,h3;
	int out,hit,hran,v;
	char s[8];
	cin>>n;
	for(i=0;i<n;i++) {
		out=hit=hran=v=f1=f2=f3=0;
		while(1) {
			cin>>s;
			if(strcmp("HIT",s)==0) {
				h1=h2=h3=0;
				if(f1==0) f1=1,h1=1;
				if(f2==0&&f1==1&&h1==0) f2=1,h2=1;
				if(f3==0&&f2==1&&h2==0) f3=1,h3=1;
				if(f3==1&&h3==0) v++;
			}
			if(strcmp("HOMERUN",s)==0) {
				v+=(f1+f2+f3+1);
				f1=f2=f3=0;
			}
			if(strcmp("OUT",s)==0) {
				out++;
				if(out==3) {out=0;break;}
			}
		}
		cout<<v<<endl;
	}
}
		

Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main(){
  string Number;
  while(1){
    cin >> Number;
    if(atoi(Number.c_str()) == 0)break; 

    long Len=Number.size();
    int N[11][Len];
    string str;
    int Ans=0;
    
    for(int m=0;m<Len;++m){
      for(int n=0;n<11;++n){
	N[n][m]=0;
      }
    }
    str=Number[0];
    if(atoi(str.c_str())!=0)N[atoi(str.c_str())][0]=1;
    for(int n=1;n<Len;++n){
      str=Number[n];
      int k=atoi(str.c_str());
      if(k!=0)N[k][n]+=1;
      for(int m=0;m<11;++m){
	if(N[m][n-1]!=0){
	  N[(m*10+k)%11][n]+=N[m][n-1];
	}
      }
      Ans+=N[0][n];
    }
    cout << Ans << endl;
  }
}

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

int N, a, ans, K;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a == K + 1) K++;
        else ans++;
    }
    
    cout << (K ? ans : -1) << endl;
}

Measured memory_bytes: 256
N = int(input())
list = input().split()
ans = 0
is_dev = True
while True:
  for i in range(N):
    list[i] = int(list[i])
    if list[i] % 2 == 1:
      is_dev = False
      break
    list[i] = int(list[i]) / 2

  if not is_dev:
    break
  else:
    ans += 1

print(ans)

Measured memory_bytes: 3060
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def prime_factorization(n):
    res = []
    for i in range(2, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append([i, ex])
    if n != 1:
        res.append([n, 1])
    return res


a, b = map(int, input().split())
g = gcd(a, b)
res = prime_factorization(g)
print(len(res) + 1)


Measured memory_bytes: 3064