akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
   int main()
   {
       int n,k,i;
       string s;
       cin>>n>>k;
       ll res=0,r,s1,p;
       cin>>r>>s1>>p;
       cin>>s;
       for(i=0;i<n;i++)
       {
           if(s[i]=='r')
           s[i]='R';
           else if(s[i]=='p')
           s[i]='P';
           else
            s[i]='S';
       }
       char ans[n];
       for(i=0;i<k;i++)
       {
           if(s[i]=='R')
           {ans[i]='P';
           res+=p;
           }
           else if(s[i]=='P')
           {ans[i]='S';
           res+=s1;}
           else if(s[i]=='S')
           {ans[i]='R';
           res+=r;
           }
       }
       //cout<<res<<e;
       for(i=k;i<n;i++)
       {
           if(s[i]=='R')
           {
               if(ans[i-k]=='P')
           {
               if(i+k<n)
               {
                   if(s[i+k]=='P')
                   ans[i]='R';
                   else
                    ans[i]='S';
               }
               else
               {ans[i]='S';
               }
           }
           else{
               ans[i]='P';
           res+=p;
           }
           }

                      if(s[i]=='P')
           {
               if(ans[i-k]=='S')
           {
               if(i+k<n)
               {
                   if(s[i+k]=='S')
                   ans[i]='P';
                   else
                    ans[i]='R';
               }
               else
               {ans[i]='R';
               }
           }
           else{
               ans[i]='S';
           res+=s1;
           }
           }

                      if(s[i]=='S')
           {
               if(ans[i-k]=='R')
           {
               if(i+k<n)
               {
                   if(s[i+k]=='R')
                   ans[i]='S';
                   else
                    ans[i]='P';
               }
               else
               {ans[i]='P';
               }
           }
           else{
               ans[i]='R';
           res+=r;
           }
       }

   }
    cout<<res<<e;
   }


Measured memory_bytes: 512
fun mCnr(n: Long, r: Long, m: Long): Long {
    val nc = (n - r + 1).until(n + 1).fold(1L) { a, b ->
        (a * (b)) % m
    }
    val rc = 0.until(r).fold(1L) { a, b ->
        (a * (r - b)) % m
    }
    return (nc * mPow(rc, m - 2, m)) % m
}

fun mPow(n: Long, ex: Long, m: Long): Long {
    var x = n
    var remain = ex
    var result = 1L
    while (remain > 0) {
        if (remain % 2L == 1L) {
            result = (result * x) % m
        }
        x = (x * x) % m
        remain /= 2
    }
    return result
}


fun main(args: Array<String>) {
    val m = 1e9.toLong() + 7L
    val (x, y) = readLine()?.split(" ")?.map(String::toInt) ?: return
    if (y > 2 * x || y < x / 2) {
        println("0")
        return
    }
    if ((x + y) % 3 != 0) {
        println("0")
        return
    }
    val c = (x + y) / 3
    val a = (c - Math.abs(y - x)) / 2
    val b = c - a
    val count = mCnr(c.toLong(), Math.max(a, b).toLong(), m)
    
    println(count.toString())
}



Measured memory_bytes: 40712
import std;

// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}
T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}
void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;}
void scan(TList...)(ref TList Args){auto line = readln.split;
foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}}
void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length);
static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}}
alias sread=()=>readln.chomp();enum MOD =10^^9+7;
alias PQueue(T,alias less="a<b") = BinaryHeap!(Array!T,less);
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto b = new bool[](N);
    foreach (_; 0 .. K)
    {
        long d = lread();
        auto A = aryread();
        foreach (a; A)
        {
            b[a - 1] = true;
        }
    }
    b.map!"a?0:1"().sum().writeln();
}


Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(b,n) {
    int r = b+1;
    rep(a,b) {
      int ab = L[a]+L[b];
      while (r < n && L[r] < ab) ++r;
      int l = b+1;
      ans += max(0,r-l);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n[0])]

c = n[0]
d = n[1]
e = [1, -1]
f = []
for i in e:
    for j in e:
        for k in e:
         f.append([i,j,k])

ans = []
for i in f:
    g = []
    for j in a:
        g.append(sum([j[k]*i[k] for k in range(3)]))
    g.sort()
    g.reverse()
    ans.append(sum(g[:d]))

print(max(ans))

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

int main(){
  int K,a,b;
  int g=0;
  cin>>K;
  cin>>a>>b;
  for(int i=a;i<b+1;i++){
    if(i%K==0){
      g=1;
      break;
    }else{
      g=0;
    }
  }
  if(g==1){
    cout<<"OK"<<endl;
  }else{
    cout<<"NG"<<endl;
  }
}
  

Measured memory_bytes: 3636
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
m0 = 0
mh = 0
ans = 0
for i in range(1,N+1):
    d = i%K
    if d == 0:
        m0+=1
    if d == K//2 and K % 2 == 0:
        mh +=1
print(m0**3 + mh**3)

Measured memory_bytes: 38896
#include<stdio.h>

int main(){
  int n,a[100],i,j,tmp,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);

  for(i=0;i<n;i++)
    for(j=0;j<n-1;j++)
      if(a[j]>a[j+1]){
	tmp=a[j];
	a[j]=a[j+1];
	a[j+1]=tmp;
	sum++;
      }

  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",sum);

  return 0;
}

Measured memory_bytes: 604
fn main() {

  const MOD: i64 = 1000000000 + 7;

  let mut s = String::new();
  
  std::io::stdin().read_line(&mut s).ok();
  let _n: i32 = s.trim().parse().ok().unwrap();

  s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  let v: Vec<i64> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();

  let mut memo: Vec<i64> = Vec::new();
  memo.push(0);

  for i in 0..(v.len()) {
    memo.push(memo[i] + v[i])
  }

  let mut ans: i64 = 0;

  for i in 0..v.len() {
    let sum = (memo[v.len()] - memo[i + 1]) % MOD;


    ans = (ans + v[i] * sum) % MOD;
  }

  println!("{}", ans);

}



Measured memory_bytes: 7352
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 100010;
const int MOD = (int) 1e9 + 7;

int n;
ll a, b;
ll h[Maxn];

bool C(ll k) {
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        ll rest = h[i] - k * b;
        if (rest > 0) cnt += (rest + a - b - 1) / (a - b);
    }
    return cnt <= k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    ll ok = (ll) 1e10, ng = 0, mid;
    while (ok - ng > 1) {
        mid = (ok + ng) / 2;
        if (C(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for (i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while (head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0) {
            enqueue(u);
        } else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    
    return 0;
}


Measured memory_bytes: 11912
import std.algorithm;

void main()
{
    import std.stdio, std.conv, std.string;
    readln.chomp.to!int.solve.writeln;
}

int solve(int x)
{
    auto result = int.max;
    foreach (i; 0..x+1)
        result = min(result, simulate(x, i));
    return result;
}

int simulate(int x, int i)
{
    return i.withdraw(6) + (x - i).withdraw(9);
}

int withdraw(int x, int radix)
{
    int result;
    while (x)
    {
        result += x % radix;
        x /= radix;
    }
    return result;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#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 LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	
	long long int n;
	long long int k;

	cin >> n >> k;
	vector<long long int>h(n + 1);
	vector<long long int>cost(n + 1, LLINF);
	FOR(i, 1, n) {
		cin >> h[i];
	}

	cost[1] = 0;
	FOR(i, 1, n) {
		FOR(j, 1, k) {
			if (i + j > n) {
				break;
			}
			cost[i + j] = min(cost[i + j], cost[i] + abs(h[i] - h[i + j]));
		}
	}

	cout << cost[n] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
 
int main(){
    int N; cin >> N; 
    ll SUM = 0;
    set<int> ST;
    for(int i = 1; i <= N; i++){
        SUM += i;
        ST.insert(i);
        if(SUM <= N) ;//ST.insert(i);
        else break;
    }
    int sub = SUM - N;
    if(sub != 0) ST.erase(sub);
    for(auto st : ST) cout << st << endl;
    
 
}

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


def get_input() -> tuple:
    """標準入力の取得

    Returns:
        tuple -- 標準入力
    """
    A, B, C, K = list(map(int, input().split()))
    return A, B, C, K


def main(A: int, B: int, C: int, K: int) -> None:
    """求解処理.
    Kの値で場合分けする.

    Arguments:
        A {int} -- 整数
        B {int} -- 整数
        C {int} -- 整数
        K {int} -- 整数
    """
    result = int()
    if K <= A:
        result = K
    elif A < K and K <= A + B:
        result = A
    elif A + B < K and K <= A + B + C:
        result = 2*A + B - K

    # 結果出力
    print(result)


if __name__ == "__main__":
    A, B, C, K = get_input()
    main(A, B, C, K)


Measured memory_bytes: 9192
#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 inf 1e18
#define mod 1005
#define ll unsigned long long int
void solve()
{
//	freopen("input1.txt", "r", stdin); 
	int n;
	cin>>n;
	vector<ll> vect(n);
	REP(i, n)
	{
		cin>>vect[i];
	}
	int zeros = 0;
	REP(i, n)
	{
		if(vect[i]==0)
			zeros++;
	}
	if(zeros>0)
	{
		cout<<0<<"\n";
		return;
	}
	ll prod = 1;
	REP(i, n)
	{
		if(vect[i]<=1000000000000000000/prod)
		{
			prod*=vect[i];
		}
		else
		{
			cout<<"-1\n";
			return;
		}
	}
	cout<<prod<<"\n";
}
int main()
{
	int t = 1;
//	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 4060
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

// Union-Find
class UnionFind {
    private :
        std::vector<int> par;
    public :
        UnionFind(int n) {
            par.resize(n);
            for (int i=0; i<n; i++) par.at(i) = i;
        }
        void unite(int x, int y) {
            int xPar = find(x);
            int yPar = find(y);
            if (xPar == yPar) return;

            par.at(xPar) = yPar;
        }
        int find(int x) {
            if (par.at(x) == x) return x;
            else return par.at(x) = find(par.at(x));
        }
        bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> lan(m);
    for (int i=0; i<n; i++) {
        int k;
        cin >> k;
        for (int j=0; j<k; j++) {
            int l;
            cin >> l;
            lan.at(l-1).push_back(i);
        }
    }

    UnionFind uf(n);
    for (int i=0; i<m; i++) {
        for (int j=1; j<(int)lan.at(i).size(); j++) {
            uf.unite(lan.at(i).at(j), lan.at(i).at(j-1));
        }
    }

    for (int i=1; i<n; i++) {
        if (uf.find(i) != uf.find(i-1)) {
            cout << "NO" << '\n';
            return;
        }
    }
    cout << "YES" << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {

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

		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		String[] data = input.split(" ");
		int a = Integer.parseInt(data[0]);
		int b = Integer.parseInt(data[1]);
		int area = 0;
		int length = 0;

		if (a >= 1 && b <= 100) {
			area = a * b;
			length = (a + b) * 2;
			System.out.println(area + " " + length);

		}

	}

}



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

#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

void comb(int idx, int rem, int sum, V& data, V& v) {
	if (rem == 0) {
		v.push_back(sum);
		return;
	}
	if (idx == data.size()) return;
	comb(idx + 1, rem, sum, data, v);
	comb(idx + 1, rem - 1, sum + data[idx], data, v);
}

signed main() {
	int n, k, l, r; cin >> n >> k >> l >> r;
	V as(n); input(as);
	V x; x.insert(x.begin(), as.begin(), as.begin() + as.size() / 2);
	V y; y.insert(y.begin(), as.begin() + as.size() / 2, as.end());
	int ans = 0;
	rep(p, 0, k + 1) {
		int q = k - p;
		V ps, qs;
		comb(0, p, 0, x, ps);
		comb(0, q, 0, y, qs);
		sort(all(ps));
		sort(all(qs));
		for (int s : ps) {
			int t1 = upper_bound(all(qs), r - s) - qs.begin();
			int t2 = lower_bound(all(qs), r - s) - qs.begin();
			ans += upper_bound(all(qs), r - s) - lower_bound(all(qs), l - s);
		}
	}
	cout << ans << endl;
	//system("pause");
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

ll gcd( ll a, ll b ){
    if( a < b ) swap(a,b);
    ll t = a;

    while( a%b ){
        t = a;
        a = b;
        b = t%b;
    }

    return b;
}

ll lcm( ll a, ll b ){
    return a/gcd(a,b)*b;
}

int main() {

    int N;
    ll M;
    Scd(N);
    Scll(M);
    vector<ll> a(N);
    Rep(i,N) Scll(a[i]);

    int ans = 0;
    ll e = 1;

    Rep(i,N){
        e = lcm(a[i],e);
        if( e/2 > M ) {
            ans = -1;
            break;
        }
    }

    Rep(i,N){
        if( (e/a[i])%2 != 1 ) ans = -1;
    }

    if( ans == -1 ){
        printf ("%d\n", 0);
        return 0;
    }

    printf ("%lld\n", (M+e/2)/e);


    return 0;
}



Measured memory_bytes: 1024
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int t = n, ans = n, cnt = 0;
    for(int i=0; i<=n; i++){      // checking all possibility for making n using 6 and 9
        t = i;
        cnt = 0;
        while(t){           //each iteration gives index of next 9 power starting with 0
            cnt += t%6;
            t /= 6;
        }
        t = n-i;
        while(t){
            cnt += t%9;
            t /= 9;
        }
        ans = min(ans, cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;


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

	ll result;

	if(N%2==1){
		result = N*2;
	}else{
		result = N;
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int k; cin >> k;
	string s; cin >> s;
	if(s.size() > k) {
		cout << s.substr(0, k) + "..." << '\n';
	} else {
		cout << s << '\n';
	}
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int Maxn=2e5;

char s[Maxn+5];

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%s",s+1);
	int len=strlen(s+1);
	long long ans=0;
	int t=1;
	for(int i=1;i<=len;i++) {
		if(s[i]=='W') {
			ans+=(i-t);
			t++;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long ll;

int N;
int A[100],B[100];
int mem[100][100];
int fid[100][100];
ll ans = 0;

int unit(int s,int t)
{
    if(s == 0)return mem[s][t] = -1;
    if(t == 0)return mem[s][t] = 1;
    if(s == t)return mem[s][t] = 0;
    if(mem[s][t] != -2)return mem[s][t];
    if((s - 1) / 2 < t)return mem[s][t] = -1;
    for(int i = 1; i <= 50; i++)
    {
        if(unit(s % i,t) != -1)
        {
            return mem[s][t] = i;
        }
    }
    return -2;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    for(int i = 0; i < N; i++)scanf("%d",B + i);

    for(int i = 0; i < N; i++)
    {
        if(A[i] == B[i])continue;
        if(B[i] > (A[i] - 1) / 2)
        {
            printf("-1\n");
            return 0;
        }
    }

    for(int i = 0; i <= 50; i++)for(int j = 0; j <= 50; j++)mem[i][j] = -2;
    for(int i = 1; i <= 50; i++)for(int j = 0; j <= 50; j++)unit(i,j);

    for(int i = 0; i < N; i++)fid[i][A[i]] = 1;
    while(1)
    {
        int res = 0;
        for(int i = 0; i < N; i++)
        {
            int rres = 100;
            if(fid[i][B[i]] == 1)continue;
            for(int j = 0; j <= 50; j++)
            {
                if(fid[i][j] == 0)continue;
                if(mem[j][B[i]] != -1)rres = min(rres,mem[j][B[i]]);
            }
            res = max(res,rres);
        }
        if(res == 0)break;
        ans += (1LL << res);
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j <= 50; j++)
            {
                if(fid[i][j] == 0)continue;
                fid[i][j % res] = 1;
            }
        }
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
/* 
* code by: imasnegi
**/

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

#define ll long long
#define nl "\n"
#define spc " "
#define fr(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define deb(a) cout << #a << " " << a << nl;

template<typename T>
void printArray(vector<T>& v) {
	for(auto& i : v)
		cout << i << spc;
	cout << nl;
}
const int MaxN = 2e5 + 5;
const int MOD = 1e9 + 7;

int n;
ll a[MaxN];
void solve_cases() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	ll sum = 0;
	for(int i = 1; i < n; i++) {
		if(a[i] < a[i-1]) {
			sum += a[i - 1] - a[i];
			a[i] = a[i-1];
		}
	}
	
	cout << sum;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cout << setprecision(10) << fixed;
	int t = 1;
	//cin >> t;
	FOR(tt, 1, t) {
		//cout << "Case #" << tt << ": ";
		solve_cases();
	}
}

Measured memory_bytes: 5220
s = input()
if s[0]==s[1]==s[2]==s[3]:
  print('No')
elif s[0]==s[1]:
  if s[2]==s[3]:
    print('Yes')
  else:
    print('No')
elif s[0]==s[2]:
  if s[1]==s[3]:
    print('Yes')
  else:
    print('No')
elif s[0]==s[3]:
  if s[1]==s[2]:
    print('Yes')
  else:
    print('No')
elif s[1]==s[2]:
  if s[0]==s[3]:
    print('Yes')
  else:
    print('No')
elif s[2]==s[3]:
  if s[0]==s[1]:
    print('Yes')
  else:
    print('No')
elif s[1]==s[3]:
  if s[0]==s[2]:
    print('Yes')
  else:
    print('No')
if s[0] != s[1] and s[1]!=s[3] and s[0]!=s[2] and s[0]!=s[3] and s[1]!=s[2] and s[2] != s[3]:
  print('No')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    Int ans = 0;
    unordered_map<string, Int> pairs;

    string in;
    for (int i = 0; i < n; i++) {
        cin >> in;
        sort(in.begin(), in.end());
        if (!pairs.insert({in, 1}).second) {
            pairs[in]++;
        }
    }

    for (auto e : pairs) {
        ans += e.second * (e.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10660
#include<queue>
#include<iostream>
#include<string>
using namespace std;
int main() {
  priority_queue<int> Q;
  string str;
  while(cin >> str){
    if (str == "insert"){
      int x;
      cin >> x;
      Q.push(x);
    }
    else if (str == "extract"){
      cout << Q.top() << endl;
      Q.pop();
    }
  }
}

Measured memory_bytes: 5976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	int D, X; cin >> D >> X;
	vector<int> A(N, 0);
	rep (i, N) cin >> A[i];
	
	int res = X;
	rep (i, N){
		res += D / A[i]  + (int)(D % A[i] != 0);
//		cerr << res << endl;
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;

#define vi vector<int>
#define vii vector<vector<int>>

void testcase()
{
    string s1, s2;
    cin >> s1 >> s2;
    int change = INT_MAX,x = 0;
    for (int i = 0; i + s2.length() - 1 < s1.length(); i++)
    {
        x = 0;
        for (int j = 0;j < s2.length(); j++)
        {
            if(s1[i + j] != s2[j]){
                // cout << s1[i + j] << " " << s2[j ] << "\n";
                x++;
            } 
        }
        change = min(change,x);
    }
    cout << change << " ";
}

int main()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    testcase();
    return 0;
}


Measured memory_bytes: 3628
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  landscape <- getLine :: IO String
  let ans = solve' landscape :: [Int]
      ansShow = (length ans):ans
  print . sum $ ans
  putStrLn . unwords . map show $ ansShow

solve' :: String -> [Int]
solve' ls = go [] [(0, 0)] $ zip [0..] ls
  where
    go :: [Int] -> [(Int, Int)] -> [(Int, Char)] -> [Int]
    go _ ponds [] = tail . reverse . map snd $ ponds
    go [] ponds ((i, l):ls)
      | l == '\\' = go [i] ponds ls
      | otherwise = go [] ponds ls
    go stk ponds ((i, l):ls)
      | l == '\\' = go (i:stk) ponds ls
      | l == '_' = go stk ponds ls
      | l == '/' = go tailStk newPonds ls
      where
        (s:tailStk) = stk
        ((x, prevArea):tailPonds) = ponds
        areaIncrement = i - s
        newPonds = unitePonds (s, areaIncrement) ponds

unitePonds :: (Int, Int) -> [(Int, Int)] -> [(Int, Int)]
unitePonds (x, ax) ponds@((y, ay):tailPonds) = 
  if x < y 
  then unitePonds (x, ax + ay) tailPonds
  else (x, ax):ponds



Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
#define rep(i ,a, n) for (long long int i=a;i<=n;i++)
#define pb  push_back
#define mp make_pair
#define fp first
#define sp second
#define be(v) v.begin(),v.end()
typedef long long ll;
typedef vector<ll> vi ;
typedef vector<pair<ll , ll > >  vpi ;
const int ma1=3e5+5;
string no="NO",yes="YES";
#define MOD 1000000007
int max_char=26;
ll max1=1e15;
vector<ll> v[100005];
bool visited[100005];
ll dp[100005];



int main()
{
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    while(t--)
    {
         ll n,m;
         cin>>n>>m;
         char a[n][m];
         ll dp[n+1][m+1]={0};
         for(int i=0;i<n;i++)
         {
             for(int j=0;j<m;j++)
                cin>>a[i][j];
         }
        dp[1][1]=1;
         for(int i=1;i<=n;i++)
         {
             for(int j=1;j<=m;j++)
             {
                 if(a[i-1][j-1]=='#')
                    continue;
                 if(i==1 && j==1)
                    continue;
                 if(i==1 && j!=1)
                    dp[i][j]=dp[i][j-1];
                 else if(j==1 && i!=1)
                    dp[i][j]=dp[i-1][j];
                 else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
             }
         }
         cout<<dp[n][m];
    }
    return 0;
}
















Measured memory_bytes: 14808
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    if(A + B <= 9) {
        cout << A + B << endl;
    } else {
        cout << "error" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
t_ = 0
x_ = 0
y_ = 0
for i in range(n):
    t, x, y = map(int, input().split())
    d = (t-t_)-abs(x-x_)-abs(y-y_)
    if d < 0 or d%2 != 0:
        print('No')
        exit()
    else:
        t_ = t
        x_ = x
        y_  = y

else:
    print('Yes')


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))
from collections import deque

def main():
    s = input().strip()
    if s[-1] == '1' or s[0] == '0':
        print(-1)
    else:
        edges = deque([])
        for i in range(len(s)-1):
            if s[i] != s[len(s)-i-2]:
                print(-1)
                return
            elif s[i] == '1':
                edges.append(i)
        edges.append(len(s)-1)
        for i in range(len(s)-1):
            if edges[0] == i:
                edges.popleft()
            print(i+1, edges[0]+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 51160
#include <iostream>
using namespace std;
int main()
{
	int x1,x2,y1,y2,x3,x4,y3,y4;
	cin>>x1>>y1>>x2>>y2;
	int Dx=abs(x1-x2);
	int Dy=abs(y1-y2);
	if(x1<=x2 && y1<=y2)//(x1,x2) is in the left-bottom of (y1,y2)
	{
		x3=x2-Dy;
		y3=y2+Dx;
		x4=x1-Dy;
		y4=y1+Dx;
	}
	else if(x1>=x2 && y1<=y2)//(x1,x2) is in the right-bottom of (y1,y2)
	{
		x3=x2-Dy;
		y3=y2-Dx;
		x4=x1-Dy;
		y4=y1-Dx;
	}
	else if(x1<=x2 && y1>=y2)//(x1,x2) is in the left-top of (y1,y2)
	{
		x3=x2+Dy;
		y3=y2+Dx;
		x4=x1+Dy;
		y4=y1+Dx;
	}
	else//(x1,x2) is in the right-top of (y1,y2)
	{
		x3=x2+Dy;
		y3=y2-Dx;
		x4=x1+Dy;
		y4=y1-Dx;
	}
	cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
	return 0;
}

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

using ll = long long;

const ll MOD = 1000000007;
vector<ll> fact(300000);

ll pow(ll a, ll b){
    if(b == 1)
        return a;
    if(b % 2 == 1)
        return a * pow(a,b-1) % MOD;
    ll x = pow(a,b/2);
    return x * x % MOD;
}

ll invarse(ll a){
    return pow(a , MOD - 2);
}

ll Comb(ll n, ll k){//組み合わせnCkの計算
    return fact[n] * invarse(fact[k] * fact[n-k] % MOD) % MOD;
}

int main(){
    ll h,w,a,b;
    cin >> h >> w >> a >> b;
    fact[0] = 1;
    fact[1] = 1;
    for(int i = 2; i < 300000; i++){
        fact[i] = (fact[i-1] * i) % MOD;
    }
    ll ans = 0;
    int i = 0;
  
    i=h-a;
    for(int j = b+1; j <= w; j++){

        ans = (ans + Comb(i + j - 2, i - 1) * Comb(a + w - j + 1 - 2, a - 1)  % MOD) % MOD; 
     }
    cout << ans << endl;
    return 0;
}

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

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

  vector<int> a(N), b(N+1);
  b.at(0) = 1;

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  bool flag = false;
  for (int i = 0; i < N; i++) {
    b.at(i+1) = a.at(b.at(i)-1);
    if (b.at(i+1) == 2) {
      cout << i+1 << endl;
      break;
    }
    else if (i == N-1) 
      cout << -1 << endl;
  }
}

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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int k;
vector< pair<int, int> > g[N];
int D[N];

bool read() {
    if (!(cin >> k))
        return false;

    return true;
}

void solve() {
    for (int i = 0; i < k; ++i) {
        g[i].emplace_back((i + 1) % k, 1);
        g[i].emplace_back((i * 10) % k, 0);
    }

    deque<int> Q;
    fill(D, D + k, MOD);
    D[1] = 1;
    Q.push_back(1);

    for (; !Q.empty(); ) {
        auto v = Q.front();
        Q.pop_front();

        for (const auto& to : g[v])
            if (D[to.first] > D[v] + to.second) {
                if (to.second == 0)
                    Q.push_front(to.first);
                else
                    Q.push_back(to.first);

                D[to.first] = D[v] + to.second;
            }
    }

    cout << D[0] << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = a == b && a == c;
    if (a != b) ans++;
    if (b != c) ans++;
    if (a != c) ans++;
    cout << ans << '\n';
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3612
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
public class Main {
	int N;
	int[] A,B;
	HashMap<Integer,Integer> a,b;
    public void solve() {
		N = nextInt();
		A = new int[N];
		B = new int[N];
		a = new HashMap<Integer,Integer>();
		b = new HashMap<Integer,Integer>();
		
		for(int i = 0;i < N;i++){
			A[i] = nextInt();
			a.put(A[i],i);
			
			B[i] = A[i];
		}
		Arrays.sort(B);
		for(int i = 0;i < N;i++){
			b.put(B[i],i);
		}
		int ans = 0;
		for(int key : b.keySet()){
			
			int aIndex = a.get(key);
			int bIndex = b.get(key);
			
			if(aIndex % 2 == 1 && bIndex % 2 == 0){
				ans++;
			}
		}
		
		out.println(ans);
    }
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
		/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if( d <= a || c >= b ){
    cout << 0 << endl;
	return 0;
  }
  if( a >= c ){
    if( b <= d ){
      cout << b-a << endl;
    }else{
      cout << d-a << endl;
    }
  }else if( a <= c ){
    if( b <= d ){
	  cout << b-c << endl;
    }else{
      cout << d-c << endl;
    }
  }
  return 0;
}

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

int main (){
	int N;
	int a[1000];
	cin>>N;
	for(int t=0;t<N;t++)cin>>a[t];

	sort(a,a+N);

	int ans=abs(a[0]-a[N-1]);
	cout<<ans;
	return 0;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> d(n, vector<int>(n, -1));
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      d.at(i).at(x) = y;
    }
  }

  ll res = 0;
  rep(i, 1 << n) {
    bool ok = true;
    rep(j, n) {
      if (i >> j & 1) {
        rep(k, n) {
          int x = d.at(j).at(k);
          if (x == -1) {
            continue;
          }
          if (x == 1 && !(i >> k & 1)) {
            ok = false;
          }
          if (x == 0 && (i >> k & 1)) {
            ok = false;
          }
        }
      }
    }
    if (!ok) {
      continue;
    }
    // 正直者を数える
//    ll tmp = __builtin_popcount(i);
    ll tmp = 0;
    rep(j, n) {
      if (i >> j & 1) {
        tmp++;
      }
    }
    res = max(res, tmp);
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  int N, M;
  vector<int> s(M), c(M);
  cin >> N >> M;
  for(int i = 0; i < M; i++) cin >> s.at(i) >> c.at(i);
  
  bool isOK = false;
  string str;
  for (int i = 0; i < 1000; i++) {
    bool isOKsize = true;
    bool isOKdigit = true;
    stringstream iss;
    iss << i;
    str = iss.str();
    if (str.size() != N) {
      isOKsize = false;
    }
    if (isOKsize) {
      for (int j = 0; j < M; j++) {
        if (str.at(s.at(j)-1) != (char)(c.at(j) + '0')) {
          isOKdigit = false;
          break;
        }
      }
    }
    isOK = (isOKsize && isOKdigit); 
    if (isOK) break;
  }
  (isOK) ? cout << str << endl : cout << -1 << endl; 
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

string s;
int dp[100010][2];
bool vis[100010][2];

int solve(int x, int f)
{
    if (vis[x][f])
        return dp[x][f];
    vis[x][f] = true;
    int res = 0;
    if (x == s.size())
        return dp[x][f] = 1;
    if (s[x] == '1')
    {
        if (f)
        {
            res = (3 * solve(x + 1, 1)) % mod;
        }
        else
        {
            res = (2 * solve(x + 1, 0) + solve(x + 1, 1)) % mod;
        }
    }
    else
    {
        if (f)
        {
            res = 3 * solve(x + 1, 1) % mod;
        }
        else
        {
            res = solve(x + 1, 0);
        }
    }
    return dp[x][f] = res;
}

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

    cin >> s;
    cout << solve(0, 0) << endl;
}

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

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

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

	ll N;
	cin >> N;
	ll S = 0;
	for (ll T = N; T > 0; T /= 10) {
		S += T % 10;
	}

	cout << (N % S == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
program main 
implicit none

integer :: n,m,c
integer :: i,j,sm,cnt=0;
integer,allocatable :: a(:,:),b(:)
read(*,*)n,m,c
allocate(a(n,m),b(m))

read(*,*)b(1:m)
do i=1,n
	read(*,*)a(i,1:m)
end do
do i=1,n
	sm=0;
	do j=1,m
        sm = sm + a(i,j)*b(j)
    end do
    if (sm+c > 0) then 
    	cnt = cnt +1
    end if
end do

write(*,'(i0)')cnt

end program

Measured memory_bytes: 384
use proconio::input;
use proconio::marker::{Chars};
use std::collections::VecDeque;

fn main() {
    input!{
        h: usize,
        w: usize,
        c: [usize; 2],
        d: [usize; 2],
        sdash: [Chars; h],
    }
    let inf: usize = 999999999999;
    let mut v = vec![vec![inf; w+4]; h+4];
    let mut s = vec![vec!['#'; w+4]; h+4];
    for i in 0..h {
        for j in 0..w {
            s[i+2][j+2] = sdash[i][j];
        }
    }
    let mut q = VecDeque::new();

    q.push_back((c[0]+1, c[1]+1, 0));

    while q.len() > 0 {
        let (x, y, cost) = q.pop_front().unwrap();
        if v[x][y] <= cost {
            continue;
        }
        v[x][y] = cost;
        for i in -2..3 {
            for j in -2..3 {
                let fx = (x as isize + i) as usize;
                let fy = (y as isize + j) as usize;
                if v[fx][fy] == inf && s[fx][fy] == '.' {
                    if (i, j) == (1, 0) || (i, j) == (0, 1) || (i, j) == (-1, 0) || (i, j) == (0, -1) {
                        q.push_front((fx, fy, cost));
                    }
                    else {
                        q.push_back((fx, fy, cost+1));
                    }
                }
            }
        }
    }
    if v[d[0]+1][d[1]+1] == inf {
        println!("-1");
    }
    else {
        println!("{}", v[d[0]+1][d[1]+1]);
    }
}


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

int main() {
        int n; cin >> n; // 入力
		if(n==22) cout << "Christmas Eve Eve Eve" <<endl;
  		else if(n==23) cout << "Christmas Eve Eve" <<endl;
  		else if(n==24) cout << "Christmas Eve" <<endl;
  		else if(n==25) cout << "Christmas" <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  
  map<int, int> m;

  for (int i = 0; i < N; i++) {
      int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int b;
      cin >> b;
      m[b]++;
    }
  }
  
  int cnt = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (itr->second == N) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {

	/*

	int D, T, S;
	cin >> D >> T >> S;
	int hour = D / S;
	if (D % S != 0)hour++;
	if (hour <= T) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
	
	*/

	string S;
	cin >> S;
	if (S == "RRR") {
		cout << 3 << endl;
	}
	else if (S == "SSS") {
		cout << 0 << endl;
	}
	else if (S == "SRR" || S == "RRS") {
		cout << 2 << endl;
	}
	else {
		cout << 1 << endl;
	}
		
}

Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> books[10];
int sale[10][2001],dp[11][2000];
int main() {
	int N,K;
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++) {
		int C,G;
		scanf("%d %d",&C,&G);
		books[G-1].push_back(C);
	}
	for(int i=0;i<10;i++) {
		sort(books[i].rbegin(),books[i].rend());
	}
	for(int i=0;i<10;i++) {
		int sum=0;
		for(int j=1;j<=books[i].size();j++) {
			sale[i][j]=(sum+=books[i][j-1])+j*(j-1);
		}
	}
	for(int i=0;i<10;i++) {
		for(int j=0;j<=K;j++) {
			for(int k=0;k<=min(j,(int)books[i].size());k++) {
				dp[i+1][j]=max(dp[i+1][j],dp[i][j-k]+sale[i][k]);
			}
		}
	}
	printf("%d\n",dp[10][K]);
}

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

using namespace std;

typedef long long LL;

int n,m,a[305][305],ans,cnt[305],id,dq;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j) scanf("%d",&a[i][j]);
	ans=n;
	for (int z=1;z<=m;++z)
	{
		for (int i=1;i<=m;++i) cnt[i]=0;
		for (int i=1;i<=n;++i) cnt[a[i][1]]++;
		id=1;
		for (int i=1;i<=m;++i) if (cnt[i]>cnt[id]) id=i;
		ans=min(ans,cnt[id]);
		for (int i=1;i<=n;++i)
		{
			for (int j=1;j<=m;++j) if (a[i][j]==id) dq=j;
			for (int j=dq;j<=m;++j) a[i][j]=a[i][j+1];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
"""
master of 整数
素因数分解
https://qiita.com/drken/items/a14e9af0ca2d857dad23
"""

N = int(input())
ans = len(str(N))
for i in range(2, int(N**0.5) + 1):
    if N % i == 0:
        f_ab = max(len(str(i)), len(str(N//i)))
        ans = min(f_ab, ans)

print(ans)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;
int gcd(int n, int m) {
  if (n < m) {
    int tmp = m;
    m = n;
    n = tmp;
  }
  if(m == 0) {
    return n;
  }
  return gcd(m, n % m);
}

int main() {
  int n;
  int a[100000];
  int l[100000], r[100000];

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


  l[0] = a[0];
  FOR(i,1,n) {
    l[i] = gcd(l[i-1], a[i]);
  }

  r[n-1] = a[n-1];
  for(int i = n-2; i >= 0; i--) {
    r[i] = gcd(r[i+1], a[i]);
  }

  int result = max(r[1], l[n-2]);

  FOR(i,1,n-1) {
    result = max(result, gcd(l[i-1], r[i+1]));
  }

  cout << result << endl;
}


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

int main(){
	int N, cnt = 0, hmin;
	cin >> N;
	vector<int> h(N);
	vector<int> start, end;

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

	while(true){
	start.clear();
	end.clear();

	if(h[0]!=0) { start.push_back(0); }
	for(int i=1; i<N; i++){
		if(h[i-1]==0 && h[i]!=0){
			start.push_back(i);
		}else if(h[i-1]!=0 && h[i]==0){
			end.push_back(i);
		}
	}
	end.push_back(N);

	if(start.size() == 0) break;

	hmin = 100;
	for(int i=0; i<start.size(); i++){
		for(int j=start[i]; j<end[i]; j++){
			hmin = min(hmin, h[j]);
		}
		for(int j=start[i]; j<end[i]; j++){
			h[j] -= hmin;
		}
		cnt += hmin;
	}

	}
	cout << cnt << endl;
}

Measured memory_bytes: 256