akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static  void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> array = new ArrayList<>();
        for(int i = 0; i < n; i++){
            array.add(scanner.nextInt());
        }
        int count = 0;
        int pre = 0;
        for(int i = 0; i < n; i++){
            count += Math.abs(array.get(i) - pre);
            pre = array.get(i);
        }
        count += Math.abs(array.get(array.size()-1));
        //System.out.println(count);

        for(int i = 0; i < n; i++){
            int ans = count;
            if(i == 0){
                ans -= Math.abs(array.get(i));
                ans -= Math.abs(array.get(i) - array.get(i+1));
                ans += Math.abs(array.get(i+1));
            }else if(i == n-1){
                ans -= Math.abs(array.get(i-1) - array.get(i));
                ans -= Math.abs(array.get(i));
                ans += Math.abs(array.get(i-1));
            }else{
                ans -= Math.abs(array.get(i-1) - array.get(i));
                ans -= Math.abs(array.get(i) - array.get(i+1));
                ans += Math.abs(array.get(i-1) - array.get(i+1));
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 74068
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()
t = input()

a = []
for i in range(len(s) - len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if t[j] == s[i + j]:
            cnt += 1
    a.append(cnt)
print(len(t) - max(a))


Measured memory_bytes: 8996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll inf = 3e18;
const char sp = ' ';

int N;

int main() {
	cin >> N;
	for (int i = 0; i <= N; i++) {
		if (int((i + 0.000001)*1.08) == N) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}

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

int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    int x3=x2-(y2-y1);
    int y3=y2+(x2-x1);
    int x4=x1-(y2-y1);
    int y4=y1+(x2-x1);
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

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

unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return b != 0 ? gcd(b, a % b) : a;
}
unsigned long long lcm(unsigned long long m, unsigned long long n) {
    return m*n / gcd(m,n);
}

int main(void){

    unsigned long long a, b, c, d;
    cin >> a >> b >> c >> d;

    unsigned long long div_count_c = 0;
    unsigned long long div_count_d = 0;
    
    div_count_c = (b/c)-(a/c);
    div_count_d = (b/d)-(a/d);
    if(a%c==0) div_count_c++;
    if(a%d==0) div_count_d++;
    
    unsigned long long g = lcm(c, d);
    unsigned long long same_count = (b/g)-(a/g);
    if(a%g==0) same_count++;

    unsigned long long result = (b-a+1)-(div_count_c+div_count_d)+same_count;

    cout << result << endl;

    return 0;
}


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

string solve() {
    ll A, B;
    cin >> A >> B;
    if ( A > 0 ) return "Positive";
    else if ( A <= 0 && 0 <= B ) return "Zero";
    else if ( (B-A) % 2 == 0 ) return "Negative";
    else return "Positive";
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <queue>
#include <set>

using namespace std;

const int inf = 1 << 30;

int solve(const vector<int> &a, int k, int v, int q) {
  const int n = a.size();

  vector<int> t;

  for(int i = 0; i < n; ){
    if(a[i] < v){ i++; continue; }

    vector<int> tt;
    for(; i < n && a[i] >= v; i++) tt.push_back(a[i]);

    if(k <= (int)tt.size()){
      sort(tt.begin(), tt.end());
      REP(j,k-1) tt.pop_back();
      for(int j : tt) t.push_back(j);
    }
  }

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

  if(q >(int)t.size()) return inf;
  return t[q - 1] - t[0];
}

int main(){
  const int n = getInt();
  const int k = getInt();
  const int q = getInt();

  vector<int> a(n);
  REP(i,n) a[i] = getInt();

  int ans = inf;
  REP(i,n) ans = min(ans, solve(a, k, a[i], q));

  printf("%d\n", ans);

  return 0;
}

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

#define WMAX 30
#define NMAX 30

int v_pos[WMAX]; // ??????????????????????????????????????¶???

void exchange(int v_pos[], int a, int b){
	swap(v_pos[a], v_pos[b]);
}

int main(){
	int w, n;
	int a, b;
	char input[6], *token1, *token2;
	cin >> w >> n;
	for(int i=1;i<=w;i++){
		v_pos[i] = i;
	}

	for(int i=1;i<=n;i++){
		scanf("%d,%d", &a, &b);
		exchange(v_pos, a, b);
	}
	for(int i=1;i<=w;i++){
		printf("%d\n", v_pos[i]);
	}
	return 0;
}

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

#define N_MAX 200002

using namespace std;

string a;

int n;

string b;

int main()
{
    cin >> a;
    n = a.size();
    a = " " + a;
    b = " ";
    for(int i = 1; i <= n; i++)
    {
        if(i < n && a[i] == 'B' && a[i + 1] == 'C')
        {
            b += 'X';
            i++;
            continue;
        }
        b += a[i];
    }
    int cnta = 0;
    long long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(b[i] == 'A')
            cnta++;
        else if(b[i] == 'X')
            ans += cnta;
        else
            cnta = 0;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll INV[200005];
void MI() 
{     ll n=200005;
INV[0] = INV[1] = 1; 
    for (ll i = 2; i <= 200005; i++)  
        INV[i] = INV[mod % i]*(mod - mod / i) % mod,INV[i]%=mod;     

}
long long int ncr(ll n, ll r){
  // space O(1) time O(min(r,n-r));
       if(n-r<r){
           r=n-r;
       }
   
        long long int res=1;
        for(int i=0;i<r;i++){
           res*=(n-i),res%=mod;
            res*=INV[i+1],res%=mod;
        }
        
        return res%mod;
    }
ll find(ll n){
	ll a=2;
	ll res=1;
	while(n){
		 if(n&1)
		 res=(res*a)%mod;
		 a=(a*a)%mod;
		 n/=2;
	}
	return res%mod;
}
void solve(){
ll n,a,b;
cin>>n>>a>>b;
ll k=(find(n)-1+mod)%mod;
cout<<(k-ncr(n,a)-ncr(n,b)+2*mod)%mod;
 
}
int main(){
	MI();
    ll t=1;
   // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3 >= 22){
        print("bust");
    }else{
        print("win");
    }

    

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b,i,j;
  while(1)
       {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0){break;}
 
  for(i=1;i<=a;i++)
    {
      for(j=1;j<=b;j++)
    {
      if(j%2==1)
        {
          if(i%2==1)printf("#");
          else printf(".");
        }
      else
        {
              if(i%2==1)printf(".");
          else printf("#");
        }
    }
      printf("\n");
    }
  printf("\n");
     
       }
  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  
  int sum = 0;
  int x = N;
  while(x > 0){
    sum += x%10;
    x /= 10;
  }
  
  if( (N % sum) == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    int N;
    cin >> N;

    vector<int> A;
    int temp = 0;
    for(int i=0; i<N; i++){
        cin >> temp;
        if(temp % 2 == 1) continue;
        A.emplace_back(temp);
    }

    REP(i,A.size()){
        if((A[i] % 3 != 0) && (A[i] % 5 != 0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << "\n";

return 0;
}

Measured memory_bytes: 256
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    int32 A, B, C, D;
    cin >> A >> B >> C >> D;

    int32 start = max(A, C);
    int32 end = min(B, D);

    if(end - start > 0){
        cout << end-start << endl;
    }else{
        cout << 0 << endl;
    }
    return;
}



Measured memory_bytes: 256
// AOJ 2820 Binary Sequence
// 2018.3.22 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//// 高速数値入出力
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
// 非負整数の入力
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

// 文字列の入力　スペース以下の文字で入力終了
void ins(char *s)
{
	do *s = gc();
	while (*s++ > ' ');
	*(s - 1) = 0;
}

// 非負整数の表示、最後改行あり
void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

// 空間の併合・分割（木構造ではない）
#define MAX 100005
typedef struct { int a, b; } B;
B data[MAX]; int BN;

void b_init()
{
	BN = 2, data[0].a = data[0].b = -1, data[1].a = data[1].b = MAX;
}

// バイナリサーチ
int bsch(int x)
{
	int m, l = 0, r = BN;
	while (l < r) {
		m = (l + r) >> 1;
		if (data[m].a == x) return m;
		if (data[m].a < x) l = m + 1; else r = m;
	}
	return l - 1;
}

// ブロック移動（木構造にすればもっと高速になるのに）
static void insert(int l, int r, int a, int b)
{
	if (r < l) memmove(data + l + 1, data + l, sizeof(B)*(BN - l)), BN++;
	else if (l < r) memmove(data + l, data + r, sizeof(B)*(BN - r)), BN -= r - l;
	data[l].a = a, data[l].b = b;
}

static void delete(int l, int r)
{
	if (r < l) return;
	memmove(data + l, data + r + 1, sizeof(B)*(BN - (r + 1)));
	BN -= r-l+1;
}
// 空間の登録
void update(int mode, int a, int b)
{
	int l = bsch(a), r = bsch(b);
	if (mode) {
		if (b <= data[l].b) return;
		if (data[l].b < a && data[l].b + 1 != a) l++; else a = data[l].a;
		if (b < data[r].b) b = data[r].b;
		if (data[r + 1].a == b + 1) b = data[++r].b;
		insert(l, r, a, b);
	}
	else {
		if (l == r) {
			if (data[l].a == a) {
				if (data[l].b <= b) delete(l, l);
				else data[l].a = b + 1;
			}
			else if (b < data[l].b) {
				memmove(data+l+2, data+l+1, sizeof(B)*(BN-l-1)), BN++;
				data[l+1].a = b+1, data[l+1].b = data[l].b;
				data[l].b = a-1;
			} else if (a <= data[l].b) data[l].b = a - 1;
		}
		else {
			if (data[l].a == a) ;
			else {
				if (a <= data[l].b) data[l].b = a - 1;
				l++;
			}

			if (b < data[r].b) data[r].a = b + 1, r--;
			delete(l, r);
		}
	}
}

// 離れた空間の数
int query() { return BN - 2; }


// 本問題関連
char x[MAX]; int N;

int main()
{
	int i, ii, Q, l, r, b;

	// 入力受付
	N = in(), ins(x+1);
	
	// 連続する'1'の空間登録
	b_init();     // 初期化
	ii = 0; for (i = 1; i <= N; i++) {
		if (x[i] & 1) {
			if (!ii) ii = i;
		}
		else {
			if (ii) update(1, ii, i - 1), ii = 0;
		}
	}
	if (ii) update(1, ii, i - 1);

	Q = in(); while (Q--) {
		l = in(), r = in(), b = gc(), gc();
		if (l > r) update(b & 1, r, l);
		else       update(b & 1, l, r);
		out(query());
	}
	return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<iomanip>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
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 long long INF = 1LL << 60;
//以下変更可能領域

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];
    sort(d.begin(),d.end());
    cout << d[N/2] - d[N/2-1] << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define dbg(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    long long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        long long d = (a[i] + ans) % b[i];
        if (d) ans += b[i] -d;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
A, B, C, D =map(int, input().split())
t = 0
while A > 0 and C > 0:
  if t%2 == 0:
    C = C - B
  else:
    A = A - D
  t += 1
if C <= 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

const ll INF = 1LL << 61;

int main(){
    string a,b;
    cin >> a >> b;
    if (a.size() < b.size()) {
        cout << "LESS" << endl;
        return 0;
    }
    else if (a.size() > b.size()) {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (a.size() == b.size()){
        for (int i=0;i < a.size();i++){
            int x,y;
            x=stoi(a.substr(i,1));
            y=stoi(b.substr(i,1));
            if ( x == y) continue;
            else if (x < y){
                cout << "LESS" << endl;
                return 0;
            } 
            else {
                cout << "GREATER" << endl;
                return 0;
            }
         }
    }
    cout << "EQUAL" << endl;
    return 0;
}

Measured memory_bytes: 256
n, d = map(int, input().split())

l = []

for i in range(n):
	list_temp = list(map(int, input().split()))
	l.append(list_temp)

# 入力取得

# カウントする

cnt = 0

# 二重for

for i in range(n) :
#	print(i,l[i])
	for j in range (i+1,n):
#		print(i,j,l[j])
		s = 0
		
		for k in range(d):
#			print(d,l[i][d],l[j][d])
			s += ( l[i][k] - l[j][k]) ** 2 
		result = s ** (1/2)

		if result.is_integer():
			cnt += 1

print(cnt)

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

using namespace std ;

#define ll long long

ll a , b , d , e , f , g , h , cnt , ans = 1e9 , sum ;

int main ()
{
        cin >> a >> b ;
    vector < ll > c ( a ) ;
    for ( int i = 0 ; i < a ; ++ i ){
        cin >> c [ i ] ;
    }
    for ( int i = 0 ; i < a - b + 1 ; ++ i ){
        ans = min ( ans , c [ i + b - 1 ] - c [ i ] + min ( abs ( c [ i + b - 1 ] ) , abs ( c [ i ] ) ) ) ;
    }
    cout << ans ;
}

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

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

    vector<ll> h(n);
    rep(i,n) cin >> h[i];

    sort(h.begin(), h.end(), greater<int>() );

    ll ans = 0;
    for (int i = k; i < n; i++) {
        ans += h[i];
    }

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

Measured memory_bytes: 4784
#include<bits/stdc++.h>
      using namespace std;
      #define ll long long
      #define pb push_back
      #define pll  pair <long long,long long>
      #define mp make_pair
      #define ss second
      #define ff first
      #define maa 1000000007
      #define endl '\n'
      #define ld long double
      #define all(x) x.begin(),x.end()
      ll  power(ll  i,ll  j)
      {
        if(j==0)
        return 1 ;
        ll t=power(i,j/2)%maa ;
        if(j%2==0)
        return (t%maa*t%maa)%maa ;
        else
        return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
      }
      bool is(ll  i)
      {
        if(i==1)
            return 0 ;
        ll  f=0 ;
        for(ll  j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                f=1 ;
                break ;
            }
        }
        return !f ;
      }
      ll n ;
      double p[3001] ;
      double dp[3001][3001] ;
      int main()
      {

        /// 50-4
        /// freopen("input.txt","r",stdin);
        /// freopen("output.txt","w",stdout);
        cout<<fixed<<setprecision(10) ;
        cin>>n ;
        for(ll i=1;i<=n;i++)
        cin>>p[i] ;
        for(ll i=0;i<3001;i++)
        {
            for(ll j=0;j<3001;j++)
            dp[i][j]=0.0 ;
        }
        dp[1][1]=p[1] ;
        dp[1][0]=(1.0-p[1]) ;
        for(ll i=2;i<=n;i++)
        {
            for(ll j=0;j<=i;j++)
            {
                dp[i][j]=dp[i-1][j]*(1.0-p[i]) ;
                if(j-1>=0)
                dp[i][j]+=dp[i-1][j-1]*p[i] ;
            }
        }
        ld ans=0.0 ;
        for(ll j=(n+1)/2;j<=n;j++)
        {
            ans+=dp[n][j] ;
           // cout<<dp[n][j]<<endl ;
        }
       /* for(ll i=1;i<=n;i++)
        {
            for(ll j=0;j<=i;j++)
            {
                cout<<dp[i][j]<<" " ;
            }
            cout<<endl ;
        }*/
        cout<<ans ;
        
        
       
        
        

      }








Measured memory_bytes: 70656
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = 0
    for n in range(1, N + 1):
        if len(str(n)) % 2 != 0: ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10220
#include <bits/stdc++.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(){
    int a, b, c, m;
    cin >> a >> b >> c;
    m = MAX(a, MAX(b, c));
    cout << a + b + c - m << endl;


}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	fast;
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=0; i<n; i++){
        cin>>arr[i+1];
    }
    if(k>=n){cout<<abs(arr[n]-arr[1]);return 0;}
    int dp[n+1]={};
    for(int i=1; i<=k ;i++){
      dp[i] = abs(arr[i]-arr[1]);
    }

    int temp;
    for(int i=k+1; i<=n; i++){
            temp = numeric_limits<int>::max();

            for(int j=1; i-j>=1 && j<=k; j++){
                temp = min(temp,dp[i-j]+abs(arr[i]-arr[i-j]));
            }
            dp[i] = temp;
    }
    cout<<dp[n];
    return 0;
}



Measured memory_bytes: 1024
require "set"

m, n, k = gets.split.map(&:to_i)

a = (1..m).map { [?X] + gets.chomp.split("") + [?X] }
a << [?X] * (n+2)
a.unshift([?X] * (n+2))

points = []
(1..m).each{|i|
	(1..n).each{|j|
		case a[i][j]
		when ?S
			points[0] = [i,j]
		when /\d/
			points[a[i][j].to_i] = [i,j]
		end
	}
}

total_dist = 0

points.each_cons(2){|s, t|
	reached = Set[s]
	dist = 0
	queue = [s]
	found = false
	loop {
		next_queue = []
		until queue.empty?
			u = queue.shift
			if u == t
				found = true
				break
			end
			i, j = u
			[[1,0],[-1,0],[0,1],[0,-1]].each{|dx, dy|
				y, x = i+dy, j+dx
				v = [y, x]
				if a[y][x] != ?X && !reached.include?(v)
					reached << v
					next_queue << v
				end
			}
		end	
		break if found
		queue = next_queue
		dist += 1
	}
	total_dist += dist
}
p total_dist

Measured memory_bytes: 166764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


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

a, b, c  = in_ints()
print(c, a, b)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    
   string s;
   cin >> s;
   if(s[2] == s[3] && s[4] == s[5]){
       cout << "Yes";
   } else{
       cout << "No";
   }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 1e5;
int a[MXN+5], dp[MXN+5];
int N,K;

int rec(int pos){

    if(pos==N) return 0;
    if(pos>=N) return 1<<30;
    if(dp[pos]!=-1) return dp[pos];
    return dp[pos] = min( rec(pos+1) + abs(a[pos+1]-a[pos]) , rec(pos+2) + abs(a[pos+2]-a[pos]) );
}

void solve(){

    cin>>N;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=N; i++) cin>>a[i];
    cout<< rec(1) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int num = 0;
  rep(i, 0 , 3)
  {
    int a;
    cin>>a;
    num = num*10 + a;
  }
  if(num%4 == 0) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; ++i) { cin >> L[i]; }
	sort(L.begin(), L.end());

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int l = upper_bound(L.begin(), L.end(), L[j] - L[i]) - L.begin();
			int r = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();

			if (l >= r || i <= l || i > r) { continue; }
			ans += min(i, r) - l;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
INF = 100010
array = [[] for _ in range(n)]
ans = [0 for _ in range(m)]

for i in range(m):
    p, y = map(int, input().split())
    array[p-1].append([y, i])

for i, elem in enumerate(array):
    elem = sorted(elem)
    for index, e in enumerate(elem):
        str = "{0:06d}{1:06d}".format(i+1, index+1)
        ans[e[1]] = str
print("\n".join(ans))


Measured memory_bytes: 41496
d,*s,=map(int,open(i:=0).read().split())
c,*l=[0]*27
for v in s[-d:]:
  i+=1
  l[v-1]=i
  print(c:=c+s[i*26+v-1]-sum(x*(i-y)for x,y in zip(s,l)))

Measured memory_bytes: 10164
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a;
	cin >> a;
	if (a[0] == a[1] && a[1] == a[2]) {
		cout << "Yes" << endl;
	}
	else if (a[1] == a[2] && a[2] == a[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
  const string cli = "rsp";
  const string pli = "prs";
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  const int points[3] = {P, R, S};
  int pts = 0;
  char kis = 0;
  string klis = "";
  for (int i = 0; i < N; i++) {
    if (i >= K) kis = klis.at(i - K);
    char p = pli.at(cli.find(T.at(i)));
    if (p != kis) {
      pts += points[pli.find(p)];
      klis.push_back(p);
    } else {
      klis.push_back(0);
    }
  }
  cout << pts << "\n";
  return 0;
}

Measured memory_bytes: 512
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let a: usize = parse_line().unwrap();
    let b: usize = parse_line().unwrap();
    let c: usize = parse_line().unwrap();
    let d: usize = parse_line().unwrap();

    println!("{}", a.min(b) + c.min(d));
}


Measured memory_bytes: 2152
A = int(input())
B = int(input())
C = int(input())
X = int(input())

a, b, c = (0, 0, 0)

counter = 0

for a in range(A+1):
	
	'''
	if X == sum_c:
		counter += 1
		break
	elif sum_c > X:
		break
	'''
	for b in range(B+1):
	
		'''
		if X == sum_bc:
			counter += 1
			break
		elif sum_bc > X:
			break
		'''
		for c in range(C+1):
			if X == a * 500 + b * 100  + c * 50:
				counter += 1
				#break


print(counter)



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end();
int main() {
  int a,ans=0,MAX=0;
  cin >> a;
  int b[a];
  rep(i,a){
    cin >> b[i];
    ans += b[i];
    MAX = max(MAX,b[i]);
    }
  if(ans<=(MAX*2))cout << "No";
  else cout << "Yes";
}

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N, M;
   cin >> N >> M;
   vector<vector<int>> adj(N);
   for (int i = 0; i < M; ++i) {
      int v, u;
      cin >> v >> u;
      adj[--v].emplace_back(--u);
      adj[u].emplace_back(v);
   }
   int Q;
   cin >> Q;
   vector<int> color(Q + 1);
   vector<array<int, 11>> dp(N);
   for (int i = 1; i <= Q; ++i) {
      int v, d;
      cin >> v >> d >> color[i];
      dp[--v][d] = i;
   }
   for (int d = 10; d > 0; --d) {
      for (int v = 0; v < N; ++v) {
         dp[v][d - 1] = max(dp[v][d - 1], dp[v][d]);
         for (int u : adj[v]) {
            dp[u][d - 1] = max(dp[u][d - 1], dp[v][d]);
         }
      }
   }
   for (int i = 0; i < N; ++i) cout << color[dp[i][0]] << "\n";
   return 0;
}


Measured memory_bytes: 11256
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] lr = new int[n][2];
        for (int i = 0; i < n;i++){
            for (int j = 0; j < 2; j++){
                lr[i][j] = sc.nextInt();
            }
        }
        int result = 0;
        for (int i = 0;i < n;i++){
            result += lr[i][1] - lr[i][0] + 1;
        }
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 27080
n,m=map(int,input().split())
yakusuu=[]
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    yakusuu.append(m//i)
    if m//i==i:continue
    yakusuu.append(i)
ans=0
for y in yakusuu:
  if y<n:continue
  if m%y==0:
    ans=max(ans,m//y)
print(ans)


Measured memory_bytes: 9380
n = int(input())
a = [1]

for i in range(1, 7):
    a.append(pow(6, i))

for i in range(1, 6):
    a.append(pow(9, i))

dp = [0] * 100001
for i in range(1, n+1):
    m = dp[i-1] + 1
    for v in a:
        if i - v < 0:
            continue
        if m > dp[i-v] + 1:
            m = dp[i-v] + 1
    dp[i] = m

print(dp[n])


Measured memory_bytes: 3828
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,b,c,x,y,z;

  scanf("%d%d%d", &a,&b,&c);
  x=abs(a-b);
  y=abs(b-c);
  z=abs(c-a);

  if(x<=z && y<=z){
    printf("%d\n", x+y);
  }else if(x<=y && z<=y){
    printf("%d\n", x+z);
  }else{
    printf("%d\n", y+z);
  }

  return 0;
}

Measured memory_bytes: 128
n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
c = 0
for i in range(n-1):
  if abs(a[i+1]-p/2) < abs(a[i]-p/2):
    c = a[i+1]
  else:
    break
print(p,c)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "YES" << '\n'; exit(0); }
inline void no() { cout << "NO" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  pqdesc<pair<int, char>> pq;
  {
    vi32 cnt(26);
    rep(i, n) {
      cnt[s[i] - 'a']++;
    }
    rep(i, 26) if (cnt[i] > 0) pq.emplace(cnt[i], (char) i + 'a');
  }
  rep(i, n / 3) {
    auto x = pq.top(); pq.pop();
    if (pq.size() == 0) no();
    auto y = pq.top(); pq.pop();
    if (pq.size() == 0) no();
    auto z = pq.top(); pq.pop();
    if (x.first > 1) pq.emplace(x.first - 1, x.second);
    if (y.first > 1) pq.emplace(y.first - 1, y.second);
    if (z.first > 1) pq.emplace(z.first - 1, z.second);
  }
  cerr << pq.size() << endl;
  if (pq.size() == n - n / 3 * 3) {
    yes();
  } else {
    no();
  }
}


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

typedef long double ld;
//#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
ld pi= 3.14159265358979;
const int mod = 1e9+7;
const int N = 1e6+7;
int h[N];
void solve()
{  
	int n ; cin>>n;
	int a[n];
	int mx = 0;
	rep(i, 0, n){
		cin>>a[i];
		mx = max(a[i], mx); 
	}
	sort(a, a+n);
	int mul[N]={};
	rep(i, 0, n){
		if(!h[a[i]] && !mul[a[i]]){
			for(int j=2*a[i]; j<=mx; j+=a[i]){
				mul[j] = 1;
			}
		}
		h[a[i]]++;
	}
	int ans=0;
	rep(i, 1, 1000001){
		if(h[i] == 1 && !mul[i]) ans++;
	}
	cout<<ans;
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout<<setprecision(20);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


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

using namespace std;

long long int n;
long long int tablica[403];
long long int dp[403][403];

long long int suma(long long int lewa,long long int prawa)
{
    long long int x = 0;
    for(int j = lewa; j <= prawa; j++){
        x += tablica[j];
    }
    return x;
}

long long int licz(long long int lewa,long long int prawa)
{
    if(lewa==prawa){
        return 0;
    }
    if(dp[lewa][prawa]!=0){
        return dp[lewa][prawa];
    }
    dp[lewa][prawa]=2000000000000000000;
    for(long long int s=lewa;s<=prawa;s++){
        dp[lewa][prawa]=min(dp[lewa][prawa], licz(lewa, s)+licz(s+1, prawa)+suma(lewa, prawa));
    }
    return dp[lewa][prawa];
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tablica[i];
    }
    cout << licz(0, n-1);
    return 0;
}


Measured memory_bytes: 1536
/**
 *  Amida, the City of Miracle (Problem A, Practice Contest for Japan Domestic, 2006-06-18)
 *  by Kenji Inoue, 2007-01-05
 **/

#include <iostream>
#include <map>
#include <set>

using namespace std;

typedef multimap< int, pair<int, int> > HL; // horizontal line

int main() {
  int n, m, a;
  while (cin >> n >> m >> a, (n || m || a)) {
    HL hl;
    set<int> hs; // heights
    for (int i=0; i<m; i++) {
      int h, p, q;
      cin >> h >> p >> q;
      hl.insert( make_pair(h, make_pair(p, q)) );
      hs.insert(h);
    }

    int c = a; // current line
    for (set<int>::reverse_iterator sit = hs.rbegin(); sit != hs.rend(); sit++) {
      int h = *sit;
      for (HL::iterator it = hl.lower_bound(h); it != hl.upper_bound(h); it++) {
        pair<int, int> v = it->second;
        if (v.first == c) {
          c = v.second;
          break;
        } else if (v.second == c) {
          c = v.first;
          break;
        }
      }
    }

    cout << c << endl;
  }

  return 0;
}

Measured memory_bytes: 3196
s = input()
n = len(s)

k1 = int((n-1)/2)
k2 = int((n+3)/2)

ans = 0
a = 0

for i in range(k1):
    a += 1
    if s[i] != s[n-a]:
        ans += 1

a = 0
for x in range(int(k1/2)):
    a += 1
    if s[x] != s[k1-a]:
        ans += 1

a = 0
for y in range(k2-1,n):
    a += 1
    if s[y] != s[n-a]:
        ans += 1

if ans == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
/*  
    Come feed the rain
	Cos I'm thirsty for your love
	Dancing underneath the skies of lust
	Yeah feed the rain...
	Cos without your love my life
	Ain't nothing but this carnival of rust
    _________________________
    _________________________
    816 Hours of Solitude
    Quarantine_Day : 34
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005

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

	int k, s; 
	cin>>k>>s;

	int res = 0;
	FOR(x, 0, k){
		FOR(y, 0, k){
			int z = s - x - y;
			if(z >= 0 && z<= k) res++;
		}
	}
	cout<<res<<"\n";

	return 0;
}


Measured memory_bytes: 256
import sys
def main():
    input=sys.stdin.readline
    h,w=map(int,input().split())
    a=[list(map(int,input().split())) for _ in range(h)]
    b=[list(map(int,input().split())) for _ in range(h)]
    ofset = 80*164
    #mask = (1 << (ofset*2)) - 1
    dp=[[0 for i in range(w)] for j in range(h)]
    dp[0][0] |= 1 << (a[0][0] - b[0][0] + ofset)
    dp[0][0] |= 1 << (b[0][0] - a[0][0] + ofset)
    for i in range(h):
        for j in range(w):
            if i < h - 1:
                A = abs(a[i+1][j] - b[i+1][j])
                dp[i+1][j] |= (dp[i][j] << A)
                dp[i+1][j] |= (dp[i][j] >> A)
            if j < w - 1:
                A = abs(a[i][j+1] - b[i][j+1])
                dp[i][j+1] |= (dp[i][j] << A)
                dp[i][j+1] |= (dp[i][j] >> A)
    ans = 10000000000
    for i in range(ofset, 80*330):
        if (dp[h-1][w-1]>>i)&1: ans = min(ans, i - ofset)
    for i in range(ofset):
        if (dp[h-1][w-1]>>i)&1: ans = min(ans, ofset - i)
    print(ans)
if __name__=='__main__':
  main()


Measured memory_bytes: 63452
input = gets.chomp.to_i
i = 1
j = 1
k = 1
a = 0
(1..input).each{|i|
  (1..input).each{|j|
    (1..input).each{|k|
      a += i.gcd(j).gcd(k)
    }
  }
}
puts a

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

int main() {
  ll N;
  cin >> N;
  ll ans = 1e18;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i != 0) continue;
    ll j = N / i;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  string S,T;
  int N;
  cin>>N>>S>>T;
  
  rep(i,N){cout<<S.at(i)<<T.at(i);}
  cout<<endl;
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(){
  int n,k;
  char s[100];
  char c;
  scanf("%d%d",&n,&k);
  scanf("%s",s);
  c = s[k-1];
  if(c == 'A')c = 'a';
  else if(c == 'B')c = 'b';
  else c = 'c';
  s[k-1] = c;
  printf("%s",s);
}

Measured memory_bytes: 128
//it was hard to write
//so it should be hard to read
#include <bits/stdc++.h>
#define sz size
#define pb push_back
#define ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define last(x) (x).size() - 1
#define mp make_pair

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef double ld;

const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 7;
const int inf = 1e9 + 7;
const double EPS = 1e-9;

int to_int(char a, char b) {
    return (a - '0') * 10 + (b - '0');
}

string s;
int a, b;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    cin >> s;
    a = to_int(s[0], s[1]);
    b = to_int(s[2], s[3]);
    if (a == 0 && b == 0) {
        cout << "NA";
    }
    else if (a >= 12 && b == 0) {
        cout << "NA";
    }
    else if (b >= 12 && a == 0) {
        cout << "NA";
    }
    else if (b > 12 && a > 12) {
        cout << "NA";
    }
    else if (a <= 12 && b <= 12) {
        if (a > 0 && b > 0) cout << "AMBIGUOUS";
        else if (a == 0) cout << "YYMM";
        else if (b == 0) cout << "MMYY";
    }
    else {
        if (b >= 12 && a <= 12) {
            cout << "MMYY";
        }
        if (a >= 12 && b <= 12) {
            cout << "YYMM";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    string s,t;cin>>s>>t;
  string u = s;
    int sz = s.size();
    rep(i,sz){
      s = u[sz-i-1]+s.erase(sz-1);
        if(s==t){cout<<"Yes";return 0;}
      //cout<<s<<endl;
        //s = u;
    }
    cout<<"No";
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N, K;
  scanf("%lld %lld", &N, &K);

  vector<ll> list(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list[i] = v;
  }
  sort(list.begin(), list.end());

  ll left = 0;
  ll right = K - 1;

  ll ans = INF;
  for (;;) {
    ll df = list[right] - list[left];
    ans = min(ans, df);

    left++;
    right++;

    if (right >= N) {
      break;
    }
  }
  cout << ans << endl;
}


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

vector<vector<int>> G;
vector<int> V;
int ans;

void dfs(int v) {
  if (accumulate(V.begin(), V.end(), 0) == V.size() - 1) {
    ans++;
    return;
  }
  for (auto g : G.at(v)) {
    if (V.at(g)) continue;
    V.at(v) = 1;
    dfs(g);
    V.at(v) = 0;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  G.resize(N);
  V.resize(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b), G.at(b).push_back(a);
  }
  dfs(0);
  cout << ans << "\n";
}


Measured memory_bytes: 256
n,m = map(int,input().split())

person = []
point= []

for _ in range(n):
    a,b = map(int,input().split())
    person.append((a,b))

for _ in range(m):
    c,d = map(int,input().split())
    point.append((c,d))

for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(person[i][0]-point[j][0]) + abs(person[i][1]-point[j][1]))
    ind = ans.index(min(ans))
    print(ind + 1)


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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;
int fct[200005], ifct[200005];

int N, X, Y;
vector <int> w[200005];
bitset <200005> f;
vector <int> clr;
int cnt[200005];
int tot;

int power(int x, int y)
{
    int p = x, r = 1;
    while(y)
    {
        if(y & 1)   r = (1LL * r * p) % mod;
        p = (1LL * p * p) % mod;
        y >>= 1;
    }
    return r;
}

bool cmp(int a, int b)
{
    return w[a][0] < w[b][0];
}

void calc(int c, int vmin, int valc)
{
    int p = 0;
    int u = (int)w[c].size() - 1;
    int pos = 0;
    while(p <= u)
    {
        int mij = p + (u - p) / 2;
        int val = w[c][mij];
        if(Y - vmin >= val || X - valc >= val)
        {
            pos = mij;
            p = mij + 1;
        }
        else
            u = mij - 1;
    }
    cnt[c] = pos + 1;
    tot += cnt[c];
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d%d", &N, &X, &Y);
    for(int i = 1; i <= N; i++)
    {
        int c, v;
        scanf("%d%d", &c, &v);
        w[c].push_back(v);
        if(f[c])    continue;
        f[c] = 1;
        clr.push_back(c);
    }

    if(clr.size() == 1)
    {
        printf("1\n");
        return 0;
    }

    fct[0] = 1;
    for(int i = 1; i <= N; i++) fct[i] = (1LL * fct[i - 1] * i) % mod;
    ifct[N] = power(fct[N], mod - 2);
    for(int i = N - 1; i >= 1; i--) ifct[i] = (1LL * ifct[i + 1] * (i + 1)) % mod;
    ifct[0] = 1;

    for(auto c: clr)    sort(w[c].begin(), w[c].end());
    sort(clr.begin(), clr.end(), cmp);
    int vmin = w[ clr[0] ][0];
    for(int i = 1; i < clr.size(); i++)
    {
        int c = clr[i];
        if(Y - vmin < w[c][0]) break;
        int valc = w[c][0];
        calc(c, vmin, valc);
    }

    if(cnt[ clr[1] ] == 0)
    {
        printf("1\n");
        return 0;
    }

    calc(clr[0], w[ clr[1] ][0], vmin);

    int ans = fct[tot];
    for(auto c: clr)    ans = (1LL * ans * ifct[ cnt[c] ]) % mod;

    printf("%d\n", ans);


    return 0;
}


Measured memory_bytes: 12148