akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
typedef long long ll;
const int N = 1e5 + 5 , Mod = 998244353 , G = 3 , INF = 0x3f3f3f3f;
double PI = acos(-1);

struct Virt{
    double x , y;
    Virt(double _x = 0.0 , double _y = 0.0):x(_x) , y(_y){}
};

Virt operator + (Virt x , Virt y){return Virt(x.x + y.x , x.y + y.y);}
Virt operator - (Virt x , Virt y){return Virt(x.x - y.x , x.y - y.y);}
Virt operator * (Virt x , Virt y){return Virt(x.x * y.x - x.y * y.y , x.x * y.y + x.y * y.x);}

int read(){
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1 ; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}

struct edge{
	int pos , nx;
}e[N << 1];

int nxt[N] , pre[N] , hd , tl , num , head[N] , dep[N][2] , n;
int length , s[2][N] , cnt[N] , d[N];

void add(int u , int v){
	e[++num].pos = v; e[num].nx = head[u]; head[u] = num;
	e[++num].pos = u; e[num].nx = head[v]; head[v] = num;
}

void get_deep(int now , int fa){
	int fir = 0 , sec = 0;
	dep[now][0] = 1 , dep[now][1] = now;
	for(int i = head[now] ; i ; i = e[i].nx){
		if(e[i].pos == fa) continue;
		get_deep(e[i].pos , now);
		if(dep[e[i].pos][0] + 1 > dep[now][0]){
			dep[now][0] = dep[e[i].pos][0] + 1;
			dep[now][1] = dep[e[i].pos][1];
		}
		if(dep[e[i].pos][0] > dep[fir][0]) sec = fir , fir = e[i].pos;
		else if(dep[e[i].pos][0] > dep[sec][0]) sec = e[i].pos;
	}
	if(dep[fir][0] + dep[sec][0] + 1 > length){
		hd = dep[fir][1];
		tl = dep[sec][1];
		length = dep[fir][0] + dep[sec][0] + 1;
	}
	if(dep[now][0] > length){
		hd = now;
		tl = dep[now][1];
		length = dep[now][0];
	}
}

int comp(int a[] , int b[]){
	for(int i = 1 ; i <= n ; i++){
		if(a[i] == b[i]) continue;
		else return a[i] < b[i] ? 0 : 1;		
	}
	return 0;
}

bool dfs(int now , int fa){
	if(now == tl) return true;
	for(int i = head[now] ; i ; i = e[i].nx){
		if(e[i].pos == fa) continue;
		if(dfs(e[i].pos , now)){
			pre[e[i].pos] = now , nxt[now] = e[i].pos;
			cnt[now] = d[now] - 2;
			return true;		
		}
	}
	return false;
}

int main(){
	int u , v;
	n = read();
	for(int i = 1 ; i < n ; i++){
		u = read() , v = read(); add(u , v);
		d[u]++; d[v]++;
	}
	get_deep(1 , 0);
	dfs(hd , 0);
	cnt[hd]++;
	bool flag = true;
	for(int i = 1 ; i <= n ; i++){
		if(nxt[i] == 0){
			for(int j = head[i] ; j ; j = e[j].nx)
				if(nxt[e[j].pos] == 0) flag = false;
		}
	}
	if(!flag) return 0 * printf("-1\n");
	int cur = 1 , now = 1 , temp;
	int i = 0; nxt[0] = hd;
	do{
		i = nxt[i];
		temp = cur;
		for(int j = 1 ; j <= cnt[i] ; j++){
			cur++;
			s[0][now++] = cur;
		}
		s[0][now++] = temp; cur++;
	}while(i != tl);
	cur = now = 1 , i = 0 , pre[0] = tl;
	do{
		i = pre[i];
		temp = cur;
		for(int j = 1 ; j <= cnt[i] ; j++){
			cur++;
			s[1][now++] = cur;
		}
		s[1][now++] = temp; cur++;
	}while(i != hd);
	int ans = comp(s[0] , s[1]);
	for(int i = 1 ; i <= n ; i++) printf("%d " , s[ans][i]);
	return 0;
}

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

#ifdef DEBUG
    #include "debug.h"
    #define DEB
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define DEB if (false)
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
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 V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

/*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)


void solve(){
    int N;
    cin >> N;
    vector<int> a(N);
    int s = 0;
    rep(i,N){
        cin >> a[i];
        s = s^a[i];
    }
    
    rep(i,N){
        cout << (s^a[i]) << " ";
    }
    cout << endl;
    
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 4836
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdlib.h>

using namespace std;

int main(){
	int N,**coord;
	cin>>N;
	coord=(int**)malloc(sizeof(int*)*N);
	for(int i=0;i<N;i++){
     	coord[i]=(int*)malloc(sizeof(int)*3);
    	int x,y,h;
	    cin>>x>>y>>h;
	    coord[i][0]=x;
	    coord[i][1]=y;
	    coord[i][2]=h;
	    }
	
	int tempH;
	for(int x=0;x<101;x++)
	      for(int y=0;y<101;y++)
		     for(int i=0;i<N;i++){
		     	
		     	if((i==0)&&(coord[0][2]==0))
		     	    for(int j=0;j<N;j++)
		     		   if(coord[j][2]){
						tempH=coord[j][2]+abs(coord[j][0]-x)+abs(coord[j][1]-y);
						break;
						}
						
				if((i==0)&&(coord[0][2]!=0))
				    tempH=coord[0][2]+abs(coord[0][0]-x)+abs(coord[0][1]-y);       
		     	
		     	if(coord[i][2]==0){
					int ph=max(tempH-abs(coord[i][0]-x)-abs(coord[i][1]-y),0);
					if(ph!=0) break;
				}
				
		     	if(coord[i][2]>0){
			    	int mH=coord[i][2]+abs(coord[i][0]-x)+abs(coord[i][1]-y);
			        if(mH!=tempH) break;
			        int ph=max(mH-abs(coord[i][0]-x)-abs(coord[i][1]-y),0);
			        if(ph!=coord[i][2]) break;
				}
				
	      	    if(i==N-1){
				   cout<<x<<' '<<y<<' '<<tempH<<endl;
				   return 0;
				   } 
		  }
	return 0;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int dp[90001] = {};
  pair<int, int> data[90001] = {};
  int h, w, d;
  cin >> h >> w >> d;
  REP(i, h) {
    REP(j, w) {
      int a;
      cin >> a;
      data[a] = make_pair(i, j);
    }
  }

  FOR(i, d, h * w + 1) {
    int cost = abs(data[i].first - data[i - d].first) +
               abs(data[i].second - data[i - d].second);
    dp[i] = dp[i - d] + cost;
  }

  int q;
  cin >> q;
  REP(i, q) {
    int l, r;
    cin >> l >> r;
    cout << dp[r] - dp[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val n = sc.next
  for(i <- 0 to 2){
    if(n.charAt(i)=='1'){
     print('9') 
    }
    else{
      print('1')
    }
  }
}

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

int main() {
  	int N,K;
  	cin >> N >> K;
  
  	string S;
  	cin >> S;
  
  	if(S.at(K-1) == 'A')
      S.at(K-1) = 'a';
  	else if(S.at(K-1) == 'B')
      S.at(K-1) = 'b';
    else
      S.at(K-1) = 'c';
  
  	cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;

    vl x(m);
    rep(i, m) {
        cin >> x[i];
    }
    sort(all(x));

    if(m <= n) {
        out(0);
        re0;
    }

    vl L(m-1);
    rep(i, m-1) {
        L[i] = x[i+1] - x[i];
    }
    sort(all(L));

    ll ans = 0;
    rep(i, m-n) {
        ans += L[i];
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1792
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}


fun solve(out: PrintWriter) {
    val (a, b, n) = readLongList()
    val x = Math.min(b - 1, n)
    println(a * x / b - a * (x / b))
//    val (a, b, n) = Triple(5, 7, 4)
//    for (x in 0..20) {
//        println(f1(a, b, x) - f2(a, b, x))
//    }
}

fun f1(a: Int, b: Int, x: Int) = Math.floor(a.toDouble() * x / b)
fun f2(a: Int, b: Int, x: Int) = a * Math.floor(x.toDouble() / b)

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36396
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-29 14:45
# @url:https://atcoder.jp/contests/abc163/tasks/abc163_d
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
   nk=list(map(int,input().split()))
   n,k=nk[0],nk[1]
   ans=0
   mod=10**9+7
   for i in range(k,max(n+2,k)):
       ans+=((n+1)*i-i*i+1)
   print (ans%mod)
if __name__ == "__main__":
    main()

Measured memory_bytes: 68420
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct edge{int to; int cost;};
vector<vector<edge>> graph(0);
vector<int> d(0);
const int MAX_dist=1e9;

void init(int n){
    graph.resize(n);
    d.resize(n,MAX_dist);
}

void dijkstra(int s){
if(d.size()==0){cout<<"You Should init"<<endl;return;}
    priority_queue<P, vector<P>, greater<P>> que;
    d[s]=0;
    que.emplace(0,s);
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,graph[v].size()){
            edge e=graph[v][i];
            if(d[e.to]>d[v]+e.cost){
            d[e.to]=d[v]+e.cost;
            que.emplace(d[e.to],e.to);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,x,y;
    cin>>n>>x>>y;
    x --,y --;
    init(n);
    rep(i,n-1){
        graph[i].push_back({i+1,1});
        graph[i+1].push_back({i,1});
    }
    graph[x].push_back({y,1});
    graph[y].push_back({x,1});
    map<int,int> a;
    rep(i,n-1){
        dijkstra(i);
        REP(j,i+1,n) a[d[j]] ++;
        rep(j,n) d[j]=MAX_dist;
    }
    REP(i,1,n) cout<<a[i]<<'\n';
}

Measured memory_bytes: 512
#include<stdio.h>
#define NIL -1
#define MAX 102000


struct Node{ int p, l, r;
};
struct Node T[MAX];
int n, H, D[MAX];

int wowDep(int x){
  int depth = 0;
  for(; T[x].p != NIL ;depth++) x = T[x].p;
  return depth;
} 

void print(int x){
  int i, c;
  printf("node %d: ",x);
  printf("parent = %d, ", T[x].p);
  printf("depth = %d, ", D[x]);

  if ( T[x].p == NIL ) printf("root, ");
  else if ( T[x].l == NIL ) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i = 0, c = T[x].l; c != NIL; i++, c = T[c].r){
    if (i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

main(){
  int i, j, d, v, c, l,n,m;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      if ( j == 0 ) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  
  H = 0;
  for ( i = 0; i < n; i++ ){
    D[i] = wowDep(i);
    if ( D[i] > H ) H = D[i];
  }

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}



Measured memory_bytes: 3336
object Main extends App{
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  val n = readInt
  val dx = readLine.split(" ").map(_.toInt)
  
  val cookies = (1 to n).map(x => readInt).map(a => ((dx(0) - 1) / a) + 1)
  println((cookies.sum + dx(1)).toString)
}


Measured memory_bytes: 54940
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1000*1000*1000+7;
lli bpow(lli a, lli b) {
	if(b == 0) return 1;
	if(b == 1) return a % MOD;
	lli r = bpow(a, b >> 1);
	r = (r * r) % MOD;
	return (r * (((b&1)?a:1) % MOD)) % MOD;
}
lli multInverse(lli a) {
	return bpow(a, MOD - 2);
}
lli modMult(lli a, lli b) {
	return (a * b) % MOD;
}
lli modSub(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli modAdd(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	string S, T;
	cin >> S >> T;
	int a, b;
	cin >> a >> b;
	string U;
	cin >> U;
	if(U == S) a--;
	else b--;
	cout << a << " " << b << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
	
	int n;
	cin >>n;
	for(int i=0;i<n;i++){
        int a,b,c;
        cin >>a >>b >>c;
        int tmp;
        if(b>=a && b>=c){
            tmp = b;
            b = a;
            a = tmp;
        }else if(c>=a && c>=b){
            tmp = c;
            c = a;
            a = tmp;
        }
        if(a*a == b*b + c*c){
            cout <<"YES" <<endl;
        }else{
            cout <<"NO" <<endl;
        } 
        
    }
        
        return 0;
    }

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define mid (low + high) / 2
using namespace std;
long long n,Ans,idx,val,L,R,h[200001],a[200001],S[800001],dp[200001];
void upd(int low, int high, int pos)
{
    if(low > idx || idx > high) return;
    if(low == high) { S[pos] = val; return; }
    upd(low,mid,2*pos);
    upd(mid+1,high,2*pos+1);
    S[pos] = max(S[2*pos],S[2*pos+1]);
}
long long get(int low, int high, int pos)
{
    if(L > R) return 0;
    if(low > R || high < L) return 0;
    if(L <= low && R >= high) return S[pos];
    return max(get(low,mid,2*pos),get(mid+1,high,2*pos+1));
}
int main()
{
    cin >> n;
    for(int i=1; i<=n; i++) cin >> h[i];
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++)
    {
        L = 1;
        R = h[i] - 1;
        dp[i] = get(1,n,1) + a[i];
        idx = h[i], val = dp[i];
        //cout << idx << " " << val << endl;
        upd(1,n,1);
        Ans = max(dp[i],Ans);
    }
    cout << Ans;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Query {
  char c;
  char d;
};

std::string s;
std::vector<Query> query;
int n, q;

bool isOK_r(int index) {
  int pos = index;
  for (int i = 0; i < q; i++) {
    if (s[pos] == query[i].c) {
      if (query[i].d == 'L') {
        pos--;
      } else {
        pos++;
      }
    }
    if (pos == n)
      return true;
    else if (pos == -1)
      return false;
  }
  return false;
}
bool isOK_l(int index) {
  int pos = index;
  for (int i = 0; i < q; i++) {
    if (s[pos] == query[i].c) {
      if (query[i].d == 'L') {
        pos--;
      } else {
        pos++;
      }
    }
    if (pos == -1)
      return true;
    else if (pos == n)
      return false;
  }
  return false;
}

int binary_search_r(void) {
  int left  = -1;
  int right = n;
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (isOK_r(mid))
      right = mid;
    else
      left = mid;
  }

  return right;
}
int binary_search_l(void) {
  int left  = -1;
  int right = n;
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (!isOK_l(mid))
      right = mid;
    else
      left = mid;
  }

  return right;
}

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

  cin >> n >> q;

  cin >> s;

  query.resize(q);
  for (int i = 0; i < q; i++) {
    Query m1;
    cin >> m1.c;
    cin >> m1.d;
    query[i] = m1;
  }
  // // right
  // cerr << binary_search_r() << endl;
  // // left
  // cerr << binary_search_l() << endl;

  cout << binary_search_r() - binary_search_l() << endl;

  return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
#define ll long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, start) for (int i = start; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "
#define tests int test; cin >> test; while (test--)
#define fileio() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

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

    int n;
    cin >> n;

    int answ = 0;
    
    int a = 0, b = 0, ba = 0;

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;

        if (s[0] == 'B' && s.back() == 'A') ++ba;
        else if (s[0] == 'B') ++b;
        else if (s.back() == 'A') ++a;

        for (int j = 1; j < s.size(); ++j) {
            if (s[j] == 'B' && s[j - 1] == 'A') ++answ;
        }
    }

    if (ba > 0) {
        answ += ba - 1;

        if (a > 0) {
            ++answ;
            --a;
        }

        if (b > 0) {
            ++answ;
            --b;
        }
    }

    answ += min(a, b);
    cout << answ;
}



Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n,k,x,y;cin>>n>>k>>x>>y;
    if(n<=k) cout << n*x;
    else cout << k*x + (n-k)*y;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int n;ll x;
    cin>>n>>x;
    ll a[n];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    ll ind=0;
    while(x>0&&ind<n){
        x-=a[ind];
        ind++;
    } 
    if(ind==n&&x!=0){
        cout<<n-1<<endl;return 0;
    }
    if(x==0){
        cout<<ind<<endl;
    }
    else{
        cout<<ind-1<<endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int N,M;
    vector<int> T;
    vector<long long int > ans;
    cin >> N;
    long long sum = 0;
    for (int i=0; i<N; ++i)
    {
        int tmp;
        cin >> tmp;
        T.push_back(tmp);
        sum += tmp;
    }
    cin >> M;
    for (int i=0; i<M; ++i)
    {
        int p,x;
        cin >> p >> x;
        ans.push_back(sum-T[p-1]+x);
    }

    for (int i=0; i<M; ++i)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

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

void solve() {
	int k;
	cin >> k;
	int md = 7 % k;
	int rem = md;
	for (int i = 1; i <= k; i++) {
		if (rem % k == 0) {
			cout << i;
			return;
		}
		md = (md * (10 % k)) % k;
		rem = (rem + md) % k;
	}
	cout << -1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include <bitset>

using namespace std;

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        /* code */
        cin >> h[i];
        if(h[i] >= K){
            ans++;
        }
    }
    cout << ans << endl;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    n--;
    ll cc=0;
    ll temp=n;
    mii mm;
    for(ll i=2;i*i<=temp;i++){
        // if(temp%i==0){
            // mm[i]++;
            while(temp%i==0) mm[i]++,temp/=i;
        // }
    }
    if(temp>1) mm[temp]++;
    temp=n+1;
    for(ll i=2;i*i<=temp;i++){
        if(temp%i==0){
            // ll poss=0;
            ll fk=temp;
            while(fk%i==0) fk/=i;
            if(fk%i==1) cc++;
            if(i*i!=temp){
                ll zz=temp/i;
                // ll poss=0;
            ll fk=temp;
            while(fk%zz==0) fk/=zz;
            if(fk%zz==1) cc++;
            }
        }
    }
    if(temp>1) cc++;
    // return;
    // cout<<cc;
    ll tot=1;
    for(auto it:mm) tot=(tot*(it.S+1));
    tot--;
// cout<<tot<<" ";
    cout<<tot+cc;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

while True:
  n = int(input())
  if n==0:break
  A = input().split()
  data = [0]*26
  M = 0
  for i,ai in enumerate(A):
    index = ord(ai)-ord("A")
    data[index] += 1
    if M < data[index]:
      M = data[index]
      MD= index
    data[MD] = 0
    M2 = max(data);data[MD] = M
    if M2 + n - (i+1) < M:
      print(chr(MD+ord("A")),i+1)
      break
  else:
    print("TIE")
  




Measured memory_bytes: 6480
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

dp = [float("inf")] * (h + 10010)
dp[0] = 0

for i in range(h + 1):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
print(min(dp[h:]))

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

int main() {
    int a;
    cin >> a ;
    char s;
    char* c="Three";
    for (;a>0;a--){
        cin >> s;
        if (s == 'Y') {
            c="Four";
        }
    }
    
    cout << c <<endl;
}

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

typedef long long ll;

main()
{
    ll n, i, j, c, a, m = 0;
    cin >> n;
    for(i = 1; i <= sqrt(n) + 1; i++){
        if(n % i == 0){
            a = n / i;
            m = max(m, i);
        }
    }
    c = (m - 1) + ((n / m) - 1);
    cout << c;


}





///promy_pompom
//hello world


Measured memory_bytes: 3624
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}

bool is753(int n){
    bool x[3]={false,false,false};

    while(n>0){
        switch (n%10){
            case 3:
                x[0]=true;
                break;
            case 5:
                x[1]=true;
                break;
            case 7:
                x[2]=true;
                break;
            default:
            return false;
        }
        n/=10;
    }
    if(x[0]&& x[1]&&x[2]){
        return true;
    }else{
        return false;
    }

}

int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    if(is753(n)){
        ret=1;
    }else{
        ret=0;
    }
    FOR(i,3){
        ret+=dfs(10*n + (2*i+3),N);
    }
    return ret;
}


int main(){
    int N;
    cin >> N;
    int A[N+2];
    bool LR[N+2]; //came from left:True
    int tmp=0;
    int totalmoney=0;
    for(int i=1;i<N+1;i++){
        cin >> A[i];
        
        totalmoney+=abs(A[i]-tmp);
        tmp=A[i];
    }
    A[0]=0;
    A[N+1]=0;
    totalmoney+=abs(A[N]);
    //cout <<"total" << totalmoney << endl;
    

    for(int i=1;i<N+1;i++){
        int dif;
        int X=A[i-1];
        int Y=A[i];
        int Z=A[i+1];

        if(X<=Y && Y<=Z || Z<=Y && Y<=X){
            dif=0;
        }else if(Y<X && X <Z || Z < X && X <Y){
            dif=2*abs(X-Y);
        }else{
            dif=2*abs(Y-Z);
        }

        cout << totalmoney-dif<<endl;

    }

    return 0;

    


}

Measured memory_bytes: 1664
n = int(input())
dp = [n+1 for i in range(n+1)]
dp[0] = 0
for i in range(n):
    dp[i+1] = min(dp[i]+1, dp[i+1])
    j = 1
    while i + 6 ** j <= n:
        dp[i+6**j] = min(dp[i]+1, dp[i+6**j])
        j += 1
    j = 1
    while i + 9 ** j <= n:
        dp[i+9**j] = min(dp[i]+1, dp[i+9**j])
        j += 1
print(dp[n])

Measured memory_bytes: 7064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        Set<String> S = new HashSet<>();

        String s = null;
        for (int i = 0; i < N; i++) {
            s = sc.next();
            S.add(s);
        }
        System.out.println(S.size());

    }

}


Measured memory_bytes: 77064
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int main() {
    int D; cin >> D;
    string s = "Christmas";
    while (D<25) {
        ++D;
        s += " Eve";
    }

    cout << s << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		int t = n % 39;
		if ( t == 0 ) t = 39;
		printf( "3C%02d\n", t );
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <stdio.h>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
    int N, D, X;
    scanf(" %d %d %d", &N, &D, &X);

    int choco = 0;
    for(int i = 0; i < N; i++) {
        int A;
        scanf(" %d", &A);
        choco += 1 + (D - 1) / A; 
    }

    printf("%d\n", choco + X);
    return 0;
}

Measured memory_bytes: 256
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn dfs(
    now: usize,
    val: u64,
    ans: &mut Vec<u64>,
    graph: &mut Vec<Vec<usize>>,
    seen: &mut Vec<bool>,
) {
    if seen[now] {
        return;
    }

    seen[now] = true;
    ans[now] += val;
    for &next in graph[now].clone().iter() {
        dfs(next, ans[now], ans, graph, seen);
    }
}

fn main() {
    input! {
        n: usize,
        q: usize,
        edge: [(usize, usize);n-1],
        add: [(usize,u64);q],
    }

    let mut ans = vec![0; n];
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];

    for (i, e) in add {
        ans[i - 1] += e;
    }

    for e in edge {
        graph[e.0 - 1].push(e.1 - 1);
        graph[e.1 - 1].push(e.0 - 1);
    }

    let mut seen = vec![false; n];
    dfs(0, 0, &mut ans, &mut graph, &mut seen);

    for i in 0..n - 1 {
        print!("{} ", ans[i]);
    }
    println!("{}", ans[n - 1]);
}


Measured memory_bytes: 36384
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long

/*  ordered_set<int>  s;
    s.insert(1); 
    s.insert(3);
    cout << s.order_of_key(2) << endl; // the number of elements in s less than 2
    cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based) */

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    long long ans = 0;
    ordered_set < pair < int, int > > s;
    s.insert({0, 0});
    long long sm = 0;
    for(int i = 1 ; i <= n ; ++i){
        int x;
        cin >> x;
        sm += x;
        ans += s.order_of_key({sm - k * i, i});
        s.insert({sm - i * k, i});
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 12800
n,m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
g = Array.new(n+1){[]}

m.times do
  a,b = gets.split.map(&:to_i).map{|x|x-1}
  g[a] << b
  g[b] << a
end

ans = 0
n.times do |i|
  t = []
  g[i].each do |j|
    t << h[j]
  end
  ans += 1 if t.empty? || h[i] > t.max
end
p ans

Measured memory_bytes: 28216
n,t = [int(i) for i in input().split()]
k = []
for i in range(n):
    ci,ti = [int(i) for i in input().split()]
    if t >= ti:
        k.append([ci,ti])

if len(k) == 0:
    print('TLE')
else:
    k.sort()
    print(k[0][0])

Measured memory_bytes: 3060
package main

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

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)
var N, ss, ans, A, B, C int

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))
// sort.Sort(sort.Reverse(sort.IntSlice(arr)))

func main() {
	// A := strings.Split(nextLine(), " ")

	X := strings.Split(nextLine(), " ")

	// Z := strings.Split(nextLine(), " ")
	// n, _ := strconv.Atoi(input[0])

	A, _ := strconv.Atoi(X[0])
	B, _ := strconv.Atoi(X[1])
	C, _ := strconv.Atoi(X[2])

	// K, _ := strconv.Atoi(X[2]) //strconv.ParseInt(X[2], 10, 64)

	// Y := strings.Split(nextLine(), " ")

	// q := make(que, 0)
	// taQue := make(tailAscQue, M)

	// ch := make(que, M)
	// mp := make(map[int]item, M)
	var ans = 0
	if B/A >= C {
		ans = C
	} else {
		ans = B / A
	}

	/*文字列連結高速化
	初期化:buf := make([]byte, 0,N+1)
	連結:buf=append(buf,str)
	出力:string(buf)
	*/
	// sort.Sort(sort.Reverse(dp[M][N]))

	fmt.Fprintln(wtr, ans)

	_ = wtr.Flush()
}

// func dfs(dp []int, times int, arr []int) {
// 	if times >= N {
// 		ans = min(ans, calc(dp, arr))
// 		return
// 	}

// 	for i := 0; i < 4; i++ {
// 		dp[times] = i
// 		dfs(dp, times+1, arr)
// 	}
// }

type otosidama struct {
	x float64
	v string
}

type LR struct {
	l int
	r int
}

func chmax(a *string, b string) {
	if len(*a) < len(b) {
		*a = b
	} else if len(*a) == len(b) && *a < b {
		*a = b
	}
}

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

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func com(a, b int) int {

	if a > b {
		return 0
	}
	return 0 //abs(a - b)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}
func sum(a []int) (sum int) {
	for _, num := range a {
		sum += num
	}
	return
}

type item struct {
	x int
	l int
	r int
}

type que []item

func (p *que) Len() int {
	return len(*p)
}

func (p *que) Swap(i, j int) {
	(*p)[i], (*p)[j] = (*p)[j], (*p)[i]
}

func (p *que) Less(i, j int) bool {

	// return p[i].point > p[j].point //p[i].x+p[i].y > p[j].x+p[j].y
	return (*p)[i].x > (*p)[j].x
}

func (p *que) Push(in item) {
	var tmp *que = new(que)
	*tmp = make(que, len(*p)+1)
	copy(*tmp, *p)
	*tmp = append(*tmp, in)
	*p = *tmp
	// p = append(p, in)
	sort.Sort(p)
}

func (p *que) Pop() item {
	res := (*p)[0]
	*p = (*p)[1:]
	return res
}

func (p *que) Peek() item {
	return (*p)[0]
}

type tailAscQue []item

func (p *tailAscQue) Len() int {
	return len(*p)
}

func (p *tailAscQue) Swap(i, j int) {
	(*p)[i], (*p)[j] = (*p)[j], (*p)[i]
}

func (p *tailAscQue) Less(i, j int) bool {

	return (*p)[i].r < (*p)[j].r
}

func (p *tailAscQue) Push(in item) {
	var tmp *tailAscQue = new(tailAscQue)
	*tmp = make(tailAscQue, len(*p)+1)
	copy(*tmp, *p)
	*tmp = append(*tmp, in)
	*p = *tmp
	sort.Sort(p)
}

func (p *tailAscQue) Pop() item {
	res := (*p)[0]
	*p = (*p)[1:]
	return res
}

func (p *tailAscQue) Peek() item {
	return (*p)[0]
}


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

int a[200009], b[200009], n, m, p = 1;

int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	scanf("%d", &m);
	for (int i=1; i<=m; i++) scanf("%d", &b[i]);
	sort(a+1, a+n+1); sort(b+1, b+m+1);
	for (int i=1; i<=n; i++)
		if (a[i] == b[p]) p++;
	puts(p == m+1 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile
from math import sqrt


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n = readi()

    def f(a, b):
        return max(len(str(a)), len(str(b)))

    ans = 10 ** 10
    for i in range(1, int(sqrt(n)) + 1):
        d, m = divmod(n, i)
        if m == 0:
            ans = min(ans, f(d, i))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4208
let sum x =
  let c = ref 0 in
  Bytes.iter (fun x -> c := !c + Char.code x - Char.code '0') x;
  !c

let () =
  let rec loop () =
    let x = Scanf.scanf "%s\n" (fun x -> x) in
    if x = "0" then ()
    else (Printf.printf "%d\n" (sum x); loop ()) in
  loop ()

Measured memory_bytes: 2444
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int m = sc.nextInt();
		int[] arrA = new int[a];
		int minA = Integer.MAX_VALUE;
		for (int i = 0; i < a; i++) {
		    arrA[i] = sc.nextInt();
		    minA = Math.min(minA, arrA[i]);
		}
		int[] arrB = new int[b];
		int minB = Integer.MAX_VALUE;
		for (int i = 0; i < b; i++) {
		    arrB[i] = sc.nextInt();
		    minB = Math.min(minB, arrB[i]);
		}
		int min = minA + minB;
		for (int i = 0; i < m; i++) {
		    min = Math.min(min, arrA[sc.nextInt() - 1] + arrB[sc.nextInt() - 1] - sc.nextInt());
		}
	    System.out.println(min);
	}
}


Measured memory_bytes: 137828
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main(void)
{
  int count=0,i=0,j=0,k=0,N=IN(),sz=0,x=0,L[100];
  while(N--){L[sz++]=IN();}
  while(i<sz-2)
  {
    j=i+1;while(j<sz-1)
    {
      k=j+1;while(k<sz)
      {
        if(L[i]<L[j]+L[k]&&L[j]<L[k]+L[i]&&L[k]<L[i]+L[j]&&L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]){count++;}k++;
      }j++;
    }i++;
  }
  return OUT(count),0;
}

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

using namespace std;

int a[100][100];
bitset<26000> f[100][100];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for (int i=1;i<=n;i++)
        for (int j=1,x;j<=m;j++)
        {
            scanf("%d",&x);
            a[i][j]=abs(x-a[i][j]);
        }
    f[1][0][13000]=1;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            f[i][j]=(f[i-1][j]<<a[i][j])|(f[i-1][j]>>a[i][j])|(f[i][j-1]<<a[i][j])|(f[i][j-1]>>a[i][j]);
    int res=30000;
    for (int i=0;i<26000;i++)
        if (f[n][m][i])
            res=min(res,abs(i-13000));
    printf("%d\n",res);
}

Measured memory_bytes: 26240
//don't go gentle into
// the goodnight.

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

#define int       long long
#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define i_m_speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
    }
    return r;
}


void solve(){
    map <int,int> m;
    int n;
    cin >> n;
    bool lol = true;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        m[a]++;
        if(m[a]>1)
            lol = false;
    }
    if(lol)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return;
}
int32_t main(){
    i_m_speed
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
  char C;
  cin >> C;
  string alp = "abcdefghijklmnopqrstuvwxyz";
  char answer;
  for(int I = 0; I < 25; I++){
    if(alp.at(I) == C && C != 'z'){
      answer = alp.at(I + 1);
    }
    else if(C == 'z'){
      answer = 'a';
    }
  }
  cout << answer << endl;
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;


//---------------------------------------------------------------
template<int MOD> struct ModInt { int x;
    explicit operator bool() const { return !!x; }
    ModInt(int v = 0) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt(long long v) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt &operator+=(const ModInt &r) { if ((x += r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt &r) { if ((x += MOD - r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(const ModInt &r) { x = 1LL * x * r.x % MOD; return *this; }
    ModInt &operator/=(const ModInt &r) { return *this *= r.inv(); }
    ModInt operator-() const { return x ? ModInt(MOD - x) : ModInt(x); }
    ModInt operator+(const ModInt &r) const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt &r) const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt &r) const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt &r) const { return ModInt(*this) /= r; }
    ModInt inv() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u); } // x.pow(MOD-2)
    ModInt pow(long long k) const { ModInt r(1), a(x);
        while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
    bool operator==(const ModInt r) const { return x == r.x; }
    bool operator!=(const ModInt r) const { return x != r.x; }
    bool operator< (const ModInt r) const { return x <  r.x; }
    friend ostream& operator<<(ostream &os, const ModInt<MOD>& a) { return os << a.x; }
    friend istream& operator>>(istream &is, ModInt<MOD>& a) { return is >> a.x; }
};
template<typename T, int SZ> struct Comb { vector<T> _fac, _ifac, _inv;
    Comb() : _fac(SZ + 1), _ifac(SZ + 1), _inv(SZ + 1) {
        _fac[0] = _ifac[SZ] = _inv[0] = 1;
        for (int i = 1; i <= SZ; i++) _fac[i] = _fac[i - 1] * i;
        _ifac[SZ] /= _fac[SZ];
        for (int i = SZ - 1; i >= 0; i--) _ifac[i] = _ifac[i + 1] * (i + 1);
        for (int i = 1; i <= SZ; i++) _inv[i] = _ifac[i] * _fac[i - 1]; }
    T inv(int n) { return n < 0 ? T(0) : _inv[n]; }
    T fac(int n) { return n < 0 ? T(0) : _fac[n]; }
    T ifac(int n) { return n < 0 ? T(0) : _ifac[n]; }
    T P(int a, int b) { return (b < 0 || a < b) ? T(0) : _fac[a] * _ifac[a - b]; }
    T C(int a, int b) { return b < 0 ? T(0) : P(a, b) * _ifac[b]; }
    T H(int n, int k) { if (n < 0 || k < 0) return T(0);
        return k == 0 ? T(0) : C(n + k - 1, k); }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 250000> com;
    int n, k; cin >> n >> k;
    cout << com.C(k, n) << endl;
    return 0;
}


Measured memory_bytes: 5568