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

public class Main{
	public static void main(String[] args)throws IOException{
		Print p = new Print();
		
		for(int i = 1; i <= 9; i++){
			for(int j = 1; j <= 9; j++){
				p.print((i + "x" + j + "=" + i * j + "\n").getBytes());
			}
		}
		p.close();
	}
}

class Print{
	private final OutputStream op = System.out;
	
	public void print(byte buffer[])throws IOException{
		op.write(buffer);
		op.flush();
	}
	public void close()throws IOException{
		op.close();
	}
}

Measured memory_bytes: 24136
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3560
unittest
{
	assert( [ "5", "24 11 8 3 16" ].parse.expand.solve == 3 );
	assert( [ "4", "5 5 5 5" ].parse.expand.solve == 0 );
	assert( [ "10", "33 18 45 28 8 19 89 86 2 4" ].parse.expand.solve == 5 );
	
	assert( [ "4", "5 5 6 6" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	as.sort();
	
	auto ans = 0L;
	auto ds = new bool[ 10L ^^ 6 + 1 ];
	LOOP: foreach( i, a; as )
	{
		if( i + 1 < as.length && as[ i ] == as[ i + 1 ] )
		{
			ds[ a ] = true;
		}
		
		auto s = cast( long ) a ^^ 0.5L;
		for( auto d = 1L; d <= s; d++ )
		{
			if( a % d != 0 ) continue;
			if( ds[ d ] || ds[ a / d ] )
			{
				continue LOOP;
			}
		}
		
		ds[ a ] = true;
		ans++;
	}
	return ans;
}


Measured memory_bytes: 12692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=100100100;
const int MOD=(int)1e9+7;
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<b; i++)

int main(){
    int s,w;
    cin>>s>>w;
    if(s>w){
        cout<<"safe"<<endl;
    }
    else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3584
A, B, C, X, Y = map(int, input().split())

ans = A*X + B*Y
for i in range(2, 2*max(X, Y)+1, 2):
    tmp = A*(max(0, X-i//2)) + B*(max(0, Y-i//2)) + C*i
    if tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int k = 100; k > 0; k--) {
		int tmp = 0;
		bool beet = true;
		for(int i = 0; i < n; i++) {
			tmp += a[i];
			if(tmp < k) {
				beet = false;
				break;
			}
			tmp -= k;
		}
		if(beet) {
			printf("%d\n", k);
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll x,y;
  cin >> x >> y;
  ll sum = 0;
  if(x >= 0 && y >= 0 && x <= y){
    sum = y-x;
  }
  else if(x >= 0 && y >= 0 && x > y){
    sum = x-y+2;
    if(y == 0)
      sum = x+1;
  }
  else if(x >= 0 && y < 0){
    sum = abs(abs(y)-abs(x))+1;
  }
 
  else if(x < 0 && y >= 0){
    sum = abs(abs(x)-abs(y))+1;
    if(y == 0)
      sum = abs(x);
  }
  else if(x < 0 && y < 0 && x <= y){
    sum = abs(y-x);
  }
  else if(x < 0 && y < 0 && x > y){
    sum = abs(abs(x)-abs(y))+2;
  }
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> multi_vector(size_t a){return vector<T>(a);}template<class T, class... Ts>auto multi_vector(size_t a, Ts... ts){return vector<decltype(multi_vector<T>(ts...))>(a, multi_vector<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}

/* ここからコード開始 */

int main(){
  kyopro;
  ll N, D;
  cin >> N >> D;
  vector<vector<ll>> zahyou(N, vector<ll>(D));
  for(auto&& i : zahyou){
    for(auto&& j : i){
      cin >> j;
    }
  }
  ll sum{};
  rep(i, 0, N){
    rep(j, i+1, N){
      ll sum1{};
      rep(k, 0, D){
        sum1 += (zahyou[i][k]-zahyou[j][k])*(zahyou[i][k]-zahyou[j][k]);
      }
      if((ll)round(pow(sum1, 0.5)) * (ll)round(pow(sum1, 0.5)) == sum1) sum++;
    }
  }
  cout << sum << rt;
}

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

public class StructuredProgramming
{
    //??\??????????????°????????§?????´??°??§3????????°????????????3?????????2????????°???????????????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int integer;
        int inputNum;
        int calculatedNum;
        /*---??£?¨???¨---*/

        /*??\????????????????????????*/
        inputNum = int.Parse(Console.ReadLine());

        /*3????????°????????????3???????????°?????????????????????*/
        for (integer = 1; integer <= inputNum; integer++){
            //3????????°????????????3?????????????????£???????????????????????????
            if (integer % 3 == 0){
                Console.Write(" {0}", integer);
            }
            else{  
                calculatedNum = integer;
                while (true){
                    if (calculatedNum % 10 == 3){
                        Console.Write(" {0}", integer);
                        break;
                    }
                    else if (calculatedNum == 0){
                        break;
                    }
                    calculatedNum = calculatedNum / 10;
                }
            }
        }
        Console.Write("\n");
    }
}

Measured memory_bytes: 9208
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
 	int a,b,c,d,e,f;//声明a，b，c，d，e，f 
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);//输入 
	int ans1=0,ans2=0;//总质量，糖质量 
	double rate=0.0;//糖水密度 
	for(int i=0;i*100*a<=f;++i)//枚举操作1次数 
	{
		for(int j=0;j*100*b+i*100*a<=f;++j)//枚举操作2次数 
		{
      		if(i+j==0) //如果
				continue;
      		int sum=j*100*b+i*100*a;//计算水的质量 
      		int lim=min(sum/100*e,f-sum);//取最小：需糖水的质量，剩下的空间 
      		for(int k=0;k*c<=lim;++k)//枚举操作3次数 
			{
    			int l=(lim-k*c)/d;//l=(lim-当前操作3次数)/操作4 
    			int sugar=l*d+k*c;//sugar=l*操作4+当前操作3次数 
    			if(double(sugar)/sum>rate)//sugar强制转换double型/水总质量>最大密度（寻找最大密度） 
				{
      				rate=double(sugar)/sum;//最大密度 
      				ans1=sum+sugar;ans2=sugar;//计算总质量，糖质量 
    			}
      		}
    	}
  	}
	if(rate==0)//如果最大密度为0 
		printf("%d %d\n",100*a,0);//总质量为操作1的水（操作几都无所谓，因为密度都为0），糖为0  
  	else 
	  	printf("%d %d\n",ans1,ans2);//输出总质量，糖质量 
  return 0;
}

Measured memory_bytes: 128
import numpy as np
def resolve():
    s = np.array(list(input()))
    t = np.array(list(input()))

    dp = np.zeros([len(s) + 1, len(t) + 1], dtype=np.int64)

    match = s.reshape(-1, 1) == t.reshape(1, -1)

    for i in range(len(s)):
        dp[i + 1][1:] = np.maximum(dp[i][:-1] + match[i], dp[i][1:])
        dp[i + 1] = np.maximum.accumulate(dp[i + 1])

    res = ''
    i = len(s)
    j = len(t)

    while i > 0 and j > 0:
        if dp[i][j] == dp[i - 1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j - 1]:
            j -= 1
        elif dp[i][j] == dp[i - 1][j - 1] + 1:
            res = s[i - 1] + res
            i -= 1
            j -= 1

    print(res)
    
resolve()

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

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ifaxb(a, x, b) if (a < x && x < b)
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vi p(n);
    rep(i, 0, n) {
        cin >> p[i];
    }
    int ans = 0;
    rep(i, 1, n - 1) {
        ifaxb(p[i - 1], p[i], p[i + 1]) ans++;       // pi-1<pi<pi+1
        else ifaxb(p[i + 1], p[i], p[i - 1]) ans++;  // pi+1<pi<pi-1
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char t1[1510];
char t2[1510];
char t3[1510];
int main(){
    int n;
    int a,b;
    int i,j;
    char t;
    scanf("%s",&t1);
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",&t3);
        if(strcmp(t3,"replace")==0){
            scanf("%d %d %s",&a,&b,&t2);
            for(j=0;j<b-a+1;j++){
                t1[a+j]=t2[j];
            }
        }
        else if(strcmp(t3,"reverse")==0){
            scanf("%d %d",&a,&b);
            while(a<b){
                t=t1[a];
                t1[a]=t1[b];
                t1[b]=t;
                a++;
                b--;
            }
        }
        else if(strcmp(t3,"print")==0){
            scanf("%d %d",&a,&b);
            for(j=a;j<b+1;j++){
                printf("%c",t1[j]);
            }
            puts("");
        }
    }
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>

using ll = long long;

int main()
{
    std::vector<int> in(3);
    for (int i = 0; i < 3; i++)
    {
        std::cin >> in[i];
    }

    std::sort(in.begin(), in.end());
    std::cout << in[2] * 10 + in[1] + in[0] << std::endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    string S;
    cin >> S;
    sort(ALL(S));
    cout << (S == "abc" ? "Yes" : "No") << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
//Referred Professors code
import java.util.Scanner;
 
public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] aa = new int[n];
		for (int i=0; i<n; i++)
			aa[i] = sc.nextInt();
		int gap = aa[0] + k - aa[n-1];
		for (int i = 1; i < n; i++)
			gap = Math.max(gap, aa[i]-aa[i-1]);
		System.out.println(k-gap);
	}
}

Measured memory_bytes: 78616
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238 


long long binpow(long long a, long long b) {
    a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
void solve(){
    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC\n";
    else cout<<"ABC\n";
}   
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }    
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                a[i]--;
            }
            for (int i = 0; i < n; i++)
            {
                if (a[a[i]] == i) ans++;
            }
            Console.WriteLine(ans/2);
        }
    }
}


Measured memory_bytes: 10968
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int T =sc.nextInt();
        int result=0;
       
       
        
        int cost[] = new int[N];
        int time[] = new int[N];
        
        for(int i=0;i<N;i++){
            cost[i]=sc.nextInt();
            time[i]=sc.nextInt();
        }
        
        int Min=cost[0];
        
        for(int j=0;j<N;j++){
            if(T>=time[j]){
                if(Min>cost[j]){
                    Min=cost[j];
                }
                result=1;
            }

        }
        
        if(result==0){
            System.out.println("TLE");
        }else{
            System.out.println(Min);
        }
        
    }
}


Measured memory_bytes: 35532
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int A,B;

int main(){
	cin>>A>>B;
	if(A<=B){
		cout<<"Impossible"<<endl;
		return 0;
	}
	int B_=B,t=1;
	vi a;
	a.push_back(0);
	while(a.size()<=B_){
		cout<<"? "<<a.back()<<' '<<t<<endl;
		char c;
		cin>>c;
		if(c=='Y') a.push_back(t),t++;
		else{
			a.pop_back();
			t++;B_--;
			if(a.empty()) a.push_back(t++);
		}
	}
	int x=a.back();
	string s="!";
	for(int i=0;i<A+B;i++){
		cout<<"? "<<x<<' '<<i<<endl;
		char c;
		cin>>c;
		if(c=='Y') s+='1';
		else s+='0';
	}
	cout<<s<<endl;
}

Measured memory_bytes: 724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new int[26];
            var w = Console.ReadLine();
            foreach (var c in w)
            {
                a[(int) (c - 'a')]++;
            }
            var flag = true;
            foreach (var b in a)
            {
                if (b%2 != 0)
                {
                    flag = false;
                    break;
                }
            }
            Console.WriteLine(flag ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 2648
N = int(input())
A = list(map(int, input().split())) 

A.sort()
counter = 0
for i in A:
  second = [m for m in A if i < m]
  for j in second:
    third = [n for n in second if j < n]
    if len(third) > 0:
      for k in third:
        if i + j > k:
          counter += 1
print(counter)

Measured memory_bytes: 9180
import sys
input = sys.stdin.readline
N = int(input())
ts = list(map(int, input().split())) + [0]
vs = list(map(int, input().split())) + [0]
cst = [0] * (N + 1)
for i in range(N): cst[i + 1] = cst[i] + ts[i]

def check(l, r, ti, x):
  return ((x - l) + max(0, x - r)) <= ti
ps = set()
dp = [0] * (N + 1)
#print(cst)
for i in range(N):
  ok = 0
  ng = vs[i] + 0.1 ** 12
  l = min(dp[i], vs[i])
  r = min(vs[i + 1], cst[-1] - cst[i + 1])
  for j in range(i + 1, N): r = min(r, vs[j] + (cst[j] - cst[i + 1]))
  ti = ts[i]
  while ng - ok > 0.1 ** 12:
    m = (ok + ng) / 2
    if check(l, r, ti, m): ok = m
    else: ng = m
  if (cst[-1] - (abs(ok - l) + cst[i])) <= ok:
    ng = ok + 0
    ok = 0
    while ng - ok > 0.1 ** 12:
      m = (ok + ng) / 2
      if abs(l - m) + m <= cst[-1] - cst[i]: ok = m
      else: ng = m
    ps.add((cst[-1] - ok, ok))
    break
  ps.add((abs(ok - l) + cst[i], ok))
  ps.add((cst[i + 1] - max(0, ok - r), ok))
  #print(ok, ng, l, r, cst[i + 1])
  dp[i + 1] = min(ok, r)

ps.add((0, 0))
ps.add((cst[-1], 0))
#print(ps)
sps = sorted(ps, key = lambda x: x[0])
res = 0
for i in range(len(sps)):
  res += sps[i][0] * sps[i - 1][1] - sps[i][1] * sps[i - 1][0]
print(abs(res) / 2)

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

int main(void) {
    int A,B;cin>>A>>B;
    if ((B - 1) % (A - 1) == 0) cout << (B - 1) / (A - 1) << endl;
    else cout << (B - 1) / (A - 1) + 1 << endl;
    return 0;
}

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

string s;
ll ans = 0;

int main(){
    cin >> s;
    ll N = s.size();
    ll i = 0, num = 0;
    while(i < N){
        if(s[i] == 'A') num++;
        else num = 0;
        if(i + 2 < N){
            if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
                ans += num;
                s[i+2] = 'A';
                num--;
                i++;
            }
        }
        i++;
    }
    cout <<  ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
using namespace std;

int main() {
	int N, K; cin >> N >> K;
	int a = 1;
	for (int i = 0; i < N; ++i) {
		a = min(a + K,2 * a);
	}
	cout << a << endl;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string s;
    cin >> s;

    int cnt[2][2];
    array_fill(cnt, 0);

    rep(i, s.size()){
        ++ cnt[i % 2][s[i] - '0'];
    }

    cout << min(cnt[0][0] + cnt[1][1], cnt[0][1] + cnt[1][0]) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define REP(i,p,n) for(int i=p;i<n;++i)
#define rep(i,n) REP(i,0,n)

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<pii> vpii;
typedef vector<vint> det1;
typedef vector<vpii> det2;


int main()
{
    int N;
    string A, B, C;

    cin >> N;
    cin >> A >> B >> C;

    int ans = 0;

    rep(i, N)
    {
        int res = 0;

        if (A[i] != B[i] && A[i] != C[i] && B[i] != C[i]) { ans += 2; }
        else if (A[i] != B[i] && A[i] == C[i] && B[i] == C[i]) { ++ans; }
        else if (A[i] == B[i] && A[i] != C[i] && B[i] == C[i]) { ++ans; }
        else if (A[i] == B[i] && A[i] == C[i] && B[i] != C[i]) { ++ans; }
        else if (A[i] == B[i] && A[i] != C[i] && B[i] != C[i]) { ++ans; }
        else if (A[i] != B[i] && A[i] == C[i] && B[i] != C[i]) { ++ans; }
        else if (A[i] != B[i] && A[i] != C[i] && B[i] == C[i]) { ++ans; }

        // cout << i << ": " << A[i] << B[i] << C[i] << " "<< ans << endl;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<string,int> P;
 
bool check(string a,string b){
    for(int i = 0 ; i < 8 ; i++){
	if(b[i] != '*' && a[i] != b[i]){
	    return false;
	}
    }
    return true;
}
 
int main(){
    int n,m;
 
    while(cin >> n >> m ,(n | m)){
	P a[n];  
	string b;
 
	for(int i = 0 ; i < n ; i++){
	    cin >> a[i].first >> a[i].second;
	}
 
	int ans = 0;
	for(int i = 0 ; i < m ; i++){
	    cin >> b;
	    for(int j = 0 ; j < n ; j++){
		if(check(b,a[j].first)){
		    ans += a[j].second;
		    break;
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  string s;
  cin>>s;
  if(s!="AAA" && s!="BBB") co("Yes");
  else co("No");
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int prime[200000] = {2};
int len = 1;

int main(void)
{
    int n;
    int i, j;

    for (i = 3; i < 999999; i += 2){
        for (j = 3; j * j < i && i % j; j += 2);
        if (j * j > i) prime[len++] = i;
    }

    while (scanf("%d", &n) != EOF){
        for (i = 0; i < len && prime[i] <= n; ++i);
        printf("%d\n", i);
    }

    return (0);
}

Measured memory_bytes: 904
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
 
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
signed main(){
    int x;cin>>x;
    if(x<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int, readline().split())
*a, = map(int, readline().split())
*b, = map(int, readline().split())
*c, = map(int, readline().split())

a.sort()
c.sort()

from bisect import bisect_left, bisect_right

ans = 0
for bi in b:
    ans += bisect_left(a,bi) * (n-bisect_right(c,bi))

print(ans)





Measured memory_bytes: 109176
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

string s[9]={".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

int main(){
  int n;
  string input;
  
  cin >> n;
  
  for(int i=0; i<n; i++){
    char output[76] = "";
    cin >> input;
    char num = '0';
    int kaisu = 0;
    int outlength = 0;
    
    for(int j=0; j<(int)input.length(); j++){
      if(input[j] != '0'){
	num = input[j];
	kaisu++;
      }else if(input[j] == '0' && kaisu != 0){
	output[outlength] = s[atoi(&num)-1][(kaisu-1)%s[atoi(&num)-1].length()];
	kaisu = 0;
	num = '0';
	outlength++;
      }
    }
    output[outlength] = '\0';
    cout << output << endl;
  }
  return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	while (a > 0 || b > 0) {
	    for (int i = 0; i < a; i++) {
	        for (int o = 0; o < b; o++) {
	            cout << "#";
	        }
	        cout << endl;
	    }
	    cout << endl;
	    cin >> a >> b;
	}
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A, B; cin >> N >> A >> B;
  if(A%2 == B%2){
    cout << (B - A)/2 << endl;
    return 0;
  }else{
    ll ans1 = A + (B - A -1) / 2;
    ll ans2 = N - B + 1 + (B - A - 1) / 2;
    cout << min(ans1, ans2) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> v(n,0);
  int ans_w=0;
  int ans_a=0;
  for(int i=1;i<=m;i++){
    int p;
    string s;
    cin>>p>>s;
    if(v[p-1]<=0 & s=="WA"){
      v[p-1]-=1;
    }
    else if(v[p-1]<=0 & s=="AC"){
      ans_a+=1;
      ans_w+=v[p-1]*(-1);
      v[p-1]=1;
    }
  }
  cout<<ans_a<<" "<<ans_w<<endl;
  return 0;
}

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

void check ( ll x, int& cnt ) {
    bool flg3 = 0;
    bool flg5 = 0;
    bool flg7 = 0;
    bool flgo = 0;
    while(1) {
        if ( x == 0 ) {
            break;
        }
        if ( x % 10 == 3 ) {
            flg3 = 1;
        }
        else if ( x % 10 == 5 ) {
            flg5 = 1;
        }
        else if ( x % 10 == 7 ) {
            flg7 = 1;
        }
        else {
            flgo = 1;
        }
        x /= 10;
    }
    if ( !flgo && flg3 && flg5 && flg7 ) {
        ++cnt;
    }
    return;
}

void dfs ( ll x, int& cnt, ll n ) {
    if ( x <= n ) {
        check ( x, cnt );
        dfs(10 * x + 3, cnt, n);
        dfs(10 * x + 5, cnt, n);
        dfs(10 * x + 7, cnt, n);
    }
    return;
}


int main(){
    ll n;
    cin >> n;
    int cnt = 0;
    dfs(0LL, cnt, n);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
//Md.Tahsin Amin
//Atcoder
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main(){
 int a,b;
    cin>>a>>b;
    if(a>0&&a<10&&b>0&&b<10)
    {
    int result=a*b;
     cout<<result<<endl;
}
    else
    cout<<"-1"<<endl;
    
    

    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 99999999
using namespace std;

int main() {
    int k,tmp;
    long long ans = 0;
    cin >> k;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int l = 1; l <= k; ++l) {
                tmp = std::__algo_gcd(i,j);
                tmp = std::__algo_gcd(tmp,l);
                ans += tmp;
            }

        }

    }
    cout << ans << endl;
}

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

int main(){
	int n;cin>>n;
	string ss;cin>>ss;
	int r=0,b=0;
	for(int i=0;i<n;i++) {
        if(ss[i]=='R') r++;
        else b++;
	}
	puts(r>b?"Yes":"No");
	return 0;
}





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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    REP(i, n + 1) REP(j, n + 1) {
        int k = n - i * r - j * g;
        if (k >= 0 and k % b == 0) ans++;
    }
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn main() {
    let (n, m) = {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut it = buf.split_whitespace();
        (usize::from_str(it.next().unwrap()).unwrap(),
        usize::from_str(it.next().unwrap()).unwrap())
    };
    let mut av: Vec<bool> = vec![true; n + 1];
    for _ in 0..m {
        let mut a = String::new();
        io::stdin().read_line(&mut a).unwrap();
        let an: usize = a.trim_right().parse().unwrap();
        av[an] = false;
        if av[an] && av[an - 1] {
            println!("0");
        }
    }
    let mut dp: Vec<u64> = vec![0; n + 1];
    dp[0] = 1;
    for now in 0..n {
        let st = now + 1;
        let ed = std::cmp::min(n, now + 2) + 1;
        for next in st..ed {
            if av[next] {
                dp[next] += dp[now];
                dp[next] %= 1000000007;
            }
        }
    }
    println!("{}", dp[n]);
}

Measured memory_bytes: 4352
N, C = map(int, input().split())
TV = [[0]*(2*10**5) for i in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    TV[c-1][2*s-2] += 1
    TV[c-1][2*t-1] -= 1

for i in range(C):
    for j in range(1, 2*10**5):
        TV[i][j] = TV[i][j]+TV[i][j-1]

for i in range(C):
    for j in range(1, 2*10**5):
        TV[i][j] = min(1, TV[i][j])

ans = 0
for i in range(2*10**5):
    tmp = 0
    for j in range(C):
        tmp += TV[j][i]
    ans = max(ans, tmp)
print(ans)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    ll a;
    string b;
    cin >> a >> b;
    b.erase(find(all(b), '.'));
    ll ans = a * stoi(b) / 100;
    cout << ans << endl;
    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    for(int n = 0; n < 10000; n++) {
        int za = n * 8 / 100;
        int zb = n * 10 / 100;
        if(A == za && B == zb) {
            cout << n << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	sort(a.begin(), a.end());
	bitset<1 << 22> possible;
	possible[0] = true;
	for(const int x : a){ possible = possible | (possible << x); }
	const int sum = accumulate(a.begin(), a.end(), 0);
	int answer = (sum + 1) / 2;
	while(!possible[answer]){ ++answer; }
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 2304
X, K, D = map(int, input().split())

if K * D < abs(X):
    if X < 0:
        print(abs(X + K * D))
    else:
        print(X - K * D)
else:
    a = abs(X // D)
    if (K - a) % 2 == 0:
        print(X % D)
    else:
        print(abs(X % D - D))


Measured memory_bytes: 61604
import java.util.*;

public class Main{
	
	public static int[][] table;
	public static int[] depth;
	public static int[] first;
	public static int time =1;
	
	public static void dfs(int v) {
		depth[v] = time;
		time++;
		int j =0;
		while (table[v][j] != 0) {
			if (depth[table[v][j]] ==0) {
				dfs(table[v][j]);
				
			}
			j++;
		}
		first[v] = time;
		time++;
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		table = new int [input+1][100];
		depth = new int [input+1];
		first = new int [input +1];
		
		for (int i=1; i<=input; i++) {
			
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int j=0; j< k; j++) {
				int v = sc.nextInt();
				table[u][j] = v;
				
				
			}
		}
		for (int k=1; k<= input; k++) {
			
			if (depth[k]==0) {
				dfs(k);
				
			}
		}
		for (int l=1; l<=input; l++) {
			
			System.out.println(l+ " " + depth[l] + " " + first[l]);
		}
		
		
	}

}



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

int main() {
  int s; cin >> s;
  map<int, int> P;
  int i = 1;
  while (true) {
    if (P[s] != 0) {
      cout << i << endl;
      break;
    } else {
      P[s]++;
      if (s % 2 == 0) {
        s /= 2;
      } else {
        s = s * 3 + 1;
      }
    }
    i++;
  }
}
      

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int X = sc.nextInt();

    int[] m = new int[N];

    for (int i = 0; i < N; i++) {
      m[i] = sc.nextInt();
    }

    sc.close();

    int count = 0;
    int min = 1001;

    for (int i = 0; i < N; i++) {
      count++;
      min = Math.min(min, m[i]);
      X -= m[i];
    }
    
    System.out.println(count + X / min);

  }

}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int ans=0;
  REP(i,N){
    int a;
    cin>>a;
    if(i%2==0 and a%2==1)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

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

int main(){
	while(1){
		int n = in.nextInt();
		if(n == 0) return 0;
		vi v(n), u(n-1);
		rep(i, n) v[i] = in.nextInt();
		rep(i, n-1) u[i] = in.nextInt();


		ll sv = 0LL;
		rep(i, n) sv += v[i];
		sort(rall(u));
		ll ans = sv * n;
		ll su = 0LL;
		for(int i = 0; i < n-1; i++){
			su += u[i];
			ans = max(ans, (sv+su)*(n-i-1));
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1532
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readInts >>= print . uncurry solve . mp

solve 0 _ = 0
solve n k = 1 + solve ( n `div` k ) k

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

long long int goodSequence(int a[], int n, int k)
{
    long long int ans = 0;
    map<int, int> cnt;

    vector<int> pref;
    pref.push_back(0);
    for(int i = 0; i < n; i++) pref.push_back((a[i] + pref[i]) % k);

    cnt[0] = 1;

    for(int i = 1; i <= n; i++)
    {
        int remIdx = i - k;
        if(remIdx >= 0)
        {
            cnt[(pref[remIdx] - remIdx % k + k)%k]--;
        }
        ans += cnt[(pref[i] - i % k + k) % k];
        cnt[(pref[i] - i % k + k) % k]++;
    }
    return ans;
}

int main()
{
    

   /* int a[] = {4, 2, 4, 2, 4, 2, 4, 2};
    int n = sizeof(a) / sizeof(a[0]);

    int k = 4;*/

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];

    cout << goodSequence(a, n, k);
    
    return 0;
}



Measured memory_bytes: 14312
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

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

  double V = a * a * b;
  if (x <= V / 2) {
    double ans = atan(a * b * b / (2.0 * x)) / M_PI * 180.0;
    printf("%.14f\n", ans);
  } else {
    x = V - x;
    double ans = atan(2.0 * x / pow(a, 3)) / M_PI * 180.0;
    printf("%.14f\n", ans);
  }
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        int a = sn.nextInt();
        int b = sn.nextInt();
        System.out.println(String.format("%d %d", a * b, 2 * (a + b)));
    }
}

Measured memory_bytes: 17332
inf = 10**9
 
S = int(input())
 
if S == 10 ** 18:
    print(0, 0, inf, 0, inf, inf)
else:
    S1 = S // inf + 1
    S2 = inf - (S % inf)
 
    print(0, 0, S1, 1, S2, inf)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int l=0,h=n-1;
    int c=0;
    while(l<n && h>=0 &&l<h)
    {
        while(l<n && s[l]=='R')
        {
            l++;
        }
        while(h>=0 && s[h]=='W')
        {
            h--;
        }
        if(l<n && h>=0 &&l<h)
         {
             swap(s[l],s[h]);
             c++;
         }
    }
    cout<<c;
}



Measured memory_bytes: 3756
h,w = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())


from collections import deque

def solve(x,y):
    dx = [1, 0]
    dy = [0, 1]

    start = [x, y]
    dist = [[10**3]*w for i in range(h)]
    dist[y][x] = 0
    Q = deque()
    Q.append([start,l[0][0]])
    mx = 0

    while Q:
        p,color = Q.popleft()
        for i in range(2):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < w and 0 <= ny < h:
                if l[ny][nx]!=color:
                    cost=1
                else:
                    cost=0
                if dist[ny][nx] > dist[p[1]][p[0]] + cost:
                    Q.append([[nx, ny],l[ny][nx]])
                    dist[ny][nx] = dist[p[1]][p[0]] + cost
    return dist

dist=solve(0,0)
if l[0][0] == "#" or l[-1][-1]=="#":
    print(1+dist[-1][-1]//2)
else:
    print(dist[-1][-1]//2)

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





int main() {
  int N;
  cin>>N;
  vector<int> data(N);
  for (int i;i<N;i++){
    cin>>data.at(i);
  }
  
  int check=1;
    
    for (int i;i<N;i++){
      check=data.at(check-1);
      if (check==2){
        cout<<i+1<<endl;
        break;
      }
    }
  if (check!=2){
    cout<<-1<<endl;
  }
    
    
  
  
}













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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i)
		cin >> d[i];
	sort(d.begin(), d.end());
	int ans = d[n / 2] - d[n / 2 - 1];
	if (ans) cout << ans << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 640
n,m = map(int,input().split())
z = [[]for i in range(0,8)]
for i in range(0,n):
    X,Y,Z = map(int,input().split())
    z[0].append(X + Y + Z)
    z[1].append(X + Y - Z)
    z[2].append(X - Y + Z)
    z[3].append(-X + Y + Z)
    z[4].append(X - Y - Z)
    z[5].append(-X + Y - Z)
    z[6].append(-X - Y + Z)
    z[7].append(-X - Y - Z)
for i in range(0,8):
    z[i].sort()
    z[i].reverse()
ans = 0
for i in range(0,8):
    ans = max(ans,sum(z[i][0:m]))
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <cstring>
using namespace std;
char s[100005];
int main()
{
	cin >> s;
	int ans = 0;
	for(int i = 0;i < strlen(s)-1;i++)
	if(s[i]!=s[i+1])
	ans++;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

const int mod = (int)1e9 + 7, LOG = 60;
int dp[LOG][2][2][2];
ll l, r;

int add(int _a, int _b) {
    _a += _b;
    if (_a >= mod) _a -= mod;
    return _a;
}

int calc(int i, bool down, bool up, bool nonZero) {
    if (i == -1) return 1;
    int &ret = dp[i][down][up][nonZero];
    if (ret != -1) return ret;
    ret = 0;

    int lX = 0, rX = 1, lY = 0, rY = 1;
    if (!down) lX = (l >> i) & 1;
    if (!up) rY = (r >> i) & 1;

    for (int x = lX; x <= rX; ++x) {
        for (int y = lY; y <= rY; ++y) if (x <= y && (nonZero || x == y) ) {
            ret = add(ret, calc(i - 1, down | (x > lX), up | (y < rY), nonZero | (x > 0) ) );
        }
    }
    return ret;
}

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

    cin >> l >> r;
    memset(dp, -1, sizeof dp);
    cout << calc(LOG - 1, 0, 0, 0);

    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    Lmax = 0; Rmin = N+1
    for _ in range(M):
        L, R = map(int, input().split())
        Lmax = max(L, Lmax)
        Rmin = min(R, Rmin)
    ans = max(0, Rmin-Lmax+1)
    print(ans)
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back             
#define se second                
#define fi first  
#define be begin()
#define en end()
#define all(v) v.be, v.en
// template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
// template<typename... T> void po(T... args) { ((cout << args << " "), ...); cout<<""; }

 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
     int test=1;
     //cin>>test;
     for(int tt=1; tt<=test; tt++){
       ll n;
       cin>>n;
       ll ans=n%1000;
       ans=1000-ans;
       ans%=1000;
       cout<<ans<<endl;
     //cout<<"Case #"<<tt<<": ";  
     }
 
    return 0;
}

Measured memory_bytes: 3636
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()

ans = 1
start = T[0]
cnt = 1
for i in range(1, N):
    cnt += 1
    if T[i] > start + K or cnt > C:
        ans += 1
        cnt = 1
        start = T[i]

print(ans)


Measured memory_bytes: 7444