akhauriyash/Code-Regression huggingface dataset:
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1LL << 60;
ll MOD = 1e9+7;

int main() {

    string S,T; cin>>S>>T;
    int mini = 1000;

    for (int i = 0; i < (S.size()-T.size())+1; ++i) {
        int au = 0;
        for (int j = 0; j < T.size(); ++j) {
            if(S[i+j] == T[j]) au++;
        }
        au = T.size() - au;
        mini = min(mini, au);
    }

    cout<<mini<<endl;

}


Measured memory_bytes: 3628
a, b, k = gets.chomp.split.map(&:to_i)
if a > b
  tmp = a
  a = b
  b = tmp
end

i = 0
count = 0
while count < k
  i += 1
  count += 1 if a % i == 0 && b % (a / i) == 0
end

puts a / i

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000

int main(){
    ll y,m,d;
    char c[2];
    cin>>y>>c[0]>>m>>c[1]>>d;
    cout<<(m<=4 ? "Heisei":"TBD");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n; cin>>n;
    ll count=0,num;
    REP(i,n){
        cin>>num;
        while(num%2==0){
            num/=2;
            count++;
        }
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3620
a,b,c,d=map(int,input().split())
import fractions
lcm=c*d//fractions .gcd(c,d)
C=b//c-(a-1)//c
D=b//d-(a-1)//d
CD=b//lcm-(a-1)//lcm
al=b-a+1
print(al-C-D+CD)

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

int main(){
  int H,W;
  while(1){
    cin >> H >> W;
    if(H==0&&W==0)break;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
/*
输入 N 个数字 A1, A2, . . . , AN，
输入 K。 如果对于所有包含 Ai，
且和大于等于 K 的集合，
去掉 Ai 后和还大于等于 K，
那么 Ai 就是可有可无 的。 
问有多少个元素是可有可无的。
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int n, k, a[maxn], dp[maxn][maxn];
bool check(int x) {
	memset(dp, 0, sizeof dp);
	if(x == 1) {
		dp[2][0] = 1; dp[2][a[2]] = 1;
		for (int i = 3; i <= n; ++i) 
			for (int j = 0; j <= k; ++j) {
				dp[i][j] = dp[i - 1][j];
				if(j >= a[i]) dp[i][j] |= dp[i - 1][j - a[i]]; 
			}
	}
	else {
		dp[1][0] = dp[1][a[1]] = 1;
		for (int i = 2; i <= n; ++i) {
			if(x == i) {
				for (int j = 0; j <= k; ++j) dp[i][j] = dp[i - 1][j]; continue;
			}
			for (int j = 0; j <= k; ++j) {
				dp[i][j] = dp[i - 1][j];
				if(j >= a[i]) dp[i][j] |= dp[i - 1][j - a[i]];
			}
		}
	}
	for (int i = k - a[x]; i < k; ++i) if(dp[n][i]) return 0;
	return 1; 
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]); a[i] = min(a[i], k);
	}
	if(n == 1) {
		if(a[1] >= k) puts("0");
		else puts("1"); return 0;
	}
	sort(a + 1, a + n + 1);
	int l = 1, r = n, ans = 0;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(check(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 98176
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 105;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  char temp[n + 5];
  cin >> (temp + 1);

  ll arr[n + 5];
  ll arr2[n + 5];
  memset(arr, 0, sizeof(arr));
  for (ll i = 1; i <= n; i++) {
    arr[i] = temp[i] - '0';
    arr2[i] = arr[i];
  }

  if (n <= 60) {
    for (ll it = 2; it <= n; it++) {

      for (ll i = 1; i <= n + 1 - it; i++) {
        arr[i] = abs(arr[i] - arr[i + 1]);
      }
      arr[n + 2 - it] = 0;
    }
    cout << arr[1] << en;
    return 0;
  }
  for (ll it = 2; it <= 50; it++) {
    for (ll i = 1; i <= n + 1 - it; i++) {
      arr2[i] = abs(arr2[i] - arr2[i + 1]);
    }
  }
  /*
    vector<ll> curr;
    curr.push_back(0);
    for (ll it = 11; it <= n; it++) {
      vector<ll> curr2;
      for (ll &x : curr) {
        curr2.push_back(x + 1);
      }
      vector<ll> nCurr;
      ll it1 = 0, it2 = 0;
      while (it1 < curr.size() && it2 < curr2.size()) {
        if (curr[it1] == curr2[it2]) {
          it1++;
          it2++;
          continue;
        }
        if (curr[it1] < curr2[it2])
          nCurr.push_back(curr[it1++]);
        else
          nCurr.push_back(curr2[it2++]);
      }
      while (it1 < curr.size())
        nCurr.push_back(curr[it1++]);

      while (it2 < curr2.size())
        nCurr.push_back(curr2[it2++]);
      curr = nCurr;
    }
    */
  ll res = 0;
  ll rem = n - 50;
  for (ll i = 0; i <= n; i++) {
    if ((rem & i) == i)
      res ^= arr2[i + 1];
  }
  cout << res << en;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N>>M;
}
//=============================
void func(){}
//=============================
void solve()
{
    cout<<max({M*N, N-M, M+N})<<endl;
}
//=============================
signed main()
{
    input();
    solve();
    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)
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    int res = 0;
    rep(i,n){
        cin>>a[i];
        while(a[i]%2 ==0){
            a[i] /= 2;
            res++;
        }
    }
    cout<<res<<endl;
    return 0;
}


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

int main()
{
    int N, D;
    cin >> N >> D;
    vector<vector<double>> X(N,vector<double>(D));

    for(int i = 0; i < N; i++)
        for(int j = 0; j < D; j++)
            cin >> X[i][j];

    int cnt = 0;
    const double E = 0.000000001;
    for(int i = 0; i < N; i++)
    {
        for(int j = i+1; j < N; j++)
        {
            double tmp = 0;
            for(int k = 0; k < D; k++)
            {
                tmp += pow(X[i][k]-X[j][k],2);
            }
            tmp = sqrt(tmp);
            long long a = (long long)tmp;
            double b = (double)a;
            tmp -= b;
            if(tmp < E) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

int n, l;
int a[M];

void read() {
  cin >> n >> l;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
}


void kill() {
  int j = -1;

  for (int i = 0; i + 1 < n; ++i)
    if (a[i] + a[i + 1] >= l)
      j = i;

  if (j == -1) {
    cout << "Impossible\n";
    return;
  }

  cout << "Possible\n";

  for (int x = 0; x < j; ++x)
    cout << x + 1 << "\n";

  for (int x = n - 2; x > j; --x)
    cout << x + 1 << "\n";

  cout << j + 1 << "\n";
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int a, b, c;
long long h[100010];

long long dp[100010];


int main(){
	cin >> a >> b >> c;

	if(a-b < c){
		cout << c - (a - b) << endl;
	}else{
		cout << 0 << endl;
	}

	return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
 int N;
 cin >> N;
 int flag = 0;
int ans = N;
 rep(i,3){
     if(ans % 10 == 7) flag = 1;
     ans /= 10;
 }   
 if(flag==1)cout << "Yes" << endl;
 else cout << "No"<< endl;
}

Measured memory_bytes: 3624
N = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
b = [0]*(N+1)
#print(b)

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

for i in range(N,0,-1):
    #print("i:"+str(i))
    #print("sum(b[i::i])%2="+str(sum(b[i::i])%2))
    b[i] = a[i]^(sum(b[i::i])%2)
    #print(b[i])

print(sum(b[1:]))
idx = func1(b,1)
print(*idx)


Measured memory_bytes: 14132
n, m, c = map(int, input().split(" "))
b_arr = list(map(int, input().split(" ")))
ans = 0
a_arr = []
for _ in range(n):
    a_arr = list(map(int, input().split(" ")))
    sum_num = c

    for i in range(m):
        sum_num += a_arr[i] * b_arr[i]

    if sum_num > 0:
        ans += 1
print(ans)


Measured memory_bytes: 9172
import java.util.Scanner;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        while(true) {
            String input = scanner.nextLine();
            if ("0 0".equals(input)) {
                break;
            }
            
            String[] numbers = input.split(" ");
            int h = Integer.parseInt(numbers[0]);
            int w = Integer.parseInt(numbers[1]);
            
            for (int i=0; i<h; i++) {
                for (int j=0; j<w; j++) {
                    if ( (i%2 == 0 && j%2 == 0) || (i%2 == 1 && j%2 == 1) ) {
                        System.out.print("#");
                    } else if( (i%2 == 0 && j%2 == 1) || (i%2 == 1 && j%2 == 0)) {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 34192
#include <bits/stdc++.h>
using namespace std;
#define AB_BHI_NI_DEGI                \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double
#define endl "\n"

void solve()
{
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0, i = 0;
    while (i < n)
    {
        int cnt = 0;
        while (i < n and s[i] == 'R')
            cnt++, i++;
        ans = max(ans, cnt);
        i++;
    }
    cout << ans << "\n";
}
int32_t main()
{
    AB_BHI_NI_DEGI
    int Test = 1;
    //cin >> Test;
    //init();
    while (Test--)
        solve();
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long d;
long long p[20];
int dx1[20],dx2[20];
vector<long long> v;
void dfs(int s,int e,vector< pair<long long ,long long> > &w,long long val,long long cnt)
{
	if(s==e){
		w.push_back(make_pair(val,cnt));
		return ;
	}
	for(int i=-9;i<=9;i++)
		dfs(s+1,e,w,val+i*v[s],cnt*(s==0?dx2[i+10]:dx1[i+10]));
}
long long solve(int l)
{
	v.clear();
	for(int i=0;l-1-i>i;i++)
		v.push_back(p[l-1-i]-p[i]);
	vector< pair<long long,long long> > v1,v2;
	dfs(0,(v.size()+1)/2,v1,0,1);
	dfs((v.size()+1)/2,v.size(),v2,0,1);
	long long ans=0;
	map<long long,long long> mp;
	for(int i=0;i<v2.size();i++)
		mp[v2[i].first]+=v2[i].second;
	for(int i=0;i<v1.size();i++)
		ans+=mp[v1[i].first+d]*v1[i].second;
	if(l%2==1)
		ans*=10;
	return ans; 
}
int main()
{
	p[0]=1;
	for(int i=1;i<20;i++)
		p[i]=p[i-1]*10;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++)
			dx1[i-j+10]++;
	}
	for(int i=1;i<10;i++){
		for(int j=0;j<10;j++)
			dx2[i-j+10]++;
	}
	cin>>d;
	long long ans=0;
	for(int i=2;i<=18;i++)
		ans+=solve(i);
	cout<<ans<<endl;
	return 0;
}

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

typedef struct{
	int n;
	int day[1000];
	int d_n;
}data;

int main(void){
	data com[1001];
	data tem[1001];
	int sec[1001];
	int index = 0;
	int sec_index = 0;
	char str[100];
	int num;
	int a;

	for(int i=0; i<1001; i++){
		com[i].d_n = 0;
	}

	while(1){
		fgets(str, 99, stdin);
		for(int i=0;; i++){
			if(str[i] == '\n'){
				str[i] = '\0';
				break;
			}
		}
		if(strlen(str) == 0) break;
		sscanf(str, "%d,%d", &num, &a);

		int i;
		for(i=0; i<index; i++){
			if(com[i].n == num){
									com[i].day[com[i].d_n] = a;
					(com[i].d_n)++;
				break;
			}
		}
		if(i == index){
			com[index].n = num;
			com[index].day[com[index].d_n] = a;
			(com[i].d_n)++;
			index++;
		}
	}

	for(int i=0; i<index; i++){
		tem[i] = com[i];
	}

	while(scanf("%d,%d", &num, &a) != EOF){
		for(int i=0; i<index; i++){
			if(tem[i].n == num){
				int j;
				for(j=0; j<sec_index; j++){
					if(sec[j] == num) break;
				}
				if(j == sec_index){
					sec[sec_index] = num;
					sec_index++;
				}
			}
		}
		int i;
		for(i=0; i<index; i++){
			if(com[i].n == num){
					com[i].day[com[i].d_n] = a;
					(com[i].d_n)++;
				break;
			}
		}
		if(i == index){
			com[index].n = num;
			com[index].day[com[index].d_n] = a;
			(com[i].d_n)++;
			index++;
		}
	}

	for(int i=sec_index-1; i>0; i--){
		for(int j=0; j<i; j++){
			if(sec[j] > sec[j+1]){
				int temp = sec[j];
				sec[j] = sec[j+1];
				sec[j+1] = temp;
			}
		}
	}

	for(int i=0; i<sec_index; i++){
		printf("%d ", sec[i]);
		int cnt = 0;
		for(int j=0; j<index; j++){
			if(com[j].n == sec[i]){
				printf("%d\n", com[j].d_n);
			}	
		}
	}

	return 0;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;

struct Four_digit {
    string s1;
    string s2;
    int m;
    int c;
    int x;
    int i;
};

vector<int> rewrite (string str); 
void sum(vector<int> &v1, vector<int> &v2); 
void output (vector<int> number); 

int main(void) {
    int n;
    cin >> n;
    vector<int> s1;
    vector<int> s2;
    for (int i = 0; i < n; i++) {
        Four_digit num;
        cin >> num.s1 >> num.s2;
        s1 = rewrite(num.s1);
        s2 = rewrite(num.s2);
        sum(s1, s2);
        output(s1);
    }
    return 0;
}

vector<int> rewrite (string str) {
    vector<int> number(4, 0);

    if (str[0] == 'm') {
        number[0] = 1;
    } else if (str[0] == 'c') {
        number[1] = 1;
    } else if (str[0] == 'x') {
        number[2] = 1;
    } else if (str[0] == 'i') {
        number[3] = 1;
    }

    for (int i = 1; i < str.length(); i++) {
        if (str[i] == 'm') {
            if (str[i - 1] >= '0' && str[i - 1] <= '9') {
                number[0] = str[i - 1] - '0';
            } else {
                number[0] = 1;
            }
        } else if (str[i] == 'c') {
            if (str[i - 1] >= '0' && str[i - 1] <= '9') {
                number[1] = str[i - 1] - '0';
            } else {
                number[1] = 1;
            }
        } else if (str[i] == 'x') {
            if (str[i - 1] >= '0' && str[i - 1] <= '9') {
                number[2] = str[i - 1] - '0';
            } else {
                number[2] = 1;
            }
        } else if (str[i] == 'i') {
            if (str[i - 1] >= '0' && str[i - 1] <= '9') {
                number[3] = str[i - 1] - '0';
            } else {
                number[3] = 1;
            }
        }
    }
    return number; 
}

void sum(vector<int> &v1, vector<int> &v2) {
    for (int i = 0; i < v1.size(); i++) {
        v1[i] += v2[i];
    }
    for (int i = 3; i > 0; i--) {
        if (v1[i] >= 10) {
            v1[i] -= 10; 
            v1[i - 1]++;
        }
    }
    return;
}

void output (vector<int> v) {
    char kigou[4] = {'m', 'c', 'x', 'i'};
    for (int i = 0; i < 4; i++) {
        if (v[i] == 0) {
            continue; 
        } else if (v[i] == 1) {
            cout << kigou[i];
        } else {
            cout << v[i] << kigou[i];
        }
    }
    cout << endl;
    return;
}

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

int main() {
    int N;
    cin >> N;
    int ans = ((N + 999) / 1000) * 1000 - N;
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <deque>
using namespace std;

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

	int N, M, A, B;
	cin >> N >> M >> A >> B;

	deque<int> D(N);
	for(int i = 0; i < N; i++) {
		cin >> D[i];
	}

	deque<int> H;
	for(int i = 0; i < N; i++) {
		if(D[i] >= A) H.push_back(D[i]);
		else break;;
	}

	int cnt = N - H.size();
	if(cnt < M) {
		while(1) {
			if(H.size() == 0) break;
			if(H.back() <= B) {
				cnt++;
				H.pop_back();
			}
			else break;
		}
	}
	cout << N - cnt << endl;
}

Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();

		System.out.println(u.equals(s) ? a - 1 + " " + b : a + " " + (b - 1));
	}
}

Measured memory_bytes: 38640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<long long int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  for(int i = 0; i < n; i++){
    v[i] = v[i] - (i + 1);
  }
  sort(v.begin(), v.end());
  long long x = v[n / 2], y = v[n / 2 - 1], ansx = 0, ansy = 0;
  for(int i = 0; i < n; i++){
    ansx += abs(v[i] - x);
    ansy += abs(v[i] - y);
  }
  cout << min(ansx, ansy) << endl;
  return;
}
int main(){
  solve();
  return 0;
}


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B && B==C){
    cout << 1 << endl;
  }
  else if((A == C &&C != B) ||(A ==B && B !=C) ||(B==C && C != A)){
    cout << 2 << endl;
  }
  else{
    cout << 3 << endl;
  }
}

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

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

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

int a,b,c;
int x,y;
int ans;
main () {
      cin >> a >> b >> c;
      cin >> x >> y;

      while (y > 0 && x > 0) {
            if (a + b >= c * 2)
                  ans += (c * 2);
            else
                  ans += (a + b);
            x --,y --;
      }
      cout << ans + (x * min(a,c * 2)) + (y * min(c * 2,b)) << endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
x = gets.chomp

left = 0
right = x.count("E")
ans = n

n.times do |i|
  s = 0
  curr = x[i]
  if curr == "W"
    s = left + right
    left += 1
  else
    right -= 1
    s = left + right
  end
  ans = s if s < ans
end
puts ans

Measured memory_bytes: 2436
N,K = map(int, input().split())
A = list(map(int, input().split())) 
A.sort()
A.reverse() 
x = A[0]   
for i in range (1, N):
  while A[i] != 0:
    x , A[i] = A[i] , x % A[i]
if K > A[0]:
  print('IMPOSSIBLE')
else:
  print('POSSIBLE' if K%x == 0 else 'IMPOSSIBLE')

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

using namespace std;

//#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 200005;

int N, Q;
string s;
char t[limit], d[limit];


int g[limit], ng[limit];
int solve0() {
  rep(i, N)g[i] = 1;

  rep(i, Q) {
    rep(j, N) ng[j] = 0;
    rep(j, N) {
      if(s[j] == t[i]) {
        if(d[i] == 'L' && j>0) ng[j-1] += g[j];
        else if(d[i] == 'R' && j+1<N) ng[j+1] += g[j];
      } else ng[j] += g[j];
    }
    rep(j, N) g[j] = ng[j];
  }

  int ans = 0;
  rep(i, N) ans += g[i];
  return ans;
}

int emu(int k) {
  int idx = k;
  rep(i, Q) {
    if(s[idx] == t[i]) idx += (d[i] == 'L' ? -1 : 1);
    if(idx<0 || N<=idx) break;
  }
  return idx;
}

int solve1() {
  int ans = 0, ng, ok;

  ng = -1;
  ok = N;
  while(abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if(emu(mid)>=0) ok = mid;
    else ng = mid;
  }
  ans += ng+1;

  ng = -1;
  ok = N;
  while(abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if(emu(mid)>=N) ok = mid;
    else ng = mid;
  }
  ans += N-ok;

  return N-ans;
}

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

  cin >> N >> Q;
  cin >> s;
  rep(i, Q) cin >> t[i] >> d[i];

  cout << solve1() << endl;

  return 0;
}


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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

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

  Sieve s(1000005);
  auto fs = s.factor(n);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7784
<?php
    $input_line = trim(fgets(STDIN));
    
    $num = explode(" ",$input_line);
    
    $x = intval($num[0]);
    $y = intval($num[1]);
    
    echo floor($x/$y);
    echo " ";
    echo $x%$y;
    echo " ";
    printf("%.5f",$x/$y);
    echo "\n";
?>


Measured memory_bytes: 9212
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

l = [True for _ in range(n)]
for a, b in ab:
    if h[a-1] > h[b-1]:
        l[b-1] = False
    elif h[a-1] < h[b-1]:
        l[a-1] = False
    else:
        l[a-1] = l[b-1] = False

print(len(list(filter(lambda x: x, l))))

Measured memory_bytes: 32668
#include <stdio.h>
#include <string.h>
#include <stdlib.h>




int main(void)
{
	int n;
	int dig[11];
	int sum = 0;

	scanf("%d", &n);

	int tmp = n;

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

		if (n < 1) break;
		dig[i] = tmp % 10;
		tmp /= 10;
		sum += dig[i];
		
	}

	int ans = n % sum;

	if (ans == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 128
import itertools
import heapq
N,M,Q = list(map(int,input().split()))
list1 = [list(map(int,input().split())) for i in range(Q)] 
q1 = []
heapq.heapify(q1)

ans = [None]
def dfs(x,n2,m1):
  if len(x) == n2:
    heapq.heappush(q1,-sum(x1[3] for x1 in list1 if x[x1[1]-1]-x[x1[0]-1] == x1[2]))
  else:
    for i in range(1,m1+1,1):
      if i >= x[-1]:
        x.append(i)
        dfs(x,n2,m1)
        x.pop()

dfs([1],N,M)
print(-heapq.heappop(q1))

Measured memory_bytes: 74392
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DBinomialCoefficients solver = new DBinomialCoefficients();
        solver.solve(1, in, out);
        out.close();
    }

    static class DBinomialCoefficients {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            int col = a[n - 1];
            int min = col / 2;
            int max = min + (col % 2 == 0 ? 0 : 1);
            out.print(col);
            out.print(' ');
            int d = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int cd = Math.min(Math.abs(max - a[i]), Math.abs(min - a[i]));
                if (cd < d) {
                    d = cd;
                } else {
                    out.println(a[i - 1]);
                    return;
                }
            }
            out.println(a[n - 1]);
        }

    }
}



Measured memory_bytes: 50964
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A
import sys

nums_len = int(sys.stdin.readline())
nums_str = sys.stdin.readline().split(' ')
nums = map(int, nums_str)

print ' '.join(map(str, nums))
for i in range(1, nums_len):
    v = nums[i]
    for j in reversed(range(0, i)):
        if v < nums[j]:
            nums[j + 1] = nums[j]
            nums[j] = v
        if v > nums[j]:
            break
    print ' '.join(map(str, nums))

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <numeric>

#define FOR(i,l,n) for(int i=(l);i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define MAX_JUDGE 100
using namespace std;

int main(){
  int n,score[MAX_JUDGE];
  while(cin>>n,n){
    REP(i,n)cin>>score[i];
    sort(score,score+n);
    int sum = accumulate(score+1,score+n-1,0);
    cout << sum/(n-2) <<endl;
  }
  return 0;
}



Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    C = input()
    C2 = input()

    for i in range(3):
        if C[i] != C2[2-i]:
            print('NO')
            return
    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 62616
N, M = map(int, input().split())

X = []
for _ in range(N):
    temp = list(map(int,input().split()))
    X.append(temp)
X = sorted(X)

bottle = 0
money = 0

for n in range(N):
    bottle += X[n][1]
    money += X[n][0] * X[n][1]

    if bottle >= M:
        money -= (bottle - M) * X[n][0]
        break

print(money)


Measured memory_bytes: 28656
#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(){
    string s;
    long long k;
    cin >> s >> k;
    int i = 0;
    char ans;
    rep(i,100){
        if(s[i] != '1'){
            ans = s[i];
            break;
        }
        if(i+1 == k){
            ans = '1';
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define MOD1 1000000009
#define MOD2 1000000033

const int M1 = 1000007;
const int M2 = 1000003;

string S;
map< pair<long long, long long>, int> Z;
long long P1[5005], H1[5005], X1[5005];
long long P2[5005], H2[5005], X2[5005];

int func(int len)
{
    for(int i=0; i<S.size(); i++)
        X1[i] = X2[i] = 0;

    Z.clear();
    
    X1[len - 1] = H1[len - 1];
    X2[len - 1] = H2[len - 1];

    Z[ { X1[len-1], X2[len-1] } ]++;

    for(int i=len; i<S.size(); i++)
    {
        X1[i] = (H1[i] + MOD1 - H1[i-len] * P1[len] % MOD1) % MOD1;
        X2[i] = (H2[i] + MOD2 - H2[i-len] * P2[len] % MOD2) % MOD2;
        Z[ { X1[i], X2[i] } ]++;
    }

    int ptr = len - 1, lim = ptr + len - 1;

    while(ptr <= lim)
    {
        long long x1 = X1[ptr], x2 = X2[ptr];
        Z[ {x1, x2}]--;

        if(Z[{x1, x2}] == 0)
            Z.erase({x1, x2});
        
        ptr++;
    }

    for(int i=len-1; i<S.size(); i++)
    {
        if(Z.count({X1[i], X2[i]}))
            return 1;

        if(ptr < S.size())
        {
            long long x1 = X1[ptr], x2 = X2[ptr];
            Z[ {x1, x2}]--;

            if(Z[{x1, x2}] == 0)
                Z.erase({x1, x2});
            
            ptr++;
        }
    }

    return 0;
}

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

    int N;
    cin >> N >> S;

    H1[0] = H2[0] = S[0];
    P1[0] = P2[0] = 1;

    for(int i=1; i<=N; i++)
    {
        P1[i] = P1[i-1] * M1 % MOD1;
        P2[i] = P2[i-1] * M2 % MOD2;
    }

    for(int i=1; i<N; i++)
    {
        H1[i] = (H1[i-1] * M1+ S[i]) % MOD1;
        H2[i] = (H2[i-1] * M2 + S[i]) % MOD2;
    }

    int ans = 0;
    int left = 1, right = N/2;

    while(left <= right)
    {
        int mid = (left + right) / 2;

        if(func(mid))
            ans = mid, left = mid + 1;
        else
            right = mid - 1;
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 768
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int gcd(int a, int b)
{
	while (b != 0) {
		a = a % b;
		std::swap(a, b);
	}
	return a;
}

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, C;
	std::cin >> A >> B >> C;
	auto g = gcd(A, B);
	if (C % g == 0) {
		std::cout << "YES\n";
	} else {
		std::cout << "NO\n";
	}
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, K, ans;

int main()
{
	in >> N >> K;
	std::vector<LL>a(N), max(N + 1);
	rep(i, N)
	{
		in >> a[i];
		max[i + 1] = a[i];
	}
	rep(i, N) max[i + 1] = std::max(max[i + 1], max[i]);
	ans = 112345678901;
	rep(bit, (1LL << N))
	{
		std::vector<LL>idxs;
		rep(i, N)
		{
			if (bit&(1LL << i)) idxs.push_back(i);
		}
		if (idxs.size() != K) continue;
		LL maxH = 0, res = 0;
		rep(i, K)
		{
			maxH = std::max(maxH, max[idxs[i]]);
			if (a[idxs[i]] <= maxH)
			{
				++maxH;
				res += maxH - a[idxs[i]];
			}
			else maxH = a[idxs[i]];
		}
		ans = std::min(ans, res);
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	L := sc.NextFloat()
	l := 0.1
	r := L
	for r-l > 1e-9 {
		c := (r + l) / 2

		if c+c+c <= L {
			l = c
		} else {
			r = c
		}
	}

	fmt.Println(l * l * l)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
a=[int(input()) for i in range(5)]
k=int(input())

flag=0
for i in range(4):
    for j in range(i+1, 5):
        d=a[j]-a[i]
        if d > k:
            flag=1

if flag==1:
    print(":(")
else:
    print("Yay!")

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    string s;
    cin >> s;
    if(s=="ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>
#include <cmath>

using namespace std;

int N;
string S[55];
map<char, int> mp_nums;

void clear_mp_nums(string S){
    for(auto itr = mp_nums.begin(); itr != mp_nums.end(); ++itr) 
        if((int)S.find(itr->first) == -1) mp_nums.erase(itr->first);
}

int cnt_chars(string S, char c){
    int cnt = 0;
    for(int i = 0; i < S.size(); i++)
        if(S[i] == c) cnt++;
    return cnt;
}

void solve(){
    for(int i = 0; i < S[0].size(); i++){
        char c = S[0][i];
        mp_nums[c] = cnt_chars(S[0], c);
    }
    
    for(int i = 1; i < N; i++){
        for(int j = 0; j < S[i].size(); j++){
            char c = S[i][j];
            if(mp_nums[c]==0) continue;
            else {
                mp_nums[c] = min(mp_nums[c],cnt_chars(S[i], c));
            }
        }
        clear_mp_nums(S[i]);
    }

    if(mp_nums.size()==0) cout << "";
    else{
        for(auto itr = mp_nums.begin(); itr != mp_nums.end(); ++itr) {
            for(int k = 0; k < mp_nums[itr->first]; k++)
                    cout << itr->first;
        }
    }
    cout << endl;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> S[i];

    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N);
  VEC(ll, a, N);
  int d1 = 0;
  int d2 = 0;
  int d4 = 0;
  each(x, a) {
    if (x % 4 == 0) {
      d4++;
    } else if (x % 2 == 0) {
      d2++;
    } else {
      d1++;
    }
  }
  if (d4 - d1 - (d2 % 2) < -1) {
    print("No");
  } else {
    print("Yes");
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = 2e5 + 10;
int n, m, u[M], v[M], ok[N][N], pos[N][N], vis[N][N], ok2[N][N];
vector<int> g[N];
void dfs(int h, int u) {
    ok[u][h] = 1;
    for(auto v : g[u]) if(!ok[v][h]) dfs(h, v);
}
void dfs1(int h, int u, int fr) {
    pos[h][u] = fr;
    for(auto v : g[u])
        if(!pos[h][v]) dfs1(h, v, u);
}
void dfs2(int h, int u) {
    vis[h][u] = 1;
    for(int i = g[u].size() - 1; i >= 0; --i) {
        int v = g[u][i];
        if(!vis[h][v]) {
            if(pos[h][v] != u || u != h) ok2[h][v] = 1;
            dfs2(h, v);
        }
    }
}
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= m; ++i) 
        scanf("%d %d", &u[i], &v[i]), g[u[i]].push_back(v[i]);
    for(int i = 1; i <= n; ++i) dfs(i, i);
    for(int i = 1; i <= n; ++i) dfs1(i, i, i);
    for(int i = 1; i <= n; ++i) dfs2(i, i);
    for(int i = 1; i <= m; ++i) {
        if(ok[u[i]][v[i]] ^ ok2[u[i]][v[i]]) printf("diff\n");
        else printf("same\n");
    }
    return 0;
}


Measured memory_bytes: 22352
#include <iostream>

using namespace std;

typedef long long LL;

const LL MAX = 100005;

LL n, DP[MAX] = {}, stone[MAX] = {};

int main(void)
{
  cin >> n;
  for(LL i0 = 0; i0 < n; i0++) cin >> stone[i0];
  DP[n-1] = 0;
  DP[n-2] = abs(stone[n-1] - stone[n-2]);
  
  for(LL i0 = n-3; i0 >= 0; i0--)
  {
    DP[i0] = min(DP[i0+1] + abs(stone[i0+1] - stone[i0]), DP[i0+2] + abs(stone[i0+2] - stone[i0]));
  }
  
  cout << DP[0] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int h, w, k;
string s[11];

int c[10][1005];

int main() {
    cin >> h >> w >> k;
    rep(i, h) cin >> s[i];

    int ans = INF;
    rep(bit, 1<<(h-1)) {
        int g = 0;
        vector<int> id(h);
        rep(i, h) {
            id[i] = g;
            if (bit & (1 << i)) g++;
        }
        g++;

        rep(i, g) rep(j, w) c[i][j] = 0;
        rep(i, h) rep(j, w) {
            c[id[i]][j] += s[i][j] - '0';
        }

        int sum = g - 1;
        vector<int> now(g);
        auto add = [&](int j) {
            rep(i, g) now[i] += c[i][j];
            rep(i, g) if (now[i] > k) return false;
            return true;
        };
        rep(j, w) {
            if (!add(j)) {
                sum++;
                now = vector<int>(g);
                if (!add(j)) {
                    sum = INF;
                    break;
                }
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){

  int l[10];
  int a,b;
  int i;

  while(scanf("%d",&l[0])!=EOF){

    int ac=0;
    int sum=0;
    
    for(i=1;i<10;i++)
      scanf(",%d",&l[i]);
    scanf(",%d,%d",&a,&b);

    for(i=0;i<10;i++)
      sum+=l[i]*100;

    //printf("%d\n",sum);
    
    for(i=0;sum>ac;i++){
      ac+=l[i]*100;
      sum-=b*l[i]*100/a;
    }
    printf("%d\n",i);
    

  }
  return 0;
}

Measured memory_bytes: 596
#[macro_use]extern crate text_io;

struct Node(i32,i32,i64);

impl std::cmp::Eq for Node {}

impl std::cmp::PartialEq for Node {
    fn eq(&self,other:&Self) -> bool {
        self.2 == other.2
    }
}

impl std::cmp::PartialOrd for Node {
    fn partial_cmp(&self,other: &Self) -> Option<std::cmp::Ordering>{
        Some(other.2.cmp(&self.2))
    }
} 

impl std::cmp::Ord for Node {
    fn cmp(&self,other:&Self) -> std::cmp::Ordering{
        other.2.cmp(&self.2)
    }
}

fn main() {
    let n:i32 = read!();
    let m:i32 = read!();
    let s:i32 = read!();
    let s = std::cmp::min(s,2500);
    let mut train = vec![vec![];n as usize];//(linked city,money,time)
    for _ in 0..m {
        let (mut u,mut v,a,b):(i32,i32,i32,i32) = (read!(),read!(),read!(),read!());
        u-=1; v-=1;
        train[u as usize].push((v,a,b));
        train[v as usize].push((u,a,b));
    }
    let mut exc:Vec<(i32,i32)> = Vec::with_capacity(n as usize);//(money,time)
    for _ in 0..n{
        exc.push((read!(),read!()));
    }
    let mut dp = vec![vec![std::i64::MAX;2505];n as usize];
    let mut pq = std::collections::BinaryHeap::<Node>::new();
    pq.push(Node(0,s,0_i64));//(city,money,time)
    while !pq.is_empty() {
        let Node(c,m,t) = pq.pop().unwrap();
        if dp[c as usize][m as usize] <= t {
            continue;
        }
        dp[c as usize][m as usize] = t;
        for (nc,nm,nt) in train[c as usize].iter() {
            if *nm > m {continue;}
            pq.push(Node(*nc,m - *nm,t + (*nt) as i64));
        }
        if m+exc[c as usize].0 > 2500 {continue;}
        pq.push(Node(c,m+exc[c as usize].0,t+exc[c as usize].1 as i64));
    }
    for i in dp[1..].iter() {
        println!("{}",i.iter().min().unwrap());
    }
}

Measured memory_bytes: 7044
#include <iostream>
#include <cmath>
int main(){
        long long N,K,A[100000],BitLine0[100],BitLine1[100],tmp,mod,KBitLine[100],Kdig=1,maxdig=0,result=0,KLess=1;
        std::cin>>N>>K;
        for(int i=0; i<N; i++)
                std::cin>>A[i];

        for(int i=0; i<100; i++) {
                BitLine0[i]=0;
                BitLine1[i]=0;
        }

        int j=0;
        while(K!=0) {
                KBitLine[j]=K%2;
                K=K/2;
                j++;
        }
        Kdig=j;

        for(int i=0; i<N; i++) {
                tmp=A[i];
                j=0;
                while(tmp!=0) {
                        mod=tmp%2;
                        if(mod==1) BitLine1[j]++;
                        else BitLine0[j]++;
                        tmp=tmp/2;
                        j++;
                }
                for(int k=j; k<Kdig; k++)
                        BitLine0[k]++;

                if(maxdig<j) maxdig=j;
        }

        for(int i=std::max(maxdig,Kdig)-1; i>=0; i--) {
                long long A=std::pow(2,(double)i);
                if(i>Kdig)
                        result+=BitLine1[i]*A;

                else if(KLess==0)
                        result+=std::max(BitLine0[i],BitLine1[i])*A;

                else{
                        if(KBitLine[i]==0) result+=BitLine1[i]*A;
                        else{
                                if(BitLine0[i]<=BitLine1[i]) {
                                        KLess=0;
                                        result+=BitLine1[i]*A;
                                }
                                else result+=BitLine0[i]*A;
                        }
                }
        }
        std::cout<<result;
        return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int w;
	cin >> w;
	for(int i = 0; i < s.size(); i += w){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
  int N, K;
  int ans=0;

  cin>>N>>K;

  vector<int> vec(N);

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

  sort(vec.begin(),vec.end());
  
  for (int i = 0; i < K; i++)
  {
    ans+=vec.at(i);
  }
  
  cout<<ans;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

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



Measured memory_bytes: 256