akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
bool ifokay(ll x){
    bool three=false, five=false, seven=false;
    while(x>0){
        if(x%10==3) three=true;
        else if(x%10==5) five=true;
        else if(x%10==7) seven=true;
        else return false;
        x/=10;
    }
    if(three && five && seven) return true;
    else return false;
}


int main(){
    ll n; cin>>n;
    vector<ll> v={3,5,7};
    ll res=0;
    rep(i,10){
        vector<ll> _v={};
        for(ll x:v){
            if(ifokay(x) && x<=n) res++;
            _v.push_back(x*10+3);
            _v.push_back(x*10+5);
            _v.push_back(x*10+7);
        }
        v=_v;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const long long N = 9000;
long long arr[N] = {};
int main() {
    long long x;
    cin >> x;
    if (x == 0) {
        cout << "0 0\n";
        return 0;
    }
    if (x == 1) {
        cout << "1 0\n";
        return 0;
    }
    long long a, b;
    for (long long i = 1; i < N; i++)
        for (long long j = i + 1; j < N; j++) {
            a = j, b = i;
            long long t = a * a + b * b;
            if (a != b && x % (a - b) == 0)
                if (x / (a - b) - t * t == a * b * (t - a * b)) {
                    cout << a << " " << b;
                    return 0;
                }
            a = j, b = -i;
            if (x % (a - b) == 0)
                if (x / (a - b) - t * t == a * b * (t - a * b)) {
                    cout << a << " " << b;
                    return 0;
                }
        }
    return -1;
}

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

int main() {

    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n){
        cin >> vec.at(i);
    }
    int m;
    cin >> m;
    rep(i, m){
        int wa;
        cin >> wa;
        int vecsin = vec.at(wa - 1) + 1;
        if(find(vec.begin(), vec.end(), vecsin) == vec.end() && vecsin <= 2019) vec.at(wa - 1) += 1;
        
    }
    rep(i, n){
        cout << vec.at(i) << endl;
    }

}





Measured memory_bytes: 3116
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main() {
	unsigned int  a, b, c, a2, b2, c2;
	cin >> a >> b >> c;
	a2 = a;
	b2 = b;
	c2 = c;
	unsigned int cnt = 0;
	bool masatoy = true;
	while (1) {
		if (cnt > 0) {
			if (a == a2&&b == b2&&c == c2) {
				masatoy = false;
				break;
			}
		}
		if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			unsigned int a3 = a / 2;
			unsigned int b3 = b / 2;
			unsigned int c3 = c / 2;
			 a = c3 + b3;
			 b = a3 + c3;
			 c = a3 + b3;
			//cout << a << " " << b << " " << c << endl;
			cnt++;
		}
		else {
			break;
		}
	}
	if (masatoy == true) {
		cout << cnt << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

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

int main() {
   int x, a, b;
   cin >> x >> a >> b;

   if (abs(x - a) < abs(x- b)) {
       cout << "A" << endl;
   } else {
       cout << "B" << endl;
   }
}

Measured memory_bytes: 256
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================


void fun(){
    int n;cin>>n;
    int val=7%n;
    for(int i=1;i<1e8;i++){
        if(val==0){
            cout<<i;
            return;
        }
        val=(val*10+7)%n;
    }
    cout<<-1;
}

signed  main() {
    lets_go

      int t;
      t=1;
// cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}


Measured memory_bytes: 3616
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i,j,k;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());
    int cnt = 0;
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            for (k = j + 1; k < n; k++) {
                if (a[i] != a[j] && a[j] != a[k] && (ll)a[i] + a[j] > a[k]) {
                    cnt++;
                }
            }
        }
    }
    printf("%d\n", cnt);
    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 3228
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates


int main()
{
    string n;
    cin >> n;
    ll s = 0;
    rep(i, n.length()) {
        s += n[i] - '0';
    }
    if (s % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[1000005];
int pr[1000005];
set<pair<int,int> >s;
int ind[1000005];

signed main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ind[a[i]]++;
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        pr[i]=pr[i-1]+a[i];
        s.insert({a[i],i});
    }
    int mx=0;
    int l=1,r=1e6;
    while(l<=r)
    {
        int sum=0,cnt=0;
        int mid=l+(r-l)/2;
        for(int i=1;i<=n;i++)
        {
            auto j=s.lower_bound({mid-a[i]+1,-1});
            if(j==s.end())
                continue;
            if(n-(j->second-1)+cnt<=m)
            {
            sum+=a[i]*(n-j->second+1)+(pr[n]-pr[j->second-1]);
            cnt+=n-(j->second-1);
            }
            else
            {
                int z=(pr[n]-pr[n-(m-cnt)])+(m-cnt)*a[i];
                sum+=z;
                cnt=m;
                break;
            }
        }
        int count=0;
        for(int i=1;i<=mid;i++)
        {
            count+=ind[i]*ind[mid-i];
        }
        if(count+cnt>=m)
        {
            sum+=(m-cnt)*mid;
        }
        cnt+=count;
        if(cnt>=m)
        {
            l=mid+1;
            mx=max(mx,sum);
        }
        else
        {
            r=mid-1;
        }
    }
    
    cout<<mx;
    return 0;
}


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

int main() {
  int X;
  cin>>X;
  
  vector<int> vec={2};
  int n,p;
  n=vec.size();
  p=3;
  while(vec.at(n-1)<X){
    int count=0;
    for(int i=0;i<n;i++){
      if(p%vec.at(i)==0){
        count++;
        break;
      }
    }
    if(count==0){
      vec.push_back(p);
    }
    n=vec.size();
    p++;
  }
  cout<<vec.at(n-1)<<endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    string s;
    cin >> s;
    cout << s.substr(0, s.size() - 8) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int[] primeCountList = calcPrimeNumber();

    while (true) {
      String tmp = br.readLine();
      if (tmp == null) {
        break;
      }
      int num = Integer.valueOf(tmp);
      System.out.println(primeCountList[num]);
    }
  }

  private static int[] calcPrimeNumber() {
    int maxN = 1_000_000;
    int sqrtN = (int) Math.sqrt(maxN);

    boolean[] isPrimeList = new boolean[maxN];
    for (int i = 2; i < maxN; i++) {
      isPrimeList[i] = true;
    }

    for(int i = 2; i < sqrtN + 1; i++) {
      if (!isPrimeList[i]) {
        continue;
      }
      for (int j = i*i; j <maxN; j += i) {
        isPrimeList[j] = false;
      }
    }

    int[] primeCountList = new int[maxN];
    int count = 0;
    for (int i = 2; i < maxN; i++) {
      if (isPrimeList[i]) {
        count++;
      }
      primeCountList[i] = count;
    }

    return primeCountList;
  }
}

Measured memory_bytes: 30064
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main ()
{
    int x,y,m=1000,i,z,d;
    string s;
    cin >> s;
    z=s.length();
    z=z-2;
    for(i=0;i<z;i++)
    {
        y=(s[i]-48)*100+(s[i+1]-48)*10+(s[i+2]-48);
        d=abs(753-y);
        m=min(m,d);
    }
    cout << m ;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    double n,m,k;
    cin>>n>>m>>k;
    double tmp=n/k;
    if(tmp<=m) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3704
function main()
    s = chomp(readline())
    if s[1] != 'A'
        print("WA\n")
        return
    end
    cnt = 0
    for i in 3:length(s)-1
        if s[i] == 'C'
            cnt += 1
        elseif isupper(s[i])
            print("WA\n")
            return
        end
    end
    if cnt != 1
        print("WA\n")
        return
    end
    if isupper(s[2]) || isupper(s[end])
        print("WA\n")
        return
    end
    print("AC\n")
    return
end

main()


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

int  main(){
	lli  n,m;
	cin>>n>>m;
	vector<lli > w(n);
	vector<lli > v(n);
	lli sum = 0;
	for(lli  i=0;i<n;i++){
		cin>>w[i]>>v[i];
		sum += v[i];
	}
	vector<lli >dp(sum+1,1e9+1);
	dp[0]=0;
	for(lli  i=0;i<n;i++){
		for(lli  j=sum ;j>0;j--){
			if((j-v[i])>=0)dp[j]=min(dp[j-v[i]]+w[i],dp[j]);	
		}
	}
	int ans = 1e9+1;
	for(int i=0;i<=sum;i++){
		if(dp[i]<=m)ans=i;
	}
	cout<<ans;
}

Measured memory_bytes: 4008
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;

    int balls[n+1];
    fill(balls, balls+n+1, 0);

    REP(i, n) {
        int input;
        cin >> input;
        balls[input]++;
    }

    // count non-zero
    int cnt_non_zero = 0;
    REP(i, n+1) {
        if (balls[i] != 0) cnt_non_zero++;
    }

    sort(balls, balls+n+1);

    int cnt = 0;
    REP(i, n+1) {
        if (cnt_non_zero <= k) break;
        if (balls[i] != 0) {
            cnt += balls[i];
            cnt_non_zero--;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;
//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  vector<int> a(3);
  rep(i,3){
    cin >> a.at(0) >> a.at(1) >> a.at(2);
  }
  sort(a.begin(),a.end());
  cout << a.at(2) - a.at(0) << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0

for i in range(1000): #0~999を全探索
  flg1 = False #1桁目があるか
  flg2 = False #2桁目があるか
  flg3 = False #3桁目があるか
  one = str(i//100) #1桁目
  two = str(i%100//10) #2桁目
  three = str(i%10) #3桁目
  t = 0
  
  for j in range(n-2):
    if s[j] == one:
      flg1 = True
      t = j+1
      break
  for j in range(t,n-1):
    if s[j] == two:
      flg2 = True
      t = j+1
      break
  for j in range(t,n):
    if s[j] == three:
      flg3 = True
      t = j+1
      break
  if flg1 and flg2 and flg3:
    ans += 1
print(ans)

Measured memory_bytes: 74296
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll N;
	scll(N);
	ll count = 0;
	for (ll i = 2; i <= N; i += 2) {
		for (ll j = 1; j <= N; j += 2) {
			++count;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.ArrayList;

class Pair {
    long first;
    long second;

    Pair (long first, long second) {
        this.first = first;
        this.second = second;
    }
}

@SuppressWarnings("unchecked")
public class Main {
    // 約数
    static void devisor(ArrayList<Pair> dev,long N) {
        long n;
        long i = 1;

        n = N;

        while (i <= Math.sqrt(n)) {
            if (n % i == 0) dev.add(new Pair(i, n / i));
            i++;
        }
    }

    static int f(long first, long second) {
        return (int)Math.max(Math.log10(first), Math.log10(second)) + 1;
    }

    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        long N = Long.parseLong(s);

        ArrayList<Pair> dev = new ArrayList<Pair>();

        devisor(dev, N);

        int ans = Integer.MAX_VALUE;

        for (int i = 0; i < dev.size(); i++) {
            Pair p = dev.get(i);

            int tmp = f(p.first, p.second);

            ans = Math.min(ans, tmp);
        }

        out.println(ans);

        out.flush();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    int lb = 0, ub = *max_element(a.begin(), a.end());
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        ll c = 0;
        for(int i = 0; i < n; ++i){
            c += (a[i] + mid - 1) / mid - 1;
        }
        if(c <= k)  ub = mid;
        else    lb = mid;
        // cerr << c << ' ';
        // cerr << lb << ' ' << ub << endl;
    }
    cout << ub << endl;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  v.pb(0);

  int ans = 0;
  int cur = 1;
  rep(i,n) {
    if(v[i] != v[i+1]){
      ans += cur/2;
      cur = 1;
    } else {
      cur++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import math


class RangeMaximumQuery:
    """
    RangeMaximumQuery by Segment Tree
    query:
    1. update(i, val): update i-th value to val
    2. query(low, high): find maximun value in [low, high)
    time complexity: O(log n)
    space complexity: O(2n)
    """
    def __init__(self, N, zero=0):
        self.N = 1 << math.ceil(math.log(N, 2))
        self.zero = zero
        self.segtree = [self.zero] * (self.N * 2 - 1)

    def update(self, i, val):
        i += self.N - 1
        self.segtree[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.segtree[i] = max(self.segtree[2*i+1], self.segtree[2*i+2])

    def query(self, low, high, k=0, left=0, right=-1):
        if right == -1:
            right = self.N
        if right <= low or high <= left:
            return self.zero

        if low <= left and right <= high:
            return self.segtree[k]
        else:
            mid = (left + right) // 2
            return max(self.query(low, high, 2*k+1, left, mid),
                       self.query(low, high, 2*k+2, mid, right))

N = int(input())
X = [int(x) for x in input().split()]
dp = RangeMaximumQuery(N)
for x, i in sorted((x, i) for i, x in enumerate(X)):
    dp.update(i, dp.query(0, i) + x)
print(N * (N + 1) // 2 - dp.query(0, N))

Measured memory_bytes: 28048
import java.util.*;

public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   	
    String wa = sc.next();
        
   if(wa.equals("Sunny")){
       System.out.println("Cloudy");
   }else if(wa.equals("Cloudy")){
   		System.out.println("Rainy");
   }else if(wa.equals("Rainy")){
   		System.out.println("Sunny");
   }
    }
}

Measured memory_bytes: 21588
import java.util.*;
public class Main
{
    public static void main (String[] args)
    {
        Scanner scanner = new Scanner(System.in);
    	int num[] = new int[3];
    	for(int i=0;i<3;i++){
    	num[i] = scanner.nextInt();
    	}
    	
    	Arrays.sort(num);
    	for(int i=0;i<3;i++){
    		if(i < 2){
    			System.out.print(num[i] + " ");
    		}else{
    			System.out.println(num[i]);
    		}
    	}
    }
}

Measured memory_bytes: 26236
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long K = sc.nextLong();
        long sum = 0;
        if(A>=K)
        {
            sum = K;
        }
        else if(K - A - B <=0)
        {
            sum = A;
        }
        else
        {
            K = K - A - B;
            sum = A - K;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 35900
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0; true; i++)
    {
        if (i % 2)
        {
            a -= d;
            if (a <= 0)
            {
                cout << "No" << endl;
                break;
            }
        }
        else
        {
            c -= b;
            if (c <= 0)
            {
                cout << "Yes" << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3536
#include <iostream>

using namespace std;

int main()
{
  string s;
  cin >> s;
  for (auto i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      s[i] = '9';
    } else if (s[i] == '9') {
      s[i] = '1';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))

ll n,m,ans=0;
void work(int x){
	if(n%x==0)ans++;
	while(n%x==0)n/=x;
}
int main(){
	//ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n>>m;
	n=__gcd(n,m);
	repeat(i,2,int(sqrt(n)+2))work(i);
	if(n!=1)++ans;
	cout<<(ans+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
#-*- coding: utf-8 -*-


def selection_sort(l):
    N = len(l)
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        if i != minj:
            l[i], l[minj] = l[minj], l[i]


def bubble_sort(l):
    N = len(l)
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
    pass


if __name__ == '__main__':
    N = raw_input()
    l1 = raw_input().split()
    l2 = l1[:]
    bubble_sort(l1)
    print ' '.join(l1)
    print "Stable"
    selection_sort(l2)
    print ' '.join(l2)
    if l1 == l2:
        print "Stable"
    else:
        print "Not stable"


Measured memory_bytes: 4688
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();
    
    let min: usize = *a.iter().min().unwrap();
    let mut dp: Vec<usize> = vec![0; k+1];
    for i in min..k+1 {
        let mut not: Vec<bool> = vec![true; k+1];
        for j in 0..n {
            if i >= a[j] {
                not[dp[i-a[j]]] = false;
            }
        }
        let mut j = 0;
        while !not[j] {
            j += 1;
        }
        dp[i] = j;
    }
    println!("{}", if dp[k] != 0 {"First"} else {"Second"});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
N, M, K = map(int, input().split())

MOD = 10**9 + 7
L = N*M

fact = [1]*(L+1)
rfact = [1]*(L+1)
r = 1
for i in range(1, L+1):
  fact[i] = r = r * i % MOD
rfact[L] = r = pow(fact[L], MOD-2, MOD)
for i in range(L, 0, -1):
  rfact[i-1] = r = r * i % MOD

L = max(N, M)
D = [0]*(L+1)
for i in range(L):
    D[i+1] = D[i] + (i+1)

ans = 0
for i in range(N):
    for j in range(M):
        ans += D[j] * (i+1) + D[M-1-j] * i + D[i] * M
    ans %= MOD
print(ans * fact[N*M-2] * rfact[N*M-K] * rfact[K-2] % MOD)

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a<=b)
    {
        cout<<a*c<<endl;
    }
    else
    {
        int e = a-b;
        int sum = (b)*(c)+e*d;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

// AtCoder Grand Contest 038
int main(){

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<vector<int>> ans(H, vector<int>(W, 0));
    rep(i, B)rep(j, A)ans[i][j] = 1;
    for(int i = B; i < H; i++)for(int j = A; j < W; j++)ans[i][j] = 1;
    
    rep(i, H){
        rep(j, W){
            cout << ans[i][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 5120
#include <iostream>
using namespace std;
int main(void){
   
   for(;;){
   int h,w;
   
   cin>>h>>w;
   
   if(!h) break;
   
   for(int i=0;i<h;i++){
     
     for(int j=0;j<w;j++) cout<<"#";
     cout<<endl;
   }
   
   cout<<endl;
   
}
   
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
   long long n,ans=1,t=1,p=1;
  cin>>n;
  if(n==1)
  {
    cout<<0;
    return 0;
  }
  while(n)
  {
    ans=(ans%mod*10)%mod;
    t=(t%mod*9)%mod;
    p=(p%mod*8)%mod;
    n--;
  }
  
  cout<<(ans-t+mod-t+mod+p)%mod;
  
  return  0;
}

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

int main(){
	long long n, m,k,t;
	map<long long, vector<long long> > edges;
	cin >> n >> m;
	vector<int> visited(n + m, 0);
	
	for(int i=0;i<n;i++){
		cin >> k;
		for(int j=0;j<k;j++){
			cin >> t;
			t--;
			edges[i].push_back(t + n);
			edges[t + n].push_back(i);
		}
	}
	
	queue<long long> q;
	q.push(0);
	while(!q.empty()){
		long long cur = q.front();
		q.pop();
		
		for(long long next: edges[cur]){
			if(visited[next])
				continue;
			
			visited[next] = true;
			q.push(next);
		}
	}
	
	for(int i=0;i<n;i++){
		if(!visited[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	
	cout << "YES" << endl;
	return 0;
}

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int[] a = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		Arrays.sort(a);
		if (a[0] + a[1] == a[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}

main()
{
    int n; cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];

    int l[n],r[n];
    l[0]=v[0];
    r[n-1]=v[n-1];
    rep2(i,1,n)
    {
        l[i]=gcd(l[i-1],v[i]);
        r[n-1-i]=gcd(r[n-1-i+1],v[n-1-i]);
    }
    int m[n];
    m[0]=r[1]; m[n-1]=l[n-2];
    rep2(i,1,n-1)m[i]=gcd(l[i-1],r[i+1]);

    //rep(i,n)printf("%d %d %d\n",l[i],r[i],m[i]);

    int mx=0;
    each(it,m)mx=max(mx,it);
    cout<<mx<<endl;
}

Measured memory_bytes: 1792
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAX 1000000

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

bool prime[MAX+1];

void hurui(void) {
    for (int i = 0; i <= MAX; i++) prime[i] = true;
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= MAX; i++) {
        if (prime[i]) {
            for (int j = 2; i * j <= MAX; j++) {
                prime[i*j] = false;
            }
        }
    }
}

int main(void) {
    hurui();
    int a, d, n;
    while (cin >> a >> d >> n) {
        if (a == 0 && d == 0 && n == 0) break;
        int cur = 1;
        while (1) {
            if (prime[a]) {
                if (cur == n) {
                    cout << a << endl;
                    break;
                } else {
                    cur++;
                }
            }
            a += d;
        }
    }
    return 0;
}

Measured memory_bytes: 2136
H,W = map(int,input().split())
res = min(H,W)
hr,ht,vr,vt = 0,0,0,0
hr,vr = H%3*W,W%3*H
def t(x,y):
    if x%3==0:
        return 0
    elif x%3==1:
        a = ((x//3)*2+1)*(y//2)
        b = x//3*y
        c = x*y-a-b
        return max(a,b,c)-min(a,b,c)
    else:
        a = ((x//3)*2+1)*(y//2)
        b = (x//3+1)*y
        c = x*y-a-b
        return max(a,b,c)-min(a,b,c)
ht = t(H,W)
vt = t(W,H)
print(min(res,hr,ht,vr,vt))

Measured memory_bytes: 3064
# include <iostream>
# include <iomanip>
# include <math.h>
# include <cmath>
using namespace std;
int main()
{
	double l;
	double a,b;
	cin>>l;
	a=(l*l*l)/27;
	cout<<fixed<<setprecision(10)<<l*l*l/27;
}

Measured memory_bytes: 3712
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();

    for i in 0..(s.len()) {
        if s[i] != t[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2144
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [A, B, C] = input[0].split(' ').map(x => parseInt(x))

  console.log(Math.min(Math.floor(B / A), C))
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 30732
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
  if(b == 0) return a;
  return gcd(b, a%b);
}

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


int main()
{
  int a, b;

  while(cin>>a>>b){
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>

constexpr auto PI = 3.14159265359;

using namespace std;

int main() {
	int M, D;
	cin >> M >> D;

	int count = 0;
	for (int m = 1; m <= M; ++m) {
		for (int j = 1; j <= D; ++j) {
			int d1 = j % 10;
			int d2 = j / 10;
			if (d1 >= 2 && d2 >= 2 && d1 * d2 == m) {
				++count;
			}
		}
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sumcif(int x)
{
    int sum=0;
    while(x)
    {
        sum+=x%10;
        x/=10;
    }
    return sum;
}
int main()
{
    int n;
    cin>>n;
    int sol=1000;
    for(int i=1;i<n;i++)
    {
        int a=i;
        int b=n-i;
        sol=min(sol,sumcif(a)+sumcif(b));
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
c = [0,0,0]
for i in range(n):
    t,x,y = map(int,input().split())
    time = t-c[0]
    coor = abs(c[1]-x)+abs(c[2]-y)
    if not (time>=coor and coor%2==time%2):
        print('No')
        exit()
    c = [t,x,y]
print('Yes')


Measured memory_bytes: 3060
N= int(input())
A  = list(map(int,input().split()))
B  = list(map(int,input().split()))
short = []
margine = []
for a,b in zip(A,B):
    if a > b :
        margine.append(a-b)
    elif b > a:
        short.append(b-a)
        
ss = sum(short)
sc = len(short)
margine.sort()
if sum(short)>sum(margine):
    print(-1)
    exit()
while ss>0:
    ss -= margine.pop()
    sc += 1
print(sc)



Measured memory_bytes: 24348
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    s = S()
    c = Counter(s)
    mosts = c.most_common()
    ans = len(s)

    for most in mosts:
        t = [i for i in s]
        loop = 0
        while not all([i == most[0] for i in t]):
            cur = []
            for i in range(len(t)):
                if i < len(t) - 1 and t[i+1] == most[0]:
                    cur.append(t[i+1])
                else:
                    cur.append(t[i])
            cur.pop()
            t = cur
            loop += 1
        ans = min(ans, loop)

    print(ans)


if __name__ == '__main__':
    main()


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


void solve() {
	int k, a, b;
	cin >> k >> a >> b;
	int flag = 0;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			flag = 1;
			break;
		}
	}
	if (flag)
		cout << "OK";
	else
		cout << "NG";
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	return 0;
}

Measured memory_bytes: 3640
open Printf open Scanf
open Array

let rec gcd m n = match m,n with | m,0 -> m | m,n -> gcd n (m mod n)

let print_array f a = Array.iter (fun v -> printf "%s " @@ f v) a; print_newline ()

let () = scanf " %d" @@ fun n ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  let lr = make n a.(0) in
  let rl = make n a.(n-1) in
  for i=1 to n-1 do
    lr.(i) <- gcd lr.(i-1) a.(i)
  done;
  for i=n-2 downto 0 do
    rl.(i) <- gcd rl.(i+1) a.(i)
  done;
  (* print_array string_of_int lr;
  print_array string_of_int rl; *)
  init n (fun i ->
    let w =
      if i=0 then rl.(1)
      else if i=n-1 then lr.(n-2)
      else gcd rl.(i+1) lr.(i-1)
    in w)
  |> fold_left max 0
  |> print_int



Measured memory_bytes: 6272
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if(a+b>=10){
        cout << "error";
    }else{
        cout << a+b;
    }
    
    return 0;
}

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

int n, k;
int l, r;
int a[200200];
int pre_pos[22][200200], suf_pos[22][200200];
int q;
ll pre_sum[22][200200], suf_sum[22][200200];

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	r = 0;
	for(int i = 0; i < n; i++){
		while(r < n && a[r] - a[i] < k) r++;
		suf_pos[0][i] = r;
		suf_sum[0][i] = i;
	}
	l = n-1;
	for(int i = n-1; i >= 0; i--){
		while(l >= 0 && a[i] - a[l] < k) l--;
		pre_pos[0][i] = l;
		pre_sum[0][i] = i;
	}
	for(int i = 0; i < 20; i++){
		for(int j = 0; j < n; j++){
			pre_pos[i + 1][j] = (pre_pos[i][j] < 0) ? -1 : pre_pos[i][pre_pos[i][j]];
			pre_sum[i + 1][j] = (pre_pos[i][j] < 0) ? pre_sum[i][j] : (ll)(pre_sum[i][j] + pre_sum[i][pre_pos[i][j]]);
			suf_pos[i + 1][j] = (suf_pos[i][j] >= n) ? n : suf_pos[i][suf_pos[i][j]];
			suf_sum[i + 1][j] = (suf_pos[i][j] >= n) ? suf_sum[i][j] : (ll)(suf_sum[i][j] + suf_sum[i][suf_pos[i][j]]);
		}
	}
	cin >> q;
	while(q--){
		cin >> l >> r;
		l--, r--;
		int nl = l, nr = r;
		int l_ans = 1, r_ans = 1; 
		ll l_sum = 0, r_sum = 0;
		for(int i = 20; i >= 0; i--){
			if(suf_pos[i][nl] <= r){
				l_ans += (1 << i);
				l_sum += suf_sum[i][nl];
				nl = suf_pos[i][nl];
			}
		}
		l_sum += nl;
		for(int i = 20; i >= 0; i--){
			if(pre_pos[i][nr] >= l){
				r_ans += (1 << i);
				r_sum += pre_sum[i][nr];
				nr = pre_pos[i][nr];
			}
		}
		r_sum += nr;
		assert(l_ans == r_ans);
		cout << r_sum - l_sum + l_ans << endl;
	}
	return 0;
}

Measured memory_bytes: 102848
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

typedef vector<ll> vl;
typedef vector<vl> vvl;

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

	vvi con(N, vi());
	int a, b;
	REP(i, M) {
		cin >> a >> b;
		a--;
		b--;
		con[a].push_back(b);
		con[b].push_back(a);
	}

	queue<int> Q;
	Q.push(0);
	vi visited(N, 0);
	visited[0] = 1;
	while (!Q.empty()) {
		int p = Q.front();
		Q.pop();

		if (p == N - 1 && visited[p] <= 3) {
			cout << "POSSIBLE" << endl;
			return 0;
		}

		int l = con[p].size();
		REP(i, l) {
			int ne = con[p][i];
			if (visited[ne] == 0) {
				visited[ne] = visited[p] + 1;
				Q.push(ne);
			}
		}
	}

	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 13168
s = gets.chomp

ret = Array.new(s.length, 0)

last_r = 0
r = 0

(0..(s.length-1)).each do |i|
    if s[i] == "R"
        last_r = i
        r += 1
    elsif s[i] == "L"
        if (r > 0)
           ret[i-1] = (r+1) / 2
           ret[i] =  r / 2
        end
        index = (last_r - i).even? ? last_r : last_r + 1
        ret[index] += 1
        r = 0
    end
end

puts ret.join(" ")


Measured memory_bytes: 3196
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        int K = in.nextInt();
        int[] P = new int[N];
        int[] C = new int[N];
        for (int n = 0; n < N; n++)
            P[n] = in.nextInt() - 1;
        for (int n = 0; n < N; n++)
            C[n] = in.nextInt();

        int[] cycle = new int[N];
        long[] cycleSum = new long[N];
        long ans = -10000000000L;
        for (int n = 0; n < N; n++) {
            if (cycle[n] == 0) {
                Set<Integer> set = new HashSet<>();
                long sum = 0;
                for (int c = n; set.add(c); c = P[c])
                    sum += C[c];
                for (int c : set) {
                    cycle[c] = set.size();
                    cycleSum[c] = sum;
                }
            }
            long score = 0;
            int k = 0;
            if (cycleSum[n] <= 0) {
                k = cycle[n];
            } else if (K < cycle[n] * 2) {
                k = K;
            } else {
                score = (K / cycle[n] - 1) * cycleSum[n];
                k = K % cycle[n] + cycle[n];
            }
            long max = -10000000000L;
            for (int i = 0, c = n; i < k; i++) {
                c = P[c];
                score += C[c];
                max = Math.max(max, score);
            }
            ans = Math.max(ans, max);
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}


Measured memory_bytes: 38952
// Try CADDi 2018 for Beginners
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut n = get!();
    let mut ans = 0;
    while n > 0 {
    	if n % 10 == 2 {
        	ans += 1;
        }
        n /= 10;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352