akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
    {
        static void Main(string[] args)
        {
            string temp=Console.ReadLine();
            int place_num=int.Parse(temp);
          　string[] temp_d = Console.ReadLine().Split(' ');
            int tempature_base=int.Parse(temp_d[0]);
            int target=int.Parse(temp_d[1]);
            string[] temp_h = Console.ReadLine().Split(' ');
            double[] tempature_place=new double[place_num];
            double abs=1000000;
            int output=0;
            for(int i=0;i<place_num;i++){
            int h=int.Parse(temp_h[i]);
            tempature_place[i]=tempature_base-h*0.006d;
              if(abs>Math.Abs(tempature_place[i]-target))
              {abs=Math.Abs(tempature_place[i]-target);
               output=i+1;             
              }
            }
            
            Console.WriteLine(output);
        }
    }

Measured memory_bytes: 13212
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    text = (['Sunny', 'Cloudy'], ['Cloudy', 'Rainy'],['Rainy','Sunny'])
    s = SI()
    for i in text:
        if s == i[0]:
            print(i[1])

main()

Measured memory_bytes: 3064
///
// File:  cgl_2_c.cpp
// Author: ymiyamoto
//
// Created on Mon Oct 23 00:28:22 2017
//
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;
#define EPS 1e-10
#define equals(x, y) (fabs(x - y) < EPS)

struct vector_t {
  double x;
  double y;

  vector_t(double a, double b) : x(a), y(b)
  {
  }

  double norm2()
  {
    return x * x + y * y;
  }

  double norm()
  {
    return sqrt(norm2());
  }

  double dot(vector_t a)
  {
    return x * a.x + y * a.y;
  }

  double cross(vector_t a)
  {
    return x * a.y - y * a.x;
  }

  vector_t operator*(double a)
  {
    return vector_t(a * x, a * y);
  }
};

struct point_t {
  double x;
  double y;

  point_t operator+(const point_t a)
  {
    return point_t({x + a.x, y + a.y});
  }

  void print()
  {
    cout << fixed << setprecision(10) << x << " " << y << endl;
  }

  point_t operator+(const vector_t vec)
  {
    return point_t({x + vec.x, y + vec.y});
  }

  vector_t operator-(const point_t p)
  {
    return vector_t({x - p.x, y - p.y});
  }

  point_t project(point_t p1, point_t p2)
  {
    vector_t vec1(x - p1.x, y - p1.y);
    vector_t vec2(p2.x - x, p2.y - y);
    return point_t({x, y}) + vec1 * (vec1.dot(vec2) / vec1.norm2());
  }

  point_t reflect(point_t p1, point_t p2)
  {
    point_t proj = project(p1, p2);
    return p2 + (proj - p2) * 2.0;
  }
};

enum pos_t {
  CCLOCKWISE = -1,
  CLOCKWISE = 1,
  ONLINE_BACK = 2,
  ONLINE_FRONT = -2,
  ON_SEGMENT = 0,
};

pos_t ccw(point_t p0, point_t p1, point_t p2)
{
  if ((p1 - p0).cross(p2 - p0) > EPS) {
    return CCLOCKWISE;
  } else if ((p1 - p0).cross(p2 - p0) < -EPS) {
    return CLOCKWISE;
  } else if ((p1 - p0).dot(p2 - p0) < -EPS) {
    return ONLINE_BACK;
  } else {
    if ((p1 - p0).norm2() < (p2 - p0).norm2()) {
      return ONLINE_FRONT;
    } else {
      return ON_SEGMENT;
    }
  }
}

bool intersection(point_t p0, point_t p1, point_t p2, point_t p3)
{
  return (ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0) && (ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0);
}

struct segment_t {
  point_t a;
  point_t b;

  double distance(point_t p0)
  {
    if ((b - a).dot(p0 - a) < 0.0) {
      return (p0 - a).norm();
    } else if ((a - b).dot(p0 - b) < 0.0) {
      return (p0 - b).norm();
    } else {
      return fabs((b - a).cross(p0 - a) / (b - a).norm());
    }
  }
};

int32_t main()
{
  uint32_t q;
  cin >> q;

  for (uint32_t i = 0; i < q; i++) {
    double x, y;
    cin >> x >> y;
    point_t p0({x, y});
    cin >> x >> y;
    point_t p1({x, y});
    cin >> x >> y;
    point_t p2({x, y});
    cin >> x >> y;
    point_t p3({x, y});
    double d1 = fabs((p1 - p0).cross(p2 - p0)) / (p1 - p0).norm();
    double d2 = fabs((p1 - p0).cross(p3 - p0)) / (p1 - p0).norm();
    (p2 + (p3 - p2) * (d1 / (d1 + d2))).print();
  }

  return 0;
}

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

int main(){
	int n;
	cin>>n;
	if(n%1000==0){
		cout<<"0"<<endl;
	}
	else {
		n=n%1000;
		n=abs(n-1000);
		cout<<n<<endl;
	}
	
}

Measured memory_bytes: 3636
import heapq
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(l)

def f(x):
    # xの最後の数値だけ取り出す
    min_x = int(list(str(x))[-1])
    x = str(x)
    if min_x == 0:
        yield int(x + "0")
        yield int(x + "1")
    elif min_x == 9:
        yield int(x + "8")
        yield int(x + "9")
    else:
        yield int(x + str(min_x - 1))
        yield int(x + str(min_x))
        yield int(x + str(min_x + 1))

K = int(input())
ans = 1
for i in range(K):
    if i == K - 1:
        ans = heapq.heappop(l)
        break
    for y in f(heapq.heappop(l)):
        heapq.heappush(l, y)
print(ans)

Measured memory_bytes: 10780
import Data.Bool (bool)

main :: IO ()
main = do
    s <- getLine
    answer $ solve s

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: String -> Answer
solve = inner . bool 'W' 'B' . ('B' ==) . head <*> id
  where
    inner x (c : s)
      | x == c    = inner x s
      | otherwise = inner c s + 1
    inner _ []    = 0


Measured memory_bytes: 5244
n = int(input())

w = []
for i in range(n):
    w.append(input())

if len(set(w)) != n:
    print('No')
    exit()
    
for i in range(n - 1):    
    x = w[i]
    y = w[i + 1]
    if x[-1] != y[0]:
        print('No')
        exit()
print('Yes')

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

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	ll ans = 0;ll c=0;
	for(int i = (int)s.size()-1; i>=0; i--){
		if(s[i]=='B')ans+=(int)s.size()-1-i-c,c++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int main(){
	int n;
	while(cin >> n, n){
		string s;
		cin >> s;
		vector<int> v(n, 0);
		int field = 0;
		rep(i, s.size()){
			++v[i%n];
			switch(s[i]){
			case 'S':
				field += v[i%n];
				v[i%n] = 0;
				break;
			case 'L':
				v[i%n] += field;
				field = 0;
				break;
			}
		}
		sort(ALL(v));
		rep(i, n) cout << v[i] << ' ';
		cout << field << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
n=gets.to_i
s=gets.split.map!(&:to_i)
for i in 1..100
  ans=0
  for j in 0..n-1
    ans+=(s[j]-i)**2
  end
  if i==1
    max=ans
  elsif max>ans
    max=ans
  end
end
puts max


Measured memory_bytes: 14256
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x % y, y)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for x in a:
    ans = gcd(ans, x)
print(ans)


Measured memory_bytes: 14252
def main():
    mod=998244353
    n,s=map(int,input().split())
    A=tuple(map(int,input().split()))
    DP=[[x+1]+[0]*s for x in range(n+1)]
    for i,a in enumerate(A):
        for j in range(1,s+1):
            if j-a<0:
                DP[i+1][j]=DP[i][j]
            else:
                DP[i+1][j]=DP[i][j]+DP[i][j-a]
            DP[i+1][j]%=mod
    ans=0
    for dp in DP:
        ans+=dp[-1]
        ans%=mod
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 121308
#include <iostream>
using namespace std;
//R:0 L:1 U:2 D:3


int map[11][7], type, x=2, y=1;
char a[4], b[5];


void init(){
	for(int i=1; i<=9; i++){
		if(i%2){
			cin>>a;
			for(int n=0; n<4; n++)map[i][n+1] = char(a[n])-'0';
		}
		else {
			cin>>b;
			for(int m=0; m<5; m++)map[i][m+1] = char(b[m])-'0';
		}			
	}
}


void Right(){
	if(map[y-1][x])type=2, y-=2, cout<<'U';
	else if(map[y][x])type=0, x+=1, cout<<'R';
	else if(map[y+1][x])type=3, y+=2, cout<<'D';
	else  type=1, x-=1, cout<<'L';
}
void Left(){
	if(map[y+1][x])type=3, y+=2, cout<<'D';
	else if(map[y][x-1])type=1, x-=1, cout<<'L';
	else if(map[y-1][x])type=2, y-=2, cout<<'U';
	else type=0, x+=1, cout<<'R';
}
void Up(){
	if(map[y][x-1])type=1, x-=1, cout<<'L';
	else if(map[y-1][x])type=2, y-=2, cout<<'U';
	else if(map[y][x])type=0, x+=1, cout<<'R';
	else type=3, y+=2, cout<<'D';
}
void Down(){
	if(map[y][x])type=0, x+=1, cout<<'R';
	else if(map[y+1][x])type=3, y+=2, cout<<'D';
	else if(map[y][x-1])type=1, x-=1, cout<<'L';
	else type=2, y-=2, cout<<'U';
}


void solve(){
	while(!(x==1&&y==1)){
		switch(type){
			case 0: Right(); break;
			case 1: Left(); break;
			case 2: Up(); break;
			case 3: Down(); break;
			default: return;
		}
	}
}
 
int main(){
	init();
	
	cout<<'R';
	solve();
	cout<<"\n";	
    return 0;  
}  

Measured memory_bytes: 0
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int a[N];

int main() {
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    scanf("%d", a + i);
  }
  sort(a + 1, a + 1 + n);
  ll sum = a[1];
  int last = 0;
  for(int i = 2; i <= n; ++i){
    if(a[i] > sum + sum){
      last = i - 1;
    }
    sum += a[i];
  }
  printf("%d\n", n - last);
  return 0;
}


Measured memory_bytes: 640
n, k, q = gets.chomp.split(" ").map(&:to_i)

points = Array.new(n, 0)
q.times do
    a = gets.chomp.to_i - 1
    points[a] += 1
end

points.each do |point|
    if k - (q - point) <= 0
        puts "No"
    else
        puts "Yes"
    end
end


Measured memory_bytes: 3196
#include<iostream>
using namespace std;
typedef unsigned long long ull;
static const int MAX_N = 100000;
int N, Q;
ull V[MAX_N], x;

ull solve(ull x){
  ull cnt = 0, s = 0;
  int l = 0, r = 0;
  while (l < N){
    while( r < N && s + V[r] <= x ) s += V[r++];
    cnt += r - l;
    s -= V[l++];
  }
  return cnt;
}

int main(){
  cin >> N >> Q;
  for ( int i = 0; i < N; i++ ) cin >> V[i];
  for ( int i = 0; i < Q; i++ ){
    cin >> x;
    cout << solve(x) << endl;
  }
  return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<long long> a(n);
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		string s;
		cin >> s;
		vector<long long> gauss(61);
		auto add = [&](long long x){
			for(int i = 60; i >= 0; i--){
				if(x&(1ll<<i)){
					if(gauss[i] == 0){
						gauss[i] = x;
						break;
					}
					x ^= gauss[i];
				}
			}
		};
		auto can = [&](long long x){
			for(int i = 60; i >= 0; i--) x = min(x, x ^ gauss[i]);
			return x;
		};
		int ans = 0;
		for(int i = n - 1; i >= 0; i--){
			if(s[i] == '1'){
				if(can(a[i])){
					ans = 1;
					break;
				}
			} else {
				add(a[i]);
			}
		}
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B,N,K=0;
  cin >>N;
 
 while (N!=0){
     int C;
     cin >>A>>B;
     C=B-A;
     C++;
     K+=C;
     N--;
 }
    
    cout << K << endl;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int X = int.Parse(s[1]);
            int T = int.Parse(s[2]);

            int ans = 0;
            if (N % X != 0)
                ans = ((N / X) + 1) * T;
            else ans = (N / X) * T;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)



int main(){
    int n;
    cin >> n;
    if(n == 1) cout << "Hello World" << endl;
    else{
        int a,b;
        cin >> a >> b ;
        cout << a+b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N, C;
int A[410], B[410];
ll dp[410][410];
ll pw[410][410];
const ll mod = 1e9 + 7;

ll mod_pow(ll x, int a){
    if(a == 0) return 1;
    ll e = mod_pow(x, a / 2);
    e = e * e % mod;
    return e * (a % 2 ? x : 1) % mod;
}

int main(){
    cin >> N >> C;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    for(int i = 1; i <= N; i++){
        cin >> B[i];
    }

    for(int i = 0; i <= 400; i++){
        for(int j = 0; j <= 400; j++){
            pw[i][j] += mod_pow(i, j);
            pw[i][j] %= mod;
            pw[i + 1][j] += pw[i][j];
        }
    }
    dp[0][C] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= C; j++){
            for(int k = 0; k <= C - j; k++){
                dp[i][j] += dp[i - 1][j + k] * (pw[B[i]][k] - pw[A[i] - 1][k] + mod);
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[N][0] << endl;
    return 0;
}

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

int main() {
	int n;
	cin>>n;
int b[n];
for(int i=0;i<n;i++){
    cin>>b[i];
}
int sum=0;
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        sum+=b[i]*b[j];}}
        cout<<sum;
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int a[100005],b[100005],k,n,tot1,tot2;
int main()
{
	n=read();k=read();
	for(int i=1;i<=n;i++)
	{
		int x=read();
		if(x==0) k--;
		else if(x<0)
		{
			a[++tot1]=-x;
		}
		else b[++tot2]=x;
	}
	sort(a+1,a+tot1+1);
	sort(b+1,b+tot2+1);
	int ans=2000000000;
	for(int i=0;i<=k;i++)
	{
		if(tot1<i) continue;
		else if(tot2<k-i) continue;
		ans=min(ans,a[i]+b[k-i]+min(a[i],b[k-i]));
	}
	cout<<ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);


int main()
{
    string s;

    cin >> s;

    unsigned ll a = 0;
    for (const auto &c : s) { a += (c - '0'); }
    if (a % 3 == 0) { cout << "Yes" << endl; }
    else
    {
        cout << "No" << endl;
    }


    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


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

using namespace std;

int main()
{
	string str,str2;
	vector<short int> array[4001];
	int i,j;
	
	for(i=0;i<4001;i++)
		for(j=0;j<4001;j++)
			array[i].push_back(0);
	
	for(;cin >> str;)
	{
		cin >> str2 ;
		int ans=0;
		for(i=1;i<=str.size();i++)
		{
			for(j=1;j<=str2.size();j++)
			{
				array[i][j]=0;
				if(str[i-1]==str2[j-1])
					array[i][j]=array[i-1][j-1]+1;
				if(ans<array[i][j])
					ans=array[i][j];
			}
		}
		cout << ans << endl;
	}
}

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

const int INF=1e9;

int main(){
    int H,N; cin >> H >> N;
    int a[N],b[N];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i];
    }
    int dp[3*10000];
    for(int i=0;i<3*10000;i++){
        dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=H;j++){
            dp[j+a[i]]=min(dp[j+a[i]],dp[j]+b[i]);
        }
    }
    int ans=INF;
    for(int i=H;i<3*10000;i++){
        ans=min(dp[i],ans);
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
#include<bitset>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int MOD=1000000007;int inf=1000000007;
int n;
int a[3];
signed main(){
    cin>>n;
    rep(i,3)cin>>a[i];
    vector<int> l(n);
    rep(i,n)cin>>l[i];
    int max=0;
    max|=(1<<n*2);
    int min=inf;
    for(int bit=0;bit<max;bit++){
        vector<int> buf(3,0);
        int mp=0;
        for(int i=0;i<n*2;i+=2){
            int flag=0;
            if(bit&(1<<i))flag++;
            if(bit&(1<<(i+1)))flag+=2;
            if(flag==3){
 
            }
            else{
                buf[flag]+=l[i/2];
                mp+=10;
            }
            //cout<<flag<<endl;
        }
        bool flag=false;
        rep(i,3){
            if(buf[i]==0)flag=true;
        }
        if(flag)continue;
        rep(i,3){
            mp+=abs(buf[i]-a[i]);
        }
        mp-=30;
        if(mp<min)min=mp;
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define INF 1000000000
#define ll long long

string s;
int main()
{
	cin >> s;

	string str = s;
	RREP(i, 0, s.size()) if (str[i] == 'x') str.erase(str.begin() + i);

	string rev = str;
	reverse(rev.begin(), rev.end());
	if (str != rev) {
		cout << -1 << endl;
		return 0;
	}

	int cnt = 0;
	int l = 0, r = s.size() - 1;
	while (1) {
		if (l >= r) break;

		if (s[l] == s[r]) {
			l++;
			r--;
		}
		else if (s[l] == 'x') {
			cnt++;
			l++;
		}
		else {
			cnt++;
			r--;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2003;

int n;
int a[N],b[N];
struct point{
	int x,y;
	friend bool operator < (point a,point b){
		return a.x<b.x;
	}
}p[N];
int k;
int rig[N],lef[N];
int preb[N];
int cnt[N];

int getv(int l,int r){
	if (l<=r)return preb[r]-preb[l-1];
	return preb[r]-preb[l-1]+preb[n];
}

int main(){
	char s[N];
	scanf("%s",s+1);
	n=strlen(s+1);
	fo(i,1,n)a[i]=s[i]-'0';
	scanf("%s",s+1);
	fo(i,1,n)b[i]=s[i]-'0';
	fo(i,1,n)preb[i]=preb[i-1]+b[i];
	if (!preb[n]){
		fo(i,1,n)
		if (a[i]){
			printf("-1\n");
			return 0;
		}
		printf("0\n");
		return 0;
	}
	int w=0;
	fo(i,1,n)if (b[i]){w=i;break;}
	rig[n]=(1-b[n])*w;fd(i,n-1,1)rig[i]=(1-b[i])*(rig[i+1]+1);
	fd(i,n,1)if (b[i]){w=i;break;}
	lef[1]=(1-b[1])*(n-w+1);fo(i,2,n)lef[i]=(1-b[i])*(lef[i-1]+1);
	int ans=1e+9;
	fo(l,-n+1,n-1){
		k=0;int v=0;
		fo(i,1,n){
			if (a[i]&&!b[(i+n-l-1)%n+1]){
				int x=(i+n-l-1)%n+1;
				if (l>=0&&getv(x,i)==0){p[++k].x=rig[i];p[k].y=lef[x];}
				if (l<0&&getv(i,x)==0){p[++k].x=lef[i];p[k].y=rig[x];}
			}
			if (a[i]!=b[(i+n-l-1)%n+1])v++;
		}
		fo(i,0,n)cnt[i]=0;
		sort(p+1,p+1+k);
		fo(i,1,k)cnt[p[i].y]++;
		int w=n;
		int mv=0;
		while(w&&!cnt[w])w--;
		mv=w*2;
		fo(i,1,k){
			cnt[p[i].y]--;
			while(w&&!cnt[w])w--;
			mv=min(mv,w*2+p[i].x*2);
		}
		mv+=v+abs(l);
		ans=min(ans,mv);
	}
	printf("%d\n",ans);
	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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    vector<int> l(5) ;
    l = {105, 135, 165, 189, 195};
    int N;
    cin >> N;
    int cnt = 0;
    int i = 0;
    while (i < 5) {
        if (l[i] <= N ) {
            cnt++;
            i++;
        }
        else {
            break;
        }
    }
    cout << cnt << endl;
}


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

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  ll n,k;
  cin >> n >> k; 
  cout << n * k <<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h[100005];
int dp[100005];
int n,k;
 int mincost(int i,int j)
 {
     if(i==j){
         return 0;
     }
     if(i>j){
         return INT_MAX;
     }
     if(dp[i] != -1){
         return dp[i];
     }
     int ans = INT_MAX;
     for(int p=1;p<=k;p++){
         if(i+p<=j){
             int val = abs(h[i+p] - h[i])+ mincost(i+p,j);
         ans = min(ans,val);
         }
     }
     

     return dp[i] = ans;

 }
 int32_t main(){
     cin>>n>>k;
     memset(h,0,sizeof(h));
     for(int i=1;i<=n;i++){
         cin>>h[i];
     }
     memset(dp,-1,sizeof(dp));
     cout<<mincost(1,n);
 }

Measured memory_bytes: 12924
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,l;
	ll total=0;
	cin>>n>>l;

	for(int i=1; i<n+1; i++){
		total+=l+i-1;
	}
	if(l<=0&&abs(l)<n)cout<<total<<endl;
	if(l<=0&&abs(l)>=n)cout<<total-(l+n-1)<<endl;
	if(l>0)cout<<total-l<<endl;

	return 0;

}


Measured memory_bytes: 256
s = input()
s1 = s[0 : 2]
s2 = s[2 : 4]
if 1 <= int(s1) <= 12 and 1 <= int(s2) <= 12:
    print("AMBIGUOUS")
elif 1 <= int(s1) <= 12:
    print("MMYY")
elif 1 <= int(s2) <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(), A.end()
#define MEM(a, b) memset(a, b, sizeof(a))
#define FOR(n) for (int i = 0; i < n; ++i)
#define FOR_(n) for (int i = 1; i <= n; ++i)
#define FOR_J(n) for (int j = 0; j < n; ++j)
#define FOR_J_(n) for (int j = 1; j <= n; ++j)
#define IT_FOR(A) for (auto i = A.begin(); i != A.end(); ++i)
#define INF 0x3f3f3f3f
#define N ((int)1e6)
//#define max(_a,_b) (((_a) > (_b)) ? (_a) : (_b))
//#define min(_a,_b) (((_a) < (_b)) ? (_a) : (_b))
const int mod = 1000000007;
typedef long long ll;

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

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("wa4.txt","w",stdout);
	int _ = 1;
	//_ = read();
	while (_--) {
		char c;
		cin >> c;
		char t = tolower(c);
		if (c == t)
			cout << "a\n";
		else
			cout << "A\n";
	}
	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n; int ans=0;
	vector<int> a(n), b(n), c(n-1);
	for(auto &x:a) cin >> x;
	for(auto &x:b) cin >> x;
	for(auto &x:c) cin >> x;
	for(int i=0;i<n;i++){
		if(i != 0) if(a[i]-1 == a[i-1]) ans += c[a[i]-2];
		ans += b[a[i]-1];
		//cout << b[a[i]-1] << "\n";
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#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()
const int INF=1000000001;
const double PI=3.141592653589;

int dp[100005];

int main(){
  int N; cin>>N;
  rep(i,N+1) dp[i]=INF;

  vector<int> w={1};
  int a=6;
  rep(i,7){
    w.pb(a);
    a*=6;
  }
  a=9;
  rep(i,6){
    w.pb(a);
    a*=9;
  }

  dp[0]=0;
  rep(i,N+1){
    rep(j,w.size()){
      if(i-w[j]<0) continue;
      dp[i]=min(dp[i],dp[i-w[j]]+1);
    }
  }
  // rep(i,N+1)
  // cout<<dp[i]<<" ";
  cout<<dp[N]<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pri 1000000007
#define MP make_pair
#define mx 1000000000
#define PB push_back
using namespace std;
void run(){
	ll n,k;
	cin>>n>>k;
	
	ll a[n];
	ll pos[200002]={n+1};
	ll st[200002]={n+1};
	
	for(ll i=0;i<200002;i++){st[i]=n+1;pos[i]=n+1;}
	
	ll ans[n+2];
	
	for(ll i=0;i<n;i++){cin>>a[i];if(st[a[i]]==n+1)st[a[i]]=i;}
		
	ans[n+1]=200001;
	ans[n]=200001;
	
	ll last=n+1;
	
	for(ll i=n-1;i>=0;i--){
		
	 last=pos[a[i]];
	 
	 if(last==n+1)
	    {ll f=a[i];ans[i]=f;}
	 
	 else{     ans[i]=ans[last];}
	 
	    pos[a[i]]=i+1;
	}
	
	ll x=200001;
	ll f[n+3]={0};
	ll cy=0;
	map <ll,ll> re;
	
	for(ll i=0;i<n+2;i++){
	    //cout<<x<<endl;
		if(re[x]==1){cy=i;break;}
		re[x]=1;
		f[i]=x;
	    if(x==200001)x=ans[0];
	    else{ x=ans[st[x]+1];}
	    
	}

	
	ll z=(k-1)%cy;
	ll j=f[z];
	
	set <ll> p;
	stack <ll> ch;
	
	if(j!=200001){
	p.insert(j);
	ch.push(j);}
	
	for(ll i=0;i<n;i++){

	if(p.find(a[i])!=p.end()){
		p.erase(a[i]);
		
		while(ch.top()!=a[i]){
		p.erase(ch.top());ch.pop();
		}
		
		ch.pop();
	}
	else{
	        ch.push(a[i]);
	        p.insert(a[i]);
	}
	
	}
	
	vector <ll> ze;
	while(!ch.empty()){
	ll j=ch.top();ch.pop();
	ze.PB(j);}
	
	ll fee=ze.size();
	for(ll i=fee-1;i>=0;i--)cout<<ze[i]<<" "; 
	
	
	
	
	
	
	
	
}
int main() {
	ll t=1;//cin>>t;
	for(ll i=0;i<t;i++)run();
	// your code goes here
	return 0;
}

Measured memory_bytes: 34548
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  vector<string> w;
  w.push_back("SUN");
  w.push_back("MON");
  w.push_back("TUE");
  w.push_back("WED");
  w.push_back("THU");
  w.push_back("FRI");
  w.push_back("SAT");
  map<string, int> m;
  for(int i = 0; i < 7; ++i){
    m[w[i]] = 7 - i;
  }
  cout << m[s] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;int main(){int n,k;while(true){cin>>n;if(n==0)break;int ans=1;bool na=true;for(int i=0;i<n;i++){cin>>k;if(k>0)ans++;if(k>1)na=false;}if(na==true)cout<<"NA"<<endl;else cout<<ans<<endl;}return 0;}

Measured memory_bytes: 1160
#include<iostream>
typedef long long ll;
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	ll h, r, t;
	cin >> h >> r;
	if(h==1 || r==1){
		t = 1;
		cout << t << endl;
		return 0;
	}
	t = (h*r+1)/2;
	//if(t%2==0) t = t/2;
	//else t = (t+1)/2;
	cout << t << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int q, h, s, d;
	cin >> q >> h >> s >> d;
	h = min(h, 2 * q);
	s = min(s, 2 * h);
	d = min(d, 2 * s);
	int n;
	cin >> n;
	ll res = (ll)1e18;
	if (n % 2 == 0) {
		res = 1LL * d * ((n + 1) / 2);
	} else {
		res = 1LL * d * (n / 2) + s;
	}
	cout << res << endl;
}



Measured memory_bytes: 256
s = input()
l = len(s)
ans = 0
i = 1
j = 0
if l%2 == 0:
	while(i <= l/2):
		if s[j] != s[-i]:
			ans += 1
		j+=1
		i+=1
else:
	max = l/2
	while(j < max):
		if s[j] != s[-i]:
			ans += 1
		j+=1
		i+=1
			
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=1e7;
const ll ms=(2e5)+5;



int main()
{
    idfc;
    ll a,b,n;

    cin>>a>>b>>n;

    ll ans=((a*n)/b)- (a*(n/b));

    ll tt=(n/b)*b-1;

    if(tt>=0)
    {
        ans=max(ans,((a*tt)/b)-((a*(tt/b))));
    }
    cout<<ans<<"\n";

    return 0;

}

Measured memory_bytes: 3664
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;


struct node {
    int v; double d;
    node(int v, double d):v(v),d(d){}
    bool operator<(const node &n) const { return d > n.d; }
};
struct edge { int to; double d; edge(int ti, double di){to = ti; d = di;} };
vector<edge> G[ 1010 ];
double dist[ 1010 ]; // shortest distance

void dijkstra(int s) {
    REP(i,1010) dist[i] = -1.0;
    priority_queue<node> que;
    que.push(node(s, 0.0));
    while(!que.empty()){
        int v = que.top().v;
        double d = que.top().d;
        que.pop();
        if(dist[v] >= 0 and dist[v] <= d) continue;
        dist[v] = d;
        for(auto j : G[v])
            que.push(node(j.to, d+j.d));
    }
}
double xs,ys,xt,yt;
int n;
double x,y,r;

struct barrier {double x,y,r; barrier(double xi, double yi, double ri){x = xi; y = yi; r = ri;}};
vector<barrier> inputs;

int main(){
    cin >> xs >> ys >> xt >> yt;
    inputs.pb(barrier(xs,ys,0));
    inputs.pb(barrier(xt,yt,0));
    I(n);
    REP(i,n){
        cin >> x >> y >> r;
        inputs.pb(barrier(x,y,r));
    }

    REP(i,n+2){
        REP(j,n+2){
            if (i==j) continue;
            double dists = (inputs[i].x - inputs[j].x) * (inputs[i].x - inputs[j].x);
            dists += (inputs[i].y - inputs[j].y) * (inputs[i].y - inputs[j].y);
            dists = sqrt(dists) - inputs[i].r - inputs[j].r;
            dists = max(0.0,dists);
            G[i].pb(edge(j,dists));
            G[j].pb(edge(i,dists));
        }
    }
    dijkstra(0);
    printf("%.12f\n",dist[1]);
}

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

int main() {
  int n; 
  cin >> n;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  for (auto i = a.rbegin(); i < a.rend(); ++i) {
    if (*i == *(i + 1) - 1) {
      *(i + 1) = *(i + 1) - 1;
    } else if (*i < *(i + 1) - 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long 
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define F first 
#define S second 
#define pb push_back 
#define mp make_pair 
#define P(a,b) pair<a,b> 
#define M(a,b) map<a,b> 
#define V(i) vector<i> 

using namespace std;


void test(){
	int n,m;
	cin>>n>>m;
	if(n<m)swap(n,m);
	f(i,n)cout<<m;
	cout<<"\n";	
}

int main(){
	int t=1;
//	cin>>t;
	while(t-->0){
		test();
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD (1e9+7)
#define yn(f) (f?"Yes":"No")

int N, M;

int com(int n, int m){
  if(m == 0) return 1;
  if(m == 1) return n;
  //m = min(n-m,m);
  return com(n,m-1)*(n-m+1)/m;
}

int huga(int a, int b){
  int ans = 0;
  for(int i = 0; i < b; i++){
    ans += com(a,i);
  }
  return ans;
}

int foo(string &a, int k, int m){//cout<<k<<" "<<m<<endl;
  for(int i = 0, sum = 0; i <= k; i++){// cout<<"i = "<<i<<" "<<com(k,i)<<" "<<sum<<endl;
    sum +=com(k,i);
    
    if(sum == m){
      for(int j = 0; j < i; j++){
	a += '1';
      }
      for(int j = i; j < k; j++){
	a += '0';
      }
      return 0;
    }
    else if(sum >  m){
      if(sum <  m+com(k-1,i-1)){//cout<<"111--"<<huga(k-1,i-1)<<" "<<com(k-1,i-1)<<endl;
	a += "1";
	//return foo(a, k-1,m-com(k,i-1)-com(k-1,i)+huga(k-1,i-1));
       	//return foo(a, k-1,m);
	//return foo(a,k-1,m-com(k-1,i-1)-(sum-com(k,i))+huga(k-1,i-1));
	return foo(a,k-1,m + huga(k-1,i-1)-(sum-com(k,i))-com(k-1,i));
      }else {
	//cout<<"000---"<<" "<<huga(k-1,i)<<" "<<m-(sum-com(k,i))<<endl;
	a += "0";
	//return foo(a,k-1,m-com(k-1,i-1)+huga(k-1,i-2));
	//return foo(a,k-1,huga(k-1,i)+m-com(k,i-1));
	return foo(a,k-1,m-(sum-com(k,i))+huga(k-1,i));
	
      }
    }
  }
  return 0;
}

signed main(){
  while(true){
    string a;
    cin>>N>>M;
    if(!N&&!M) break;
    //cout<<com(n,m)<<endl;
    
    //cout<<foo(a,N,M)<<endl;
    foo(a,N,M);
    cout<<a<<endl;
  }


  return 0;
}



Measured memory_bytes: 3148
import math
A,B,H,M = (int(x) for x in input().split())
arg = (math.pi*H/6 + math.pi*M/360) - math.pi*M/30
if (arg < 0):
  arg = -arg
s = A**2 + B**2 - 2*A*B*math.cos(arg)
print(math.sqrt(s))

Measured memory_bytes: 9576
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  ll x;
  cin >> x;

  ll diff = 0;
  ll i = 0;
  while (diff < x) {
    i++;
    diff += i;
  }
  diff = -x + diff;
  cout << (diff == 0 ? i : i);
  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Rainy")
    cout << "Sunny" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  return 0;
}

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int n; cin >> n;
  vector<ll> t(n), a(n);
  REP(i,n) cin >> t[i]; REP(i,n) cin >> a[i];
  vector<bool> f(n, false);
  f[0] = true; f[n-1] = true;
  ll max = 0;
  REP(i,n) {
    if (t[i] > max) {
      if (t[i] > a[i]) {
        cout << 0 << endl; return 0;
      } else {
        f[i] = true;
        max = t[i];
      }
    }
  }
  max = 0;
  REP(i,n) {
    if (a[n-1-i] > max) {
      f[n-1-i] = true;
      t[n-1-i] = a[n-1-i];
      max = a[n-1-i];
    } else if (a[n-1-i] < t[n-1-i]) t[n-1-i] = a[n-1-i];
  }
  ll ans = 1;
  REP(i,n) {
    if (f[i]) continue;
    ans = ans*t[i]%MOD;
  }
  cout << ans << endl;
}


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

def readlines(n):
    for i in range(n):
        for j, x in enumerate(input().split()):
            yield int(x), (i, j)


def main():
    N = int(input())
    for i in range(1, N+1):
        x = i
        count = 0
        while x > 0:
            x //= 2
            count += 1

        yield i, count


print(max(main(), key=lambda x: x[1])[0])


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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,x,t,i;
    cin>>n>>x>>t;
    i=ceil((n*1.0)/x)*t;
    cout<<i<<endl;


}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 28)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  int h[100005];
  ll dpt[100005];
  fill(dpt, dpt + 100005, 1000000000);

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

  dpt[0] = 0;
  for(int i = 0;i < n;i++){
    for(int j = 1;i + j < n && j <= k;j++){
      dpt[i + j] = min(dpt[i + j], abs(h[i] - h[i + j]) + dpt[i]);
    }
  }
  
  cout << dpt[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll c[502],s[502],f[502];
int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n){
        ll cur=s[i]+c[i];
        FOR(j,i,n-2){
            while(cur%f[j+1]) ++cur;
            cur=max(s[j+1],cur);
            cur+=c[j+1];
        }
        cout<<cur<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
point = {"r"=>p, "s"=>r, "p"=>s}
t = []
k.times{ t << Array.new }
gets.chomp.chars.each_with_index{|c,i| t[i%k] << c }
ans = 0
t.each{|tt|
  flag = true
  ans += tt.map.with_index{|ti,i|
    flag = !flag if (i!=0 && tt[i-1]==ti) || (!flag)
    ((i!=0 && tt[i-1]!=ti) || flag) ? point[ti] : 0
  }.inject(:+)
}
p ans


Measured memory_bytes: 17916
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <cstring>

using namespace std;
typedef long long ll;


int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> a(N);

  for( int i=0;i<N;i++ )
    cin >> a[i];

  vector< vector<int> > dp(2, vector<int>(K+1, -1));
  dp[0][0] = 0;
  dp[0][1] = 0;

  for( int i=0;i<K+1;i++ )
    {
      bool flg = false;
      for( const auto &e:a)
	{
	  if( i-e>=0 && dp[1][i-e]==0 )
	    {
	      flg = true;
	      break;
	    }
	}
      if(flg)
	dp[0][i] = 1;
      else
	dp[0][i] = 0;

      flg = false;
      for( const auto &e:a)
	{
	  if( i-e>=0 && dp[0][i-e]==0 )
	    {
	      flg = true;
	      break;
	    }
	}
      if(flg)
	dp[1][i] = 1;
      else
	dp[1][i] = 0;
    }

  if( dp[0][K] == 1 )
    cout << "First" << endl;
  else
    cout << "Second" << endl;    
}


Measured memory_bytes: 1408
x = gets.to_i
require 'set'
s = Set.new
s << x
1000000.times{|i|
  if x.odd?
    x = 3 * x + 1
  else
    x = x / 2
  end
  if s.include?(x)
    p i+2
    exit
  end
  s << x
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int a;
    cin >> a;

    cout << a + a * a + a*a*a << endl;

    return 0;
}



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

const int limit = 50;
int n, m;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v) {
  visited[v] = true;
  for (int v2 = 0; v2 < n; ++v2) {
    if (graph[v][v2] == false) continue;
    if (visited[v2] == true) continue;
    dfs(v2);
  }
}


int main(void) {
  cin >> n >> m;

  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;

  rep(i, m) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    rep(j, n) {
      visited[j] = false;
    }

    dfs(0);

    bool bridge = false;
    rep(j, n) if (visited[j] == false) bridge = true;
    if (bridge) ++ans;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

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

Measured memory_bytes: 3596
from sys import stdin
import numpy as np
import itertools


# noinspection PyShadowingBuiltinsInspection

def main():
    N = int(input())
    P = [int(x) for x in input().split()]
    Q = [int(x) for x in input().split()]
    p = 0
    q = 0
    i = 0
    for x in itertools.permutations(list(range(1,N+1))):
        i += 1
        x = list(x)
        if P == x:
            p = i
        if Q == x:
            q = i
    print(abs(p - q))
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 21432
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
rslt = 0
for i in range(n-1):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        c = bisect.bisect_left(l, a+b)
        rslt += c-j-1
print(rslt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int N;
vector<lint> A;

int main()
{
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++)
    {
        lint tmp;
        cin >> tmp;
        A[i] = tmp - i - 1;
    }
    sort(A.begin(), A.end());
    if (N == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    lint ans1 = 0, ans2 = 0;
    for (auto v : A)
    {
        ans1 += abs(v - A[N / 2]);
        ans2 += abs(v - A[N / 2 + 1]);
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 1792
main :: IO ()
main = do
    n <- readLn
    print $ fib n

fib :: Int -> Int
fib = (map fib' [0..] !!)
    where
        fib' 0 = 1
        fib' 1 = 1
        fib' n = fib (n-1) + fib (n-2)

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

int cnt = 0;

void test_G(const vector<int> &num,const vector<set<int>> &G,const int &n){
  bool ck = true;
  for(int i=0;i<n-1;i++){
    if(G.at(num.at(i)).count(num.at(i+1))) continue;
    else{
      ck = false;
      break;
    }
  }
  if(ck) cnt++;
}
  

int main() {
  int n,m;
  cin >> n >> m;
  vector<set<int>> G(n+1);
  vector<int> num(n);
  
  for(int i=0;i<n;i++){
    num.at(i) = i+1;
  }
  
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    G.at(a).insert(b);
    G.at(b).insert(a);
  }
  
  do{
    if(num.at(0) == 1) test_G(num, G, n);
  }while(next_permutation(num.begin(),num.end()));
  
  cout << cnt << endl;  
    
}


Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var cup = new int[] { 1, 0, 0 };
        var cup2 = new string[] { "A", "B", "C" };
        string line;
        var a = 0;
        var b = 0;
        for (; (line = Console.ReadLine()) != null;)
        {
            string[] s = line.Trim().Split(',');
            if (s[0] == "A") a = 0;
            if (s[0] == "B") a = 1;
            if (s[0] == "C") a = 2;
            if (s[1] == "A") b = 0;
            if (s[1] == "B") b = 1;
            if (s[1] == "C") b = 2;
            cup = Change(cup, a, b);
        }
        for (int i = 0; i < 3; i++)
            if (cup[i] == 1) Console.WriteLine(cup2[i]);
    }
    public static int[] Change(int[] a, int x, int y)
    {
        var buf = a[x];
        a[x] = a[y];
        a[y] = buf;
        return a;
    }
}

Measured memory_bytes: 8836
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int num[] = new int[3];
  int i=0,j=0;
  int tmp = 0;
  num[0] = sc.nextInt();
  num[1] = sc.nextInt();
  num[2] = sc.nextInt();
  for(i = 0 ; i < 2 ; i++)
  {
   for(j = 2 ; j > i ; j--)
   {
    if(num[j - 1] > num[j])
    {
     tmp = num[j - 1];
     num[j - 1] = num[j];
     num[j] = tmp;
    }
   }
  }
  System.out.printf("%d %d %d\n",num[0],num[1],num[2]);
 }
}


Measured memory_bytes: 26228
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c=0,d=INT_MAX;cin>>a;
  rep(i,a){
    c=0;
    cin>>b;
    while(b%2==0){
      c++;
      b/=2;
    }
    d=min(d,c);
  }
  cout<<d<<endl;
}

Measured memory_bytes: 23680
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

// utility of stdin,stdout
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long

int main(int argc, char const *argv[]){
	int n,k;
	int d = 0;

	cin >> n >> k;
	std::vector<int> x(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> x.at(i);
		d += 2 * min(abs(k - x.at(i)), abs(x.at(i)));
	}
	OUT(d) BR;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	char x[1001];//数値を文字列として定義
	
	int num;	//数値格納用変数
	int sum;	//各桁の合計
	
	scanf("%s",x);	//最初の入力
	
	while(1){
		sum = 0;	//合計の初期化
		for(int i = 0;x[i] != '\0';i++){
			num = x[i] - '0';	//各桁の数値化
			sum += num;	//合計に追加
		}
		printf("%d\n",sum);	//表示
		
		scanf("%s",x);	//次の入力
		if(x[0] == '0') break;	//最初の文字が0ならループを抜ける
	}
	
	return 0;
}



Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        String str[] = w.split("");
        Arrays.sort(str);
        boolean ans = true;
        int count = 1;
        for(int i = 0;i<w.length()-1;i++){
            
            if(str[i].equals(str[i+1])){
                
                count++;
                
            }else if(count%2==1){
                
                ans = false;
                break;
                
            }else{
                count = 1;
            }
        }
        if(count%2==1){
            ans = false;
        }
        if(ans) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 35600
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for i in range(8):
    value_list = []
    for a in A:
        value_list.append((2*(i&1)-1)*a[0] + (2*((i>>1)&1)-1)*a[1] + (2*((i>>2)&1)-1)*a[2])
    value_list.sort(reverse=True)
    ans = max(ans, sum(value_list[:m]))

print(ans)


Measured memory_bytes: 3316