akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

long long dp[512][100'010];

int main(){
  //using namespace std;
  int n;
  cin>>n;
  long long V[n], W[n];
  REP(i, n) cin>>V[i]>>W[i];
  int q;
  cin>>q;
  int v[q];
  long long l[q];
  REP(i, q){
    cin>>v[i]>>l[i];
    v[i]--;
  }
  
  int m = min(1<<9, n);
  //vector<vector<long long>> dp(m, vector<long long>(100'010, 0));
  REP(i, m){
    REP(j, 100'010){
      if(i == 0){
        if(W[i] <= j) dp[i][j] = V[i];
        continue;
      }
      dp[i][j] = dp[(i + 1)/2 - 1][j];
      if(j < W[i]) continue;
      dp[i][j] = max(dp[i][j], dp[(i + 1)/2 - 1][j - W[i]] + V[i]);
    }
  }
  
  auto query = [&](int qv, long long ql) -> long long {
    long long res = 0;
    if(qv < m) return dp[qv][ql];
    int tv = qv;
    typedef pair<long long, long long> P;
    vector<P> temp;
    while(tv >= m){
      temp.emplace_back(V[tv], W[tv]);
      tv = (tv + 1) / 2 - 1;
    }
    int k = temp.size();
    REP(s, 1<<k){
      long long totv = 0, totw = 0;
      REP(i, k){
        if(s>>i&1){
          totv += temp[i].first;
          totw += temp[i].second;
        }
      }
      if(totw > ql) continue;
      res = max(res, totv + dp[tv][ql - totw]);
    }
    return res;
  };
  
  REP(i, q){
    long long ans = query(v[i], l[i]);
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 408988
#include <iostream>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <algorithm>
using namespace std ;
int main(){
    int N ;
    int c = 0 ;
    cin >> N ;
    int nrbke[N];
    for(int i = 0; i < N; i++) cin >> nrbke[i] ;
    for(int i = 0; i < N; i++){
        if(nrbke[i] != i +1){
         c = c + 1 ;
        }
    }
    if(c <= 2 ){
        cout << "YES" << endl ;
    }
    else{
        cout << "NO" << endl ;
    }
    return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int main() {
	int N, M;
	int H[100000];
	int A, B;
	int ans[100000];

	memset(ans, 0x00, sizeof(ans));
	cin >> N >> M;

	for (int ii = 0; ii < N; ii++) {
		cin >> H[ii];
	}
	for (int ii = 0; ii < M; ii++) {
		cin >> A >> B;
		if (H[A - 1] > H[B - 1]) {
			ans[B - 1] = -1;
		}
		else if (H[A - 1] == H[B - 1]) {
			ans[A - 1] = ans[B - 1] = -1;
		}
		else {
			ans[A - 1] = -1;
		}
	}
	int cnt = 0;
	for (int ii = 0; ii < N; ii++) {
		if (ans[ii] == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;

int main(){
    int X,A;
    cin >> X >> A;
    if(X<A){
        cout << 0;
    }else{
        cout << 10;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int x, y ;
    for(int i = 1 ; i<=5 ;i++)
    {
        cin >> x;
        if(x==0)
        {
            y=i;
        }
    }
    cout << y;
    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int M[102];
    int p;
    int K;
    int l[101];
    
    while(cin>>N,N){
        int mp[101][101]={};
        for(int i=1;i<=N;i++){
            cin>>M[i];
            for(int j=0;j<M[i];j++){
                cin>>p;
                mp[i][p]=1;
            }
        }
        cin>>K;
        for(int i=0;i<K;i++) cin>>l[i];
        
        int mx=0;
        int ans[102]={};
        
        for(int i=1;i<=N;i++){
            int sum=0;
            for(int j=0;j<K;j++){
                sum+=mp[i][l[j]];
            }
            ans[i]=sum;
            mx=max(mx,sum);
        }
        
        bool flag=true;
        int a=0;
        
        for(int i=1;i<=N;i++){
            if(mx==ans[i]){
                if(a!=0){
                    flag=false;
                    break;
                }
                a=i;
            }
        }
        
        if(flag && mx==K) cout<<a<<endl;
        else cout<<-1<<endl;
        
    }
    
    return 0;
}



Measured memory_bytes: 3120
#include <stdio.h>

int main(){
  int a,b,c,d,sum=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a>=b) sum+=b;
  else sum+=a;
  if(c>=d) sum+=d;
  else sum+=c;
  printf("%d",sum);
}

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

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

  map<char, ll> cnt;
  for (int i = 0; i < N; ++i) {
    if (S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' ||
        S[i][0] == 'C' || S[i][0] == 'H') {
      cnt[S[i][0]]++;
    }
  }

  ll ans = 0;
  for (auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
    for (auto itr2 = next(itr, 1); itr2 != cnt.end(); ++itr2) {
      for (auto itr3 = next(itr2, 1); itr3 != cnt.end(); ++itr3) {
        ans += itr->second * itr2->second * itr3->second;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {

	ll N;
	cin >> N;

	ll w = 0;
	repn(h, 3500) {
		repn(n, 3500) {
			ll x = N * h*n;
			ll y = 4 * h*n - N * (h + n);

			if (y > 0 && x%y == 0) {
				w = x / y;
				cout << h << " " << n << " " << w;
				break;
			}
		}
		if (w != 0) { break; }
	}
	

	system("PAUSE");
}


Measured memory_bytes: 504
#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() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int X,Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1){
        ans += 300000;
    } else if(X == 2){
        ans += 200000;
    } else if(X == 3){
        ans += 100000;
    }
    if(Y == 1){
        ans += 300000;
    } else if(Y == 2){
        ans += 200000;
    } else if(Y == 3){
        ans += 100000;
    }

    if(X == 1 && Y == 1){
        ans += 400000;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string a;
  	int ans = 0;
    cin >> a;
  	if(a[0] == '1') ans++;
  	if(a[1] == '1') ans++;
  	if(a[2] == '1') ans++;
    cout << ans << endl;
}


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

using namespace std;

int main(){
  string s;
  cin >> s;
  int before = s.size();
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  if(before == s.size()){
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}


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

#define F first
#define S second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define in(x) insert(x)
#define forr(i, a, b) for(int i = a;i <= b;i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define did_you_calis_enough ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define int long long

using namespace std;

const int INF =  4294967295;
const int  N = 2e6 + 667;
const int mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double PI = acos(-1.0);

vector <int> a;

void input(int &n, int &k){
	cin >> k >> n;
	for(int i = 0;i < n;i++){
		int t;
		cin >> t;
		a.pb(t);
	}
}

main() {
	did_you_calis_enough
	int n, k;
	input(n, k);
	sort(all(a));
	int mx = -1;
	for(int i = 1;i < n;i++)
	 	mx = max(mx, abs(a[i] - a[i-1]));
	cout << k - max(mx, (k - a[--n]) + a[0]);
	return 0;
}

//Coded by LoliThief

Measured memory_bytes: 5292
a,b,k = [int(i) for i in input().split(" ")]
 

if a < k:
    
    ra = 0
    k = k-a
    
    if b < k:
        rb = 0
    else:
        rb = b-k
else:
    ra = a-k
    rb = b

print(ra,rb)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<char, char> P;
const ll mod = 1000000007;
ll n, q, lar[30], sma[30];
string s;
bool jud;
vector<P> vec;

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

ll div(ll x)
{
	return pow(x, mod - 2);
}

bool left(ll x)
{
	for (ll i = 0; i < q; i++)
	{
		if (s[x] == vec[i].first)
		{
			if (vec[i].second == 'L')
			{
				x--;
			}
			else
			{
				x++;
			}
		}
		if (x == -1) return true;
		if (x == n) return false;
	}
	return false;
}

bool right(ll x)
{
	for (ll i = 0; i < q; i++)
	{
		if (s[x] == vec[i].first)
		{
			if (vec[i].second == 'L')
			{
				x--;
			}
			else
			{
				x++;
			}
		}
		if (x == n) return true;
		if (x == -1) return false;
	}
	return false;
}

int main(void)
{
	cin >> n >> q >> s;
	for (int i = 0; i < q; i++)
	{
		char t, d;
		cin >> t >> d;
		vec.push_back(P(t, d));
	}
	ll lb = -1, ub = n;
	while (lb + 1 < ub)
	{
		ll mid = (lb + ub) / 2;
		if (left(mid))
		{
			lb = mid;
		}
		else
		{
			ub = mid;
		}
	}
	ll sma = lb;
	lb = -1, ub = n;
	while (lb + 1 < ub)
	{
		ll mid = (lb + ub) / 2;
		if (right(mid))
		{
			ub = mid;
		}
		else
		{
			lb = mid;
		}
	}
	ll lar = ub;
	cout << (lar - sma - 1 > 0 ? lar - sma - 1 : 0) << endl;
	int www;
	cin >> www;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Bomb
{
    int map[8][8];
} BOMB;
 
int x_cnt, y_cnt;
 
Input(BOMB *);
BOMB *explode(BOMB *);  /*Recursion*/
 
int main()
{
    int input_times, input_cnt;
    BOMB Bomb[50];
    int x, y;
     
    scanf("%d", &input_times);
    
    for(input_cnt = 0; input_cnt < input_times; input_cnt++){
        Input(&Bomb[input_cnt]);
		scanf("%d\n%d", &x, &y);
		Bomb[input_cnt].map[x - 1][y - 1] = 2;
        explode(&Bomb[input_cnt]);
    }
     
    /*Output*/
    input_cnt = 0;
    while(input_cnt < input_times)
    {
        printf("Data %d:\n", input_cnt + 1);
        for(y_cnt = 0; y_cnt < 8; y_cnt++)
        {
            for(x_cnt = 0; x_cnt < 8; x_cnt++)
            {
                printf("%d", Bomb[input_cnt].map[x_cnt][y_cnt]);
            }
            printf("\n");
        }
        input_cnt++;
    }
	
    return 0;
}

Input(BOMB *bomb)
{
    /*Read input map*/
    char dump;      /*Get rid of enter*/
    dump = getchar();
    for(y_cnt = 0; y_cnt < 8; y_cnt++)
    {
        dump = getchar();
        for(x_cnt = 0; x_cnt < 8; x_cnt++)
            bomb->map[x_cnt][y_cnt] = getchar() - 48;    /*ASCII table*/
    }
    
}
 
BOMB* explode(BOMB* bomb_map)
{
    int explode_cnt;
    for(y_cnt = 0; y_cnt < 8; y_cnt++)
        for(x_cnt = 0; x_cnt < 8; x_cnt++)
        {
            /*Find exploded bomb and process*/
            if(bomb_map->map[x_cnt][y_cnt] == 2)
            {
                bomb_map->map[x_cnt][y_cnt] = 0;
                /*Left*/
                explode_cnt = 1;
                while((x_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt - explode_cnt][y_cnt]) == 1)
                        (bomb_map->map[x_cnt - explode_cnt][y_cnt]) = 2;
                    explode_cnt++;
                }
                /*Right*/
                explode_cnt = 1;
                while((x_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt + explode_cnt][y_cnt]) == 1)
                        (bomb_map->map[x_cnt + explode_cnt][y_cnt]) = 2;
                    explode_cnt++;
                }
                /*Down*/
                explode_cnt = 1;
                while((y_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt][y_cnt - explode_cnt]) == 1)
                        (bomb_map->map[x_cnt][y_cnt - explode_cnt]) = 2;
                    explode_cnt++;
                }
                /*Up*/
                explode_cnt = 1;
                while((y_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt][y_cnt + explode_cnt]) == 1)
                        (bomb_map->map[x_cnt][y_cnt + explode_cnt]) = 2;
                    explode_cnt++;
                }
                return explode(bomb_map);
            }
        }
    return bomb_map;
}

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

int main(){
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	int ans[N]={};
	for(int i = 0; i < N; ++i){
		if(S[i] == 'A' && S[i+1] == 'C'){
			ans[i+1] = ans[i] + 1;
		}
		else ans[i+1] = ans[i];
	}
	for(int i = 0; i < Q; ++i){
		int l, r;
		cin >> l >> r;
		cout << ans[r-1] - ans[l-1] << endl;
	}
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
}

int main(void) {
  int n,t,s;
  scanf("%d",&n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(int),cmp);
  t = s = a[0];
  int tmp = (t+1) / 2;
  int min = 1e9;
  for (int i = 0; i < n; i++) {
    int k = abs(tmp-a[i]);
    if (min >= k) {
      min = k;
      s = a[i];
    }
  }
  
  printf("%d %d\n", t, s);
  
  return 0;
}

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


int main(){

    long long n; cin >> n;
    vector<long long> a(n + 1);
    a[0] = 0;
    for(long long i = 1; i <= n; i++){
        cin >> a[i];
    }

    for(long long i = 1; i <= n; i++) a[i] += a[i-1];

    sort(a.begin(), a.end());
    //for(long long i = 0; i <= n; i++) cout << a[i] << endl;

    long long now = 1000202020;
    long long count = 1;
    long long ans = 0; 

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

        if(a[i] == now) count++;
        else{
            ans += count * (count - 1) / 2;
            count = 1;
            now = a[i];            
        }
    }
    
    ans += count * (count - 1) /2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define INPUT()              freopen("input.txt", "r", stdin)
    #define OUTPUT()             freopen("output.txt", "w", stdout)
    #define F                    first
    #define S                    second
//Templatefunctions
    template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
    template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
    template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
//datatypes
    typedef long long int ll;
    typedef unsigned long long int ull;
    typedef long double ld;
//constants
    const double INF = 1e+9;
    const double INFLL = 1e+18;
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
           //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
           //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
//helpers
    //#define MOD         1000000007LL
    #define MAX         2000005
    const ll MOD = 1000000000 + 7;
    //int arr[10000005];
    char str[MAX+10];
//Global Variables
    int dp[MAX],n;
    std::map<int,int>::iterator it;
    int ans;
    int main()
    {
//        int t;
//        scanf("%d",&t);
//        int x = 2;
//        while(t--)
//        {
//        }
        ll n , k;
        scanf("%lld%lld",&n,&k);

        for(int i = 0 ;i < n ; i++)
        {
            scanf("%d",&dp[i]);
        }
        vector<int> m,d;
        int cnt = 0, cnt2 = 0;
        for(int i = 0 ; i < n  ; i++)
        {
            for(int j = i+1 ; j < n ; j++)
            {
                if(dp[j] < dp[i])cnt++;
            }
            for(int j = 0 ; j < i ; j++)
            {
                if(dp[j] < dp[i])cnt2++;
            }
        }
        ll ans = 0;
        ll temp = (k * (k+1))/2L;
        temp -= k;
        temp = temp%MOD;
        //printf("temp-%lld\n",temp);
        ans += ((temp+k)*cnt)%MOD;
        ans += (temp*cnt2)%MOD;
        printf("%lld\n",ans%MOD);
    }
//


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int A,B,C;

void func(){

	if(A == 0 && B != 0){
		printf("-1\n");
		return;
	}

	int tmp,work,amari;
	stack<int> S;

	bool OVER_FLG,Found = false;

	if(A != 0){

		for(int base = 2; base <= 16; base++){
			tmp = A;

			OVER_FLG = true;
			while(tmp > 0){
				amari = tmp%base;
				if(amari >= 10){
					OVER_FLG = false;
					break;
				}
				S.push(amari);
				tmp /= base;
			}
			if(!OVER_FLG){
				while(!S.empty())S.pop();
				continue;
			}

			work = 0;
			while(!S.empty()){
				work = 10*work + S.top();
				S.pop();
			}

			if(work == B){
				Found = true;
				break;
			}
		}
		if(!Found){
			printf("-1\n");
			return;
		}
	}

	int min_age = B,next_min_age,tmp_min_age;

	for(int age = A+1; age <= C; age++){

		next_min_age = BIG_NUM;

		for(int base = 2; base <= 16; base++){

			tmp = age;
			OVER_FLG = true;

			while(tmp > 0){
				amari = tmp%base;
				if(amari >= 10){
					OVER_FLG = false;
					break;
				}
				S.push(amari);
				tmp /= base;
			}
			if(!OVER_FLG){
				while(!S.empty())S.pop();
				continue;
			}

			tmp_min_age = 0;

			while(!S.empty()){
				tmp_min_age = 10*tmp_min_age+S.top();
				S.pop();
			}

			if(tmp_min_age < min_age)continue;

			next_min_age = min(next_min_age,tmp_min_age);
		}
		min_age = next_min_age;
		if(min_age == BIG_NUM)break;
	}

	if(min_age == BIG_NUM){
		printf("-1\n");
	}else{
		printf("%d\n",min_age);
	}
}


int main(){

	while(true){
		scanf("%d %d %d",&A,&B,&C);
		if(A == -1 && B == -1 && C == -1)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    string now;
    cin >> now;
    for(int i = 0; i < 3; i++){
        if(day[i] == now){
            cout << day[(i + 1) % 3] << endl;
            return 0;
        }
    }
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> xy(n);
	int a, x, y;
	for (int i = 0; i < n; i++) {
		cin >> a;
		for (int j = 0; j < a; j++) {
			cin >> x >> y;
			x--;
			xy[i].emplace_back(make_pair(x, y));
		}
	}
	
	int ans = 0;
	bool f;
	int t;
	for (int i = 0; i < (1 << n); i++) {
		vector<int> s(n);
		f = true;
		for (int j = 0; j < n; j++) {
			s[j] = ((i >> j) & 1) == 1 ? 1 : 0;
		}

		for (int j = 0; j < n; j++) {
			if (s[j]) {
				for (int k = 0; k < xy[j].size(); k++) {
					if (xy[j][k].second != s[xy[j][k].first]) {
						f = false;
						break;
					}
				}
			}
			if (!f) {
				break;
			}
		}

		if (f) {
			t = 0;
			for (int j = 0; j < n; j++) {
				t += ((i >> j) & 1) == 1 ? 1 : 0;
			}
			ans = max(ans, t);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
dp = [0]

for i in range(1, N + 1):
	cur = min(1 + dp[i - 1], 10 ** 10)
	
	j = 1
	while i - 6 ** j >= 0:
		cur = min(1 + dp[i - 6 ** j], cur)
		j += 1
	
	j = 1
	while i - 9 ** j >= 0:
		cur = min(1 + dp[i - 9 ** j], cur)
		j += 1
		
	dp.append(cur)
	
print(dp[-1])

Measured memory_bytes: 45276
N=int(input())
A=list(map(int,input().split()))
pbox=[]
nbox=[]
if 0 in A:
  count=0
  for i in A:
    count += abs(i)
  print(count)
else:
  for i in A:
    if i > 0:
      pbox.append(i)
    else:
      nbox.append(i)
  if len(nbox)%2==0:
    count=0
    for i in A:
      count += abs(i)
    print(count)
  else:
    box=[]
    for i in A:
      box.append(abs(i))
    mi=min(box)
    count=0
    for i in A:
      count += abs(i)
    print(count-2*mi)

Measured memory_bytes: 14496
#include <bits/stdc++.h>
using namespace std;
#define LL long long

const int S = 205;

LL n;
int bit[60], m;
int s[S], tot;

int main() {
	cin >> n;
	for (m = -1; n > 0; n >>= 1)
		bit[++m] = n & 1;
	
	for (int i = 1; i <= m; i++) s[++tot] = i;
	for (int i = 1; i <= m; i++) s[++tot] = i;
	int Max = (s[++tot] = m+1, s[++tot] = m+1);
	
	for (int i = m-1; i >= 0; i--) if (bit[i]) {
		for (int j = ++tot; j >= i+2; j--)
			s[j] = s[j-1];
		s[i+1] = ++Max;
		s[++tot] = Max;
	}
	
	printf("%d\n", tot);
	for (int i = 1; i <= tot; i++)
		printf("%d ", s[i]);
	puts("");
	
	return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  for(int i = 0; i < S.size(); i++) {
    if(S.at(i) + N > 'Z') {
      S.at(i) = S.at(i) + N - 26;
    }
    else S.at(i) += N;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;

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

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> dp(n,INF);
  vector<ll> h(n,0);
  rep(i,n) cin >> h[i];
  dp[0] = 0;
  for(int i=0;i<n;i++){
      for(int j=1;j <= k;j++){
          if(i+j >= n) break;
          chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]));
      }
  }
  cout << dp[n-1] << endl;
}

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

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

    deque<int> deq;
    for (int i = 0; i < N; i++) {
        int pos = int(lower_bound(deq.begin(), deq.end(), A[i]) - deq.begin());
        if (pos == 0) {
            deq.push_front(A[i]);
        } else {
            deq[pos - 1] = A[i];
        }
    }

    cout << deq.size() << endl;
    return 0;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
int A[200000];

unordered_map<int,int> st;

signed main(){
    cin >> N;
    rep(i, N) cin >> A[i];

    ll ans = 0;
    rep(i, N){
        if(st.count(i-A[i])) ans += st[i-A[i]];
        if(st.count(i+A[i]) == 0) st[i+A[i]] = 0;
        st[i+A[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12072
#include"bits/stdc++.h"
using namespace std;
int n;
int c[10];
int f;
int ansa,ansi;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(t>=3200)f++;
		else c[t/400]++;
	}
	for(int i=0;i<8;i++){
		if(c[i]){
			ansi++;
			ansa++;
		}
	}
	if(ansi==0)ansi++;
	ansa+=f;
	cout<<ansi<<" "<<ansa<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
    int n;
    int a[10000];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    int count = 0;
    for(int i=0;i<n;i++){
        while(a[i]%2==0){
                a[i] /= 2;
                count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int uchiha=1e5+6;
char arr[4],arr1[4],arr2[4];
int main(){
for(int i=0;i<3;i++)
        cin>>arr[i];
    for(int j=0;j<3;j++)
        cin>>arr1[j];
for(int l=0;l<3;l++)
    cin>>arr2[l];
cout<<arr[0]<<arr1[1]<<arr2[2];
}

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

int searcher(string s)
{
    int r = 0;
    for (int i = 0; i < s.length() - 1; i++)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            r++;
        }
    }
    return r;
}

int main()
{
    int result = 0;
    int N;
    cin >> N;
    vector<string> strs(10000, "");
    for (int i = 0; i < N; i++)
    {
        cin >> strs[i];
        result += searcher(strs[i]);
    }

    int end_a = 0, start_b = 0, both = 0;
    for (int i = 0; i < N; i++)
    {
        if (strs[i].front() == 'B')
        {
            if (strs[i].back() == 'A')
            {
                both++;
            }
            else
            {
                start_b++;
            }
        }
        else if (strs[i].back() == 'A')
        {
            end_a++;
        }
    }
    if (both > 0)
    {
        result += both - 1;
        if (end_a != 0)
        {
            end_a--;
            result++;
        }
        if (start_b != 0)
        {
            start_b--;
            result++;
        }
    }
    result += min(end_a, start_b);

    cout << result << endl;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  int K1{(Y % 10000 % 5000) / 1000};
  Y -= K1 * 1000;
  for (int i{}; i <= Y / 10000; ++i) {
    for (int j{}; j <= (Y - i * 10000) / 5000; ++j) {
      int k = (Y - i * 10000 - j * 5000) / 1000;
      if (i + j + k + K1 == N) {
        cout << i << ' ' << j << ' ' << k + K1 << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())

if len(set(s)) == 1:
    print((len(s)*k)//2)
else:
    t = [1]
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
    a = 0
    for i in t:
        a += (i//2)*k
    if s[0] == s[-1]:
        if t[0] % 2 == t[-1] % 2 == 1:
            a += k-1
    print(a)

Measured memory_bytes: 3064
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    elif m==-1 or f==-1:
        print("F")
    else:
        s=m+f
        if s>=80:
            print("A")
        if 65<=s<80:
            print("B")
        if 50<=s<65:
            print("C")
        if 30<=s<50:
            if r>=50:
                print("C")
            else:
                print("D")
        if s<30:
            print("F")
            


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (A == B) {
    cout << C << endl;
  }
  else if (B == C) {
    cout << A << endl;
  }
  else {
    cout << B <<  endl;
  }
}

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

using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int x = 0;
    int pm = 1;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        x += pm*A[i];
        pm *= -1;
    }
    for(int i = 0; i < N; ++i){
        cout << x << " ";
        x = 2*A[i] - x;
    }
    
    return 0;
}

Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            long iA = long.Parse(sS[0]);
            long iB = long.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long iX = Lcm(iA, iB);

            // 出力
            System.Console.WriteLine("{0}", iX.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 最小公倍数取得
        private static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // 最大公約数取得
        private static long Gcd(long a, long b)
        {
            if (a < b) { return Gcd(b, a); }
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#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(v) v.begin(), v.end()

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (S.size()%2) {
        cout << "No" << endl;
        return 0;
    }
    REP(i, S.size()/2) {
        if (S[i] != S[S.size()/2+i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    int maxv = max(X, x[N - 1]);
    int minv = min(Y, y[0]);
    if (maxv < minv) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    ll a, b;
    cin >> a >> b;

    if(a + b == 15) { printf("+\n"); }
    else if(a * b == 15) { printf("*\n"); }
    else { printf("x\n"); }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, A, B;
  cin >> N >> A >> B;
  cout << min(A * N, B) << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()
if S == "SUN":
    num = 0
if S == "MON":
    num = 1
if S == "TUE":
    num = 2
if S == "WED":
    num = 3
if S == "THU":
    num = 4
if S == "FRI":
    num = 5
if S == "SAT":
    num = 6
print("{}".format(7-num))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;	cin >> n;
  vector<int>	d(n);
  for(int i=0;i<n;i++)	cin >> d[i];
  
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j)	continue;
      ans+=d[i]*d[j];
    }
  }
  cout << ans/2;
}

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

int main()
{
  i64 n;
  cin >> n;
  i64 sum = 0;
  for (i64 i = 1;; i++)
  {
    sum += i;
    if (n <= sum)
    {
      for (i64 j = 1; j <= i; j++)
        if (sum - n != j)
          cout << j << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
typedef unsigned long long ull;

int main(){
  ull n,s=0,minn=0;
  cin >> n;
  int a[nmax]={},b[nmax]={};
  for(int i=1;i<=n+1;i++) cin >> a[i];
  for(int i=1;i<=n;i++) cin >> b[i];

  for(int i=1;i<=n;i++) {
    minn=min(a[i],b[i]);
    a[i]-=minn;
    b[i]-=minn;
    s+=minn;
    minn=min(a[i+1],b[i]);
    a[i+1]-=minn;
    b[i]-=minn;
    s+=minn;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 1024
def tpbc_2018_c():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    a.sort()
    low = a[:len(a) // 2]
    high = a[len(a) // 2:]
    if len(a) % 2 == 0:
        return 2 * (sum(high) - sum(low)) + max(low) - min(high)
    else:
        low2 = a[:len(a) // 2 + 1]
        high2 = a[len(a) // 2 + 1:]
        return max(2 * (sum(high) - sum(low)) - high[0]-high[1],2 * (sum(high2) - sum(low2))+low2[-2]+low2[-1])


print(tpbc_2018_c())

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

int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for(int i=0;i<H;i++)  cin >> S.at(i);

  int ans=1e9;
  for(int bit=0;bit<(1<<(H-1));bit++){
    bool pre=true;
    for(int i=0;i<W;i++){
      vector<int> sum(H,0);
      int now=0;
      for(int j=0;j<H;j++){
        if(S.at(j).at(i)=='1')  sum.at(now)++;
        if(bit&(1<<j))  now++;
      }
      for(int j=0;j<H;j++){
        if(sum.at(j)>K){
          pre=false;
          break;
        }
      }
      if(!pre)  break;
    }
    if(!pre)  continue;

    //cout << bit << endl;
    int tmp=0;
    vector<int> sum(H,0);
    bool flag=true;
    for(int i=0;i<W;i++){
      if(!flag){
        for(int j=0;j<H;j++)  sum.at(j)=0;
        flag=true;
      }
      int now=0;
      for(int j=0;j<H;j++){
        if(S.at(j).at(i)=='1')  sum.at(now)++;
        if(bit&(1<<j))  now++;
      }
      for(int j=0;j<H;j++){
        if(sum.at(j)>K){
          tmp++;
          i--;
          flag=false;
          break;
        }
      }
    }
    for(int i=0;i<H-1;i++)  if(bit&(1<<i))  tmp++;
    ans=min(ans,tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

int main() {
  int n;
  cin >> n;
  long long a[n],b[n];
  long long count = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for(int i = n-1; i >= 0; i--) {
    a[i] += count;
    if(a[i] % b[i] != 0) {
      count += b[i] - (a[i] % b[i]);
    }
  }
  cout << count << endl;
  return 0;
}

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

int main() {
int N;
cin >> N;
vector<long long> v(3*N);
for (int i = 0; i < 3*N; i++) {
cin >> v[i];
}
sort(v.rbegin(), v.rend());
unsigned long long ans = 0;
for (int i = 0; i < N; i++) {
ans += v[1+2*i];
}
cout << ans << endl;
return 0;
}

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

using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}

const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;

int cnt(int n, int k) {
	int _2k = pow(2ll, k), _2k_ = pow(2ll, k - 1);
	int res = ((n + 1) / _2k) * _2k_;

	res += max((n + 1) % _2k, _2k_) - _2k_;

	return res;
}

int get_ans(int n) {
	if (n == 0) {
		return 0;
	}

	int ans = 0;
	for (int i = 0; i <= 40; ++i) {
		int cur = cnt(n, i + 1);
		if (cur % 2 == 1) {
			ans += pow(2, i);
		}
	}

	return ans;	
}

void solve() {
	int a, b; 
	cin >> a >> b;

	int ans1 = get_ans(b), ans2 = get_ans(a - 1);

	cout << (ans1 ^ ans2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

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

struct edge {
    ll to;
    ll cost;
};

void dfs(ll s, vector<bool> & flg, vector<vector<edge>> &g, vector<ll> &cost) {
    flg[s] = true;
    for (auto u: g[s]) {
        ll to = u.to;
        ll len = u.cost;
        if (cost[to] == 1e18) {
            cost[to] = cost[s] + len;
        }
        if (cost[to] != cost[s] + len) {
            cout << "No" << endl;
            exit(0);
        }
        if (!flg[to]) {
            dfs(to, flg, g, cost);
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    vector<ll> cost(n, 1e18);
    vector<bool> flg(n, false);
    rep(i, m) {
        ll l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        g[l].push_back((edge){r, -d});
        g[r].push_back((edge){l, d});
    }
    rep(i, n) {
        if (!flg[i]) {
            cost[i] = 0LL;
            dfs(i, flg, g, cost);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 18304
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[1000000000]*n
dp[0]=0
for i in range (1,n):
    for j in range(max(i-k,0),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[n-1])

Measured memory_bytes: 52448
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
   string s;
   cin >> s;
   int n=s.length();
   int c=0;
   for(int i=0; i<n/2; i++){
       if(s[i]!=s[n-i-1])c++;
   }
   cout << c;
  
   return 0;
}



Measured memory_bytes: 256
merge [] [] = []
merge (x:xs) (y:ys) = (x:y:(merge xs ys))

riffle c =
  let n = (length c) `div` 2
      h = take n c
      t = drop n c
  in
    merge h t

cut k c =
  let h = take k c
      t = drop k c
  in
    t ++ h

ans' c [] = c
ans' c (k:ks) =
  let c' = if k == 0 then (riffle c) else (cut k c)
  in
    ans' c' ks

ans (n:m:x) =
  let c = [1..(2*n)]
      a = ans' c $ take m x
  in
    a

main = do
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = ans i
  mapM_ print o



Measured memory_bytes: 5512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  map<int,int> d;
  rep(i,n){
    int x;
    cin>>x;
    d[x]++;
  }
  int m;
  cin>>m;
  rep(i,m){
    int x;
    cin>>x;
    if(d[x]<=0){
      cout<<"NO"<<endl;
      return 0;
    }
    d[x]--;
  }


  cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	int A[n + 1];
	for(int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	sort(A, A + n);
	reverse(A, A + n);
	int sum = 0;
	for(int i = 0; i < k; i++)
		sum += A[i];
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256