akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a%b));
}
ll n,ans = -1;
int main() {
	cin >> n;
	REP(i, n) {
		ll a; cin >> a;
		if (ans == -1)ans = a;
		ans = gcd(ans, a);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long a,b,res,temp,l,maxi;
    cin>>a>>b;
    if(a<b)
    {
        temp=a;
        a=b;
        b=temp;
    }
    maxi=a;l=b;
    while(maxi%l!=0)
    {
        res=maxi%l;
        maxi=l;l=res;
    }
    cout<<(a*b)/l<<endl;

}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	count := 0
	for i := a; i <= b; i++ {
		if c%i == 0 {
			count++
		}
	}
	fmt.Println(count)
}



Measured memory_bytes: 1092
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    ll a, b, c, n;
    cin >> a >> b >> c >> n;
    if (n == 0)cout << a - b << endl;
    else if (n % 2 == 1)cout << -a + b << endl;
    else if (n % 2 == 0)cout << a - b << endl;
    return 0;
}

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

int a[3][3],n;
bool m[3][3];
bool b[105];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    cin>>n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        b[t]=1;
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            m[i][j]=b[a[i][j]];
        }
    }
    if(m[0][0]&&m[0][1]&&m[0][2]){cout<<"Yes"<<endl;return 0;}
    if(m[1][0]&&m[1][1]&&m[1][2]){cout<<"Yes"<<endl;return 0;}
    if(m[2][0]&&m[2][1]&&m[2][2]){cout<<"Yes"<<endl;return 0;}

    if(m[0][0]&&m[1][0]&&m[2][0]){cout<<"Yes"<<endl;return 0;}
    if(m[0][1]&&m[1][1]&&m[2][1]){cout<<"Yes"<<endl;return 0;}
    if(m[0][2]&&m[1][2]&&m[2][2]){cout<<"Yes"<<endl;return 0;}

    if(m[0][0]&&m[1][1]&&m[2][2]){cout<<"Yes"<<endl;return 0;}
    if(m[2][0]&&m[1][1]&&m[0][2]){cout<<"Yes"<<endl;return 0;}

    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args ){
        Scanner scanner = new Scanner(System.in);
        while (true){
            int n = scanner.nextInt();
            int p = scanner.nextInt();
            if (n ==0 && p ==0) {
                System.exit(0);
            }
            int[] candidates = new int[n];
            int rocks = p;

            OUT:  while (true) {
                for (int i = 0; i < n; i++){
                    if (rocks == 0) {
                        rocks = candidates[i];
                        candidates[i] = 0;
                    }
                    else {
                        --rocks;
                        ++candidates[i];
                        if (candidates[i] == p){
                            System.out.println(i);
                            break OUT;
                        }
                    }
                }
            }
        }
    }


}



Measured memory_bytes: 26796
#include <iostream>

using namespace std;

int n;
int fr[200001], a[200001];
long long int k;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    int cntOne = 0, cntTwo = 0, posCycle = 0;
    int i = 1;

    while (i) {
        fr[i]++;
        if (fr[i] == 1)
            cntOne++;
        if (fr[i] == 3)
            break;
        if (fr[i] == 2) {
            cntTwo++;
            if (!posCycle)
                posCycle = i;
        }

        i = a[i];
    }
    cntOne -= cntTwo;
    int cycle, j = 1;
    if (k > cntOne) {
        cycle = (k - cntOne) % cntTwo;
        while (cntOne--)
            j = a[j];
    }
    else
        cycle = k;

    while (cycle--) {
        j = a[j];
    }

    cout << j << "\n";

    return 0;
}


Measured memory_bytes: 5196
n=int(input())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  l[a-1].append([b-1,c])
  l[b-1].append([a-1,c])
ans=[-1]*n
q,k=map(int,input().split())
ans[k-1]=0
from collections import deque
d=deque([k-1])
while d:
  now=d.pop()
  for x in l[now]:
    a,b=x
    if ans[a]<0:
      ans[a]=ans[now]+b
      d.append(a)
for i in range(q):
  a,b=map(int,input().split())
  print(ans[a-1]+ans[b-1])

Measured memory_bytes: 50880
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    string s,t;
    cin >> n;
    cin >> s >> t;
    string ans;
    REP(i,n){
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
l = list(list(map(int, input().split())) for _ in range(r))

col_sum = [0]*(c+1)
for li in l:
    li.append(sum(li))
    for i in range(c+1):
        col_sum[i] += li[i]

for li in l:
    print(*li)
print(*col_sum)


Measured memory_bytes: 6244
#include <iostream>
#include <string>
using namespace std;
typedef long long int lli;

int main(){
    string s;
    cin >> s;
    int len = s.length();
    lli ans = 0;
    for(int i=0; i<1<<(len-1); i++){
        lli num = stoll(s);
        lli p10=1;
        for(int j=0; j<len-1; j++){
            p10 *= 10;
            if((i & 1<<j) != 0){
                ans += num%p10;
                num /= p10;
                p10 = 1;
            }
        }
        ans += num;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {

  int N,K,result=0;
  cin >> N >> K;
  result = 0;
  for(int i=0;i < N;i++){
    int xi;
    cin >> xi;
    if(xi > K - xi)
      result += 2 * (K - xi);
    else
      result += 2*xi;
  }

  cout << result << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}

ll pow_mod(ll a, ll b){
    ll sum =1;
    while(b>0){
        if(b&1){
            sum *= a%MOD;
        }
        a = a* a%MOD;
        b >>= 1;
    }
    return sum;
}
int a[110];
int b[110];
int main() {
    for(int i=0; i<3; ++i) cin >> a[i];
    sort(a, a+3);
    cout << a[2]*10+a[1]+a[0] << endl;
    
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n+1),vis(n+1,0),ans;
	for(ll i=1;i<=n;i++)
	cin>>a[i];
	ll i=1;
	while(vis[i]==0)
	{
		vis[i]=1;
		ans.push_back(i);
		i=a[i];
	}
	for(ll j=0;j<ans.size();j++)
	{
		if(ans[j]==i)
		{
			i=j;
			break;
		}
	}
	if(k<ans.size())
	cout<<ans[k];
	else
	{
		cout<<ans[i+(k-i)%(ans.size()-i)];
	}
	

	
	
	

}

Measured memory_bytes: 8476
#include <bits/stdc++.h>
using namespace std;
long long a[100010], n;
int main(){
    cin>>n;
    for(int i=0; i<n; ++i){
        cin>>a[i];
    }
    long long mx=1, ans=a[0]-1;
    for(int i=1; i<n; ++i){
        if(a[i]==mx+1){
            ++mx;
        }
        else{
            ans+=(a[i]-1)/(mx+1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
#define printl(x,f) printf("%d%c",(x),(f)?'\n':' ')
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int K,X;
  while(input(K,X)) {
    for (int i=X-K+1; i<=X+K-1; i++) {
      printl(i, i==X+K-1);
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin>>s;
  int N=s.size();
   s+='B';
  string t="";
  for(int i=0;i<N;i++){
  if(s.at(i)!='B')
    t+=s.at(i);
    else{
     if(s.at(i+1)=='C')
       t+='X';
      else{
       t+='B';
        t+=s.at(i+1);
      }
        i++;
    }
  };int64_t ans=0;
  int64_t sum=0;
  reverse(t.begin(),t.end());
  int M=t.size();
  for(int i=0;i<M;i++){
  if(t.at(i)=='X')
    sum++;
    else if(t.at(i)=='A')
      ans+=sum;
    else
      sum=0;
  
  }cout<<ans<<endl;
  
  
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;

int inf = 1e18;
const int N = 6e5+5;
int mod = 1e9+7;
/*
    int ncr(int n , int r ){
    	r = min(r,n-r);
    	int res = 1 ;
    	for(int i = 1 ; i <= r ; i++ ){
    		( res *= n-i+1 )%= mod;
    		res /= i ;
    	}
    	return res ;
    }
*/
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int a,b;
       cin>>a>>b;
       int gcd = __gcd(a,b);
       cout<<(a*b)/gcd;

    }

    return 0;
}


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


using namespace std;
int A, B, C, D;
int main()
{
		cin>>A>>B>>C>>D;
		int turn = 0;
		while(true)
		{
				if(turn == 0)
				{
						C -= B;
						if(C <= 0)
						{
								cout<<"Yes"<<endl;
								break;
						}
				}
				else
				{
						A -= D;
						if(A <= 0)
						{
								cout<<"No"<<endl;
								break;
						}
				}
				turn = 1 - turn;
		}
		return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  auto p = prime_table(200000);
  ll x,y;
  cin >> x;
  y = x;
  while(1){
    if(p[y]){ cout << y; return 0;}
    y++;
  }

  return 0;
}

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

int main() {
	int n;
	cin>>n;
	int arr[n]={0},brr[n]={0};
	int i=0;
	for(i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	brr[1]=abs(arr[1]-arr[0]);
	if(n>=2)
	brr[2]=abs(arr[2]-arr[0]);
	
	for(i=3;i<n;i++)
	{
	   brr[i]=min(brr[i-1]+abs(arr[i]-arr[i-1]),brr[i-2]+abs(arr[i]-arr[i-2])) ;
	}
	
	cout<<brr[n-1];
	
	return 0;
}


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

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

   cout << n / 3 << endl;
}

Measured memory_bytes: 256
import sys
readline=sys.stdin.readline
 
N = int(readline())
if N == 1:
  print(0)
  exit(0)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
# 同じ素数の組から、1つ、2つと選び方を変えて選ぶ

arr = factorization(N)
ans = 0
for a in arr:
  facts = a[1]
  i = 1
  while i <= facts:
    ans += 1
    facts -= i
    i += 1
print(ans)




Measured memory_bytes: 9484
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
#include <numeric>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;



int main(void)
{
    int n;
    cin >> n;
    int a[n], b[n];
    REP(i,n)
    {
        cin >> a[i];
    }
    REP(i,n)
    {
        cin >> b[i];
    }
    int ans = 0;
    REP(i,n)
    {
        ans += max(0, a[i] - b[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans[ohara],a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>x;
    if(x==1||x==2*n-1)Cout("No");
    else{
        map<ll,ll> out;
        if(x==2){
            ans[(n*2-1)/2]=x;
            ans[(n*2-1)/2+1]=x-1;
            ans[(n*2-1)/2-1]=x+1;
            out[x]=1;
            out[x-1]=1;
            out[x+1]=1;
            cnt=1;
            rep(i,2*n-1){
                if(ans[i]!=0)continue;
                while(1){
                    if(out[cnt]==0)break;
                    cnt++;
                }
                ans[i]=cnt;
                out[cnt]=1;
                cnt++;
            }
        }
        else{
            ans[(n*2-1)/2]=x;
            ans[(n*2-1)/2+1]=x+1;
            ans[(n*2-1)/2+2]=x-2;
            ans[(n*2-1)/2-1]=x-1;
            out[x]=1;
            out[x-1]=1;
            out[x-2]=1;
            out[x+1]=1;
            cnt=1;
            rep(i,2*n-1){
                if(ans[i]!=0)continue;
                while(1){
                    if(out[cnt]==0)break;
                    cnt++;
                }
                ans[i]=cnt;
                out[cnt]=1;
                cnt++;
            }
        }
        Cout("Yes");
        rep(i,2*n-1)Cout(ans[i]);
    }
    return 0;
}


Measured memory_bytes: 15616
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <string>

using namespace std;

int main() {
    int n;
    cin>>n;
    char ss[55];
    cin>>ss;
    int cnt=0;
    for (int i = 2; ss[i]; ++i) {
            if(ss[i-2]=='A'&&ss[i-1]=='B'&&ss[i]=='C')
                cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n,w;
	while(scanf("%d%d", &n, &w),n||w){
		int block[100];
		rep(i,100) block[i] = 0;
		rep(i,n){
			int a;
			scanf("%d", &a);
			block[a/w]++;
		}
		int high = 0, last = 0;
		rep(i,100) high = max(high,block[i]);
		rep(i,100) if(block[i] > 0) last = i;
		double ans = 0.0;
		rep(i,last){
			ans += (double)block[i]*(double)(last-i)/(double)last/(double)high;
		}
		printf("%.9f\n", ans+0.01);
	}
}

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

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	string x;
	cin >> x;
	int a = x.size();
	for(int i = 0 ;i < a; i++) cout << 'x';
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3628
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)

n,k=l()
A=l()
A.sort()
print(sum(A[:k]))







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

int main()
{
	string S;
  cin >> S;
  bool flag = false;
  
  for(int i = 0; i < S.size(); i++){
   if(i%2 == 0){
     if(S.at(i) == 'L'){
       cout << "No" << endl;
       return 0;
     }	else {
       continue;
     }
   } else{
     if(S.at(i) == 'R'){
       cout << "No" << endl;
       return 0;
     } else {
     continue;
     }
   }
  }    
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
ll gcd(ll a, ll b)
{
   if (b == 0)
   {
       return a;
   }
    return gcd(b, a%b);
}
void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}
vector<int>ans(10005,0);
void f(ll n){
    for (ll x = 1; x*x<n;x++){
        for (ll y = 1; y*y<n;y++){
            for (ll z = 1; z*z<n;z++){
                ll v = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
                if(v<10005) ans[v]++;
            }
        }
    }
}

int main() {
    int n;
    f(10001);
    string s;
    cin>>n;
    rep(i,1,n+1){
        cout << ans[i]<<endl;
    }
   
   
    return 0;
}


Measured memory_bytes: 5980
package main

import (
	"fmt"
	"reflect"
)

func right(tp, fr int) int {
	r := [][]int{
		{},
		{2, 3, 5, 4},
		{6, 3, 1, 4},
		{2, 6, 5, 1},
	}
	n := 1
	if tp > 3 {
		tp = 7 - tp
		n = 3
	}
	for k := 0; k < 4; k++ {
		if r[tp][k] == fr {
			k += n
			k %= 4
			return r[tp][k]
		}
	}
	return 0
}

func ident(d1, d2 []int) bool {
	for i := 1; i <= 6; i++ {
		for j := 1; j <= 6; j++ {
			k := right(i, j)
			if k == 0 {
				continue
			}
			a := []int{d1[i], d1[j], d1[k], d1[7-k], d1[7-j], d1[7-i]}
			if reflect.DeepEqual(a, d2[1:]) {
				return true
			}
		}
	}
	return false
}

func combinations(n int) [][]int {
	ret := make([][]int, 0, n*(n-1)/2)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			ret = append(ret, []int{i, j})
		}
	}
	return ret
}

func main() {
	var n int
	fmt.Scan(&n)
	d := make([][]int, n)
	for i := 0; i < n; i++ {
		d[i] = make([]int, 7)
		for j := 1; j <= 6; j++ {
			fmt.Scan(&d[i][j])
		}
	}
	for _, c := range combinations(n) {
		if ident(d[c[0]], d[c[1]]) {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}



Measured memory_bytes: 6140
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,3){
        cin >> A[i];
    }
    sort(A,A+3);
    cout << A[2]-A[0] << endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> b(n-1);
    vector<int> a(n);
    for (int i = 0; i < n-1; ++i) {
        cin >> b[i];
    }
    a[0] = b[0];
    for (int i = 1; i < n; ++i) {
        a[i] = min(b[i], b[i-1]);
    }
    a[n-1] = b[n-2];

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

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

Measured memory_bytes: 256
# ABC140
# Buffet
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ct = 0
h = 25
for i in range(n):
    ct += B[i]
    if h + 1 == A[i]:
        ct += C[h - 1]
        h = A[i]
    else:
        h = A[i]
print(ct)


Measured memory_bytes: 9076
x = int(input())
if x < 600:
  print(8)
elif x < 800:
  print(7)
elif x < 1000:
  print(6)
elif x < 1200:
  print(5)
elif x < 1400:
  print(4)
elif x < 1600:
  print(3)
elif x < 1800:
  print(2)
else:
  print(1)

Measured memory_bytes: 9176
n = int(input())
A = list(map(int, input().split()))


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


# 初期値の設定
ans = A[0]
for i in range(1, n):
    ans = gcd(ans, A[i])
print(ans)

Measured memory_bytes: 14252
#include <iostream>

using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
program abc115_d
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,x,i
    integer(int64), allocatable:: a(:),p(:)
    read*, n,x
    allocate(a(0:n), p(0:n))
    a(0)=1
    p(0)=1
    do i=1,n
        a(i) = 2*a(i-1)+3
        p(i) = 2*p(i-1)+1
    end do

    print'(i0)', solve(n,x)

contains
    recursive function solve(n,x) result(ret)
        integer(int64):: n,x,ret
        if (n==0) then
            if (x <= 0) then
                ret = 0
            else
                ret = 1
            end if
        else if (x <= 1+a(n-1)) then
            ret = solve(n-1,x-1)
        else
            ret = p(n-1) + 1 + solve(n-1, x-2-a(n-1))
        end if
    end function
end program abc115_d

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 103;
int n, m, K, mod, f[N][N], fac[N], inv[N];
int qpow(int b, int p) {
  int r = 1;
  for (; p; p >>= 1, b = (ll) b * b % mod) if (p & 1) {
    r = (ll) r * b % mod;
  }
  return r;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &K, &mod);
  f[0][0] = 1;
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= max(n, m); i++) {
    fac[i] = (ll) fac[i - 1] * i % mod;
    inv[i] = mod - (ll) mod / i * inv[mod % i] % mod;
  }
  for (int i = 2; i <= max(n, m); i++) {
    inv[i] = (ll) inv[i] * inv[i - 1] % mod;
  }
  for (int step = 0; step < K << 1; step++) {
    int cnt1 = (step >> 1) + 1, cnt2 = K - (step >> 1);
    if (!(step & 1)) {
      for (int i = n; ~i; i--) {
        for (int j = m; ~j; j--) if (f[i][j]) {
          int coef = (ll) (qpow(cnt1, m - j) + mod - qpow(cnt1 - 1, m - j)) * qpow(cnt2, j) % mod;
          for (int l = 1, c = (ll) coef * f[i][j] % mod * inv[i] % mod; i + l <= n; l++, c = (ll) c * coef % mod) {
            f[i + l][j] = (f[i + l][j] + (ll) c * fac[i + l] % mod * inv[l]) % mod;
          }
        }
      }
    } else {
      for (int j = m; ~j; j--) {
        for (int i = n; ~i; i--) if (f[i][j]) {
          int coef = (ll) qpow(cnt1, n - i) * (qpow(cnt2, i) + mod - qpow(cnt2 - 1, i)) % mod;
          for (int l = 1, c = (ll) coef * f[i][j] % mod * inv[j] % mod; j + l <= m; l++, c = (ll) c * coef % mod) {
            f[i][j + l] = (f[i][j + l] + (ll) c * fac[j + l] % mod * inv[l]) % mod;
          }
        }
      }
    }
  }
  printf("%d\n", f[n][m]);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout << min(a,b) + min(c,d) << endl;
  return 0;
}



Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;
    cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];

    if(n==1) {
        cout<<0<<endl;
        return 0;
    }

    ll ans =0;
    rep(i,n-1){
        if(a[i]>a[i+1]){
            ans += a[i]-a[i+1];
            a[i+1]=a[i];
        }
    }

    cout<<ans<<endl;

    
}

Measured memory_bytes: 4744
// Minimum_Spanning_Tree.cs

using System;

class Minimum_Spanning_Tree {
	public static void Main() {

		int n = int.Parse(Console.ReadLine());
		int[,] matrix = new int[n, n];
		int count = 0;
		bool[] memoryPosition = new bool[n];
		int[] m = new int[n];

		for(int i = 0; i < n; i++) {
			m[i] = int.MaxValue;
		}

		m[0] = 0;

		for(int i = 0; i < n; i++) {
			string testString = Console.ReadLine();
			char c = ' ';
			string ss = testString.Trim(c);
		//	Console.WriteLine(ss);
			string[] str = ss.Split();

/*
			foreach(string s in str) {
				Console.WriteLine(s);
			}
*/
			for(int j = 0; j < n; j++) {
				matrix[i, j] = int.Parse(str[j]);
			}
		}
/*
		foreach(int ii in matrix) {
			Console.WriteLine(ii);
		}
*/


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

			int min = int.MaxValue;
			int position = -1;

			for(int j = 0; j < n; j++) {
				if(!memoryPosition[j] && m[j] < min) {
					min = m[j];
					position = j;
				}
			}
//			Console.WriteLine("test");
			memoryPosition[position] = true;
//			Console.WriteLine("test");
			count += m[position];

			for(int j = 0; j < n; j++) {
				m[j] = Math.Min(m[j], matrix[position, j] < 0 ? int.MaxValue : matrix[position, j]);
			}
		}

		Console.WriteLine(count);

	}
}

Measured memory_bytes: 9300
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
s = ''
for i in range(1,n+1):
  s += (str(i)+' ')*a[i-1]
k = list(s.split())
for j in range(h):
  ans = k[j*w:(j+1)*w]
  if j%2 == 0:
    print(' '.join(ans))
  else:
    print(' '.join(ans[::-1]))

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int x,y,z;cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<' '<<y<<' '<<z<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	int i,sum,a,b,c;
	int top,topn;
	char topc;
	
	i = 0;
	top = 0;
	
	while(1){
		
		scanf(" %d %d",&a,&b);
		
		if(a == 0 && b == 0){
			break;
		}
		
		c = a + b;
		
		if(top < c){
			top = c; //合計
			topn = i + 1; //店番
		}
		
		i++;
		
		if(i==5){
			switch(topn){
				case 1:
				topc = 'A';
				break;
			case 2:
				topc = 'B';
				break;
			case 3:
				topc = 'C';
				break;
			case 4:
				topc = 'D';
				break;
			case 5:
				topc = 'E';
				break;
			}
			printf("%c %d\n",topc,top);
			i = 0;
			top = 0;
		}
	}
	
	return(0);
	
}

Measured memory_bytes: 600
D, G = map(int, input().split())
Problems_info = {}
Problems = []
Bonus = []
for i in range(D):
    p, c = map(int, input().split())
    Problems_info[i] = p
    Problems += [100 * (i + 1)] * p
    Bonus.append(c)


# 点数が高い順にソート
Problems.sort(reverse=True)

ans = float('inf')
# bit全探索
for bs in range(2 ** D):
    tmp_ans = 0  # これまでに解いた問題数を管理
    tmp_score = 0  # これまでの得点を管理
    solved_point = set()  # すでに解いた点数帯を管理するための集合

    for i in range(D):
        # ボーナスをとるなら
        if (bs >> i) & 1:
            tmp_score += Bonus[i]
            tmp_score += Problems_info[i] * 100 * (i + 1)
            tmp_ans += Problems_info[i]
            solved_point.add(100 * (i + 1))

    for point in Problems:
        if tmp_score >= G:
            ans = min(ans, tmp_ans)
            break

        # ボーナスを未取得なら使える
        if point not in solved_point:
            tmp_ans += 1
            tmp_score += point

print(ans)


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



int main() {
  int a[5];
  rep(i, 5) cin >> a[i];
  rep(i, 5){
    if(a[i] != i + 1) cout << i + 1 << endl;
  }
}

Measured memory_bytes: 3592
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    def find_chi(l, r):
        if l == r:
            return l
        min_pre_i = n + 1
        pui = -1
        for ino_i in range(l, r + 1):
            if pre_i[ino_i] < min_pre_i:
                min_pre_i = pre_i[ino_i]
                pui = ino_i
        if pui - l > 0:
            chi[ino[pui]][0] = ino[find_chi(l, pui - 1)]
        if r - pui > 0:
            chi[ino[pui]][1] = ino[find_chi(pui + 1, r)]
        return pui

    def dfs(u):
        l, r = chi[u]
        if l != -1: dfs(l)
        if r != -1: dfs(r)
        pos.append(u)

    n = int(input())
    pre = list(map(int, input().split()))
    ino = list(map(int, input().split()))
    chi = {}
    for u in pre:
        chi[u] = [-1, -1]
    utoi = {u: i for i, u in enumerate(pre)}
    pre_i = []
    for u in ino:
        pre_i.append(utoi[u])
    root = ino[find_chi(0, n - 1)]
    pos = []
    dfs(root)
    print(*pos)

main()



Measured memory_bytes: 5640
N = int(input())
x = []
y = []
h = []

for i in range(N):
    xi, yi, hi = map(int, input().split(" "))
    x.append(xi)
    y.append(yi)
    h.append(hi)

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):
            if h[i] != 0:
                H = h[i] + abs(Cx - x[i]) + abs(Cy - y[i])
                break
        
        for i in range(N):
            if h[i] != max(H - (abs(Cx - x[i]) + abs(Cy - y[i])), 0):
                break
        else:
            print (Cx, Cy, H)
            break


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int x,k,r[100050],s[100050],o[100050],w[100050],q,t,a;
int main(){
	scanf("%d%d",&x,&k);
	int i,j,v=-1;
	r[0]=o[0]=w[0]=0;
	s[0]=x;
	for(i=1;i<=k;i++){
		scanf("%d",&r[i]);
		int d=(r[i]-r[i-1])*v;
		w[i]=min(max(w[i-1]+d,0),x);
		s[i]=max(min(s[i-1]+d,x),0);
		o[i]=min(o[i-1]-min(0,w[i-1]+d),x);
		v*=-1;
	}
	i=0;	
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&t,&a);
		if(t>=r[k]) i=k;
		else{
			int n=k;
			while(i<n-1){
				int c=i+(n-i)/2;
				if(r[c]<t) i=c;
				else n=c;
			}
		}
		int ans=min(w[i]+max(a-o[i],0),s[i])+(t-r[i])*((i%2)*2-1);
		printf("%d\n",min(max(ans,0),x));
	}
	return 0;
}

Measured memory_bytes: 2688
n = input()
dp = [0]*n
l = map(int, raw_input().split())
for i in range(1, n):
	dp[i] = min(dp[i-1] + abs(l[i] - l[i-1]), dp[max(0, i - 2)] + abs(l[i] - l[max(0, i-2)]))
print dp[-1]

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

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

using namespace std;

int H,W,A[30][30];

int main() {
  cin >> H >> W;
  rep(i,H) rep(j,W) cin >> A[i][j];
  int mini = INT_MAX;
  rep(y,H) {
    rep(x,W) {
      int score = 0;
      rep(i,H) rep(j,W) score += ( min(abs(x-j),abs(y-i)) * A[i][j] );
      mini = min(mini,score);
    }
  }
  cout << mini << endl;
  return 0;
}


Measured memory_bytes: 3112
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    ll S;
    cin >> S;
    for (ll i = floor(sqrt(S)); i <= pow(10, 9); i++) {
        if (0 <= i * i - S && i * i - S <= pow(10, 9)) {
            cout << 0 << " " << 0 << " " << i << " " << i * i - S << " " << 1
                 << " " << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  int n;cin>>n;
  vector<int> a(n+1, 0), c(n,0);
  fr(i, n) cin>>a[i];
  int ans = 0;
  fr(i, n) {
    int b; cin>>b;
    ans += b;
  }

  fr(i, n-1) cin>>c[i];
  fr(i, n) {
   if(a[i]+1==a[i+1]) ans += c[a[i]-1];
  }

  cout << ans<< endl;

  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define debug(a) cout << a << endl
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=100500;

//=================================================
int a[maxn];
int dp[maxn];
int n;
int main()
{
    IO;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++) {
        if(i==1) {
            dp[i]=0;
        }
        else if(i==2) {
            dp[i]=abs(a[2]-a[1]);
        }
        else {
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
    }
    cout<<dp[n]<<endl;

    return 0;
}

Measured memory_bytes: 1024
H, W = map(int, input().split())
field = [list(input()) for i in range(H)]
flag = []
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            continue
        inflag = False
        for k in range(4):
            ni = i + dx[k]
            nj = j + dy[k]
            if ni < 0 or ni >= H or nj < 0 or nj >= W:
                continue
            elif field[ni][nj] == '#':
                inflag = True
        flag.append(inflag)

if all(flag):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 40944
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


int main(){
    CIN(N);CIN(A);CIN(B);
    I v = {N,A,B};
    sort(ALL(v));
    COUT(abs(v.front()-v.back()));
    return 0;
}


Measured memory_bytes: 256
/*
 ***
 Question Name:
 ***
 Question Link:
 
 ***
 Idea:
 */

#include <memory.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

vector<vi> E;
int N,M;
int main(){
    cin>>N>>M;
    E.resize(N);
    for(int i=0;i<M;++i){
        int u,v;
        cin>>u>>v;
        E[u-1].push_back(v-1);
        E[v-1].push_back(u-1);
    }
    vb mark(N,true);
    queue<ii> que;
    mark[0]=false;
    que.push(ii(0,0));
    while(!que.empty()){
        int k = que.front().second, l = que.front().first;
        if(l==2) break;
        que.pop();
        for(auto j:E[k]) if(mark[j]){
            if(j==N-1){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
            mark[j] = false;
            que.push(ii(l+1,j));
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 12784
// Problem : C - Minimization
// Contest : AtCoder Regular Contest 099
// URL : https://atcoder.jp/contests/arc099/tasks/arc099_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define temptts template <class T, class... Ts>

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, k, pos = 0, a[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	cout << (n - 1) / (k - 1) + !!((n - 1) % (k - 1));
}


Measured memory_bytes: 256