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

using ll = long long;
using p = pair<ll, ll>;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 998244353;

int main(void) {
  ll N, S;
  cin >> N >> S;
  vector<ll> A(N);
  for (auto&& a : A) {
    cin >> a;
  }

  // Tを荷物候補、UをTの中から選ばれた荷物の集合と考える。
  vector<vector<ll> > dp(N + 1, vector<ll>(S + 1, 0));
  dp[0][0] = 1;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j] * 2; // そもそもTに選ばれるかどうかで2パターン分岐する。Tに入る or 入らないなので。
      dp[i][j] %= MOD;

      if (j + A[i - 1] > S) {
        continue;
      }

      dp[i][j + A[i - 1]] += dp[i - 1][j]; // Uに選んだら、スコアが A[i - 1] 増える。その状況に到達できるパターン数は dp[i - 1][j] 増える。
      dp[i][j + A[i - 1]] %= MOD;
    }
  }

  cout << dp[N][S] << endl;
  
  return 0;
}


Measured memory_bytes: 73748
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        n = int(input())
        a = list(map(int, input().split()))

        even_plus_ans = 0
        before = a[0]
        if a[0] <= 0:
            even_plus_ans -= a[0] - 1
            before = 1

        for i in range(1, n):
            if i % 2 == 0:
                v = a[i] + before
                if v > 0:
                    before = v
                elif v <= 0:
                    before = 1
                    even_plus_ans -= v - 1
            else:
                v = a[i] + before
                if v < 0:
                    before = v
                elif v >= 0:
                    before = -1
                    even_plus_ans += v + 1

        odd_plus_ans = 0
        before = a[0]
        if a[0] >= 0:
            odd_plus_ans += a[0] + 1
            before = -1

        for i in range(1, n):
            if i % 2 != 0:
                v = a[i] + before
                if v > 0:
                    before = v
                elif v <= 0:
                    before = 1
                    odd_plus_ans -= v - 1
            else:
                v = a[i] + before
                if v < 0:
                    before = v
                elif v >= 0:
                    before = -1
                    odd_plus_ans += v + 1

        print(min(even_plus_ans, odd_plus_ans))


# Run main
if __name__ == '__main__':
    AtCoder().main()


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()
#define Foreach(item,collection) for(auto item : collection)

using pii=pair<int,int>;
using vb=vector<bool>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
using ulong=unsigned long;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
#define OCB(c) (c&1)|(c&2)<<2|(c&4)<<4|(c&8)<<6|(c&16)<<8|(c&32)<<10|(c&64)<<12|(c&128)<<14

int main(){
    long X,Y;
    cin >> X>>Y;
    auto k=X;
    if(X%Y==0){
        out(-1)
    }else{
        out(X);
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
  string A,B,C; cin>>A>>B>>C;
  if(A[A.length()-1]==B[0]&&B[B.length()-1]==C[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<cstring>
#include<algorithm>
#define PI 3.141592653589793238462643383279 
using namespace std;
int main()
{
	double ans;
	double n;
	cin>>n;
	ans=2*PI*n;
	printf("%.20lf",ans);
	return 0;
 } 

Measured memory_bytes: 3780
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let vec: Vec<u32> = read_split_line();
    if vec[0] > vec[1] {
        println!("{}", "safe");
    } else {
        println!("{}", "unsafe");
    }
}

#[allow(dead_code)]
fn read_elem<T: FromStr>() -> T {
    let mut l = String::new();
    stdin().read_line(&mut l).unwrap();
    l.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_n_elems<T: FromStr>() -> Vec<T> {
    let n = read_elem::<u32>();
    let mut vec: Vec<T> = vec![];
    for _i in 0..n {
        vec.push(read_elem::<T>());
    }
    vec
}

#[allow(dead_code)]
fn read_split_line<T: FromStr>() -> Vec<T> {
    let mut l = String::new();
    stdin().read_line(&mut l).unwrap();
    l.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 2136
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21
int x[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int y[8] = {1, 0, -1, 1, -1, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum ^= a[i];
  }
  if (sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 1024
#標準入力
a,b = map(int,input().split())

#aの絶対値をbの絶対値で割った商をcに代入する
c = abs(a) // abs(b)

#a*bが負の数なら-c正の数ならcを出力する
print(-c if a * b < 0 else c)


Measured memory_bytes: 5592
import scala.io.Source

object Main {

  def abs(n1: Int, n2: Int): Int = {
    val diff = n1 - n2
    if (diff < 0) -diff else diff
  }

  def main(args: Array[String]) {
    val nodes = Source.stdin.getLines.toSeq.head.split(" ").map(_.toInt).toSeq
    val (car, cdr) = nodes match {
      case car +: cdr => (car, cdr)
    }
    val edges = nodes.zip(cdr :+ car).map {
      case (n1, n2) => abs(n1, n2)
    }
    println(edges.sorted.dropRight(1).sum)
  }

}

Measured memory_bytes: 25540
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1, 0,-1, 1,-1, 1, 0,-1};
const int dy[] = {1, 1, 1, 0, 0,-1,-1,-1};


const double EPS = 1e-9;

int main(){
    while(true){
        int H,W;
        cin >> H >> W;
        if(H == 0) break;
        vector<string> donut(H);
        for(int i=0;i<H;i++){
            cin >> donut[i];
        }
        map<string,int> spells;
        for(int y=0;y<H;y++){
            for(int x=0;x<W;x++){
                for(int i=0;i<8;i++){
                    string spell = "";
                    int nx = x,ny = y;
                    set<pair<int,int> > alr;
                    while(alr.find(make_pair(ny,nx)) == alr.end()){
                        alr.insert(make_pair(ny,nx));
                        spell += donut[ny][nx];
                        if(spell.length() > 1)
                            spells[spell]++;
                        ny += dy[i];
                        nx += dx[i];
                        if(ny < 0) ny = H-1;
                        if(ny >= H) ny = 0;
                        if(nx < 0) nx = W-1;
                        if(nx >= W) nx = 0;
                    }
                }
            }
        }
        string maxi = "0";
        for(map<string,int>::iterator it=spells.begin();it!=spells.end();++it){
            if((*it).second > 1){
                if(maxi.length() == (*it).first.length()){
                    maxi = min(maxi,(*it).first);
                }else if(maxi.length() < (*it).first.length()){
                    maxi = (*it).first;
                }
            }
        }
        cout << maxi << endl;
    }
    return 0;
}

Measured memory_bytes: 36208
using System;
using System.Linq;

namespace ABC085_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NY = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NY[0];
            var Y = NY[1];

            var numi = -1;
            var numg = -1;
            var nums = -1;

            for (int i = 0; i <= N; i++)
            {
                for (int g = 0; g <= N; g++)
                {
                    var tmps = N - i - g;
                    if (Y == 10000*i + 5000*g + 1000*tmps && tmps >= 0)
                    {
                        numi = i;
                        numg = g;
                        nums = tmps;
                        break;
                    }
                    if (numi != -1) break;
                }
            }
            Console.WriteLine($"{numi} {numg} {nums}");
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
  int k,a,b,flag=0;
  cin>>k;
  cin>>a>>b;
  for(int i=a;i<=b;i++)
  {
      if(i%k==0)
      {
          flag=1;
          break;
      }
  }
  if(flag==1) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<pair<long int,long int> > v;

int N,M;
int main (){
    cin >> N >> M;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        v.push_back(make_pair(x,1));
    }
    for(int i=0; i<M; i++) {
        int b,c;
        cin >> b >> c;
        v.push_back(make_pair(c,b)); // val stock
    }
    sort(v.rbegin(),v.rend());
    long long int ans = 0;
    long long int limit = 0;
    int i=0;
    while(limit < N) {
        if( limit + v[i].second <= N ) {
            ans += v[i].first * v[i].second;
            limit += v[i].second;
        } else {
            ans += v[i].first * (abs(N - limit)) ;
            cout << ans << endl;
            return 0;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6384
import java.io.*;
import java.util.*;

public class Main implements Runnable {

    long[] ans;
    long[] vSum;
    int N;
    ArrayList<Integer>[] edges;
    private void solve() throws IOException {

        N = nextInt();
        int Q = nextInt();
        vSum = new long[ N + 1];
        edges = new ArrayList[N+1];
        ans = new long[N + 1];
        for(int i = 0; i <= N; ++i) {
            edges[i] = new ArrayList<>();
        }
        for(int i = 0; i < N - 1; ++i) {
            int a = nextInt();
            int b = nextInt();
            edges[a].add(b);
        }

        for(int i = 0; i < Q; ++i) {
            int p1 = nextInt();
            long x2 = nextLong();
            vSum[p1] += x2;
        }
        dfs(1, 0L);
        writer.print(ans[1]);
        for(int i = 2; i <= N; ++i) {
            writer.print(" " + ans[i]);
        }
        writer.println();

    }

    public void dfs(int v, long sum) {
        ans[v] = vSum[v] + sum;
        for(int child : edges[v]) {
            dfs(child, ans[v]);
        }
    }

    public static void main(String[] args) {

        new Main().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//            reader = new BufferedReader(new FileReader("a_1.txt"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
//            writer = new PrintWriter("aa_1.txt");
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while(tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }
}


Measured memory_bytes: 148992
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n, m;
    std::cin >> n >> m;
    long long sum = 0;
    for(int i = 0; i < m; i++){
        int tmp;
        std::cin >> tmp;
        sum += tmp;
    }

    if(sum > n){
        std::cout << -1 << std::endl;
    }else{
        std::cout << n - sum << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3676
import math 
a,b,h,m=map(int, input().split())
p=360*(h/12+m/(12*60))
q=360*(m/60)
if(p>=q):
    r=p-q
else:
    r=q-p
if(r>180):
    r=360-r
#print(p,q,r)
rad=math.radians(r)
cos=math.cos(rad)
c=a*a+b*b-2*a*b*cos
c2=math.sqrt(c)
#print(rad,cos,c)
print(f"{c2:.10f}")


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

#define MAX_N 200000

using namespace std;

set <int> lin[MAX_N + 1];
set <int> col[MAX_N + 1];

int rez;

int n;
int h, w;

void readFile()
{
    cin >> h >> w >> n;

    int i;
    int a, b;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a >> b;
        lin[a].insert(b);
        col[b].insert(a);
    }

    for(int i = 1; i <= w; i ++)
        col[i].insert(h + 1);
}

void solve()
{
    rez = h + w;

    int l = 1;
    int c = 1;
    int cr = 0;

    while(l <= h && c <= w)
    {
        set <int> :: iterator it = col[c].lower_bound(l);

        rez = min(rez, (*it) - l + cr);

        cr ++;
        l ++;

        if(c < w && col[c + 1].find(l) == col[c + 1].end())
            c ++;
    }
}

void printFile()
{
    cout << rez << "\n";
}

int main()
{
    readFile();

    solve();

    printFile();

    return 0;
}


Measured memory_bytes: 47104
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)
#define str string 
#define rtn return 
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vll;
typedef vector < pair<int,int> > vpii;
typedef vector < pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long long INF = (1LL<<61);
const int inf = (1<<30);
const int nn = 1e6+5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends Here!*****************************************************]

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a[3];
    fr(i, 0, 3) cin >> a[i];
    sort(a, a+3, greater<int>());
    int ans = 10*a[0] + a[1] + a[2];
    cout << ans;
    return 0;
}

//->INTUITIONS are not to be ignored. They represent data processed too fast for the conscious mind to comprehend !!

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	int red = 0;
	rep(i, 0, s.size())if (s[i] == 'R')++red;
	string a = string(red, 'R'), b = string(s.size() - red, 'W');
	string str = a + b;
	int ans = 0;
	rep(i, 0, s.size()) {
		if (s[i] != str[i])++ans;
	}
	cout << ans / 2 << "\n";

	return 0;
}

Measured memory_bytes: 4112
N,M = map(int, input().split())
shop = []
for i in range(N):
    a,b = map(int, input().split())
    shop.append([a,b])

shop.sort(reverse=True)
ans = 0
while M > 0:
    a,b = shop.pop()
    tmp = min(b,M)
    ans += tmp * a
    M -= tmp
print(ans)


Measured memory_bytes: 20072
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    string s;
    cin >> s;
    int l=s.length();
    int* c = new int[l];
    int count = 0;
    int pointer = 0;
    char before = 'R';
    bool flush = false;
    for (int i=0; i<l; i++){
      if (before == s[i])
      {
        count += 1;
      }
      else if (s[i] == 'L') // R to L
      {
        c[i-1] = count;
        pointer = i;
        count = 1;
      }
      else{
        flush = true;
      }
      
      if(i+1 == l)
      {
        flush = true;
      }
      
      if(flush)
      {
        bool swap = false;
        c[pointer] = count;
        if (max(c[pointer-1], c[pointer]) % 2 == 0)
        {
            swap = true;
            //cout << "swap";
        }
        int total = c[pointer-1] + c[pointer];
        // cout << c[pointer-1] << " "<< c[pointer] << endl;
        if (total % 2 == 0)
        {
          c[pointer] = total/2;
          c[pointer-1] = total/2;
        }
        if(total % 2 != 0)
        {
          if (c[pointer-1] < c[pointer]){
            c[pointer] = total/2;
            c[pointer-1] = total/2;
            c[pointer]++;
          }
          else if (c[pointer-1] > c[pointer])
          {
            c[pointer] = total/2;
            c[pointer-1] = total/2;
            c[pointer-1]++;
          }
          if(swap){
            int tmp = c[pointer-1];
            c[pointer-1] = c[pointer];
            c[pointer] = tmp;
          }
        }
        count = 1;
        flush = false;
        swap = false;
      }
      before = s[i];
    }
    for (int i = 0; i < l; i++){
      cout << c[i] << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;
#define int long long
#define repeat(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;

signed main(){

   int N, W;
   cin>> N>> W;
   vector<int> w(N), v(N);
   repeat(i, N) cin>> w[i]>> v[i];

   vector<int> item[4];
   int r=w[0];
   int ans=0;
   repeat(i, N) item[w[i]-r].push_back(v[i]);
   repeat(i, 4) sort(item[i].rbegin(), item[i].rend());

   repeat(i, item[0].size()+1){
      repeat(j, item[1].size()+1){
         repeat(k, item[2].size()+1){
            repeat(l, item[3].size()+1){
               int _w=0, _v=0;
               if(i)repeat(_i, i) _w+=r, _v+=item[0][_i];
               if(j)repeat(_j, j) _w+=(r+1), _v+=item[1][_j];
               if(k)repeat(_k, k) _w+=(r+2), _v+=item[2][_k];
               if(l)repeat(_l, l) _w+=(r+3), _v+=item[3][_l];
               if(_w<=W) ans=max(ans, _v);
            }
         }
      }
   }

   cout<< ans<< endl;

   return 0;
}


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

int main(){
  int n;
  cin >> n;
  string ans ="Three";
  int flg = 0;
  vector<char> s(n);
  for(int i = 0;i < n;i++){
    cin >> s.at(i);
    if(s.at(i) == 'Y'){
      flg++;
      break;
    }
  }
  if(flg != 0){
    ans = "Four";
  }

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

Measured memory_bytes: 256
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define SG string
#define DB double
#define Sec second
using namespace std;
const int Max=1e2+5;
map<int,int>Map;
map<int,int>::iterator It;
int N,Ans,F[Max],Col[Max];
inline int Read(){
	int X=0;char CH=getchar();bool F=0;
	while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
	while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
	return F?-X:X;
}
inline void Write(int X){
	if(X<0)X=-X,putchar('-');
	if(X>9)Write(X/10);
	putchar(X%10+48);
}
int Find(int X){
	return F[X]==X?X:F[X]=Find(F[X]);
}
int main(){
	int I,J,K;
	N=Read();
	for(I=1;I<=N;I++){
		F[I]=I;
		Col[I]=Read();
	}
	for(I=2;I<=N;I++){
		if(Col[I]==Col[I-1]){
			int Fx=Find(I-1),Fy=Find(I);
			F[Fy]=F[Fx];
		}
	}
	for(I=1;I<=N;I++){
		int Fx=Find(I);
		Map[Fx]++;
	}
	for(It=Map.begin();It!=Map.end();It++){
		Ans+=(It->Sec>>1);
	}
	Write(Ans);
	return 0;
}

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

def fall(p, infield):
    for w, d in spell:
        if infield[p] == w:
            p += d
    return infield[p]

n, q = [ int(v) for v in input().split() ]
field = "l" + input()[:-1] + "r"
spell = []

for i in range(q):
    w, d = input().split()
    if d == "L":
        d = -1
    else:
        d = 1
    spell.append((w,d))

left_fall = 0
left_keep = n+1

while left_keep - left_fall > 1:
    mid = (left_keep + left_fall) // 2
    if fall(mid,field) == "l":
        left_fall = mid
    else:
        left_keep = mid

right_keep = 0
right_fall = n+1

while right_fall - right_keep > 1:
    mid = (right_fall + right_keep) // 2
    if fall(mid,field) == "r":
        right_fall = mid
    else:
        right_keep = mid
right_fall = n+1-right_fall

print(n-left_fall-right_fall)

Measured memory_bytes: 67416
N,M = gets.split.map(&:to_i)
require 'prime'
class Integer
  def divisor_list
    return [1] if self == 1
    (1..Math.sqrt(self).to_i).select do |i|
      self%i == 0
    end.map {|e| [e, self/e]}.flatten.uniq.sort
  end
end
puts M.divisor_list.find_all{|i|i<M/N+1}.max
  

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

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

  ll a,b,n;
  cin >> a >> b >> n;

  ll x = min(b - 1, n);
  cout << a * x / b << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    int ans = INF;
    rep(i, sz(s)-2){
      string tmp = "";
      tmp += s[i];
      tmp += s[i + 1];
      tmp += s[i + 2];
      chmin(ans, abs(753 - stoi(tmp)));
    }
    print(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s,t,t_r;
    cin>>s;
    for(char x:s){
        if(x!='x'){
            t+=x;
            t_r+=x;
        }
    }
    reverse(t_r.begin(),t_r.end());
    if(t_r!=t){cout<<-1<<endl;return 0;}
    int d[t.size()+1];
    for(int i=0;i<t.size()+1;i++){
        d[i]=0;
    }
    int l=0;
    for(char x:s){
        if(x=='x'){
            d[l]++;
        }
        else l++;
    }
    int ans=0;
    for(int i=0;i<(t.size()+1)/2;i++){
        //cout<<d[i]<<endl;
        ans+=abs(d[i]-d[t.size()-i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
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;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,q,c[500010],last[500010],ans[500010];
vector<int>v[500010];
struct Query{int l,r,idx;};
bool comp(const Query &q1,const Query &q2){
    return q1.r<q2.r;
}
Query query[500010];
struct BIT{
    int n,beki=1;
    vector<int>bit;
    BIT(int x){
        bit.resize(x+1,0);
        n=x;
        while(beki*2<=n)beki*=2;
    }
    int sum(int i){
        int res=0;
        while(i>0){
            res+=bit[i];
            i-=i&-i;
        }
        return res;
    }
    void add(int i,int x){
        while(i<=n){
            bit[i]+=x;
            i+=i&-i;
        }
    }
    int lowerbound(int w){
        if(w<=0)return 0;
        int x=0;
        for(int k=beki;k>0;k>>=1){
            if(x+k<=n&&bit[x+k]<w){
                w-=bit[x+k];
                x+=k;
            }
        }
        return x+1;
    }
};
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>q;
    fill(last,last+n,-1);
    rep(i,n){
        cin>>c[i];
        c[i]--;
        if(last[c[i]]==-1)last[c[i]]=i;
        else{
            v[i].pb(last[c[i]]);
            last[c[i]]=i;
        }
    }
    rep(i,q){
        cin>>query[i].l>>query[i].r;
        query[i].idx=i;
        query[i].l--,query[i].r--;
    }
    sort(query,query+q,comp);
    int lastr=-1;
    BIT bit(n);
    rep(i,q){
        for(int j=lastr+1;j<=query[i].r;j++){
            for(int k:v[j]){
                bit.add(k+1,1);
            }
        }
        ans[query[i].idx]=query[i].r-query[i].l+1-(bit.sum(query[i].r+1)-bit.sum(query[i].l));
        lastr=query[i].r;
    }
    rep(i,q)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 57752
#include<iostream>
#include<algorithm>

using namespace std;

void dice2(){
        int d1,d2,d3,d4,d5,d6;
        cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6; 
        int q; cin >> q;
            
        for ( int i = 0; i < q; i++){
                int top,front;
                cin >> top >> front; 
                int tmp;
                        while (true){
                                if(d1 == top)break;
                                tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp;  //E    
                                if(d1 == top)break;
                                tmp = d1; d1 = d2; d2 = d6; d6 = d5; d5 = tmp;  //N 
                        }   
                        while (true){
                                if(d2 == front) break;
                                tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp;
                        }   
                cout << d3 << endl;
        }           

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

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 100005
#define endl "\n"
#define mod 1000000007
ll n; ll dp[N][3];
vector<ll> vc[N];
ll dfs(ll i,ll fl[],ll pre_cl){
	if(dp[i][pre_cl]!=-1){
		return dp[i][pre_cl]%mod;
	}
	if(pre_cl==2){
		ll j,c=1;
		for(j=0;j<vc[i].size();j++){
			if(fl[vc[i][j]]==0){
				fl[vc[i][j]]=1;
				c=(c*dfs(vc[i][j],fl,1))%mod;
				fl[vc[i][j]]=0;
			}
		}
		return dp[i][pre_cl]=c%mod;
	}
	else {
		ll j,c1=1,c2=1;
		for(j=0;j<vc[i].size();j++){
			if(fl[vc[i][j]]==0){
				fl[vc[i][j]]=1;
				c1=(c1*dfs(vc[i][j],fl,1))%mod;
				fl[vc[i][j]]=0;
			}
		}
		for(j=0;j<vc[i].size();j++){
			if(fl[vc[i][j]]==0){
				fl[vc[i][j]]=1;
				c2=(c2*dfs(vc[i][j],fl,2))%mod;
				fl[vc[i][j]]=0;
			}
		}
		return dp[i][pre_cl]=(c1%mod+c2%mod)%mod;
	}
}
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(i=1;i<n;i++){
		cin>>k>>l;
		vc[k].ps(l);
		vc[l].ps(k);
	}
	
	ll fl[n+1]={0}; fl[1]=1;
	ll an=dfs(1,fl,-1)%mod;
	cout<<an;
	return 0;
}


Measured memory_bytes: 18560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

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


//#define int ll

class CSwitches {
public:
    int N, M;
        vector<int> B[11];
        int P[11];
        bool ok(int pat){
            _for(m,M){
                int sum = 0;
                for(auto swi : B[m])sum += ((pat & (1<<(swi-1)))>0);
                if(sum%2 != P[m])return 0;
            }
            return 1;
        }
void solve(std::istream& cin, std::ostream& cout) {

    cin >> N >> M;
    _for(i,M){
        int t;
        cin >> t;
        _for(j,t){
            int tt;
            cin >> tt;
            B[i].emplace_back(tt);
        }
    }
    _for(i,M)cin >> P[i];
    int sum = 0;
    _for(pat, 1<<N){
        if(ok(pat))sum ++;
    }
    cout << sum << endl;
}
};


#undef int
int main() {
	CSwitches solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.Split.Int;
            var A = line[0];
            var B = line[1];
            return Math.Max(A + B, Math.Max(A - B, A * B));
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> SplitString { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)


/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
/****** define constant end ********/


/****** define variable start ******/
ll n, m;
vl p;
vector<string> s;
/******* define variable end *******/
ll solve(){
    cin >> n >> m;
    p.resize(m);
    s.resize(m);
    REP(i, m){
        cin >> p[i] >> s[i];
    }
    vl penalty(n);
    vl accepted(n);
    REP(i, n){
        accepted[i] = 0;
    }
    ll ans_p = 0;
    ll ans_a = 0;
    REP(i, m){
        if(s[i] == "WA" && accepted[p[i]-1] != 1){
            penalty[p[i]-1]++;
        }else if(s[i] == "AC" && accepted[p[i]-1] != 1){
            ans_p += penalty[p[i]-1];
            ans_a++;
            accepted[p[i]-1] = 1;
        }
    }
    cout << ans_a << " " << ans_p << endl;

    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}

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

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fr freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 5e5 + 2;
const int mod = 1e9 + 7;

int n,l;
vector<string> a;
int main ()
{
	speed;
	cin>>n>>l;
	for (int i=0;i<n;i++){
		string s;
		cin>>s;
		a.pb(s);
	}
	sort(a.begin(),a.end());
	for (int i=0;i<a.size();i++){
		cout<<a[i];
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const long long mod=1e9+7;
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; }
ll gcd(ll a,ll b){return a%b?gcd(b,a%b):b;}
ll lcm(ll c,ll d){return c*d/gcd(c,d);}

int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)cin>>a.at(i);
vector<int> ans(n,0);
for(int i=0;i<n;i++){
if(i%2==0)ans.at(0)+=a.at(i);
else ans.at(0)-=a.at(i);
}
for(int i=0;i<n;i++)a.at(i)*=2;
for(int i=1;i<n;i++){
   ans.at(i)=a.at(i-1)-ans.at(i-1);
}
for(int i=0;i<n;i++)cout<<ans.at(i)<<endl;
}


Measured memory_bytes: 2048
S = input()
N = len(S) // 2

ans = True
for i in range(N):
  if S[i] != S[-1-i]:
    ans = False
    break

M = N // 2
for i in range(M):
  if S[i] != S[N-1-i]:
    # print((S[i], S[N-i]))
    ans = False
    break

print('Yes' if ans else 'No')


Measured memory_bytes: 2940
n, a, b = map(int, input().strip().split())

if (b - a) % 2 == 1:
    dt1 = a - 1
    dt1 += 1
    b1 = b - dt1
    t1 = dt1 + (b1 - 1) // 2

    dt2 = n - b
    dt2 += 1
    a1 = a + dt2
    t2 = dt2 + (n - a1) // 2
    print(min(t1, t2))
else:
    print((b - a) // 2)


Measured memory_bytes: 9152
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	fast();

	int n; cin>>n;
	int a[n+1];
	for(int i = 1; i<=n; i++){
		cin>>a[i];
	}
	int l; cin>>l;
	int dp[n+1][31];

	for(int j = 0; j<=30; j++){
		for(int i = 1;i<=n;i++){
			if(j==0){
				dp[i][j] = (upper_bound(a+1, a+n+1, a[i]+l) - a) - 1;
			}
			else{
				dp[i][j] = dp[dp[i][j-1]][j-1];
			}
			// cout<<dp[i][j]<<' ';
		}
		// pl;
	}

	int q; cin>>q;
	while(q--){
		int a,b; cin>>a>>b;
		if(a>b){
			swap(a,b);
		}
		int ans = 0;
		while(true){
			int j;
			for(j = 0;j<=30;j++){
				if(dp[a][j]>=b){
					break;
				}
			}
			if(j==0){
				ans++;
				break;
			}
			ans += (1<<(j-1));
			a = dp[a][j-1];
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 13312
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k;

int main() {
	cin >> n >> k;
	for (int i = 1;; i++) {
		n /= k;
		if (!n) {
			cout << i << endl;
			return 0;
		}
	}
}

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

int main() {
  double n,k,ans=0;
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
    double point,num,count=0;
    point = i+1;
    num = 1.0/n;
    while(point < k) {
      num /= 2;
      point *= 2;
    }
    ans += num;
  }
  cout << fixed << setprecision(12);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    vector<int> vec(4);
    vector<int> vec2={1,4,7,9};
    rep(i,4){
        cin>>vec[i];
    }
    sort(vec.begin(),vec.end());
    int ans=1;
    rep(i,4){
        if(vec[i]!=vec2[i])ans=0;
    }
    cout<<(ans?"YES":"NO")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    double T,A;
    double H[1010];
    cin >> N;
    cin >> T >> A;
    double min_val = 1e15;
    rep(i,0,N){
        cin >> H[i];
    }
    ll ans = 0;
    rep(i,0,N){
        double val = abs(T - H[i] * 0.006 - A);
        if(min_val > val){
            min_val = val;
            ans = i;
        }
    }
    print(ans+1);
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        string s; cin >> s;
        int ans = -1;
        s.pop_back();
        while(!s.empty()){
            if((s.size())%2==0){
                bool f = true;
                for(int i = 0; i<s.size()/2; i++){
                    if(s[i] != s[i+s.size()/2])f = false;
                }
                if(f){
                    ans = s.size();
                    break;
                }
            }
            s.pop_back();
        }

        cout<<ans<<endl;

return 0;
}
//abaababaab


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
int main() {

 ll m;
 cin>>m;
 ll ans=0,pro=0;
 REP(i,0,m)
 {
     ll d,c;
     cin>>d>>c;
     pro+=d*c;
     ans+=c;
 }
 ans--;
 ans+=(pro-1)/9;
 cout<<ans;
	return 0;
}

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

int main(){
  char b;
  cin >> b;
  if(b=='A') cout << 'T' << endl;
  else if(b=='T') cout << 'A' << endl;
  else if(b=='C') cout << 'G' << endl;
  else cout << 'C' << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int main()
{
    int n;
    cin>>n;
    long long sum=0;
    long long count=0;
    long long a[N];
    long long  minn=1e15;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    count+=a[1];
    for(int i=2;i<=n;i++)
    {
        minn=min(minn,abs(sum-count*2));
        count+=a[i];
    }
    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

void shuffle (char word[300], int h);

int main () {
    char word[300];
    int m, h;
    scanf("%s", word);
    while (strcmp(word, "-") != 0) {
        scanf("%d", &m);
        for (int i = 0; i < m; i++) {
            scanf("%d", &h);
            shuffle(word, h);
        }
        printf("%s\n", word);
        scanf("%s", word);
    }
}

void shuffle (char word[300], int h) {
    int i, j;
    char save1[300];
    char save2[300];
    for (i = 0; i < 300; i++) {
        save1[i] = '\0';
        save2[i] = '\0';
    }
    strncpy(save1, word, h);
    for(i = h, j = 0; i < strlen(word); i++, j++){
        save2[j] = word[i];
    }
    strcat(save2, save1);
    strcpy(word, save2);
}


Measured memory_bytes: 2108