akhauriyash/Code-Regression huggingface dataset:
INFTY = 10**4
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

d = [[INFTY for _ in range(10)] for _ in range(10)]
for i in range(10):
    for j in range(10):
        d[i][j] = C[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            d[i][j] = min(d[i][j],d[i][k]+d[k][j])

cnt = 0
for i in range(H):
    for j in range(W):
        if A[i][j]>-1:
            cnt += d[A[i][j]][1]
print(cnt)

Measured memory_bytes: 40284
#include<stdio.h>

int main(void){
        int ans = -1, i=-1;
        char s[100010], prev = '-';
        scanf("%s", s);
        while(s[++i]){
                if(s[i]!=prev) ans++;
                prev = s[i];
        }
        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::string s;
  cin>>s;
  int result=1;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      result++;
    }
  }
  cout<<result<<endl;



  return 0;
}


Measured memory_bytes: 1144
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------
string s, as, bs;
vector<int> an(8);
vector<int> bn(8);
int cnt, n, a, b;
void solve(){
    cout << abs(a - b) << endl;
}
int main(){
    dbg = true;
    cin >> n;
    as = "", bs = "";
    for(int i = 0; i < n; i++){
        cin >> an.at(i);
        as += to_string(an.at(i));
    }
    for(int i = 0; i < n; i++){
        cin >> bn.at(i);
        bs += to_string(bn.at(i));
    }
    cnt = 0;
    s = "";
    for(int i = 0; i < n; i++){
        s += to_string(i + 1);
    }
    do{
        cnt++;
        if(s == as){
            a = cnt;
        }
        if(s == bs){
            b = cnt;
        }
} while (std::next_permutation(s.begin(), s.end()));
    solve();
    
    return 0;
}



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

int dir[2005];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int a = j - i;
      int b = abs(x - i) + 1 + abs(j - y);
      int c = abs(y - i) + 1 + abs(j - x);
      int ans = min(min(a, b), c);
      dir[ans]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << dir[i] << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
long long m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()
//nCk(comuseを使え)
long long combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//pCk(comuseを使え)
long long perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a,long long b){
  long long n;
  n=a/__gcd(a,b)*b;
  return n;
}

//auto A = div(n)
vector<long long> div(long long n){
  vector<long long> ret;
  for(long long i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a,long long n,long long mod){
  long long ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}

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



void Solve(){
  int A, B;
  cin >> A >> B;
  if(A == 1){
    if(B == 2){
      cout << 3 <<endl;
    }
    else{
      cout << 2 <<endl;
    }
  }
  else if(A == 2){
    if(B == 1){
      cout << 3 <<endl;
    }
    else{
      cout << 1 <<endl;
    }
  }
  else{
    if(B == 1){
      cout << 2 <<endl;
    }
    else{
      cout << 1 <<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll


signed main(void){
    int N;
    int a;
    cin >> N;
    int Ans=0;
    REP(i,N){
        cin >> a;
        while(1){
            if(a%2==0){
                a/=2;
                Ans++;
            }else{
                break;
            }
        }
    }
    cout << Ans << endl;
  return 0;
}


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

using namespace std;
char mas[102][102];
int main(){
  int h,w;
  cin >> h >> w;
  for(int i=0;i!=h;i++){
    for(int j=0;j!=w;j++){
      cin >> mas[i][j];
    }
  }
  for(int i=0;i!=h;i++){
    int tmp=0;
    int tmp1=0;
    for(int j=0;j!=w;j++){
      tmp1++;
      if(mas[i][j]=='.'){
        tmp++;
      }
    }
    if(tmp1==tmp){
      for(int j=0;j!=w;j++){
        mas[i][j]='h';
      }
    }
  }
  for(int j=0;j!=w;j++){
    int tmp=0;
    int tmp1=0;
    for(int i=0;i!=h;i++){
      tmp1++;
      if(mas[i][j]=='.'||mas[i][j]=='h'){
        tmp++;
      }
    }
    if(tmp1==tmp){
      for(int i=0;i!=h;i++){
        mas[i][j]='h';
      }
    }
  }
  bool ansok;
  for(int i=0;i!=h;i++){
    for(int j=0;j!=w;j++){
      if(mas[i][j]!='h'){
        ansok=true;
        cout << mas[i][j];
      }
    }
    if(ansok==true){
      cout << endl;
      ansok=false;
    }
  }
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/practice2/tasks/practice2_c
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int T;
    cin >> T;
    while (T--) {
        int n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << "\n";
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3680
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <deque>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pii pair<pi,int>
#define sqr(x) ((x)*(x))
#define FOR for(int i=0;i<n;i++)for(int j=0;j<m;j++)
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int n,m;
string asd[110];
bool f[110],c[110];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>asd[i];
    for(int i=0;i<n;i++){
        bool flag=true;
        for(int j=0;j<m;j++)if(asd[i][j]=='#'){flag=false;break;}
        f[i]=flag;}
    for(int j=0;j<m;j++){
        bool flag=true;
        for(int i=0;i<n;i++)if(asd[i][j]=='#'){flag=false;break;}
        c[j]=flag;}
    for(int i=0;i<n;i++){
        if(f[i])continue;
        for(int j=0;j<m;j++)if(!c[j])cout<<asd[i][j];
        cout<<'\n';}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#ifdef XLor
  #define dbg(args...) do {cout << #args << " -> "; err(args);} while (0)
#else
  #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 200000 + 5;

int n, m, q;
PII st;
char s[maxn], t[maxn];
int dp[maxn][4];

int main() {
    scanf("%d%d%d%d%d%s%s", &n, &m, &q, &st.first, &st.second, s + 1, t + 1);
    int x = st.first, y = st.second, flag = 0;
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'L') y--;
        if (y == 0) flag = 1;
        if (t[i] == 'R' && y != m) y++;
    }
    y = st.second;
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'R') y++;
        if (y == m + 1) flag = 1;
        if (t[i] == 'L' && y != 1) y--;
    }
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'U') x--;
        if (x == 0) flag = 1;
        if (t[i] == 'D' && x != n) x++;
    }
    x = st.first;
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'D') x++;
        if (x == n + 1) flag = 1;
        if (t[i] == 'U' && x != 1) x--;
    }
    if (flag) puts("NO");
    else puts("YES");
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//#define int long long
string A;
long long int ap[26] = {};
 
signed main() {
    cin >> A;
    for (long long int i = 0; i < A.length(); i++) {
        ap[A[i] - 'a']++;
    }
    long long ans = 0;
    for (long long i = 0; i < 26; i++) {
        ans += ap[i] * (A.length() - ap[i]);
    }
    cout << ans / 2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

using namespace std;

void solve()
{
   int n,w;
   cin>>n>>w;
   vector<vector<int> > v(n, vector<int>(2));
   int dp[2][w+1];
   memset(dp,-1,sizeof dp);

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

   dp[0][0]=0;


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

    for(int j=0;j<=w;j++)
    {
        dp[1][j] = -1;
        dp[1][j] = max(dp[1][j],dp[0][j]);

        if(j-v[i-1][0]>=0)
          dp[1][j] = max(dp[1][j],dp[0][j-v[i-1][0]]+v[i-1][1]);  
    }

    for(int j=0;j<=w;j++)
      dp[0][j] = dp[1][j];

   }

   int ans = INT_MIN;
   for(int i=0;i<=w;i++)
    ans=max(ans,dp[1][i]);

cout<<ans<<endl;



}
signed main()

{
    FAST_IO;
    int t = 1;

    // cin>>t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}


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

void Main()
{
    int n, x, l, d=0;
    int count = 1;
    cin >> n >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> l;
        d += l;
        if(d <= x) count++;
    }
    cout << count << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

#define rep(i, n) for(int i=0; i<n; i++)
typedef string::const_iterator State;
class ParseError{};

template<typename T> class Calculation
{
public:
  static void consume(State& begin, char expected) {
    if (*begin == expected) {
      begin++;
    } else {
      cerr << "Expected '" << expected << "' but got '" << *begin << "'"
           << endl;
      cerr << "Rest string is '";
      while (*begin) {
        cerr << *begin++;
      }
      cerr << "'" << endl;
      throw ParseError();
    }
  }

  static T expression(State& begin){
    T ret = term(begin);
    while(true){
      if(*begin == '+'){
        begin++;
        ret += term(begin);
      }
      else if(*begin == '-'){
        begin++;
        ret -= term(begin);
      }
      else break;
    }
    return ret;
  }

  static T term(State& begin){
    T ret = factor(begin);
    while(true){
      if(*begin == '*'){
        begin++;
        ret *= factor(begin);
      }
      else if(*begin == '/'){
        begin++;
        ret /= factor(begin);
      }
      else break;
    }
    return ret;
  }

  static T factor(State& begin){
    if(*begin == '('){
      consume(begin, '(');
      T ret= expression(begin);
      consume(begin, ')');
      return ret;
    }
    else{
      return number(begin);
    }
  }

  static T number(State& begin){
    T ret = 0;
    for(; isdigit(*begin); begin++){
      ret *= 10;
      ret += *begin - '0';
    }
    return ret;
  }
};

int N;
string s;

int main()
{
  cin >> N;
  cin.ignore();

  rep(i, N){
    getline(cin, s);
    State begin = s.begin();
    int res = Calculation<int>::expression(begin);
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
void solve(ll a[],ll n,ll k){
    vector<ll>dp(n+1,100000000005);
    ll c=1;
    dp[0]=0;
    for(ll i=1;i<n;i++){
       for(ll j=i-1;c<=k && j>=0;j--){
        dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        c++;
       }
       c=1;
    }
   // for(ll i=0;i<n;i++)
     //   cout<<dp[i]<<" ";
    cout<<dp[n-1];
}


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

    }
     solve(a,n,k);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define MAX (int)1e7+5
#define ll long long

using namespace std;


long long spf[MAX+5];
void sieve(){
    for(int i=2;i<=MAX;i+=2) spf[i]=2;
    for(int i=1;i<=MAX;i+=2) spf[i]=i;
    for(ll i=3;i*i<MAX;i+=2){
        if(spf[i]==i){
            for(ll j=i*i;j<MAX;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}
int main()
{
    sieve();
    ll ans=0,n;
    cin>>n;

    for(ll i=1;i<=n;i++){
        //printf("%lld ",spf[i]);
        ll num=i,cnt=0,x=spf[i],div=1;
        while(num!=1){
            num/=spf[x];
            cnt++;
            if(spf[x]!=spf[num]) div*=(cnt+1),cnt=0;
            x=spf[num];
        }
        ans+=i*div;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 81752
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

struct Card{
	char suit;
	char value;
};

// バブルソート
// in/out 配列
// in 配列サイズ
void bubbleSort(Card* intArray, int arraySize){
	int flag = 1;
	Card tmp;
	for (int i=0; flag; ++i){
		flag = 0;
		for (int j=0; j<arraySize-i-1; ++j){
			if (intArray[j].value > intArray[j+1].value){ // > だと降順、< だと昇順
				tmp = intArray[j+1];
				intArray[j+1] = intArray[j];
				intArray[j] = tmp;
				flag = 1;
			}
		}
	}
}



// 選択ソート
// in/out 配列
// in 配列サイズ
int selectionSort(Card *a, int n){
	Card tmp;
	int minj;
	int count = 0;
	for(int i=0; i< n; ++i){
		minj = i;
		for(int j=i; j<n; ++j){
			if (a[j].value < a[minj].value){
				minj = j;
			}
		}
		if (i != minj){
			tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			++count;
		}
	}
	return count;
}

int main(){
	int n;
	cin >> n;
	Card c1[36] = {0};
	Card c2[36] = {0};
	for(int i =0; i<n; ++i){
		cin >> c1[i].suit >> c1[i].value;
	}

	for(int i=0; i<n; ++i){
		c2[i] = c1[i];
	}
	bubbleSort(c1, n);
	selectionSort(c2, n);

	for(int i=0; i<n-1; ++i){
		cout << c1[i].suit << c1[i].value << " ";
	}
	cout << c1[n-1].suit << c1[n-1].value << endl;
	cout << "Stable" << endl;

	for(int i=0; i<n-1; ++i){
		cout << c2[i].suit << c2[i].value << " ";
	}
	cout << c2[n-1].suit << c2[n-1].value << endl;

	if(memcmp(c1, c2, n*2) == 0){
		cout << "Stable" << endl;
	}
	else{
		cout << "Not stable" << endl;
	}

	return 0;
}



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

int main() 
{
	int n;
	cin >> n;
	int a[n];
	vector<pair<int,int> > v;
	for(int i =0; i <n;i++){
		int x;
		cin >> x;
		v.push_back(make_pair(x,i));
	}
	sort(v.begin(),v.end());
	for(int i =0; i <n;i++){
		cout << v[i].second+1<<" ";
	}
}

Measured memory_bytes: 1780
#include<stdio.h>
#include<string.h>
int main()
{
	char text[101];
	scanf("%s",text);
	if(text[0]=='S'){
		printf("Cloudy");
	}else if(text[0]=='C'){
		printf("Rainy");
	}else if(text[0]=='R'){
		printf("Sunny");
	}
	return 0;
}

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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> cnt(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == 0 && j == 0) {
        if (s[0][0] == '#') cnt[0][0] = 1;
      } else if (i == 0) {
        cnt[i][j] = cnt[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#');
      } else if (j == 0) {
        cnt[i][j] = cnt[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#');
      } else {
        cnt[i][j] = cnt[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#');
        chmin(cnt[i][j],
              cnt[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'));
      }
    }
  }
  cout << cnt[h - 1][w - 1] << '\n';
  return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b/(__gcd(a,b));
    return 0;
}



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

using namespace std;

void solve()
{
    double a, b;
    cin>>a>>b;
    cout<<(long long)floor(a*b);
}
int main()
{
    long long test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3748
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	rep(i,n+1)rep(j,n+1){
		int k=m/1000-i*10-j*5;
		if(k>=0&&i+j+k==n){
			cout<<i<<" "<<j<<" "<<k<<endl;
			return 0;
		}
	}
	cout<<"-1 -1 -1"<<endl;
}





Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    map<int, int> m;
    REP(i, 3) {
        int a, b;
        cin >> a >> b;
        m[a]++;
        m[b]++;
    }

    bool yes = true;
    FOR(i, 1, 5) {
        if (m[i] == 3) yes = false;
    }

    YESNO(yes, "YES", "NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N, M, k = 0;
	bool flag = true,f=true;
	cin >> N >> M;
	vector<int>a(M);
	vector<long long int>ans(N+1,0);
	ans[0] = 1;
	for (int i = 0; i < M; i++) {
		cin >> a[i];

		ans[a[i]] = -1;
	}
	for (int i = 0; i < N+1; i++)
	{
		if (ans[i] != -1) {
			if (i > 0) {
				if(ans[i - 1]!=-1)ans[i] += ans[i - 1];
			}
			if (i > 1) {
				if(ans[i - 2] != -1)ans[i] += ans[i - 2];
			}
			ans[i] %= 1000000007;
			k = 0;
		}
		else k++;
		if (k == 2)flag = false;
	}
	if (flag)cout << ans[N];
	else cout << 0;
}

Measured memory_bytes: 1408
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	c = rll()[0]
	if 0 <= ord(c)-97 <= 25:
		print("a")
	else:
		print("A")
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 65360
#include <iostream>
#include <vector>

int main(){
  int n;
  std::cin >> n;
  std::vector<int> h(n);
  for(int i = 0; i < n; ++i)
    std::cin >> h[i];

  int ans = 0;
  int maxH = 0;

  for(int i = 0; i < n; ++i){
    if(h[i] >= maxH){
      ++ans;
      maxH = h[i];
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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() {
  ll x;
  cin >> x;
  ll ans = 0, a = 100;
  while (a < x) {
    a += a/100;
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000000000

int main(){
    int n;cin>>n;
    vector<int> a(n+1),ans(n+1);
    for(int i=1;i<=n;i++){cin>>a[i];ans[a[i]]=i;}

    for(int i=1;i<=n;i++){cout<<ans[i]<<" ";}
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1664
#import numpy as np

N = int(input())

l = [ [ 0 for i in range(9) ] for j in range(9) ]
#l = np.zeros((9,9), dtype=np.int)
# l[i][j] : i = 頭文字　j = 最後の文字

for k in range(N):
    x = str(k+1)
    i = int(x[0])
    j = int(x[-1])

    #print(i,j)

    if i == 0 or j == 0:
        continue
    l[i-1][j-1] += 1

ans = 0
for i in range(9):
    for j in range(i,9):
        if i == j:
            n = l[i][j]
            ans += n**2
        else:
            ans += l[i][j] * l[j][i] * 2
            

print(ans)









Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main () {
    string S;
    cin >> S;
    int win = 0;
    int lose = 0;
    for(int i = 0; i < S.size(); i++){
        if(S.at(i) == 'o'){
            win++;
        }
        else{
            lose++;
        }
    }
    if(win >= 7 || lose < 8){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


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

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;

int main(){
    string s = "abcdefghijklmnopqrstuvwxyz";
    char c; cin >> c; cout << s[c - 'a' + 1] << endl;
}

Measured memory_bytes: 256
//假设都是合法的输入

#include<stdio.h>
#include<iostream>
#include<stack>
#include<sstream>

using namespace std;

int main() {
    string str;
    stack<int> st;
    while(cin>>str){
        if(str[0]=='+'){
            int num1=st.top();
            st.pop();
            int num2=st.top();
            st.pop();
            st.push(num2+num1);
        }
        else if(str[0]=='-'){
            int num1=st.top();
            st.pop();
            int num2=st.top();
            st.pop();
            st.push(num2-num1);
        }
        else if(str[0]=='*'){
            int num1=st.top();
            st.pop();
            int num2=st.top();
            st.pop();
            st.push(num2*num1);
        }
        else if(str[0]=='/'){
            int num1=st.top();
            st.pop();
            int num2=st.top();
            st.pop();
            st.push(num2/num1);
        }
        else{
            int num;
            stringstream ss;
            ss<<str;
            ss>>num;
            st.push(num);
        }
    }
    printf("%d\n", st.top());
    return 0;
}


Measured memory_bytes: 3336
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define ll long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define mod(n) (n) % 1000000007
#define sp << " "
#define precision(n) cout << fixed << setprecision(n);
#define startTime time_t start, end;time(&start);
#define endTime time(&end);double tt = double(end-start);cout<<"Time taken : "<<fixed<<tt<<setprecision(5);cout <<" sec"<< endl;
 
using namespace std;

bool isPossible(ll a, ll b, ll c) {
	return (a + b > c) && (b + c > a) && (c + a > b); 
}
 
int main() { 
    IOS;
    ll n, ans = 0;
    cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
    	for (int j = i + 1; j < n; j++) {
    		for (int k = j + 1; k < n; k++) {
    			if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k] && isPossible(a[i], a[j], a[k])) ans++;
    		}
    	}
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>
#include <ctype.h> //toupper case

typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll W = 1000000007;


using namespace std;
void omajinai() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
}

class Main{
public:
    int N,M;
    vector<vector<int> > A;
    Main(){
        cin>>N>>M;
        A = vector<vector<int> >(N, vector<int>(M));
        REP(i,N)REP(j,M){ cin>>A[i][j]; A[i][j]--;}
        
    }
    
    pair<int,int> getval(vector<int> anslist){
        vector<int> ans(M,0);
        REP(i,N){
            REP(j,M){
                if(find(anslist.begin(),anslist.end(),A[i][j])==anslist.end()){
                    ans[A[i][j]]++; break;
                }
            }
        }
        pair<int,int> ret;
        ret.second = distance(ans.begin(),max_element(ans.begin(),ans.end()));
        ret.first = *max_element(ans.begin(),ans.end());
        return ret;
    }
    
    void run(){
        int ans = N;
        vector<int> anslist;
        REP(i,M){
            pair<int,int> p = getval(anslist);
            ans = min(ans,p.first);
            anslist.push_back(p.second);
        }
        cout<<ans<<endl;
    }
};

#ifndef gtest
int main(){
    omajinai();
    Main().run();
    return 0;
}
#endif

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
 
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
 
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
struct Edge{
  int to, cost;
 
  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }
 
};
using Graph = vector<vector<Edge>>;
void add_edge(Graph& graph, int u, int v, int cost = 0){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}
 
int lowlink_br(int u, int p, int& num, const Graph& G, VI& ord, VI& low){
  int res = 0;
  ord[u] = low[u] = num++;
  
  for(auto& e: G[u]){
	int to = e.to;
	if(to == p) continue;
	if(ord[to] < 0){
	  res += lowlink_br(to, u, num, G, ord, low);
	  low[u] = min(low[u], low[to]);
	  if(ord[u] < low[to])
		++res;
	}
	else{
	  low[u] = min(low[u], ord[to]);
	}
  }
 
  return res;
}
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  int N, M;
  cin >> N >> M;
 
  Graph G(N);
  REP(i,M){
	int u, v;
	cin >> u >> v;
	--u;
	--v;
	add_edge(G, u, v);
  }
 
  int num = 0;
  VI ord(N,-1), low(N);
  cout << lowlink_br(0, -1, num, G, ord, low) << endl;
  
  return 0;
}

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

int main(){
    string o, e;
    cin >> o >> e;

    for(int i = 0; i < e.length(); i++){
        cout << o[i] << e[i];
    }

    if(o.length() > e.length()) cout << o[o.length()-1];
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#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 A, B, C;
    cin >> A >> B >> C;
    if (C >= A && C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

int main(){
  int N;
  cin >> N;
  if (N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  int d[N];
  REP(i,N) {
    cin >> d[i];
  }
  sort(d,d+N);
  cout << d[N/2] - d[N/2 - 1] << endl;
}

Measured memory_bytes: 640
/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include<climits>
#include<random>
#include<cassert>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<utility>
#include<cstdint>
#include<queue>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdio>
//4611686018427387903
using namespace std;
//magic lines for ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
/*
	fuctions :

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).


*/
const int64_t mod = 998244353.;
void solve(int cnum){
    int n,x,t;
    cin >> n >> x >>t;
    cout << (t * ((n+x-1)/x)) << endl;
}
int main(){

	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);
	//initprime();
	cout << setprecision(12);
	cout << fixed;
	int t;
	int count = 1;
	for(  t = 1;t--; solve(count),count++);
	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int main(){
	int n;
  scanf("%d", &n);
  
  for(int i = 1; i <= n; i++){
  	  int x = i;
  	  if(i % 3 == 0)
  	  	  printf(" %d", i);
  	  else if(i % 10 == 3)
  	  	  printf(" %d", i);
  	  else{
  	  	  while(1){
  	  	  	  if( x == 0)
  	  	  	  	  break;
  	  	  	  if(x % 10 == 3){
  	  	  	  	  printf(" %d", i);
  	  	  	  	  break;
  	  	  	  }else
  	  	  	  	  x /= 10;
  	  	  }
  	  }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>
#include<math.h>
int main() {
	int N, K,ans,min;
	min = 2147483647;
	int a[100000];
	scanf("%d %d", &N, &K);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	//printf("aaa");
	for ( int j = 0; j < N - K + 1; j++) {
		ans = 0;
		ans = abs(a[j]) + abs(a[j + K-1] - a[j]);
		if (min > ans) {
			min = ans;
		}
		ans = 0;
		ans = abs(a[j+K-1]) + abs(a[j] - a[j+K-1]);
		if (min > ans) {
			min = ans;
		}
	}

	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

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

typedef long long ll;
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S[0]=='7' || S[1]=='7' || S[2]=='7') cout << "Yes";
    else cout << "No";
    return 0;
}

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

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

int main() {
    int n, tmp;
    cin >> n;
    vector<pair<int, int>> a;

    rep(i, n) {
        cin >> tmp;
        a.push_back(make_pair(tmp, i + 1));
    }
    sort(a.begin(), a.end());

    rep(i, n) cout << a[i].second << " ";
    cout << endl;

    return 0;
}

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

int main() {

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

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>a(n);
    int total = 0;
    REP(i,n){
        cin >> a[i];
        total += a[i];
    }
    SORT(a);
    reverse(ALL(a));
    REP(i,m){
        if((double)total/(4*m) > (double)a[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long ll;
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N],n,tr[N<<1];
int lowbit(int x) {return x&-x;}
void change(int x)
{
    x+=N;
    while(x < (N<<1))
    {
        tr[x]++;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    x+=N;
    int ans=0;
    while(x>=1)
    {
        ans+=tr[x];
        x-=lowbit(x);
    }
    return ans;
}
bool check(int now)
{
    for(int i=1;i<=n;i++) c[i]=c[i-1]+(a[i]<=now?1:-1);
    memset(tr,0,sizeof(tr));
    change(c[0]);
    ll tot=0;
    for(int r=1;r<=n;r++)
    {
        tot+=sum(c[r]-1);
        change(c[r]);
    }
    return tot>=ll(n+1)*n/4+1;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int l=1,r=1e9,ans=-1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if (check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",ans);
}


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

using namespace std;

#define __START__ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define popb pop_back
#define pf push_front
#define popf pop_front
#define nl "\n"
#define sp " "
#define hashset unordered_set
#define tostr to_string
#define ins insert
#define ct count
#define __END__ return 0;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef set<int> si;
typedef set<char> sc;
typedef string str;
typedef deque<int> di;

signed main(){
    __START__
    int n; cin >> n;
    if (n >= 30){
        cout << "Yes" << nl;
    }
    else cout << "No" << nl;
    __END__
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> v;
  for(int i=n-1;i>=0;--i) {
    if( v.empty() ) v.pb(a[i]);
    else {
      int ptr = upper_bound(ALL(v),a[i]) - v.begin();
      if( ptr < (int)v.size() ) v[ptr] = a[i];
      else v.pb(a[i]);
    }
  }
  cout << v.size() << endl;
  return 0;
}


Measured memory_bytes: 1404
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        a[n] = x;
        Arrays.sort(a);
        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i + 1] - a[i];
        }
        if (b.length == 1) {
            System.out.println(b[0]);
            return;
        }
        int ans = gcd(b[0], b[1]);
        for (int i = 2 ; i < n ; i++) {
            ans = gcd(ans, b[i]);
        }
        System.out.println(ans);


    }
    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

}


Measured memory_bytes: 50924
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> b(n);
    rep(i,n) cin>>b.at(i);
    vector<int> ans;
    rep(i,n){
        int tmp=-1;
        rep(j,b.size()){
            if(b.at(j)==j+1)tmp=j;
        }
        if(tmp==-1){
            cout<<-1<<endl;
            return 0;
        }else{
            ans.push_back(b.at(tmp));
            b.erase(tmp+b.begin());
        }
    }
    reverse(all(ans));
    rep(i,ans.size()){
        cout<<ans.at(i)<<endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    constexpr int MAX = 30000;

    int N;
    read(N);

    vector<int> ans;
    ans.reserve(N);

    i64 sum = 0;
    reps(i, 1, MAX) {
        if (i % 2 == 0 || i % 3 == 0) {
            ans.push_back(i);
            sum += i;
            if (ans.size() == N - 1) break;
        }
    }

    repr(i, MAX, 1) {
        if ((sum + i) % 6 == 0 && __gcd(sum + i, i) != 1) {
            ans.push_back(i);
            break;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,K;
  cin >> A >> B >> K;
  for (int i=0;i<K;i++)
  {
    if(i%2==0)
    {
      if(A%2==0)
     {
       B=B+A/2;      
       A=A/2;
     }
      else
     { 
       B=B+(A-1)/2;
       A=(A-1)/2;
     }
    }
     if(i%2==1)
    {
      if(B%2==0)
     {
       A=A+B/2;
       B=B/2;
     }
      else 
     {
       A=A+(B-1)/2;
       B=(B-1)/2;
     }
    }
    
  }
  cout << A <<" "<< B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=0x3f3f3f;
int a[105];
int n,i,j,k,minv=MAXN,ans;

int main(){
	cin>>n;
	
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	
	for(i=a[1];i<=a[n];i++){
		for(k=1;k<=n;k++)
		ans+=(a[k]-i)*(a[k]-i);
		minv=min(minv,ans);
		ans=0;
	}
	
	cout<<minv;
	return 0;
}

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

def main():
    K, S = map(int, input().split())

    ans = 0
    for x in range(min(S, K), -1, -1):
        for y in range(min(S - x, K), -1, -1):
            if S - x - y <= K:
                # print(x, y, S-x-y)
                ans += 1
            else:
                break
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3060