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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int MAX_N = 25;

struct Node {
    int parent, left, right, sibling;
    int depth, degree, height;
    Node(int parent=-1, int left=-1, int right=-1) :
        parent(parent), left(left), right(right), sibling(-1) {}
};

Node tree[MAX_N];

void add_node_to_tree(int id, int left, int right) {
    tree[id].left = left;
    tree[id].right = right;
    int degree = 0;
    if (left != -1) {
        tree[left].parent = id;
        tree[left].sibling = right;
        ++degree;
    }
    if (right != -1) {
        tree[right].parent = id;
        tree[right].sibling = left;
        ++degree;
    }
    tree[id].degree = degree;
}

void set_depth(int n, int d) {
    tree[n].depth = d;
    if (tree[n].right != -1) {
        set_depth(tree[n].right, d+1);
    }
    if (tree[n].left != -1) {
        set_depth(tree[n].left, d+1);
    }
}

int set_and_return_height(int n) {
    int right_h = 0, left_h = 0;
    if (tree[n].right != -1) {
        right_h = set_and_return_height(tree[n].right) + 1;
    }
    if (tree[n].left != -1) {
        left_h = set_and_return_height(tree[n].left) + 1;
    }
    int height = max(right_h, left_h);
    tree[n].height = height;
    return height;
}

void print_tree(int n) {
    FOR(i,0,n) {
        cout << "node " << i <<
            ": parent = " << tree[i].parent <<
            ", sibling = " << tree[i].sibling <<
            ", degree = " << tree[i].degree <<
            ", depth = " << tree[i].depth <<
            ", height = " << tree[i].height;
        if (tree[i].depth == 0) {
            cout << ", root";
        } else if (tree[i].left == -1 && tree[i].right == -1) {
            cout << ", leaf";
        } else {
            cout << ", internal node";
        }
        cout << endl;
    }
}

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

    int n;
    cin >> n;

    int id, left, right;
    FOR(i,0,n) {
        cin >> id >> left >> right;
        add_node_to_tree(id, left, right);
    }
    int root = -1;
    FOR(i,0,n) {
        if (tree[i].parent == -1) {
            root = i;
            break;
        }
    }
    assert(root != -1);
    set_depth(root, 0);
    set_and_return_height(root);
    print_tree(n);

    return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D;
int main () {
    ios_base::sync_with_stdio(false);
    cin>>A>>B>>C>>D;
    while(true) {
        C-=B;
        if(C <= 0) break;
        A-=D;
        if(A <= 0) break;
    }
    if(A > 0) {
        cout<<"Yes"<<"\n";
    }
    else {
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;




/************************************************/
const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}
 
vector<int64_t> fact, seq_inv, fact_inv;
 
void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}
 
void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}
 
void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}
 
void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}
 
int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}
 
int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}
 
int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}
 
int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}
 
int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}
 
int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}
/************************************************/

int main(){
  int n;
  cin >> n;
  vector<int64_t> one(60);
  rep(i,n){
    int64_t a;
    cin >> a;
    for(int j=0; j<60; j++){
      one[j] += nth_bit(a,j);
    }
  }
 
  int64_t ans=0;
  for(int i=0; i<60; i++){
    int64_t res = one[i] * (n-one[i]) % mod;
    mul(res, power_mod(2,i));
    add(ans, res);
  }
  cout << ans << endl;
  return 0;
}


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

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

  vector<int> data(N);
  int counter = 0;

  for(int i = 0;i < N;i++){
    cin >> data.at(i);
  }

  sort(data.begin(),data.end());

  for(int i = 0;i < N;i++){
    x -= data.at(i);
    if(x < 0)break;
    else counter++;
  }
  
  if(x > 0)counter -= 1;

  cout << counter << endl;
}

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

unordered_map<int,list<int>> m;
ll dp[100010][2];

ll fun(int par,int src,int c){
    if(m.count(src)==0){
        if(c==0)return 2;
        else return 1;
    }
    if(dp[src][c]>-1)return dp[src][c];
    ll w=1,b=1;
    for(int i:m[src]){
        if(i==par)continue;
        w*=fun(src,i,0);
        w%=mod;
        if(c==0){
            b*=fun(src,i,1);
            b%=mod;
        }
    }
    if(c==0){
        return dp[src][c]=(w+b)%mod;
    }
    else{
        return dp[src][c]=w;
    }
}
void solve()
{
    int n;
    cin>>n;
    if(n==1){
        cout<<2;
        return;
    }
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        m[x].push_back(y);
        m[y].push_back(x);
    }
    memset(dp,-1,sizeof dp);
    fun(-1,1,0);
    cout<<dp[1][0];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

void Main() {
  // code
  int n;
  cin >> n;

  long long int count = 0;

  rep(i, n) {
    long long int a;
    cin >> a;
    while (a && a % 2 == 0) {
      count++;
      a /= 2;
    }
  }

  cout << count << endl;
}

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] s1 = Console.ReadLine().Split(' ');
            int x = int.Parse(s1[0]), a = int.Parse(s1[1]);

            if (x < a) Console.WriteLine(0);
            else Console.WriteLine(10);
        }
    }
    //mcs Main.cs
    //mono Main.exe

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

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

  int n;
  cin >> n;

  vector<int> l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i) >> r.at(i);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += r.at(i) - l.at(i) + 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int ans = 0;
	for(int i=1; i<=n; ++i){
		int c = 0, x=i;
		while(x)
			++c, x/=10;
		if(c&1) ++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, X, L[101], i, d=0, ans=1;

    cin >> N >> X;

    for(i=1; i<=N; i++){
        cin >> L[i];
    }

    for(i=2; i<=N+1; i++){
        d += L[i-1];

        if(d <= X){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

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

Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	while (1) {
		int n, m; scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)break;
		int offset = 540;
		vector<vector<int>> time(m, vector<int>(750));
		map<pair<int, int>, int> mp;
		int r; scanf("%d", &r);
		for (int i = 0; i < r; i++) {
			int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);
			c--;
			if (d == 0) {
				for (int i = mp[{b, c}]; i < a; i++) {
					time[c][i - offset] = 1;
				}
				mp.erase({ b,c });
			}
			else {
				mp[{b, c}] = a;
			}
		}

		int q; scanf("%d", &q);
		while (q--) {
			int ts, te, a;
			scanf("%d %d %d", &ts, &te, &a);
			a--;
			int res = 0;
			for (int i = ts - offset; i < te - offset; i++) {
				res += time[a][i];
			}
			//puts("a");
			printf("%d\n", res);
		}
	}
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意！！！！！！！！！！！！
	*/
}



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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

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

  int x, t; cin >> x >> t;

  cout << max(x - t, 0) << endl;
  
  return (0);
}

Measured memory_bytes: 3636
use List::Util qw(max min);

my $s = <STDIN>;
my $K = <STDIN>;
chomp $s;
my $len = length $s;
my $length = min(5, $len);

my %h;
foreach my $l (1..$length) {
        foreach my $i (0..$len-$l) {
                my $k = substr($s, $i, $l);
                $h{$k} = ''
        }
}
my $vv;
my $j = 1;
foreach (sort {$a cmp $b} keys %h) {
        if ($j <= $K) {
                $vv = $_;
        } else {
                last;
        }
        $j++;
}
print $vv;

Measured memory_bytes: 4096
W = raw_input()

S = []

while True:
    tmp = map(str, raw_input().split())
    if tmp[0] == "END_OF_TEXT":
        break
    else:
        S.append(tmp)

cnt = 0
for i in range(len(S)):
    for j in range(len(S[i])):
        if W == S[i][j].lower():
            cnt += 1

print cnt

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

int main(){
	string s;
	cin >> s;
	int red = count(s.cbegin(), s.cend(), '0');
	int blue = count(s.cbegin(), s.cend(), '1');

	cout << 2*min(red,blue) << endl;

	return 0;
}

Measured memory_bytes: 3740
/*input
8 3
*/

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

int main() {
  int n, m;
  cin >> n >> m;
  int l = 1, r = n;
  for (int i = 1; i <= m; ++i) {
    if (n%2 == 0 && i == n/2/2+1) l++;
    cout << l << " " << r << endl;
    l++; r--;
  }
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(void){
    int N, count=0;
    cin >> N;
    int p[N];
    
    for(int i=1; i<=N; i++){
        cin >> p[i];
        
        if(p[i] != i){
            count++;
        }
    }
    
    if(count <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Collections

import scala.io.StdIn

object Main {
  def main(args: Array[String]) = {
    val N = StdIn.readInt
    val S = StdIn.readLine
    val whites = S.count(c => c == '.')
    val blacks = S.count(c => c == '#')

    var wCnt = 0
    var bCnt = 0
    var ans = Math.min(whites, blacks)
    for(i <- 0 until N) {
      if (S.charAt(i) == '.') {
        wCnt += 1
      }
      if (S.charAt(i) == '#') {
        bCnt += 1
      }
      ans = Math.min(ans, (whites - wCnt) + bCnt)
    }
    println(ans)

  }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int s;
  cin >> s;
  ll dp[s + 1] = {}, x = 0;
  dp[0] = 1;

  for (int i = 1; i <= s; ++i) {
    if (i - 3 >= 0) (x += dp[i - 3]) %= mod;
    dp[i] = x;
  }

  cout << dp[s] << endl;
  return 0;
}

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

const ll mod = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  set<int> x;
  x.insert(a);
  x.insert(b);
  x.insert(c);
  cout << x.size() << endl;
  return 0;
}


Measured memory_bytes: 3628
#import<stdio.h>
#import<queue>
int main(){
std::queue<int>q;
int w,h,f[484],i,j,a,b,t,x,z;
char p[15];
for(;scanf("%d%d ",&h,&w),h;){
for(j=0;j<w+2;j++)f[j]=f[j-~h*22]=-9;
for(i=1;i<=h;i++){
for(j=1;j<=w;j++)
f[x=i*22+j]=-1,
z=getchar(),
z-35?z>65?b=x:z>64?a=x:1:--f[x];
f[i*22]=f[i*22-~w]=-9;
getchar();
}

f[a]=t=0;
q.push(0);
for(q.push(a);a=q.front(),q.size()>1;q.pop())
if(!a)++t,q.push(0);
else for(i=4;i--;)
if(f[x=a+" 57L"[i]-54]==-1)
f[x]=t,q.push(x);

q.pop();
scanf("%s",p);
for(a=t=0;!a;){
x=b;
z=0;
for(i=0;!a&&p[i];i++){
t++;
f[j=b-54+"L65676 "[p[i]-50]]>-3?b=j:0;
f[b]>=0&&t>=f[b]?a=b:0;
f[b]>=0&&++z;
}
!z&!a&!p[i]&b==x&f[b]<0&&--a;
}
printf(a<0?"impossible\n":"%d %d %d\n",t,a/22-1,a%22-1);
}
}

Measured memory_bytes: 0
import sys
import math

S = int(input())

X1 = 0
Y1 = 0

AA = int(math.sqrt(S))

if AA**2 == S:
    print(0,0,AA,0,0,AA)
    sys.exit()

A = AA+1
B = AA+1

iS = A*A - S

if iS >= A+1:
    B = AA 
    iS = A*B - S

for i in range(1,iS+1):
    if (iS % i) == 0:
        if iS/i <= 10**9:
            a = i
            b = int(iS/i)
            print(X1, Y1, A, a, b, B)
            sys.exit()
            


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	string s;cin>>s;
	int cntr = 0;int cntb = 0;
	for(int i = 0; i < n; i++) {
		if (s[i] == 'R')cntr++;
		else cntb++;
	}
	if (cntr > cntb)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  cout << s[0] << n - 2 << s[n - 1];
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String o=sc.next();
        String e=sc.next();
        int index1 = 0;
        int index2 = 0;
        boolean flag = true;
        while (index1 < o.length() || index2 < e.length()) {
            if (flag) {
                System.out.print(o.charAt(index1++));
            } else {
                System.out.print(e.charAt(index2++));
            }

            flag = !flag;
        }
    }
}

Measured memory_bytes: 35524
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll A,B,C; cin >> A >> B >> C;
    ll K; cin >> K;
    if (K % 2 == 1) cout << B - A << endl;
    else cout << A - B << endl;
}


Measured memory_bytes: 256
nn=int(input())
nc = [0] * (nn + 1)
for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      a = x * x + y * y + z * z + x * y + x * z + y * z
      if a > nn:
        break
      nc[a] += 1
for i in range(1, nn + 1):
  print(nc[i])

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
ll N,K;

map<ll,ll> M;
ll zyou(ll x) {
  if(M.count(x)) {
return M[x];
  }
  
ll i=1;
  ll k=x;
  ll num=1000000007;
  while(i<N) {
x*=k;
    i++;
    x%=num;
  }
  M[k]=x;
  return x;
}
int main() {
  
  cin>>N>>K;

  vector<ll> vec(K+1);
  for(ll i=0;i<K;i++) {
    ll bai=K/(K-i);
    ll a=zyou(bai);

ll j=2;
    while(bai-1>0) {
      a-=vec[(K-i)*j];
      bai--;
      j++;
    }
    vec[K-i]=a;
  }
  ll ans=0;
  for(ll i=1;i<=K;i++) {
    ans+=vec[i]*i;
    if(ans>1000000007) {
ans%=1000000007;
    }
  }
  
  cout<<ans<<endl;
}

  


  
  

Measured memory_bytes: 4048
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc057/tasks/abc057_c

"""
import sys
from sys import stdin
input = stdin.readline


def calc_divisors(N):
    ans = [N]
    for i in range(2, int(N**0.5)+1):
        if N % i == 0:
            ans.append(i)
            # if N // i != i:
            #     ans.append(N//i)
    ans.sort()
    return ans


def solve(N):
    min_ans = float('inf')
    divs = calc_divisors(N)

    for d in divs:
        A = d
        B = N // d
        A_len = len(str(A))
        B_len = len(str(B))
        AB_len = max(A_len, B_len)
        min_ans = min(min_ans, AB_len)
    return min_ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3188
import math
x,k,d=map(int,input().split())
count=int(math.sqrt(x*x)/d)
if k<=count:
    count=k
    k=2
else:
    k=k-count
ans=int(math.sqrt(x*x)-d*count)
if k%2==1:
    ans=math.sqrt((d-ans)**2)
print(int(ans))

Measured memory_bytes: 9204
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



int main() {	
	int n;
	int cnt1 = 0;
	int cnt2 = 0;
	int cnt3 = 0;
	cin >> n;
	rep(i, 0, n) {
		int x;
		cin >> x;
		if (x%4==0) {
			cnt3++;
		}
		else if(x%2==0){
			cnt2++;
		}
		else {
			cnt1++;
		}
	}

	if (cnt2 == 0){
		if (cnt1 >= cnt3+2) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	else {
		if (cnt1 >= cnt3 + 1) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}




	return 0;
}


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

const int N = (int) 1e5;
long long f[N], g[N + 1];
int a[N];

int main() {
    ios::sync_with_stdio(false);
    int n, m, k; cin >> n >> m >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int t = k; t >= 1; --t) {
        for (int i = 0; i < n; ++i) g[i] = f[i];
        deque<int> q;
        q.push_back(n);
        if (t != k) g[n] = -1e18;
        for (int i = n - 1; i >= 0; --i) {
            while (!q.empty() && q.front() - i > m) q.pop_front();
            f[i] = g[q.front()] + 1LL * t * a[i];
            while (!q.empty() && g[i] >= g[q.back()]) q.pop_back();
            q.push_back(i);
        }
    }
    cout << *max_element(f, f + n) << endl;
    return 0;
}


Measured memory_bytes: 2176
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	vector<int>v(n,0);
	int i,j;
	for(i=1;i<n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			int d=j-i;
			int d1=min(abs(j-y)+abs(i-x),abs(j-x)+abs(i-y))+1;
			d=min(d,d1);
			v[d]++;
		}
	}
	for(i=1;i<n;i++)
		cout<<v[i]<<endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}
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);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/

int H,W;
int dp[55][55][55][55];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
char l[501][501],r[501][501];


int solve(){
	rep(i,0,H){
		rep(j,0,W)cin>>l[i][j];
		rep(j,0,W)cin>>r[i][j];
	}
	rep(i,0,55)rep(j,0,55)rep(k,0,55)rep(l,0,55)dp[i][j][k][l] = -1;
	int li,lj,ri,rj;
	rep(i,0,H)rep(j,0,W){
		if(l[i][j]=='L'){
			li = i;
			lj = j;
		}
		if(r[i][j]=='R'){
			ri = i;
			rj = j;
		}
	}
	stack<pair<pair<int,int>,pair<int,int>>>st;
	st.push({{li,lj},{ri,rj}});
	while(!st.empty()){
		auto t = st.top();
		st.pop();
		int li = t.fi.fi;
		int lj = t.fi.se;
		int ri = t.se.fi;
		int rj = t.se.se;
		if(dp[li][lj][ri][rj]==1)continue;
		if(l[li][lj]=='%'&&r[ri][rj]=='%')return 1;
		if(l[li][lj]=='%'||r[ri][rj]=='%')continue;
		dp[li][lj][ri][rj] = 1;
		rep(k,0,4){
			int nli = li + dy[k];
			int nlj = lj + dx[k];
			int nri = ri + dy[k];
			int nrj = rj - dx[k];
			if(nli<0||nli>=H||nlj<0||nlj>=W){
				nli = li;
				nlj = lj;
			}
			if(l[nli][nlj]=='#'){
				nli = li;
				nlj = lj;
			}
			if(nri<0||nri>=H||nrj<0||nrj>=W){
				nri = ri;
				nrj = rj;
			}
			if(r[nri][nrj]=='#'){
				nri = ri;
				nrj = rj;
			}
			if(dp[nli][nlj][nri][nrj]==-1){
				dp[nli][nlj][nri][nrj]=0;
				st.push({{nli,nlj},{nri,nrj}});
			}
		}
	}
	return 0;
}
 
signed main(){
	IOS();
	vector<int>ans;
	while(cin>>W>>H,H||W){
		int t = solve();
		ans.push_back(t);
	}
	for(auto e:ans){
		if(e)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}


Measured memory_bytes: 86596
#include <bits/stdc++.h>
#define MAXN 100010
using namespace std;

int n, k, a[MAXN], id[MAXN], ans;

inline bool cmp(register int x, register int y) {
	return a[x] < a[y];
}

inline int xceil(register int a, register int b) {
	return a % b ? a / b + 1 : a / b;
}

int main() {
	scanf("%d%d", &n, &k);
	if (n == k--) {
		putchar('1');
		return 0;
	}
	if (k == 1) {
		printf("%d", n - 1);
		return 0;
	}
	for (register int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]); id[i] = i;
	}
	sort(id + 1, id + 1 + n, cmp);
	register int l = id[1] - 1, r = n - id[1];
	ans += l / k + r / k; l %= k; r %= k; ans += xceil(l + r + 1, k + 1);
	printf("%d", ans);
	return 0;
}

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


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    answer = sum(p[0:K])
    r = answer
    for i in range(N-K):
        answer = answer - p[i] + p[i+K]
        r = max(r, answer)
    print((r+K)/2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
map<long long,long long>mp1,mp2;
long long n,a[202020],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		mp1[a[i]+i]++;
		mp2[i-a[i]]++;
	}
	for(map<long long,long long>::iterator it=mp1.begin();it!=mp1.end();it++)
	{
		long long x=it->first,y=it->second;
		ans+=y*mp2[x];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 39472
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int>a(n), b(n), c(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n - 1)cin >> c[i];

	ll point = 0;
	rep(i, n) {
		point += b[a[i] - 1]++;
	}

	rep(i, n - 1) {
		if (a[i] + 1 == a[i + 1]) {
			point += c[a[i] - 1];
		}
	}

	cout << point << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define lli long long int
#define pb push_back
using namespace std;


int main()
{
    lli n;
    lli p =  (lli)(1e9+7);
    cin>>n;
    vector<lli>arr(n+1);
    for(lli i=1;i<=n;i++)  cin>>arr[i];
    
    vector<lli>set(62,0);
    vector<lli>unset(62,0);

    for(lli i=0;i<62;i++)
    {
        for(lli j=1;j<=n;j++)
        {
            if((arr[j]&(1ll<<i))>0) set[i]++;
            else unset[i]++;
        }
    }
    lli ans=0;
    lli mul;
    lli mul2;
    lli co;
    for(int i=0;i<62;i++)
    {
        mul = (set[i]%p * unset[i]%p)%p;
        co = (1ll<<i)%p;
        mul2 = (mul%p * co%p)%p;
        ans = (ans%p + mul2%p)%p;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 5596
#include<stdio.h>

int main(){
  int x[3],i,j,temp;

  for(i=0;i<3;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<3;i++){
    for(j=2;j>i;j--){
      if(x[j]<x[j-1]){
        temp = x[j];
        x[j] = x[j-1];
        x[j-1] = temp;
      }
    }
  }
  printf("%d %d %d\n",x[0],x[1],x[2]);

  return 0;
}


Measured memory_bytes: 2108
n=int(input())
a=list(map(int,input().split()))
mod=pow(10,9)+7

#n=10000
#a=list(range(10**6,10**6-n,-1))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
lcma={}
for ai in a:
  f=factorization(ai)
  for fi in f:
    if fi[0] in lcma:
      lcma[fi[0]]=max(lcma[fi[0]],fi[1])
    else:
      lcma[fi[0]]=fi[1]
l=1
for k,v in lcma.items():
  l*=pow(k,v,mod)
  l%=mod
ans=0
for ai in a:
  ans+=l*pow(ai,mod-2,mod)
  ans%=mod
print(ans)


Measured memory_bytes: 4596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	const int mod = 10000;
	int n, k, pasta[128];
	cin >> n >> k;
	CLEAR(pasta, -1);
	while (k--)
	{
		int a, b;
		cin >> a >> b;
		--a, --b;
		pasta[a] = b;
	}

	int dp[128][3][3];
	CLEAR(dp, 0);
	for (int i = 0; i < 3; ++i)
		dp[0][i][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		if (pasta[i] != -1)
			for (int j = 0; j < 3; ++j)
				if (pasta[i] != j)
					dp[i][j][0] = dp[i][j][1] = 0;

		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 2; ++k)
				for (int l = 0; l < 3; ++l)
					(dp[i + 1][l][j == l ? k + 1 : 0] += dp[i][j][k]) %= mod;
	}

	int res = 0;
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 2; ++j)
			(res += dp[n - 1][i][j]) %= mod;
	cout << res << endl;
}

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

int main(void){
    int i,x=0,num[1000]={0};
    char a[1000]={0};

    while(1){
        x=0;
        scanf("%s",a);
        if(a[0]=='0'){
            break;
        }
        for(i=0;i<strlen(a);i++){
            num[i]=a[i]-'0';
            x+=num[i];   
        }
        printf("%d\n",x);
    }

    return 0;
}


Measured memory_bytes: 2040
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, a: [i64; n],
    }
    let mut c = 0;
    for i in 0..n - 1 {
        if a[i] < a[i + 1] {
            c += 1;
        }
    }
    puts!("{}\n", c);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 1968
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back

typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned uint;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, int> pll;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 Rand(seed);
uniform_int_distribution<ll> range(0, 1ll << 32);
inline void ucin() {
   ios::sync_with_stdio(0); cin.tie(0);
}

const int N = 4e5 + 10;
const int mod = 1e9 + 7;

int qpow(int a, int b) {
   int ans = 1;
   for(; b >= 1; b >>= 1, a = (ll) a * a % mod)
      if(b & 1) ans = (ll) ans * a % mod;
   return ans;
}
int n, f[N];
int main() {
   scanf("%d", &n);
   for(int i = 1; i * i <= n; i ++) {
      for(int j = 1; j * j <= n; j ++) {
         for(int k = 1; k * k <= n; k ++) {
            ll res = i * i + j * j + k * k + i * j + i * k + j * k;
            if(res <= n) f[res] ++;
         }
      }
   }
   rep(i, 1, n) printf("%d\n", f[i]);
   return 0;
} 


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int cnt1[N],cnt2[N];
int main()
{
	int n;
	scanf("%d",&n);
	multimap<int,int> M1,M2;
	multimap<int,int>::iterator it1,it2,it3; 
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(i%2==0){
			cnt1[x]++;
		}else{
			cnt2[x]++;
		}
	} 
	for(int i=0;i<N;i++){
		if(cnt1[i]){
			M1.insert(pair<int,int>(cnt1[i],i));
		}
		if(cnt2[i]){
			M2.insert(pair<int,int>(cnt2[i],i));
		}
	}
	int ans=INT_MAX;
	it1=M1.end();it1--;
	it2=M2.end();it2--;
	if(it1->second==it2->second){
		if(M1.size()==1&&M2.size()==1){
			ans=n/2;
		}else if(M1.size()==1&&M2.size()!=1){
			it3=it2;it3--;
			ans=n/2-it3->first;
		}else if(M1.size()!=1&&M2.size()==1){
			it3=it1;it3--;
			ans=n/2-it3->first;
		}else{
			it3=it2;it3--;
			ans=min(ans,n-it3->first-it1->first);
			it3=it1;it3--;
			ans=min(ans,n-it3->first-it2->first);			
		}
	}else{
		ans=n-it1->first-it2->first;
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5760
#include <cstdio>

using namespace std;
int main()
{
    long long n,k,i,j,flag;
    while(~scanf("%lld%lld",&n,&k))
    {
        flag=0;
        for(j=1;j<=5;j++)
        {
            for(i=1;i<=n-2;i++)
            {
                if((63*i+9*j+9)%11==k)
                {
                    flag++;
                    flag+=((n-2-i)/11);
                    i=n;
                }
            }
        }
        printf("%lld\n",flag);
    }
    return 0;
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    int ans = 1;
    while (n)
    {
        n--;
        if (ans < k)
        {
            ans *= 2;
        }
        else
        {
            ans += k;
        }
    }

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


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main()
{
    int n;
   
    do {
        cin >> n;
    } while (n > 100);

    int* a = new int[n];

    for (int i = 0; i < n; i++) {
         cin >> a[i];
    }
   
    for (int i = 0; i < n - 1; i++) {
         cout << a[n - i - 1] << " ";         
    }

    cout << a[0] << endl;        
   
    delete[] a;

    return (0);
}	     
    

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

using namespace std;
using ll = long long;


int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {

            if(s[i] == t[j])dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1], dp[i][j] + 1});
            
            else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);

        }
    }

//dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1], dp[i][j] + 1});
//dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1] + dp[i][j] + 1});

    cerr << dp[n][m] << endl;
    string ans;

    int i = n, j = m;
    while(i > 0 && j > 0) {

        if(dp[i][j] == dp[i - 1][j])i--;
        else if(dp[i][j] == dp[i][j - 1])j--;
        else {
            ans.push_back(s[i - 1]);
            i--;j--;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
using namespace std;
int main()
{ 
    cin.tie(0);
   	ios::sync_with_stdio(false); 
    
    int N;
    cin >> N;
    vector<int> A;
  
    A.push_back(0);
    for(int i=1; i<=N; i++)
    {
    	int a;
    	cin >> a;
    	A.push_back(a);
    }

   int sum = 0;
   for(int i=0; i<N; i++)
   {
   	  sum += abs(A[i+1]-A[i]);
   }
   sum += abs(A[0]-A[N]);

   int M;
   for(int i=1; i<N; i++)
   {
   	   M = sum - abs(A[i]-A[i-1]) 
   	           -abs(A[i+1]-A[i]) +abs(A[i+1]-A[i-1]);
       cout << M << endl;
   }
   M = sum - abs(A[N]-A[N-1]) 
       -abs(A[N]-A[0]) + abs(A[N-1]-A[0]);
   cout << M << endl;

   return 0;
}

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

int main() {
  
  int x, n;
  cin >> x >> n;
  
  vector<int> p(n);
  int d = 0;
  REP(i,n) {
    cin >> p[i];
    if (p[i] == x) d++;
  }

  
  int a, b, ia = 0, ib = 0, ans; 
  int c = 0;
  if (n == 0) cout << x << endl;
  else if (d == 0) cout << x << endl;
  else {
    int i = 0;
    while(1) {
      i++;
      a = x - i;
      REP(j,n) {
        if (a == p[j]) {
          ia++;
          break;
        }
      }
      if(ia == 0) {
        ans = a;
        c++;
        break;
      }
      else ia = 0;
      
      b = x + i;
      REP(k,n) {
        if (b == p[k]) {
          ib++;
          break;
        }
      }
      if(ib == 0) {
        ans = b;
        c++;
        break;
      }
      else ib = 0;
      
      if (c == 1) break;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
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; }
const ll INF=(1LL<<61)-1;

vector<int> pn;
vector<bool> is_prime(60000,true);
void make_prime(){
    for(int x=2;x*x<=60000;x++){
        int i=2;
        while(x*i<=60000){
            is_prime[x*i] = false;
            i++;
        }
    }
    is_prime[1] = false;
    for(int i=1;i<=60000;i++){
        if(is_prime[i]) pn.push_back(i);
    }
}


int main(){
    int N; cin >> N;
    make_prime();
    vector<ll> ans;
    int cnt = 0;
    for(auto it: pn){
        if(it%5==1){
            ans.push_back(it);
            cnt++;
        }
        if(cnt>=N) break;
    }
    rep(i,N) cout << ans[i] << " " ;
    cout << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int MAXN = 25;
const int inf = 0x3f3f3f3f;
typedef long long LL;
int vis[MAXN][MAXN];
char G[MAXN][MAXN];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int h, w;
typedef struct point{
     int x;
     int y;
     int step;
}P;
int bfs(int x, int y)
{
    queue<P>q;
    int ans=0;
    while(!q.empty())
        q.pop();
    vis[x][y]=1;
    q.push((P){x,y,0});
    while(!q.empty())
    {
        P tmp = q.front();
        ans=max(ans, tmp.step);
        q.pop();
        for(int i=0;i<4;++i)
        {
            int nx = dx[i] + tmp.x;
            int ny = dy[i] + tmp.y;
            if(nx<0||nx>=h) continue;
            if(ny<0||ny>=w) continue;
            if(G[nx][ny]!='.') continue;
            if(vis[nx][ny]) continue;
            vis[nx][ny]=1;
            q.push((P){nx, ny,tmp.step+1});
        }
    }
    return ans;
}

int main()
{
    scanf("%d %d", &h, &w);
    for(int i=0;i<h;++i)
        scanf("%s", G[i]);
    int ans=0;
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            if(G[i][j]=='.')
            {
                memset(vis,0, sizeof(vis));
                ans=max(ans, bfs(i,j));
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h) cin >> a[i];

    vi row, col;
    rep(i, h){
        rep(j, w){
            if(a[i][j] == '#'){
                row.push_back(i);
                break;
            }
        }
    }
    rep(i, w){
        rep(j, h){
            if(a[j][i] == '#'){
                col.push_back(i);
                break;
            }
        }
    }

    for(auto r : row){
        for(auto c : col){
            cout << a[r][c];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	reverse(a.begin(), a.end());
	for (int i = 0; i < n-1; i++) {
		cout << a.at(i) << " ";
	}
	cout << a.at(n - 1) << endl;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int a[200005],f[200005][3],n,m,num,sum;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }
    else cout<<"win"<<endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int T;
  cin >> T;
  vector<bool> ans(T);

  rep(t, T){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a - b < 0){
      ans[t] = false;
      continue;
    }
    if(d < b){
      ans[t] = false;
      continue;
    }
    if(c >= b){
      ans[t] = true;
      continue;
    }

    // c < bであって、 d >= bのとき

    ll g = gcd(b, d);
    ll max_modB = (b - g + (a % g)) % b;

    if(c < max_modB){
      ans[t] = false;
    }else{
      ans[t] = true;
    }

  }

  rep(t, T){
    if(ans[t]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }




  return 0;
}


Measured memory_bytes: 256
##n円をx円の指数の和で表すときの操作数
def getCnt(n, x):
    ret = 0
    while (n > 0):
        ret += n % x
        n //= x
    return ret

if __name__ == '__main__':
    n = int(input())
    ans = n
    for i in range(n + 1):
        cnt = 0
        cnt += getCnt(i, 6)
        cnt += getCnt(n - i, 9)
        ans = min(ans, cnt)
    print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2)%MOD;
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a % MOD * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}



in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        string s;
        int n,k;
        cin>>n>>k>>s;
        s[k-1]=s[k-1]-'A'+'a';
        cout<<s<<endl;
    }
    RETURN;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <bits/stdc++.h>

using namespace std;


int main()
{
	string s;
	cin >> s;
	bool flag = false; 
	for(int i = 0; i < s.size(); i++)
	{
		if(i % 2 == 0)
		{
			if(s[i] == 'L')
			{
				cout << "No" << endl;
				flag = true;
				break;
			}
		}else
		{
			if(s[i] == 'R')
			{
				cout << "No" << endl;
				flag = true;
				break;
			}
		}
	}
	
	if(!flag) cout << "Yes" << endl;
	
    return 0;
}

Measured memory_bytes: 256